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
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 e3fc0f595..d2ea2d1bc 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/hl/hlmodule.h;src/hl/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)
@@ -206,6 +214,11 @@ if(BUILD_TESTING)
haxe
)
+ find_program(
+ HAXELIB
+ haxelib
+ )
+
#####################
# hello.hl
@@ -309,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)
@@ -329,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
@@ -387,6 +424,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..88f8a2278 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/hl/hlmodule.h src/hl/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}
@@ -314,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)
@@ -321,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)
@@ -339,6 +356,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/hl/hlmodule.h src/hl/opcodes.h $(PACKAGE_NAME)/include/hl
+endif
release_win:
cp $(BUILD_DIR)/{hl.exe,libhl.dll,*.hdll,*.lib} $(PACKAGE_NAME)
@@ -376,6 +397,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/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
new file mode 100644
index 000000000..4ea73260f
--- /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;%(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;%(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..21028af6b
--- /dev/null
+++ b/libhljit.vcxproj.filters
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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/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 9ff3d07af..091be9d58 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,12 +19,19 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
+
+// #define HL_BOOT
+
#include
-#include
+#include
+
+#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
@@ -32,22 +39,36 @@ 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
pchar *file;
+ int file_time;
+#endif
hl_code *code;
hl_module *m;
vdynamic *ret;
- int file_time;
} 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;
@@ -87,7 +108,9 @@ 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 ) {
int time = pfiletime(m->file);
bool changed;
@@ -102,6 +125,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 +165,28 @@ 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;
+#ifndef HL_BOOT
int first_boot_arg = -1;
+#endif
+ bool isExc = false;
argv++;
argc--;
+#ifndef HL_BOOT
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 +196,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;
@@ -200,7 +237,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);
@@ -209,11 +261,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);
- ctx.file = file;
+#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;
@@ -223,29 +279,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 +323,3 @@ int main(int argc, pchar *argv[]) {
hl_global_free();
return 0;
}
-
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