From 7653bec0cbb1220bbdbf164e2352c97ea427acdf Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 13:16:04 +0000 Subject: [PATCH 1/8] Add defines for enabling features in main.c These can be used to disable the debugger, profiler, or hot reload if it is not desired. --- src/main.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 9ff3d07af..cc6da7cc1 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,10 @@ #include #include +#define HL_DEBUGGER +#define HL_PROFILER +#define HL_HOT_RELOAD + #ifdef HL_WIN # include typedef uchar pchar; @@ -41,11 +45,13 @@ typedef char pchar; #endif typedef struct { +#ifdef HL_HOT_RELOAD pchar *file; + int file_time; +#endif hl_code *code; hl_module *m; vdynamic *ret; - int file_time; } main_context; static int pfiletime( pchar *file ) { @@ -88,6 +94,7 @@ static hl_code *load_code( const pchar *file, char **error_msg, bool print_error return code; } +#ifdef HL_HOT_RELOAD static bool check_reload( main_context *m ) { int time = pfiletime(m->file); bool changed; @@ -102,6 +109,7 @@ static bool check_reload( main_context *m ) { hl_code_free(code); return changed; } +#endif #ifdef HL_VCC // this allows some runtime detection to switch to high performance mode @@ -141,20 +149,25 @@ int main(int argc, pchar *argv[]) { static vclosure cl; pchar *file = NULL; char *error_msg = NULL; +#ifdef HL_DEBUGGER int debug_port = -1; bool debug_wait = false; - bool hot_reload = false; +#endif +#ifdef HL_PROFILER int profile_count = -1; +#endif + bool hot_reload = false; bool vtune_later = false; main_context ctx; - bool isExc = false; int first_boot_arg = -1; + bool isExc = false; argv++; argc--; while( argc ) { pchar *arg = *argv++; argc--; +#ifdef HL_DEBUGGER if( pcompare(arg,PSTR("--debug")) == 0 ) { if( argc-- == 0 ) break; debug_port = ptoi(*argv++); @@ -164,19 +177,24 @@ int main(int argc, pchar *argv[]) { debug_wait = true; continue; } +#endif if( pcompare(arg,PSTR("--version")) == 0 ) { printf("%d.%d.%d",HL_VERSION>>16,(HL_VERSION>>8)&0xFF,HL_VERSION&0xFF); return 0; } +#ifdef HL_HOT_RELOAD if( pcompare(arg,PSTR("--hot-reload")) == 0 ) { hot_reload = true; continue; } +#endif +#ifdef HL_PROFILER if( pcompare(arg,PSTR("--profile")) == 0 ) { if( argc-- == 0 ) break; profile_count = ptoi(*argv++); continue; } +#endif #ifdef HL_VTUNE if( pcompare(arg,PSTR("--vtune-later")) == 0 ) { vtune_later = true; @@ -212,7 +230,6 @@ int main(int argc, pchar *argv[]) { hl_global_init(); hl_sys_init((void**)argv,argc,file); hl_register_thread(&ctx); - ctx.file = file; ctx.code = load_code(file, &error_msg, true); if( ctx.code == NULL ) { if( error_msg ) printf("%s\n", error_msg); @@ -223,29 +240,40 @@ int main(int argc, pchar *argv[]) { return 2; if( !hl_module_init(ctx.m,hot_reload,vtune_later) ) return 3; +#ifdef HL_HOT_RELOAD + ctx.file = file; if( hot_reload ) { ctx.file_time = pfiletime(ctx.file); hl_setup_reload_check(check_reload,&ctx); } +#endif hl_code_free(ctx.code); +#ifdef HL_DEBUGGER if( debug_port > 0 && !hl_module_debug(ctx.m,debug_port,debug_wait) ) { fprintf(stderr,"Could not start debugger on port %d\n",debug_port); return 4; } +#endif cl.t = ctx.code->functions[ctx.m->functions_indexes[ctx.m->code->entrypoint]].type; cl.fun = ctx.m->functions_ptrs[ctx.m->code->entrypoint]; cl.hasValue = 0; setup_handler(); +#ifdef HL_PROFILER hl_profile_setup(profile_count); +#endif ctx.ret = hl_dyn_call_safe(&cl,NULL,0,&isExc); +#ifdef HL_PROFILER hl_profile_end(); +#endif if( isExc ) { varray *a = hl_exception_stack(); int i; uprintf(USTR("Uncaught exception: %s\n"), hl_to_string(ctx.ret)); for(i=0;isize;i++) uprintf(USTR("Called from %s\n"), hl_aptr(a,uchar*)[i]); +#ifdef HL_DEBUGGER hl_debug_break(); +#endif hl_global_free(); return 1; } @@ -256,4 +284,3 @@ int main(int argc, pchar *argv[]) { hl_global_free(); return 0; } - From cf4e7970b8c4c788ab81c30ef3fd4555adf5ed9a Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 13:21:38 +0000 Subject: [PATCH 2/8] Update usage information for hl --- src/main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index cc6da7cc1..e7ae60732 100644 --- a/src/main.c +++ b/src/main.c @@ -218,7 +218,22 @@ int main(int argc, pchar *argv[]) { file = PSTR("hlboot.dat"); fchk = pfopen(file,"rb"); if( fchk == NULL ) { - printf("HL/JIT %d.%d.%d (c)2015-2023 Haxe Foundation\n Usage : hl [--debug ] [--debug-wait] \n",HL_VERSION>>16,(HL_VERSION>>8)&0xFF,HL_VERSION&0xFF); + const char* options = "[--version]" +#ifdef HL_DEBUGGER + " [--debug ] [--debug-wait]" +#endif +#ifdef HL_HOT_RELOAD + " [--hot-reload]" +#endif +#ifdef HL_PROFILER + " [--profile ]" +#endif +#ifdef HL_VTUNE + " [--vtune-later]" +#endif + ; + + printf("HL/JIT %d.%d.%d (c)2015-2025 Haxe Foundation\n Usage : hl %s \n",HL_VERSION>>16,(HL_VERSION>>8)&0xFF,HL_VERSION&0xFF,options); return 1; } fclose(fchk); From 5faf650f545747081b845c5b2e66ef2ac7fb86b5 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 13:18:10 +0000 Subject: [PATCH 3/8] Add libhljit static library --- CMakeLists.txt | 22 +++++- Makefile | 28 +++++-- hl.sln | 14 ++++ libhljit.vcxproj | 153 +++++++++++++++++++++++++++++++++++++++ libhljit.vcxproj.filters | 15 ++++ 5 files changed, 223 insertions(+), 9 deletions(-) create mode 100644 libhljit.vcxproj create mode 100644 libhljit.vcxproj.filters diff --git a/CMakeLists.txt b/CMakeLists.txt index e3fc0f595..013a9885f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,20 +173,28 @@ set_target_properties(libhl ) if (WITH_VM) - add_executable(hl + add_library(libhljit STATIC src/code.c src/jit.c - src/main.c src/module.c src/debugger.c src/profile.c ) + set_target_properties(libhljit + PROPERTIES + PUBLIC_HEADER "src/hlmodule.h;src/opcodes.h" + ) + + add_executable(hl + src/main.c + ) + if (UNIX AND NOT APPLE) set_target_properties(hl PROPERTIES INSTALL_RPATH "$ORIGIN;${CMAKE_INSTALL_PREFIX}/lib") endif() - target_link_libraries(hl libhl) + target_link_libraries(hl libhl libhljit) if (WIN32) target_link_libraries(hl user32) @@ -387,6 +395,14 @@ install( ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +if (WITH_VM) + install( + TARGETS libhljit + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hl + ) +endif() + install( FILES src/hlc_main.c TYPE INCLUDE diff --git a/Makefile b/Makefile index 957a6914e..f2522e127 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,9 @@ STD = src/std/array.o src/std/buffer.o src/std/bytes.o src/std/cast.o src/std/da src/std/socket.o src/std/string.o src/std/sys.o src/std/types.o src/std/ucs2.o src/std/thread.o src/std/process.o \ src/std/track.o -HL = src/code.o src/jit.o src/main.o src/module.o src/debugger.o src/profile.o +LIBHLJIT = src/code.o src/jit.o src/module.o src/debugger.o src/profile.o + +HL = src/main.o FMT_INCLUDE = -I include/mikktspace -I include/minimp3 @@ -212,7 +214,7 @@ all: libhl libs ifeq ($(ARCH),arm64) $(warning HashLink vm is not supported on arm64, skipping) else -all: hl +all: libhljit.a hl endif install: @@ -224,12 +226,19 @@ endif mkdir -p $(INSTALL_LIB_DIR) cp *.hdll $(INSTALL_LIB_DIR) cp libhl.${LIBEXT} $(INSTALL_LIB_DIR) +ifneq ($(ARCH),arm64) + cp libhljit.a $(INSTALL_LIB_DIR) +endif mkdir -p $(INSTALL_INCLUDE_DIR) cp src/hl.h src/hlc.h src/hlc_main.c $(INSTALL_INCLUDE_DIR) +ifneq ($(ARCH),arm64) + mkdir -p $(INSTALL_INCLUDE_DIR)/hl + cp src/hlmodule.h src/opcodes.h $(INSTALL_INCLUDE_DIR)/hl +endif uninstall: rm -f $(INSTALL_BIN_DIR)/hl $(INSTALL_LIB_DIR)/libhl.${LIBEXT} $(INSTALL_LIB_DIR)/*.hdll - rm -f $(INSTALL_INCLUDE_DIR)/hl.h $(INSTALL_INCLUDE_DIR)/hlc.h $(INSTALL_INCLUDE_DIR)/hlc_main.c + rm -f $(INSTALL_INCLUDE_DIR)/hl.h $(INSTALL_INCLUDE_DIR)/hlc.h $(INSTALL_INCLUDE_DIR)/hlc_main.c $(INSTALL_INCLUDE_DIR)/hl/hlmodule.h $(INSTALL_INCLUDE_DIR)/hl/opcodes.h libs: $(LIBS) @@ -245,8 +254,11 @@ libhl: ${LIB} hlc: ${BOOT} ${CC} ${CFLAGS} -o hlc ${BOOT} ${LFLAGS} ${EXTRA_LFLAGS} -hl: ${HL} libhl - ${CC} ${CFLAGS} -o hl ${HL} ${LFLAGS} ${EXTRA_LFLAGS} ${HLFLAGS} +libhljit.a: ${LIBHLJIT} + ${AR} rcs $@ $^ + +hl: ${HL} libhljit.a libhl + ${CC} ${CFLAGS} -o $@ ${HL} libhljit.a ${LFLAGS} ${EXTRA_LFLAGS} ${HLFLAGS} libs/fmt/%.o: libs/fmt/%.c ${CC} ${CFLAGS} -o $@ -c $< ${FMT_INCLUDE} @@ -339,6 +351,10 @@ release_prepare: mkdir $(PACKAGE_NAME) mkdir $(PACKAGE_NAME)/include cp src/hl.h src/hlc.h src/hlc_main.c $(PACKAGE_NAME)/include +ifneq ($(ARCH),arm64) + mkdir $(PACKAGE_NAME)/include/hl + cp src/hlmodule.h src/opcodes.h $(PACKAGE_NAME)/include/hl +endif release_win: cp $(BUILD_DIR)/{hl.exe,libhl.dll,*.hdll,*.lib} $(PACKAGE_NAME) @@ -376,6 +392,6 @@ clean_o: rm -f ${STD} ${BOOT} ${RUNTIME} ${PCRE} ${HL} ${FMT} ${SDL} ${SSL} ${OPENAL} ${UI} ${UV} ${MYSQL} ${SQLITE} ${HEAPS} ${HL_DEBUG} clean: clean_o - rm -f hl hl.exe libhl.$(LIBEXT) *.hdll + rm -f hl hl.exe libhl.$(LIBEXT) *.hdll *.a .PHONY: libhl hl hlc fmt sdl libs release diff --git a/hl.sln b/hl.sln index d9caa9899..9526aaf90 100644 --- a/hl.sln +++ b/hl.sln @@ -31,6 +31,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hl", "hl.vcxproj", "{BBF750 {E3F735ED-9701-46BE-A86C-C61D3CE0D525} = {E3F735ED-9701-46BE-A86C-C61D3CE0D525} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libhljit", "libhljit.vcxproj", "{CF700138-1C91-4481-9BB4-D272EF316CB2}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui", "libs\ui\ui.vcxproj", "{6534D221-34DF-404A-AFCD-6DEC9BBC9798}" ProjectSection(ProjectDependencies) = postProject {C6213FBF-BC2B-4235-A827-84A60E848C52} = {C6213FBF-BC2B-4235-A827-84A60E848C52} @@ -136,6 +138,18 @@ Global {BBF750D2-6DD2-4A41-AC3A-07C070B94FA1}.ReleaseVS2013|Win32.Build.0 = ReleaseVS2013|Win32 {BBF750D2-6DD2-4A41-AC3A-07C070B94FA1}.ReleaseVS2013|x64.ActiveCfg = ReleaseVS2013|x64 {BBF750D2-6DD2-4A41-AC3A-07C070B94FA1}.ReleaseVS2013|x64.Build.0 = ReleaseVS2013|x64 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Debug|Win32.ActiveCfg = Debug|Win32 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Debug|Win32.Build.0 = Debug|Win32 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Debug|x64.ActiveCfg = Debug|x64 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Debug|x64.Build.0 = Debug|x64 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Release|Win32.ActiveCfg = Release|Win32 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Release|Win32.Build.0 = Release|Win32 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Release|x64.ActiveCfg = Release|x64 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.Release|x64.Build.0 = Release|x64 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.ReleaseVS2013|Win32.ActiveCfg = Release|Win32 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.ReleaseVS2013|Win32.Build.0 = Release|Win32 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.ReleaseVS2013|x64.ActiveCfg = Release|x64 + {CF700138-1C91-4481-9BB4-D272EF316CB2}.ReleaseVS2013|x64.Build.0 = Release|x64 {6534D221-34DF-404A-AFCD-6DEC9BBC9798}.Debug|Win32.ActiveCfg = Debug|Win32 {6534D221-34DF-404A-AFCD-6DEC9BBC9798}.Debug|Win32.Build.0 = Debug|Win32 {6534D221-34DF-404A-AFCD-6DEC9BBC9798}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/libhljit.vcxproj b/libhljit.vcxproj new file mode 100644 index 000000000..a50ea1034 --- /dev/null +++ b/libhljit.vcxproj @@ -0,0 +1,153 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {CF700138-1C91-4481-9BB4-D272EF316CB2} + Win32Proj + libhljit + 10.0 + + + + StaticLibrary + true + Unicode + v142 + + + StaticLibrary + true + Unicode + v142 + + + StaticLibrary + false + true + Unicode + v142 + + + StaticLibrary + false + true + Unicode + v142 + + + + + + + + + + + + + + + + + + + true + $(VC_IncludePath);$(WindowsSDK_IncludePath);src + $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(Configuration) + + + true + $(VC_IncludePath);$(WindowsSDK_IncludePath);src;include/vtune + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;x64/$(Configuration) + + + false + $(VC_IncludePath);$(WindowsSDK_IncludePath);src + $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(Configuration) + + + false + $(VC_IncludePath);$(WindowsSDK_IncludePath);src;include/vtune + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;x64/$(Configuration) + + + + + + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + StreamingSIMDExtensions2 + EnableAllWarnings + /wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions) + + + + + + + EnableAllWarnings + Disabled + WIN32;_DEBUG;_CONSOLE;HL_VTUNE;%(PreprocessorDefinitions) + /wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions) + + + + + EnableAllWarnings + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + StreamingSIMDExtensions2 + /wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions) + false + + + + + EnableAllWarnings + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;HL_VTUNE;%(PreprocessorDefinitions) + /wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions) + false + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libhljit.vcxproj.filters b/libhljit.vcxproj.filters new file mode 100644 index 000000000..6ba61f1de --- /dev/null +++ b/libhljit.vcxproj.filters @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file From 0352548d88e3a58d24d8d837081ba0ae3b790ef3 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 15:16:37 +0000 Subject: [PATCH 4/8] Unset HL_VTUNE on libhljit It adds an extra dependency for linking --- libhljit.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libhljit.vcxproj b/libhljit.vcxproj index a50ea1034..5d531c1a0 100644 --- a/libhljit.vcxproj +++ b/libhljit.vcxproj @@ -104,7 +104,7 @@ EnableAllWarnings Disabled - WIN32;_DEBUG;_CONSOLE;HL_VTUNE;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) /wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions) @@ -130,7 +130,7 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;HL_VTUNE;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) /wd4456 /wd4100 /wd4204 /wd4702 /wd4457 %(AdditionalOptions) false From 9ba8ad5a570636542c91d63f86f61639bdfe49d5 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 13:14:40 +0000 Subject: [PATCH 5/8] [haxelib] Add boot command --- Makefile | 7 +++++- other/haxelib/.gitignore | 1 + other/haxelib/Run.hx | 48 ++++++++++++++++++++++++++++++++++++++++ src/main.c | 32 +++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 other/haxelib/.gitignore diff --git a/Makefile b/Makefile index f2522e127..92eac5a54 100644 --- a/Makefile +++ b/Makefile @@ -326,6 +326,10 @@ release_haxelib: ifeq ($(HLIB),hashlink) HLDIR=other/haxelib HLPACK=templates hlmem memory.hxml Run.hx + +haxelib_prepackage: + cp src/main.c ${HLDIR}/templates/hlboot.c + else HLDIR=libs/$(HLIB) ifeq ($(HLIB),directx) @@ -333,9 +337,10 @@ HLPACK=dx *.h *.c *.cpp else HLPACK=$(HLIB) *.h *.c endif +haxelib_prepackage: endif -release_haxelib_package: +release_haxelib_package: haxelib_prepackage rm -rf $(HLIB)_release mkdir $(HLIB)_release (cd $(HLDIR) && cp -R $(HLPACK) haxelib.json $(CURDIR)/$(HLIB)_release | true) diff --git a/other/haxelib/.gitignore b/other/haxelib/.gitignore new file mode 100644 index 000000000..7b7e6bba5 --- /dev/null +++ b/other/haxelib/.gitignore @@ -0,0 +1 @@ +templates/hlboot.c diff --git a/other/haxelib/Run.hx b/other/haxelib/Run.hx index aa30b646f..ef639bc52 100644 --- a/other/haxelib/Run.hx +++ b/other/haxelib/Run.hx @@ -166,6 +166,52 @@ class Build { } +class Boot { + static function findMainFile(haxelibPath:String) { + return sys.FileSystem.exists('$haxelibPath/../../src/main.c') ? '$haxelibPath/../../src/main.c' : + sys.FileSystem.exists('${Sys.getEnv("HASHLINK")}/src/main.c') ? '${Sys.getEnv("HASHLINK")}/src/main.c' : + sys.FileSystem.exists('$haxelibPath/templates/hlboot.c') ? '$haxelibPath/templates/hlboot.c' : + throw "Cannot find template main.c file. Try setting the HASHLINK environment variable"; + } + + public static function boot(module:String, haxelibPath:String) { + final cFile = StringTools.replace(sys.io.File.getContent(findMainFile(haxelibPath)), "// #define HL_BOOT", "#define HL_BOOT"); + + final inputFile = sys.io.File.read(module, true); + final outputFile = sys.io.File.write(StringTools.replace(module, ".hl", ".c")); + + final splitFile = cFile.split("::"); + + var programSize:Null = null; + for (part in splitFile) { + if (part == "program") { + programSize = 0; + var foundEnd = false; + while (!foundEnd) { + final byte = try { + inputFile.readByte(); + } catch (e) { + foundEnd = true; + continue; + }; + + outputFile.writeString('$byte,'); + programSize++; + } + } else if (part == "programSize") { + if (programSize == null) + throw "Program size unknown"; + outputFile.writeString('$programSize'); + } else { + outputFile.writeString(part); + } + } + + inputFile.close(); + outputFile.close(); + } +} + class Run { static function main() { var args = Sys.args(); @@ -185,6 +231,8 @@ class Run { var output = args.shift(); if( StringTools.endsWith(output,".c") ) return; Sys.command("hl "+output); + case "boot": + Boot.boot(args[0], haxelibPath); case cmd: Sys.println("Unknown command "+cmd); Sys.exit(1); diff --git a/src/main.c b/src/main.c index e7ae60732..74d411561 100644 --- a/src/main.c +++ b/src/main.c @@ -19,16 +19,23 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ + +// #define HL_BOOT + #include +#ifdef HL_BOOT +#include +#else #include +#endif +#ifndef HL_BOOT #define HL_DEBUGGER #define HL_PROFILER #define HL_HOT_RELOAD #ifdef HL_WIN # include -typedef uchar pchar; #define pprintf(str,file) uprintf(USTR(str),file) #define pfopen(file,ext) _wfopen(file,USTR(ext)) #define pcompare wcscmp @@ -36,13 +43,19 @@ typedef uchar pchar; #define PSTR(x) USTR(x) #else # include -typedef char pchar; #define pprintf printf #define pfopen fopen #define pcompare strcmp #define ptoi atoi #define PSTR(x) x #endif +#endif + +#ifdef HL_WIN +typedef uchar pchar; +#else +typedef char pchar; +#endif typedef struct { #ifdef HL_HOT_RELOAD @@ -54,6 +67,12 @@ typedef struct { vdynamic *ret; } main_context; +#ifdef HL_BOOT +const unsigned char program[] = { + ::program:: +}; +int program_size = ::programSize::; +#else static int pfiletime( pchar *file ) { #ifdef HL_WIN struct _stat32 st; @@ -93,6 +112,7 @@ static hl_code *load_code( const pchar *file, char **error_msg, bool print_error free(fdata); return code; } +#endif #ifdef HL_HOT_RELOAD static bool check_reload( main_context *m ) { @@ -159,11 +179,14 @@ int main(int argc, pchar *argv[]) { bool hot_reload = false; bool vtune_later = false; main_context ctx; +#ifndef HL_BOOT int first_boot_arg = -1; +#endif bool isExc = false; argv++; argc--; +#ifndef HL_BOOT while( argc ) { pchar *arg = *argv++; argc--; @@ -242,10 +265,15 @@ int main(int argc, pchar *argv[]) { argc = first_boot_arg; } } +#endif hl_global_init(); hl_sys_init((void**)argv,argc,file); hl_register_thread(&ctx); +#ifdef HL_BOOT + ctx.code = hl_code_read(program, program_size, &error_msg); +#else ctx.code = load_code(file, &error_msg, true); +#endif if( ctx.code == NULL ) { if( error_msg ) printf("%s\n", error_msg); return 1; From 00eed53efaf7120b3b26c314181072129248da42 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 15:15:13 +0000 Subject: [PATCH 6/8] Move hlmodule.h and opcodes.h to hl subdirectory hlmodule.h and opcodes.h are already installed to `.../include/hl` to avoid poluting the root include folder. It is easier to deal with this for `hashlink boot` if the repository matches this structure. --- .gitignore | 1 - CMakeLists.txt | 2 +- Makefile | 4 +- hl.vcxproj | 4 +- hl.vcxproj.filters | 4 +- libhljit.vcxproj | 4 +- libhljit.vcxproj.filters | 4 +- src/code.c | 7 +- src/debugger.c | 2 +- src/{ => hl}/hlmodule.h | 0 src/{ => hl}/opcodes.h | 306 +++++++++++++++++++-------------------- src/jit.c | 3 +- src/main.c | 4 - src/module.c | 2 +- src/profile.c | 2 +- 15 files changed, 171 insertions(+), 178 deletions(-) rename src/{ => hl}/hlmodule.h (100%) rename src/{ => hl}/opcodes.h (94%) diff --git a/.gitignore b/.gitignore index 238f253be..a909e1a91 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,6 @@ ReleaseStatic /build* /other/memory/*.dump /src/_std -/src/hl /src/haxe /src/Makefile /include/ffmpeg diff --git a/CMakeLists.txt b/CMakeLists.txt index 013a9885f..3688852f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,7 +183,7 @@ if (WITH_VM) set_target_properties(libhljit PROPERTIES - PUBLIC_HEADER "src/hlmodule.h;src/opcodes.h" + PUBLIC_HEADER "src/hl/hlmodule.h;src/hl/opcodes.h" ) add_executable(hl diff --git a/Makefile b/Makefile index 92eac5a54..88f8a2278 100644 --- a/Makefile +++ b/Makefile @@ -233,7 +233,7 @@ endif cp src/hl.h src/hlc.h src/hlc_main.c $(INSTALL_INCLUDE_DIR) ifneq ($(ARCH),arm64) mkdir -p $(INSTALL_INCLUDE_DIR)/hl - cp src/hlmodule.h src/opcodes.h $(INSTALL_INCLUDE_DIR)/hl + cp src/hl/hlmodule.h src/hl/opcodes.h $(INSTALL_INCLUDE_DIR)/hl endif uninstall: @@ -358,7 +358,7 @@ release_prepare: cp src/hl.h src/hlc.h src/hlc_main.c $(PACKAGE_NAME)/include ifneq ($(ARCH),arm64) mkdir $(PACKAGE_NAME)/include/hl - cp src/hlmodule.h src/opcodes.h $(PACKAGE_NAME)/include/hl + cp src/hl/hlmodule.h src/hl/opcodes.h $(PACKAGE_NAME)/include/hl endif release_win: diff --git a/hl.vcxproj b/hl.vcxproj index e5a85a926..8f7416eb0 100644 --- a/hl.vcxproj +++ b/hl.vcxproj @@ -267,8 +267,8 @@ - - + + diff --git a/hl.vcxproj.filters b/hl.vcxproj.filters index 57ba2170f..af17a36a2 100644 --- a/hl.vcxproj.filters +++ b/hl.vcxproj.filters @@ -9,8 +9,8 @@ - - + + \ No newline at end of file diff --git a/libhljit.vcxproj b/libhljit.vcxproj index 5d531c1a0..4ea73260f 100644 --- a/libhljit.vcxproj +++ b/libhljit.vcxproj @@ -144,8 +144,8 @@ - - + + diff --git a/libhljit.vcxproj.filters b/libhljit.vcxproj.filters index 6ba61f1de..21028af6b 100644 --- a/libhljit.vcxproj.filters +++ b/libhljit.vcxproj.filters @@ -8,8 +8,8 @@ - - + + \ No newline at end of file diff --git a/src/code.c b/src/code.c index 115bfa4ad..e504b4171 100644 --- a/src/code.c +++ b/src/code.c @@ -19,17 +19,17 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -#include "hlmodule.h" +#include "hl/hlmodule.h" #define OP(_,n) n, #define OP_BEGIN static int hl_op_nargs[] = { #define OP_END }; -#include "opcodes.h" +#include "hl/opcodes.h" #define OP(n,_) #n, #define OP_BEGIN static const char *hl_op_names[] = { #define OP_END }; -#include "opcodes.h" +#include "hl/opcodes.h" typedef struct { const unsigned char *b; @@ -1099,4 +1099,3 @@ void hl_code_hash_free( hl_code_hash *h ) { free(h->types_hashes); free(h); } - diff --git a/src/debugger.c b/src/debugger.c index 000d8e8cd..81a51b021 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -20,7 +20,7 @@ * DEALINGS IN THE SOFTWARE. */ #include -#include +#include struct _hl_socket; typedef struct _hl_socket hl_socket; diff --git a/src/hlmodule.h b/src/hl/hlmodule.h similarity index 100% rename from src/hlmodule.h rename to src/hl/hlmodule.h diff --git a/src/opcodes.h b/src/hl/opcodes.h similarity index 94% rename from src/opcodes.h rename to src/hl/opcodes.h index e07fe069e..12645224d 100644 --- a/src/opcodes.h +++ b/src/hl/opcodes.h @@ -1,153 +1,153 @@ -/* - * Copyright (C)2005-2016 Haxe Foundation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef OP_BEGIN -# define OP_BEGIN typedef enum { -# define OP_END } hl_op; -#endif - -#ifndef OP -# define OP(o,_) o, -#endif - -OP_BEGIN - OP(OMov,2) - OP(OInt,2) - OP(OFloat,2) - OP(OBool,2) - OP(OBytes,2) - OP(OString,2) - OP(ONull,1) - - OP(OAdd,3) - OP(OSub,3) - OP(OMul,3) - OP(OSDiv,3) - OP(OUDiv,3) - OP(OSMod,3) - OP(OUMod,3) - OP(OShl,3) - OP(OSShr,3) - OP(OUShr,3) - OP(OAnd,3) - OP(OOr,3) - OP(OXor,3) - - OP(ONeg,2) - OP(ONot,2) - OP(OIncr,1) - OP(ODecr,1) - - OP(OCall0,2) - OP(OCall1,3) - OP(OCall2,4) - OP(OCall3,5) - OP(OCall4,6) - OP(OCallN,-1) - OP(OCallMethod,-1) - OP(OCallThis,-1) - OP(OCallClosure,-1) - - OP(OStaticClosure,2) - OP(OInstanceClosure,3) - OP(OVirtualClosure,3) - - OP(OGetGlobal, 2) - OP(OSetGlobal,2) - OP(OField,3) - OP(OSetField,3) - OP(OGetThis,2) - OP(OSetThis,2) - OP(ODynGet,3) - OP(ODynSet,3) - - OP(OJTrue,2) - OP(OJFalse,2) - OP(OJNull,2) - OP(OJNotNull,2) - OP(OJSLt,3) - OP(OJSGte,3) - OP(OJSGt,3) - OP(OJSLte,3) - OP(OJULt,3) - OP(OJUGte,3) - OP(OJNotLt,3) - OP(OJNotGte,3) - OP(OJEq,3) - OP(OJNotEq,3) - OP(OJAlways,1) - - OP(OToDyn,2) - OP(OToSFloat,2) - OP(OToUFloat,2) - OP(OToInt,2) - OP(OSafeCast,2) - OP(OUnsafeCast,2) - OP(OToVirtual,2) - - OP(OLabel,0) - OP(ORet,1) - OP(OThrow,1) - OP(ORethrow,1) - OP(OSwitch,-1) - OP(ONullCheck,1) - OP(OTrap,2) - OP(OEndTrap,1) - - OP(OGetI8,3) - OP(OGetI16,3) - OP(OGetMem,3) - OP(OGetArray,3) - OP(OSetI8,3) - OP(OSetI16,3) - OP(OSetMem,3) - OP(OSetArray,3) - - OP(ONew,1) - OP(OArraySize,2) - OP(OType,2) - OP(OGetType,2) - OP(OGetTID,2) - - OP(ORef,2) - OP(OUnref,2) - OP(OSetref,2) - - OP(OMakeEnum,-1) - OP(OEnumAlloc,2) - OP(OEnumIndex,2) - OP(OEnumField,4) - OP(OSetEnumField,3) - - OP(OAssert,0) - OP(ORefData,2) - OP(ORefOffset,3) - OP(ONop,0) - OP(OPrefetch, 3) - OP(OAsm, 3) - // -- - OP(OLast,0) -OP_END - -#undef OP_BEGIN -#undef OP_END -#undef OP +/* + * Copyright (C)2005-2016 Haxe Foundation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef OP_BEGIN +# define OP_BEGIN typedef enum { +# define OP_END } hl_op; +#endif + +#ifndef OP +# define OP(o,_) o, +#endif + +OP_BEGIN + OP(OMov,2) + OP(OInt,2) + OP(OFloat,2) + OP(OBool,2) + OP(OBytes,2) + OP(OString,2) + OP(ONull,1) + + OP(OAdd,3) + OP(OSub,3) + OP(OMul,3) + OP(OSDiv,3) + OP(OUDiv,3) + OP(OSMod,3) + OP(OUMod,3) + OP(OShl,3) + OP(OSShr,3) + OP(OUShr,3) + OP(OAnd,3) + OP(OOr,3) + OP(OXor,3) + + OP(ONeg,2) + OP(ONot,2) + OP(OIncr,1) + OP(ODecr,1) + + OP(OCall0,2) + OP(OCall1,3) + OP(OCall2,4) + OP(OCall3,5) + OP(OCall4,6) + OP(OCallN,-1) + OP(OCallMethod,-1) + OP(OCallThis,-1) + OP(OCallClosure,-1) + + OP(OStaticClosure,2) + OP(OInstanceClosure,3) + OP(OVirtualClosure,3) + + OP(OGetGlobal, 2) + OP(OSetGlobal,2) + OP(OField,3) + OP(OSetField,3) + OP(OGetThis,2) + OP(OSetThis,2) + OP(ODynGet,3) + OP(ODynSet,3) + + OP(OJTrue,2) + OP(OJFalse,2) + OP(OJNull,2) + OP(OJNotNull,2) + OP(OJSLt,3) + OP(OJSGte,3) + OP(OJSGt,3) + OP(OJSLte,3) + OP(OJULt,3) + OP(OJUGte,3) + OP(OJNotLt,3) + OP(OJNotGte,3) + OP(OJEq,3) + OP(OJNotEq,3) + OP(OJAlways,1) + + OP(OToDyn,2) + OP(OToSFloat,2) + OP(OToUFloat,2) + OP(OToInt,2) + OP(OSafeCast,2) + OP(OUnsafeCast,2) + OP(OToVirtual,2) + + OP(OLabel,0) + OP(ORet,1) + OP(OThrow,1) + OP(ORethrow,1) + OP(OSwitch,-1) + OP(ONullCheck,1) + OP(OTrap,2) + OP(OEndTrap,1) + + OP(OGetI8,3) + OP(OGetI16,3) + OP(OGetMem,3) + OP(OGetArray,3) + OP(OSetI8,3) + OP(OSetI16,3) + OP(OSetMem,3) + OP(OSetArray,3) + + OP(ONew,1) + OP(OArraySize,2) + OP(OType,2) + OP(OGetType,2) + OP(OGetTID,2) + + OP(ORef,2) + OP(OUnref,2) + OP(OSetref,2) + + OP(OMakeEnum,-1) + OP(OEnumAlloc,2) + OP(OEnumIndex,2) + OP(OEnumField,4) + OP(OSetEnumField,3) + + OP(OAssert,0) + OP(ORefData,2) + OP(ORefOffset,3) + OP(ONop,0) + OP(OPrefetch, 3) + OP(OAsm, 3) + // -- + OP(OLast,0) +OP_END + +#undef OP_BEGIN +#undef OP_END +#undef OP diff --git a/src/jit.c b/src/jit.c index 696c3f26a..47e19d102 100644 --- a/src/jit.c +++ b/src/jit.c @@ -23,7 +23,7 @@ #pragma warning(disable:4820) #endif #include -#include +#include #ifdef __arm__ # error "JIT does not support ARM processors, only x86 and x86-64 are supported, please use HashLink/C native compilation instead" @@ -4567,4 +4567,3 @@ void *hl_jit_code( jit_ctx *ctx, hl_module *m, int *codesize, hl_debug_infos **d } return code; } - diff --git a/src/main.c b/src/main.c index 74d411561..091be9d58 100644 --- a/src/main.c +++ b/src/main.c @@ -23,11 +23,7 @@ // #define HL_BOOT #include -#ifdef HL_BOOT #include -#else -#include -#endif #ifndef HL_BOOT #define HL_DEBUGGER diff --git a/src/module.c b/src/module.c index d77ff018f..4739f1e3f 100644 --- a/src/module.c +++ b/src/module.c @@ -20,7 +20,7 @@ * DEALINGS IN THE SOFTWARE. */ #include -#include +#include #ifdef HL_WIN # include diff --git a/src/profile.c b/src/profile.c index 05b9a3e78..a8b08b46e 100644 --- a/src/profile.c +++ b/src/profile.c @@ -20,7 +20,7 @@ * DEALINGS IN THE SOFTWARE. */ #include -#include +#include #ifdef HL_LINUX #include From 8e6148776d92ce3d58e582923908398e8a61b7a3 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 16:00:57 +0000 Subject: [PATCH 7/8] [cmake] Add test for boot feature --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3688852f8..d2ea2d1bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,6 +214,11 @@ if(BUILD_TESTING) haxe ) + find_program( + HAXELIB + haxelib + ) + ##################### # hello.hl @@ -317,6 +322,27 @@ if(BUILD_TESTING) uv.hdll ) + ##################### + # hello.c (hashlink boot) + add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello_boot/hello.c + COMMAND ${HAXE_COMPILER} + -hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello_boot/hello.hl + -cp ${CMAKE_SOURCE_DIR}/other/tests -main HelloWorld + COMMAND ${HAXELIB} run hashlink boot ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello_boot/hello.hl + ) + if (WITH_VM) + add_executable(hello_boot + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello_boot/hello.c + ) + set_target_properties(hello_boot + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/hello_boot + ) + target_link_libraries(hello_boot + libhl libhljit + ) + endif() + ##################### # Tests if (WITH_VM) @@ -337,6 +363,9 @@ if(BUILD_TESTING) add_test(NAME uvsample.hl COMMAND hl ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/uvsample.hl 6001 ) + add_test(NAME hello_boot + COMMAND hello_boot + ) endif() add_test(NAME hello From d8e89a7447c372c9b7827f2887066226c6b19f13 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 17 Jan 2025 16:20:08 +0000 Subject: [PATCH 8/8] [ci] Use git version of hashlink library for test --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f6b46832..3bfd26a78 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -156,7 +156,7 @@ jobs: set -eux haxelib setup ~/haxelib - haxelib install hashlink + haxelib dev hashlink other/haxelib haxelib list