Skip to content

Instantly share code, notes, and snippets.

@ynkdir
Created September 17, 2012 01:58
Show Gist options
  • Save ynkdir/3735162 to your computer and use it in GitHub Desktop.
Save ynkdir/3735162 to your computer and use it in GitHub Desktop.
foo.zu
# $ zimbu -o foo.so --ccarg "-shared -fPIC" foo.zu
# :echo libcall('/path/to/foo.so', 'foo', '')
FUNC foo(int a, int b) int
RETURN a + b
}
FUNC MAIN() int
# dummy
>>>
// Touch function to actually generate code.
%foo%;
<<<
RETURN 0
}
>>>
// c wrapper
int foo() { return %{foo(3, 4)}%; }
void __attribute__ ((constructor)) _init_zimbu() {
int r = 0;
int round = 0;
emergencyAlloc = malloc(16384);
ZimtInit();
ZglobInit(round++);
while (!ZglobInit(round++)) {
if (round == 1002) ZthrowCstringInit("Early initialization not done within 1000 rounds");
}
round = 2001;
while (!ZglobInit(round++)) {
if (round == 3002) ZthrowCstringInit("Initialization not done within 1000 rounds");
}
//r = Fmain();
//if ((&Zenv)->x != -1) fprintf(stderr, "INTERNAL: stack index not 0: %d\n", (&Zenv)->x);
}
<<<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment