Skip to content

Instantly share code, notes, and snippets.

@cygx
Created May 3, 2015 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cygx/66fb2fd628ef6a6ef85a to your computer and use it in GitHub Desktop.
Save cygx/66fb2fd628ef6a6ef85a to your computer and use it in GitHub Desktop.
use lib <libc tinycc>;
use libc;
use TinyCC <tinycc/libtcc>;
my $p = libc::malloc(4).to(libc::int);
$p.lv = 42;
tcc.target(:MEM).set('-Ltinycc');
tcc.declare(x => $p);
tcc.compile(q:to/__END__/);
extern int printf(const char *, ...);
extern int x;
int main(void) {
printf("%i\n", x);
return 0;
}
__END__
tcc.run; # prints 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment