Skip to content

Instantly share code, notes, and snippets.

View ozra's full-sized avatar

Oscar Campbell ozra

  • Laketorp, Lillkyrka, Örebro, Sweden
View GitHub Profile
require "../crystal/**"
require "../onyx/**"
macro dump_prop(name)
io << "\n" << " " * (depth+1) << {{name.stringify}}[1..-1].cyan << ": "
case (v = {{name}})
when Nil then io << "nil"
else v.dump_inspect(io, terse_output, depth + 1)
@ozra
ozra / gist:eb66427658ab0a87963a
Created July 4, 2015 10:51
errors compiling operator overloads
Error in ./src/quate/core-embryo.cr:530: no overload matches 'Que::Add(Float64, Float64)#/' with types Float64
Overloads are:
- Que::Add(Float64, Float64)#/(other : Float32)
- Que::Add(Float64, Float64)#/(other : Float64)
- Que::Add(Float64, Float64)#/(other : Qam(T))
@ozra
ozra / normalizer.cr
Last active August 29, 2015 14:24
for -> each transformation
def transform(node : For)
block_args = [] of Var
method_name :: String
node.vars.each do |v|
block_args << v.clone # tries cloning if there are any weird node to node ties
end
if node.vars.length == 1
method_name = "each"
@ozra
ozra / gist:8c60b18fc56ecc68abf8
Last active August 29, 2015 14:23
make err output
(master) crystal-dev-fork $ make
CRYSTAL_CONFIG_PATH=`pwd`/src ./bin/crystal build -o .build/crystal src/compiler/crystal.cr
Using compiled compiler at .build/crystal
/home/oscar/1GTD/project-support/crystal/crystal-dev-fork/.crystal/home/oscar/1GTD/project-support/crystal/crystal-dev-fork/src/ecr/process.cr/main.o: In function `*Fiber::new<&( -> Void)>:Fiber':
main_module:(.text+0xf42): undefined reference to `co_set_data'
/home/oscar/1GTD/project-support/crystal/crystal-dev-fork/.crystal/home/oscar/1GTD/project-support/crystal/crystal-dev-fork/src/ecr/process.cr/main.o: In function `*Fiber#resume<Fiber>:Void':
main_module:(.text+0x1080): undefined reference to `co_get_data'
/home/oscar/1GTD/project-support/crystal/crystal-dev-fork/.crystal/home/oscar/1GTD/project-support/crystal/crystal-dev-fork/src/ecr/process.cr/main.o: In function `*FileDescriptorIO#unbuffered_write<FileDescriptorIO, Slice(UInt8), Int32>:Int32':
main_module:(.text+0x1326): undefined reference to `co_get_data'
/home/oscar/1GTD/project-su
@ozra
ozra / generics-and-oop.cr
Last active August 29, 2015 14:23
oop + generics in crystal
abstract class QamAbstract
def initialize()
@forward–deps = [] of QamAbstract
end
end
class Qam(T) < QamAbstract
def initialize()
super()
@ozra
ozra / OOP Test is wrong
Created June 15, 2015 13:40
Tinkering with Nim OOP - what's wrong?
type
A = ref A_obj
A_obj = object {.inheritable}
forward_deps: seq[A]
B[T] = ref B_obj[T]
@ozra
ozra / Throwup macro
Created June 12, 2015 16:23
Throw up macro for proc creation
macro Λ*(b: expr): expr {.immediate.} =
echo b.tree–repr
echo " < - - - >"
echo b.to–str–lit()
var par: NimNode
var params: seq[NimNode] = @[new–IdentNode("T")]
par = new–NimNode(nnk–IdentDefs)
@ozra
ozra / pipes-for-ofs
Last active August 29, 2015 14:22
Pipes as alt. to `of` in Nim
proc primary(p: var TParser, mode: TPrimaryMode): PNode =
if isOperator(p.tok):
let isSigil = isSigilLike(p.tok)
result = newNodeP(nkPrefix, p)
var a = newIdentNodeP(p.tok.ident, p)
addSon(result, a)
getTok(p)
optInd(p, a)
if isSigil:
#XXX prefix operators