# HG changeset patch # User Leonard Ritter # Date 1650743115 -7200 # Sat Apr 23 21:45:15 2022 +0200 # Node ID 8e0fb9dd1a6b1e2fe5a7f1a1069c94432f6d37de # Parent 0a24589bbdf003215d9be2e067b54960f30953b5 * improved TCC interface diff --git a/lib/tukan/tcc.sc b/lib/tukan/tcc.sc --- a/lib/tukan/tcc.sc +++ b/lib/tukan/tcc.sc @@ -1,6 +1,3 @@ -import .core -using import .globals - if (operating-system == 'windows) #load-library "SDL2.dll" # todo else @@ -16,10 +13,50 @@ using TCC.const using TCC.typedef using TCC.extern + unlet TCC TCC_RELOCATE_AUTO := (1:u64 as (mutable voidstar)) TCC_INCLUDE_PATH := module-dir .. "/../../include/libtcc/include" TCC_LIB_PATH := module-dir .. "/../../lib" + inline tcc_verify (f ...) + let res = (f ...) + assert (res == 0) + res + + type TCC :: (mutable @TCCState) + inline __typecall (cls) + bitcast (tcc_new) cls + + inline __drop (self) + tcc_delete self + + let + INCLUDE_PATH = TCC_INCLUDE_PATH + LIB_PATH = TCC_LIB_PATH + set_lib_path = tcc_set_lib_path + set_error_func = tcc_set_error_func + set_options = tcc_set_options + add_include_path = tcc_add_include_path + add_sysinclude_path = tcc_add_sysinclude_path + define_symbol = tcc_define_symbol + undefine_symbol = tcc_undefine_symbol + add_file = tcc_add_file + compile_string = tcc_compile_string + set_output_type = tcc_set_output_type + OUTPUT_MEMORY = TCC_OUTPUT_MEMORY + OUTPUT_EXE = TCC_OUTPUT_EXE + OUTPUT_DLL = TCC_OUTPUT_DLL + OUTPUT_OBJ = TCC_OUTPUT_OBJ + OUTPUT_PREPROCESS = TCC_OUTPUT_PREPROCESS + add_library_path = tcc_add_library_path + add_library = tcc_add_library + add_symbol = tcc_add_symbol + output_file = tcc_output_file + run = tcc_run + relocate = tcc_relocate + RELOCATE_AUTO = TCC_RELOCATE_AUTO + get_symbol = tcc_get_symbol + locals; diff --git a/testing/test_tcc.sc b/testing/test_tcc.sc --- a/testing/test_tcc.sc +++ b/testing/test_tcc.sc @@ -2,11 +2,6 @@ using import tukan.tcc -inline tcc_verify (f ...) - let res = (f ...) - assert (res == 0) - res - vvv bind testcode """"#include @@ -14,12 +9,14 @@ printf("Hello, World!\n"); } -cc := (tcc_new) -defer tcc_delete cc -tcc_set_lib_path cc TCC_LIB_PATH +cc := (TCC) +from (methodsof cc) let set_lib_path add_include_path add_library_path + \ set_output_type compile_string relocate get_symbol run + +set_lib_path TCC_LIB_PATH va-map inline (path) - tcc_add_include_path cc path + add_include_path path TCC_INCLUDE_PATH #"/usr/local/include/x86_64-linux-gnu" #"/usr/local/include" @@ -27,7 +24,7 @@ #"/usr/include" va-map inline (path) - tcc_add_library_path cc path + add_library_path path #"/usr/lib/x86_64-linux-gnu" #"/usr/lib" #"/lib/x86_64-linux-gnu" @@ -35,12 +32,12 @@ #"/usr/local/lib/x86_64-linux-gnu" #"/usr/local/lib" -tcc_set_output_type cc TCC_OUTPUT_MEMORY -tcc_verify tcc_compile_string cc testcode -#tcc_run cc 0 null -tcc_verify tcc_relocate cc TCC_RELOCATE_AUTO +set_output_type TCC.OUTPUT_MEMORY +tcc_verify compile_string testcode +#'run cc 0 null +tcc_verify relocate TCC.RELOCATE_AUTO -func := (tcc_get_symbol cc "main") +func := (get_symbol "main") assert (func != null) call func as (@ (function void))