diff --git a/.gitignore b/.gitignore index 6914c18..1b7aef5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,116 +1,118 @@ -.python-version -Cargo.lock -Frameworks/wasm-c-api -/yarn.lock -*/wapm -.idea/ -.vscode/ -node_modules/ -tmp/ -coverage/ -package-lock.json* -npm-debug.log -.DS_Store -cmake-build-debug/ -xxx -wasp.bc -wasp.cpp.wasm -wasp.cpp.wasm.map -wasp.cpp.wast -wasp.o -wasp.wasm -wasp.wast -CMakeCache.txt -cmake_install.cmake -eigen.natvis -wasp.cbp -CMakeFiles -wasp.cbp -*.bc -*.wat -*.wast -# we need pow.wasm etc! -*.wasm -main.wasm -test.wasm -*.o -*.i -*.dwarf -cmake-build-* -old -CNAME -angle -clean.sh -features -libSystem.B.dylib -t.c -test.angle.data -xwabt -/wabt/ -/m3/ -/cmake-build-debug/ -/cmake-build-default/ -/cmake-build-release/ -/cmake-build-wasm/ -/cmake-build-wasm-release/ -/Testing/Temporary/ -wasm-micro-runtime.me -Frameworks -playground/ -/.ninja_deps -/.ninja_log -/.wasp_history -/build.ninja -/favicon.ico -/FindSDL.cmake -/FindSDL2.cmake -/.idea.bad/ -/.cmake/api/v1/reply/ -/test/merge/target/ -.cmake -wasp -test/merge/ -/wapm/ -.fake -lib/libwasmedge.dylib -*.dylib -**/*.dylib -/samples/aoc/ -cmake-build-debug -cmake-build-debug-app -cmake-build-docker -cmake-build-emscripten-debug -cmake-build-emscripten-release -cmake-build-my_wasm -cmake-build-release -cmake-build-trace -cmake-build-universal-debug -cmake-build-universal-release -cmake-build-universal-trace -cmake-build-wasm-debug -cmake-build-wasm-runtime -cmake-build-wasm-runtime-debug -CMakeFiles -main.wasm.disassembly -main.wasm.validation -test.wasm -merged.wasm -main.wasm -lib.wasm -lib/hello_spin -lib/wai_example -*.bak -/wasp-jetbrains-plugin/.idea/kotlinc.xml -docs/out -dwarf -main.wasm.map -main.wasm.json -*.map -:=.md -wiki/:=.md +.python-version +Cargo.lock +Frameworks/wasm-c-api +/yarn.lock +*/wapm +.idea/ +.vscode/ +node_modules/ +tmp/ +coverage/ +package-lock.json* +npm-debug.log +.DS_Store +cmake-build-debug/ +xxx +wasp.bc +wasp.cpp.wasm +wasp.cpp.wasm.map +wasp.cpp.wast +wasp.o +wasp.wasm +wasp.wast +CMakeCache.txt +cmake_install.cmake +eigen.natvis +wasp.cbp +CMakeFiles +wasp.cbp +*.bc +*.wat +*.wast +# we need pow.wasm etc! +*.wasm +main.wasm +test.wasm +*.o +*.i +*.dwarf +cmake-build-* +old +CNAME +angle +clean.sh +features +libSystem.B.dylib +t.c +test.angle.data +xwabt +/wabt/ +/m3/ +/cmake-build-debug/ +/cmake-build-default/ +/cmake-build-release/ +/cmake-build-wasm/ +/cmake-build-wasm-release/ +/Testing/Temporary/ +wasm-micro-runtime.me +Frameworks +playground/ +/.ninja_deps +/.ninja_log +/.wasp_history +/build.ninja +/favicon.ico +/FindSDL.cmake +/FindSDL2.cmake +/.idea.bad/ +/.cmake/api/v1/reply/ +/test/merge/target/ +.cmake +wasp +test/merge/ +/wapm/ +.fake +lib/libwasmedge.dylib +*.dylib +**/*.dylib +/samples/aoc/ +cmake-build-debug +cmake-build-debug-app +cmake-build-docker +cmake-build-emscripten-debug +cmake-build-emscripten-release +cmake-build-my_wasm +cmake-build-release +cmake-build-trace +cmake-build-universal-debug +cmake-build-universal-release +cmake-build-universal-trace +cmake-build-wasm-debug +cmake-build-wasm-runtime +cmake-build-wasm-runtime-debug +CMakeFiles +main.wasm.disassembly +main.wasm.validation +test.wasm +merged.wasm +main.wasm +lib.wasm +lib/hello_spin +lib/wai_example +*.bak +/wasp-jetbrains-plugin/.idea/kotlinc.xml +docs/out +dwarf +main.wasm.map +main.wasm.json +*.map +:=.md +wiki/:=.md kotlinc.xml x sourceMappingURL.txt main.c +.aider* +.env diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bcb084..a945c5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,18 @@ if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") set(X86_64 1) endif () + +set(SOURCE ".") +if (NOT EXISTS "${SOURCE}") + set(SOURCE "source") +endif () + include(FetchContent) # external projects like webview #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") # save libwebview to lib ? +# Suppress warnings for unused manually-specified variables +#mark_as_advanced(Python3_EXECUTABLE Python_EXECUTABLE) + # ⚠️ SET these configurations VIA TOOLCHAIN: via CLion Preferences… Build->CMake->Profiles # MANUALLY force set these only for urgent debugging #set(RELEASE 1) # no tests todo VS: @@ -160,7 +169,7 @@ if (WEBAPP) set(WASI 0) set(CONSOLE 0) # SET(RUNTIME_ONLY 1) # we can emit to V8, right?? - set(SOURCE_FILES ${SOURCE_FILES} source/ErrorHandler.cpp) # no SIGSEGV mac popup + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/ErrorHandler.cpp) # no SIGSEGV mac popup endif () if (WASM) ADD_DEFINITIONS(-DWASM) @@ -180,7 +189,7 @@ if (SDL) ADD_DEFINITIONS(-DSDL) remove_definitions(SERVER) include_directories(${SDL2_INCLUDE_DIRS}) - set(SOURCE_FILES ${SOURCE_FILES} source/Paint.cpp) # if SDL + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/Paint.cpp) # if SDL # add_executable(wasp.sdl ${SOURCE_FILES}) # same as add_library, with or without --export-all endif () @@ -220,7 +229,7 @@ if (LINUX) ADD_COMPILE_FLAG("-Wno-ambiguous-reversed-operator") ADD_COMPILE_FLAG("-Wno-writable-strings") # dangerous! fix assert_is("square 3", 9) # DEBIAN - # 2023-10-9 /wasp/source/tests.cpp:48:25: gcc internal compiler error + # 2023-10-9 /wasp/${SOURCE}/tests.cpp:48:25: gcc internal compiler error # todo remove when gcc fixed # set(CMAKE_C_COMPILER clang) # set(CMAKE_CXX_COMPILER clang++) @@ -302,8 +311,8 @@ endif () #ADD_DEFINITIONS(-DNO_CPP_DEMANGLE) # COMMON FOR ALL -set(SOURCE_FILES ${SOURCE_FILES} source/String.cpp source/Node.cpp source/Map.cpp source/Util.cpp source/List.cpp - source/Wasp.cpp source/wasm_helpers.cpp source/Code.cpp source/NodeTypes.cpp source/smart_types.cpp) +set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/String.cpp ${SOURCE}/Node.cpp ${SOURCE}/Map.cpp ${SOURCE}/Util.cpp ${SOURCE}/List.cpp + ${SOURCE}/Wasp.cpp ${SOURCE}/wasm_helpers.cpp ${SOURCE}/Code.cpp ${SOURCE}/NodeTypes.cpp ${SOURCE}/smart_types.cpp) if (CONSOLE) @@ -311,7 +320,7 @@ if (CONSOLE) ADD_DEFINITIONS(-DCONSOLE) ADD_DEFINITIONS(-DUSE_READLINE) link_libraries(readline) - set(SOURCE_FILES ${SOURCE_FILES} source/console.cpp) # Needs to come after, because conflicting Function symbol + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/console.cpp) # Needs to come after, because conflicting Function symbol endif () if (WASM) @@ -323,14 +332,14 @@ endif () if (CURL) find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIRS}) - set(SOURCE_FILES ${SOURCE_FILES} source/Fetch.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/Fetch.cpp) # only 800 bytes via -lcurl ! endif () if (NO_TESTS) ADD_DEFINITIONS(-DNO_TESTS) else () - set(SOURCE_FILES ${SOURCE_FILES} source/tests.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/tests.cpp) endif () if (RUNTIME_ONLY) @@ -339,35 +348,35 @@ if (RUNTIME_ONLY) set(INCLUDE_MERGER 0) else () message("NOT RUNTIME_ONLY") - set(SOURCE_FILES ${SOURCE_FILES} source/Code.cpp) - set(SOURCE_FILES ${SOURCE_FILES} source/Angle.cpp) - set(SOURCE_FILES ${SOURCE_FILES} source/Interpret.cpp) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_emitter.cpp) - set(SOURCE_FILES ${SOURCE_FILES} source/DwarfEmitter.cpp) - set(SOURCE_FILES ${SOURCE_FILES} source/WitReader.h) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_reader.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/Code.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/Angle.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/Interpret.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_emitter.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/DwarfEmitter.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/WitReader.h) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_reader.cpp) endif () if (INCLUDE_MERGER) message(INCLUDE_MERGER) ADD_DEFINITIONS(-DINCLUDE_MERGER) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_linker.cpp) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/common.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/binary.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/binary-writer.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/binary-reader-linker.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/binary-reader.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/opcode-code-table.c) - #set(SOURCE_FILES ${SOURCE_FILES} FILES_MATCHING PATTERN "source/own_merge/*.cc") - #set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/binary-writer-spec.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/binding-hash.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/feature.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/leb128.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/stream.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/opcode.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/utf8.cc) - set(SOURCE_FILES ${SOURCE_FILES} source/own_merge/ir.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_linker.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/common.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/binary.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/binary-writer.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/binary-reader-linker.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/binary-reader.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/opcode-code-table.c) + #set(SOURCE_FILES ${SOURCE_FILES} FILES_MATCHING PATTERN "${SOURCE}/own_merge/*.cc") + #set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/binary-writer-spec.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/binding-hash.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/feature.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/leb128.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/stream.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/opcode.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/utf8.cc) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/own_merge/ir.cc) endif () @@ -380,7 +389,9 @@ if (APPLE) ADD_COMPILE_FLAG("-Wno-unused-parameter") # always ADD_COMPILE_FLAG("-Wno-deprecated-copy-with-user-provided-copy") # what's this? endif () +#add_compile_options(-Wno-vla-cxx-extension) # allow array[len] add_compile_options(-Werror) +add_compile_options(-Wno-return-type-c-linkage) # allow C functions to return multi-value struct / C++ types if (TRACE) @@ -394,10 +405,12 @@ endif () if (SANITIZE) # OR TRACE message("SANITIZE") - + message("Don't build with sanitizers.") + message("Just -g and -fno-omit-frame-pointer are enough for Valgrind.") + message("Mixing sanitizers and Valgrind usually doesn't work.") if (NOT EMSCRIPTEN) ADD_DEFINITIONS(-D_Backtrace_) - set(SOURCE_FILES ${SOURCE_FILES} source/Backtrace.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/Backtrace.cpp) endif () # Often gdb would be a better tool to debug this problem. Run `gdb wasp -ex r` until it crashes. @@ -451,13 +464,13 @@ if (SANITIZE) # OR TRACE endif () if (WASM) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_helpers_wasm.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_helpers_wasm.cpp) if (NO_TESTS) else () - set(SOURCE_FILES ${SOURCE_FILES} source/test_browser.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/test_browser.cpp) endif () else () - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_helpers_host.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_helpers_host.cpp) endif () # @@ -567,7 +580,7 @@ if (WASM) # OR WASI) #relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol nil_name; recompile with -fPIC ADD_COMPILE_FLAG("-Wl,--compress-relocations") # incompatible with output debug information. Please pass --strip-debug ADD_COMPILE_FLAG("-Wl,--strip-debug") # DEBUG-RELEASE - set(SOURCE_FILES ${SOURCE_FILES} source/exceptions.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/exceptions.cpp) # --no-validation --debug ADD_COMPILE_FLAG("-Oz -Qn") ADD_COMPILE_FLAG("-Wl,-O4") @@ -636,7 +649,7 @@ elseif (MICRO) # wasm-micro-vm: return() endif () - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_runner_micro.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_runner_micro.cpp) message("USING INTERNAL WASM MICRO RUNTIME TO DEBUG (not Mac M1 ready!!)") # quit() ADD_DEFINITIONS(-DWASM_ENABLE_INTERP) @@ -693,7 +706,7 @@ elseif (WABT) ADD_COMPILE_FLAG("-dM -ferror-limit=5 -g") # include(wabt/cmake_install.cmake) # add_subdirectory(wabt) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_runner_wabt.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_runner_wabt.cpp) add_executable(wasp ${SOURCE_FILES}) target_include_directories(wasp PUBLIC Frameworks/wabt/include/) target_include_directories(wasp PUBLIC Frameworks/wabt/include/wabt) @@ -702,15 +715,15 @@ elseif (WABT) target_link_libraries(wasp PRIVATE wasm) # libwabt is called libwasm.dylib DANGER! elseif (WASMER) MESSAGE("USING WASMER") - set(SOURCE_FILES ${SOURCE_FILES} source/wasmer_runner.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasmer_runner.cpp) add_executable(wasp ${SOURCE_FILES}) target_include_directories(wasp PUBLIC Frameworks/wasmer-c-api) target_link_libraries(wasp PRIVATE wasmer) elseif (WASMEDGE) MESSAGE("USING WASMEDGE") ADD_DEFINITIONS(-DWASMEDGE) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_runner_edge.cpp) - set(SOURCE_FILES source/wasm_runner_edge.cpp ${SOURCE_FILES}) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_runner_edge.cpp) + set(SOURCE_FILES ${SOURCE}/wasm_runner_edge.cpp ${SOURCE_FILES}) add_executable(wasp ${SOURCE_FILES}) # target_include_directories(wasp PUBLIC Frameworks/wasmedge) target_include_directories(wasp PUBLIC /opt/wasm/WasmEdge/include/api/) @@ -725,7 +738,7 @@ elseif (WASMEDGE) elseif (WASMTIME) MESSAGE("USING WASMTIME") ADD_DEFINITIONS(-DWASMTIME) - set(SOURCE_FILES ${SOURCE_FILES} source/wasmtime_runner.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasmtime_runner.cpp) add_executable(wasp ${SOURCE_FILES}) # BUILD_SHARED_LIBS is provided as a define if you would like to build a shared library instead. # add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Frameworks/wasmtime/crates/c-api ${CMAKE_CURRENT_BINARY_DIR}/wasmtime) @@ -746,8 +759,8 @@ elseif (WEBAPP) ADD_DEFINITIONS(-DWEBAPP) # on Windows 11, developers and end-users must have the WebView2 runtime installed! # for standalone for Windows version check choc_WebView.h (1 MB) - include(source/WebView.cmake) - set(SOURCE_FILES ${SOURCE_FILES} source/WebApp.cpp source/WebServer.cpp) + include(${SOURCE}/WebView.cmake) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/WebApp.cpp ${SOURCE}/WebServer.cpp) add_executable(wasp-app ${SOURCE_FILES}) target_link_libraries(wasp-app PUBLIC webview) target_include_directories(wasp-app PUBLIC Frameworks/webview) @@ -765,8 +778,8 @@ elseif (WASM3) # add_subdirectory(Frameworks/wasm3/source ${CMAKE_BINARY_DIR}/m3) # wat? include(Frameworks/uvwasi/cmake_install.cmake) include(Frameworks/wasm3/cmake_install.cmake) # // 2022-12: last release on Jun 2, 2021 - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_runner_wasm3.cpp) - # source/types/Number.cpp source/types/Number.h + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_runner_wasm3.cpp) + # ${SOURCE}/types/Number.cpp ${SOURCE}/types/Number.h add_executable(wasp ${SOURCE_FILES}) # target_include_directories(wasp PUBLIC Frameworks/wasm3/platforms/cpp/wasm3_cpp/include/) target_include_directories(wasp PUBLIC Frameworks/wasm3/source) @@ -779,12 +792,12 @@ elseif (WASM3) # add_custom_target(BuildWasm3 ALL DEPENDS angle) #.exe # TO EXECUTE wasm, add ONE of these: wasm_runner_console.cpp wasm_runner_wasm3.cpp wasm_runner_wabt.cpp wasm_runner_wabt.cpp wasm_runner_micro.cpp elseif (WASMX) - set(SOURCE_FILES ${SOURCE_FILES} source/wasm_runner_console.cpp) + set(SOURCE_FILES ${SOURCE_FILES} ${SOURCE}/wasm_runner_console.cpp) add_executable(wasp ${SOURCE_FILES}) elseif (V8) MESSAGE("USING V8") ADD_DEFINITIONS(-DV8_COMPRESS_POINTERS) - set(SOURCE_FILES source/wasm_runner_v8.cpp ${SOURCE_FILES}) + set(SOURCE_FILES ${SOURCE}/wasm_runner_v8.cpp ${SOURCE_FILES}) add_executable(wasp ${SOURCE_FILES}) target_include_directories(wasp PUBLIC Frameworks/wasm-c-api/include/) target_include_directories(wasp PUBLIC Frameworks/wasm-c-api/v8/include/) @@ -797,7 +810,7 @@ else () # NORMAL: add_executable(wasp ${SOURCE_FILES}) endif () # add_custom_target(BuildWasp ALL DEPENDS angle) - target_include_directories(${PROJECT_NAME} PUBLIC source/own_merge) + target_include_directories(${PROJECT_NAME} PUBLIC ${SOURCE}/own_merge) if (CURL) target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES}) target_link_libraries(${PROJECT_NAME} -lcurl) diff --git a/source/.prompt b/source/.prompt new file mode 100644 index 0000000..6084854 --- /dev/null +++ b/source/.prompt @@ -0,0 +1 @@ +Always answer in German \ No newline at end of file diff --git a/source/ABI.h b/source/ABI.h index c7818e6..fedfd60 100644 --- a/source/ABI.h +++ b/source/ABI.h @@ -46,25 +46,35 @@ struct RustData { // allows boxed return of bigint via Address to longy Node … struct Reto { - int value; - Type type; + int value; +// unsigned long long type; // -Wreturn-type-c-linkage OK + Type type; // -Wno-return-type-c-linkage }; struct Retol { - int64 value; + int64 value; Type type; }; +// example of multi-value return in C/C++ : +// extern "C" Reto swap(int a, int b); +//(func (export "add_and_subtract") (param i32 i32) (result i32 i32) +//local.get 1 +//local.get 0 +//) + + + typedef int usize; typedef int u32; struct AssemblyScriptData { - usize mmInfo;// -20 usize Memory manager info - usize gcInfo;// -16 usize Garbage collector info - usize gcInfo2;// -12 usize Garbage collector info - u32 rtId;// -8 u32 Unique id of the concrete class - u32 rtSize;// -4 u32 Size of the data following the header - void *payload;// 0 Payload starts here + usize mmInfo;// -20 usize Memory manager info + usize gcInfo;// -16 usize Garbage collector info + usize gcInfo2;// -12 usize Garbage collector info + u32 rtId;// -8 u32 Unique id of the concrete class + u32 rtSize;// -4 u32 Size of the data following the header + void *payload;// 0 Payload starts here }; @@ -126,3 +136,4 @@ static smart_pointer_64 smart_pointer_payload_mask = 0x0000FFFF00000000L; // tod static smart_pointer_64 smart_pointer_node_signature = 0xA000000000000000L;// ((smart_pointer_64)nodep) << 63; // 0xA0…0 // short smart_type_payload = (short)(smartPointer64 & 0x0000FFFF00000000L)>>16;// type payload including length (of array) + diff --git a/source/Code.h b/source/Code.h index 677f01b..eeef04f 100644 --- a/source/Code.h +++ b/source/Code.h @@ -980,7 +980,7 @@ enum Sections { data_section = 11, // extensions: datacount = 12, - tag_section = 13, + tag_section = 13, // exception handling string_section = 14, // wasm stringref table }; diff --git a/source/NodeTypes.h b/source/NodeTypes.h index f2a9955..6118c09 100644 --- a/source/NodeTypes.h +++ b/source/NodeTypes.h @@ -37,10 +37,21 @@ enum Valtype { void_block = 0x40, // ⚠️ none = 0x40, // NOT voids!!! -// ref = 0x6b, // ≠ externref plus type id! vs 0xfb… for functions struct.new struct.get … ≠ wasmtype_struct 0x5f +// ≠ externref plus type id! vs 0xfb… for functions struct.new struct.get … ≠ wasmtype_struct 0x5f wasm_struct = 0x6b, // ≠ wasmtype_struct = 0x5f in type section wasm_array = wasm_struct, // 0x6b ≠ wasmtype_array = 0x5e in type section - anyref = 0x6f,// was conceptually and namewise merged into externref +/* +ref // Abstract supertype of all references +├── funcref // References to WebAssembly functions +├── externref // References to host-managed objects (e.g., JS objects) +└── eqref // References to equality-comparable objects (e.g., GC structs, arrays) + └── i31ref // References to immutable 31-bit integers + └── (ref null ) // Typed nullable references (introduced by GC proposal) only if T is equality-comparable +*/ + ref = 0x6C, // followed by 0x00 for nullable, Followed by the index of the referenced type! + eqref = 0x6D, // gc structs, arrays + i31ref = 0x6E, + anyref = 0x6f,// was conceptually and name-wise merged into externref externref = 0x6f, // -0x11 111 (js)object ! ≠ 'ref'=wasm_struct!! object = externref, js_object = externref, @@ -117,6 +128,7 @@ extern Node StringType; // needs to be stable: Kind is returned in multivalue and thus needs to be parsed by js! // todo change naming scheme: remove false plural 's' where inappropiate: 'strings' groups … … … // compare / merge(?) with enum Primitive? nah, primitive is internal / wasm only +// e.g. Kind.longy is container for i32 i64 bool enums ... enum Kind /* 32 bit*/ {// todo: merge Node.kind with Node.class(?) // todo smartType4bit first 16 values!! // plurals because of namespace clash diff --git a/source/tests.cpp b/source/tests.cpp index d253987..cbeacd2 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -22,6 +22,124 @@ #include "own_merge/type.h" #include "own_merge/common.h" + +#include +#include + +struct debug_struct { + byte a; + byte b; + byte c; + byte d; + byte e; + byte f; + byte g; + byte h; + int i; + int j; + int k; + int l; +}; + +typedef struct { + int32_t value; // The single field in the struct +} wasm_struct1; + +int test_wasmedge_gc() { + // Initialize WasmEdge runtime + WasmEdge_ConfigureContext *Conf = WasmEdge_ConfigureCreate(); + WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_ReferenceTypes); + WasmEdge_ConfigureAddProposal(Conf, WasmEdge_Proposal_GC); + + WasmEdge_VMContext *VM = WasmEdge_VMCreate(Conf, NULL); + + // Load the WASM module +// WasmEdge_String ModulePath = WasmEdge_StringCreateByCString("gc_example.wasm"); + WasmEdge_String ModuleName = WasmEdge_StringCreateByCString("gc_example"); + const char *path = "/Users/me/dev/script/wasm/gc_structs/gc_example.wasm"; + WasmEdge_Result Result = WasmEdge_VMRegisterModuleFromFile(VM, ModuleName, path); + if (!WasmEdge_ResultOK(Result)) { + printf("Failed to load module: %s\n", WasmEdge_ResultGetMessage(Result)); + return 1; + } + + // Run the `new_object` function + WasmEdge_String FuncName = WasmEdge_StringCreateByCString("new_object"); + WasmEdge_Value Params[1] = {WasmEdge_ValueGenI32(32)}; + WasmEdge_Value Returns[1]; +// WasmEdge_VMRunWasmFromBuffer() +// Result = WasmEdge_VMRunRegisteredFunction(VM, ModuleName.Buf, FuncName.Buf, Params, 1, Returns, 1); +// Load the WASM module into a buffer + FILE *wasm_file = fopen(path, "rb"); + if (!wasm_file) { + printf("Failed to open file: %s\n", path); + return 1; + } + fseek(wasm_file, 0, SEEK_END); + long wasm_file_size = ftell(wasm_file); + fseek(wasm_file, 0, SEEK_SET); + + uint8_t *wasm_buffer = (uint8_t *) malloc(wasm_file_size); + if (wasm_buffer == NULL) { + printf("Failed to allocate memory for WASM buffer.\n"); + fclose(wasm_file); + return 1; + } + fread(wasm_buffer, 1, wasm_file_size, wasm_file); + fclose(wasm_file); + + // Run the WASM using the `WasmEdge_VMRunWasmFromBuffer` function +// WasmEdge_Value Params[1] = {WasmEdge_ValueGenI32(32)}; +// WasmEdge_Value Returns[1]; + Result = WasmEdge_VMRunWasmFromBuffer(VM, wasm_buffer, wasm_file_size, FuncName, Params, 1, Returns, 1); + + free(wasm_buffer); // Free the allocated buffer after use + + if (!WasmEdge_ResultOK(Result)) { + printf("Failed to execute function: %s\n", WasmEdge_ResultGetMessage(Result)); + return 1; + } + if (!WasmEdge_ResultOK(Result)) { + printf("Failed to execute function: %s\n", WasmEdge_ResultGetMessage(Result)); + return 1; + } + + + auto mem = WasmEdge_StringCreateByCString("memory"); +// WasmEdge_ModuleInstanceContext *module_ctx2 = WasmEdge_VMGetStoreContext(VM); + WasmEdge_StoreContext *storeContext = WasmEdge_VMGetStoreContext(VM); + const WasmEdge_ModuleInstanceContext *module_ctx = WasmEdge_VMGetActiveModule(VM); + WasmEdge_MemoryInstanceContext *memory_ctx = WasmEdge_ModuleInstanceFindMemory(module_ctx, mem); + uint8_t *memo = WasmEdge_MemoryInstanceGetPointer(memory_ctx, 0, 0); + if (memo) + wasm_memory = memo; + else + warn("⚠️Can't connect wasmedge memory"); + + + // Print the result (object reference) + WasmEdge_Value Return = Returns[0]; + void *pVoid = WasmEdge_ValueGetExternRef(Return); + wasm_struct1 *gc_struct = (wasm_struct1 *)pVoid; + printf("Result: %d\n", gc_struct->value); + if(WasmEdge_ValTypeIsRef(Return.Type)) { + printf("Result REF: %p\n", pVoid); + } else { + printf("Result: %d\n", WasmEdge_ValueGetI32(Return)); + } + debug_struct *debugs = (debug_struct *) pVoid; + printf("Result: %p\n", pVoid); + printf("Result: %d\n", *(int*)pVoid); + printf("Result: %d\n", WasmEdge_ValueGetI32(Return)); + exit(0); + + // Cleanup + WasmEdge_VMDelete(VM); + WasmEdge_ConfigureDelete(Conf); + + return 0; +} + void testMatrixOrder() { assert_emit("m=([[1, 2], [3, 4]]);m[0][1]", 2); assert_emit("([[1, 2], [3, 4]])[0][1]", 2); @@ -371,7 +489,6 @@ void testTypes2() { } - void testTypedFunctions() { // todo name 'id' clashes with 'id' in preRegisterFunctions() result = analyze(parse("int tee(float b, string c){b}")); @@ -2056,11 +2173,11 @@ void testListVarargs() { testListInitializerList(); // ^^ OK just use List oks = {1, 2, 3}; skip( - const List &list1 = List(1, 2, 3, 0); - if (list1.size_ != 3) - breakpoint_helper - check(list1.size_ == 3); - check(list1[2] == 3); + const List &list1 = List(1, 2, 3, 0); + if (list1.size_ != 3) + breakpoint_helper + check(list1.size_ == 3); + check(list1[2] == 3); ) } @@ -3294,13 +3411,13 @@ void testPaintWasm() { // todo: let compiler compute constant expressions like 1024*65536/4 // assert_emit("i=0;k='hi';while(i<1024*65536/4){i++;k#i=65};k[1]", 65)// wow SLOOW!!! //out of bounds memory access if only one Memory page! - assert_emit("i=0;k='hi';while(i<16777216){i++;k#i=65};paint()", 0)// still slow, but < 1s + assert_emit("i=0;k='hi';while(i<16777216){i++;k#i=65};paint()", 0)// still slow, but < 1s // wow, SLOWER in wasm-micro-runtime HOW!? // exit(0); //(√((x-c)^2+(y-c)^2) axx = {1, 2, 3}; // testNamedDataSections(); // testListGrowth();// pointer to a reference error // todo print as general dispatch depending on smarttype // assert_emit("for i in 1 to 5 : {print i};i", 6); +// assert_emit("a = [1, 2, 3]; a[2]", 3); assert_emit("for i in 1 to 5 : {puti i};i", 6); - testListGrowth(); testListGrowth(); testListGrowth(); @@ -3640,7 +3758,7 @@ void testCurrent() { testPolymorphism(); // testPolymorphism2(); skip( - testPolymorphism3(); + testPolymorphism3(); assert_emit("τ≈6.2831853", true); ) diff --git a/source/wasm_runner_edge.cpp b/source/wasm_runner_edge.cpp index 2d3ed28..79a29dc 100644 --- a/source/wasm_runner_edge.cpp +++ b/source/wasm_runner_edge.cpp @@ -212,19 +212,22 @@ extern "C" int64 run_wasm(bytes buffer, int buf_size) { // most are enabled by default and need explicit disabling --disable-multi-value … // ⚠️ "Though the user can specify enabling the proposal, the support for the proposal is not implemented yet." :( // Those implemented have a check mark: ✔️ https://wasmedge.org/book/en/features/proposals.html - WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_BulkMemoryOperations); - WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ReferenceTypes); // externref ≠ GC types! :( WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_Annotations); + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_BulkMemoryOperations); + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_Component); + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ExtendedConst); // i32.add in global's init + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ExceptionHandling); + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_FunctionReferences);// function pointers!! + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_GC); WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ImportExportMutGlobals); + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_Memory64); WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_MultiValue); // ✓ WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_MultiMemories); // ✓ --enable-multi-memory - WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ExtendedConst); // i32.add in global's init - WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ExceptionHandling); WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_TailCall); - WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_Memory64); - WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_FunctionReferences);// function pointers!! -// WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_Threads); -// WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_SIMD); + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_ReferenceTypes); // externref ≠ GC types! :( + WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_Threads); + +// WasmEdge_ConfigureAddProposal(conf, WasmEdge_Proposal_SIMD); BOYCOTT use WASM vector proposal instead! // --enable-function-reference NOT YET https://github.com/WasmEdge/WasmEdge/pull/2122 // ⚠️ "Though the user can specify enabling the proposal, the support for the proposal is not implemented yet." :( diff --git a/wasp.wit b/wasp.wit deleted file mode 100644 index 0b3c561..0000000 --- a/wasp.wit +++ /dev/null @@ -1,133 +0,0 @@ -// world wasp { -// node circle { -// name: "circle" -// type: null -// kind: ValueType::Node -// value: Value::Node(Node { -// name: String { pointer: 0, length: 6 } -// }) -// } -// } -package wasp - -// Enum to represent the active type in the union `Value` -enum ValueType { -node = 0, -string = 1, -data = 2, -long = 3, -real = 4, -module = 5 -} - -// Kind Enum Definition -enum Kind{ -undefined = 0 // Default kind, undefined -unknown = 1 // Unknown kind -objects = 2 // Block data with children closures -strings = 0x9 // String representation -call = 0x10 // Call representation - -groups = 0x11 // Group (meta parameters, lists, etc.) -tuples = 0x11 // Alias for groups with restrictions -patterns = 0x12 // Patterns (selectors, annotations, etc.) -generics = 0x13 // Generic node tags or lists -tags = 0x13 // Alias for generics (e.g., ) - -key = 0x14 // Key with a value -fields = 0x15 // Key in a struct/class/type without a value - -reference = 0x16 // Variable identifier (e.g., x) -global = 0x17 // Global variable - -symbol = 0x18 // Symbol (e.g., one, plus) -operators = 0x19 // Operators (semantic types) -functor = 0x1A // Functor (e.g., while(xyz){abc}) -expression = 0x1B // Expression (e.g., one plus one) -declaration = 0x1C // Declaration (e.g., x := 1) -assignment = 0x1D // Assignment (e.g., x = 1) -buffers = 0x1E // Buffer (e.g., int[]) - -bools = 0x1F // Boolean type -errors = 0x20 // Internal error type - -clazz = 0x21 // Class type -arrays = 0x22 // Untyped array of Nodes -linked_list = 0x23 // Linked list structure via children or value -meta = 0x23 // Alias for linked list -enums = 0x24 // Enum type -flags = 0x25 // Boolean enum with bitwise values -variants = 0x26 // Variant type -records = 0x27 // Record type -constructor = 0x28 // Special constructor call -modul = 0x29 // Module/interface/resource/library/package - -nils = 0x40 // Void block for compatibility -referencex = 0x41 // External reference (externref in WASM spec) -number = 0x70 // SmartNumber or boxed Number -structs = 0x77 // Struct type -reals = 0x7C // Real (double/float64) type -realsF = 0x7D // Real (float32) type -longs = 0x7E // Long integer type -long32 = 0x7F // Integer stored in long node field - -last_kind = 0x80 // Last valid kind value -codepoint1 = 0xC4 // Codepoint (stored in value.longy field) -urls = 0xC5 // Special string references in name -} - -// String type representation in WASM -type String struct { -pointer: u32 // Pointer to the start of the string in WASM memory -length: u32 // Length of the string -} - -// Union to represent the Value structure -union Value { -Node(node: Node) // Reference to another Node -String(string: String) // Reference to a String -Data(data: u64) // Data pointer -Long(long: s64) // 64-bit integer -Real(real: f64) // 64-bit float -Module(module: u64) // Module pointer -} - -// Struct to represent a Node -type Node struct { -name: String // Name as a String -type: option // Nullable reference to a type Node -kind: ValueType // Value type of the node -value: Value // Union structure defined above -length: u32 // Number of children -child: list // List of children Nodes -meta: option // Nullable reference to meta node -parent: option // Nullable reference to parent node -next: option // Nullable reference to next node in list -separator: u8 // Separator character [a b c] or [a,b,c] -} - -// Functions exposed for manipulating Nodes - -// Create a new Node with basic fields -func create_node(name: String, kind: ValueType, value: Value) -> Node - -// Add a child Node to a parent Node -func add_child(parent: Node, child: Node) - -// Set the meta Node for a given Node (nullable) -func set_meta(node: Node, meta: option) - -// Set the parent Node for a given Node (nullable) -func set_parent(node: Node, parent: option) - -// Set the next Node for a given Node (nullable) -func set_next(node: Node, next: option) - -// Update the value of a Node -func update_value(node: Node, value: Value) - -// Get the child Nodes of a given Node -func get_children(node: Node) -> list - -// Debugging or utilities -func print_node_debug(node: Node) \ No newline at end of file