Skip to content

Instantly share code, notes, and snippets.

@alexnask
Created September 3, 2011 13:34
Show Gist options
  • Select an option

  • Save alexnask/1191189 to your computer and use it in GitHub Desktop.

Select an option

Save alexnask/1191189 to your computer and use it in GitHub Desktop.
Kew
use tcc
import tcc
program := "int function(int n) \
{\
printf(\"Hello World! (%d)\\n\",n);\
doStuff(42);
return 0;\
}"
tcc := Tcc new()
f: func(a: Int) { a toString() println() }
tcc addSymbol("doStuff",f as Pointer)
tcc setOutputType(OutputType memory)
tcc compileString(program)
size := tcc relocate(null)
mem := gc_malloc(size)
tcc relocate(mem)
entry: Func(Int)->Int
entry as Closure thunk = tcc getSymbol("function")
tcc delete()
entry(42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment