Skip to content

Instantly share code, notes, and snippets.

View asterite's full-sized avatar

Ary Borenszweig asterite

  • NoRedInk
  • Buenos Aires, Argentina
View GitHub Profile
module Moo
# Moo expects `foo` to return an Int32
abstract def foo : Int32
# `bar` adds 1 to it
def bar : Int32
foo + 1
end
# And maybe it provides other methods...
class TimeDecoderText
def initialize
super
@curr = Pointer(UInt8).new(0)
end
def decode(value_ptr)
@curr = value_ptr + 0
year = get_next_int
diff --git a/src/compiler/crystal/codegen/ast.cr b/src/compiler/crystal/codegen/ast.cr
index d42583e..f1453f7 100644
--- a/src/compiler/crystal/codegen/ast.cr
+++ b/src/compiler/crystal/codegen/ast.cr
@@ -69,6 +69,10 @@ module Crystal
next_def = next_def.next
end
+ if used_by_old_call
+ str << "_" << object_id
@asterite
asterite / cryload.cr
Last active September 2, 2015 15:56
require "./cryload/*"
require "http"
module Cryload
class LoadGenerator
def initialize(@host, @number)
@stats = Stats.new @number
ch = generate_request_channel
loop do
check_log
require "benchmark"
################################ Crystal scripts
def chrono(text)
s=Time.now
yield
e=Time.now
d=(e.to_f-s.to_f)*1000
if d>1
require "../../spec_helper"
describe "Code gen: asm" do
it "codegens without inputs" do
run(%(
dst :: Int32
asm("mov $$1234, $0" : "=r"(dst))
dst
)).to_i.should eq(1234)
end
@asterite
asterite / RubyC_Crystal_notes.md
Created June 11, 2015 15:39
Some notes about sferik's RubyC great talk :-)

@sferik I really liked your talk! I liked that you talked about the language from a different angle than the usual "this is the syntax, this is the semantic", also showing why would anyone want to consider Crystal for their own projects and how they can reuse their Ruby knowledge.

These are just a few notes I made after watching the video. They are small corrections and notes, but there's no way you could have known this because it's not documented or at least it's not easy to find.

  • Mandelbrot and the HTTP server demo worked pretty well, but by default Crystal generates unoptimized binaries. To get an optimized binary use the --release flag: crystal build samples/mandelbrot.cr --release. Unoptimized binaries are still reasonably fast, and that's why it's the default: so you can use crystal as if it were a dynamic language without an intermediate compilation step. Sometimes running the (LLVM) optimizations takes a while.
  • The browser was broken in that particular release but it's now fixed, hopefull
require "crsfml"
require "./src/nes"
def color(x)
r = (x >> 16) & 0xFF
g = (x >> 8) & 0xFF
b = x & 0xFF
SF.color(r, g, b, 0xFF)
end
require "benchmark"
RANGE = (1..10_000_000)
TIMES = 100_000
a1 = nil
a2 = nil
a3 = nil
Benchmark.bm do |x|
class Object
macro enumerated(method)
{{method}}
def {{method.name}}({{*method.args}})
Enumerator(typeof({{method.name}}({{*method.args.map &.name}}) { |_z| _z })).new do |y|
{{method.name}}({{*method.args.map &.name}}) do |value|
y << value
end
end