# Pastebin FdZRxIbF fernando@fernando-OptiPlex-9020:~$ cat jit.p6 use NativeCall; sub gcc_jit_context_acquire() returns Pointer is native("gccjit") { * } sub gcc_jit_context_get_type(Pointer, int16) returns Pointer is native("gccjit") { * } sub gcc_jit_context_new_param(Pointer, Pointer, Pointer, Str) returns Pointer is native("gccjit") { * } sub gcc_jit_context_new_binary_op(Pointer, Pointer, int16, Pointer, Pointer, Pointer) returns Pointer is native("gccjit") { * } sub gcc_jit_param_as_rvalue(Pointer) returns Pointer is native("gccjit") { * }; sub gcc_jit_context_new_function(Pointer, Pointer, int16, Pointer, Str, int16, CArray[Pointer], int16) returns Pointer is native("gccjit") { * } sub gcc_jit_function_new_block(Pointer, Str) returns Pointer is native("gccjit") { * } sub gcc_jit_block_add_eval(Pointer, Pointer, Pointer) is native("gccjit") { * } sub gcc_jit_block_add_assignment(Pointer, Pointer, Pointer, Pointer) is native("gccjit") { * } sub gcc_jit_block_end_with_return(Pointer, Pointer, Pointer) returns Pointer is native("gccjit") { * } sub gcc_jit_block_end_with_void_return(Pointer, Pointer) returns Pointer is native("gccjit") { * } sub gcc_jit_context_compile(Pointer) returns Pointer is native("gccjit") { * } sub gcc_jit_context_compile_to_file(Pointer, int16, Str) is native("gccjit") { * } sub gcc_jit_result_get_code(Pointer, Str) returns Pointer is native("gccjit") { * } sub gcc_jit_context_new_call (Pointer, Pointer, Pointer, int16, CArray[Pointer]) returns Pointer is native("gccjit") { * } sub gcc_jit_context_new_rvalue_from_int(Pointer, Pointer, int16) returns Pointer is native("gccjit") { * } sub gcc_jit_context_new_string_literal(Pointer, Str) returns Pointer is native("gccjit") { * } my Pointer $context = gcc_jit_context_acquire; my Pointer $int-type = gcc_jit_context_get_type($context, 8); my Pointer $cchr-type = gcc_jit_context_get_type($context, 17); my Pointer $param-a = gcc_jit_context_new_param($context, Pointer, $int-type, "a"); my Pointer $param-b = gcc_jit_context_new_param($context, Pointer, $int-type, "b"); my Pointer $a-plus-b = gcc_jit_context_new_binary_op($context, Pointer, 0, $int-type, gcc_jit_param_as_rvalue($param-a), gcc_jit_param_as_rvalue($param-b)); my Pointer $add-func = gcc_jit_context_new_function($context, Pointer, 0, $int-type, "add", 2, CArray[Pointer].new($param-a, $param-b), 0); my Pointer $block = gcc_jit_function_new_block($add-func, "one_block"); gcc_jit_block_end_with_return($block, Pointer, $a-plus-b); my Pointer $_0 = gcc_jit_context_new_rvalue_from_int($context, $int-type, 0); my Pointer $_2 = gcc_jit_context_new_rvalue_from_int($context, $int-type, 2); my Pointer $_3 = gcc_jit_context_new_rvalue_from_int($context, $int-type, 3); my Pointer $call-add = gcc_jit_context_new_call($context, Pointer, $add-func, 2, CArray[Pointer].new($_2, $_3)); my Pointer $main = gcc_jit_context_new_function($context, Pointer, 0, $int-type, "main", 0, CArray[Pointer].new, 0); my Pointer $main-blk = gcc_jit_function_new_block($main, "_main_"); my Pointer $format = gcc_jit_context_new_param($context, Pointer, $cchr-type, "format"); my Pointer $printf = gcc_jit_context_new_function($context, Pointer, 2, $int-type, "printf", 1, CArray[Pointer].new($format), 1); #gcc_jit_block_end_with_return($main-blk, Pointer, $call-add); gcc_jit_block_add_eval( $main-blk, Pointer, gcc_jit_context_new_call( $context, Pointer, $printf, 2, CArray[Pointer].new( gcc_jit_context_new_string_literal($context, "sum: %d\n"), $call-add ) ) ); gcc_jit_block_end_with_return($main-blk, Pointer, $_0); gcc_jit_context_compile_to_file($context, 3, "a.out"); #my Pointer $result = gcc_jit_context_compile($context); #my $add = gcc_jit_result_get_code($result, "add"); #say $add.(2, 3) fernando@fernando-OptiPlex-9020:~$ perl6 jit.p6 fernando@fernando-OptiPlex-9020:~$ ./a.out sum: 5