diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cb50969..8ffacda3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.10) project(wasp) -include(FetchContent) # external projects like webview - set(CMAKE_VERBOSE_MAKEFILE OFF) # DEBUG CMAKE #set(CROSSCOMPILE x86) # needs more work / just use different docker images @@ -11,6 +9,9 @@ if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") set(X86_64 1) endif () +include(FetchContent) # external projects like webview +#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") # save libwebview to lib ? + # ⚠️ 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: @@ -64,13 +65,16 @@ endif () if (NOT WASM) set(CONSOLE 1) # can't get readline to work in wasm if (NOT RUNTIME_ONLY) + # In addition to the compiler, + # The WASP runtime can be bundled with WASM runtimes: + # TO EXECUTE wasm provide _run_wasm : # https://github.com/WebAssembly/wasm-c-api implemented by V8 Wabt Wasmtime Wasmer # as of 2022-10 wasm-c-api encompasses multiple return values and reference types, but not yet threads. - # SET(WASMEDGE 1) # fastest, easiest, bestest. todo smart multi-value returns + SET(WASMEDGE 1) # fastest, easiest, bestest. todo smart multi-value returns # SET(WASMEDGE 0) # SET(WASMTIME 1) # FASTEST but unstable / elusive bugs "object used with the wrong store" etc - set(WEBAPP 1) # FAST!! WebView for electron like standalone apps. + # set(WEBAPP 1) # FAST!! WebView for electron like standalone apps and testing of browser features # set(WASM3 1) # GOOD (backtrace…) wasm_runner_wasm3.cpp BEST API but dying to Russia :( 2022-12: last release on Jun 2, 2021 # set(MICRO 1) # WAMR 2023-02 still NOT M1 READY! wasm-micro-runtime => wasm_runner_micro.cpp TODO: use AOT/JIT mode!? # SET(V8 1) # 2024-04 Exception: EXC_BAD_ACCESS (code=1, address=0x0) :( and VERY SLOW !? @@ -700,20 +704,12 @@ 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) + include(source/WebView.cmake) set(SOURCE_FILES ${SOURCE_FILES} source/WebApp.cpp source/WebServer.cpp) add_executable(wasp-app ${SOURCE_FILES}) - - FetchContent_Declare(webview GIT_REPOSITORY https://github.com/webview/webview.git) - FetchContent_MakeAvailable(webview) - find_library(WEBVIEW webview HINTS ${webview_SOURCE_DIR}/core) - target_link_libraries(wasp-app PUBLIC ${WEBVIEW}) + target_link_libraries(wasp-app PUBLIC webview) + target_include_directories(wasp-app PUBLIC Frameworks/webview) target_include_directories(wasp-app PUBLIC ${webview_SOURCE_DIR}/core/include) - FIND_LIBRARY(OBJC_LIBRARY objc) - TARGET_LINK_LIBRARIES(wasp-app PRIVATE ${OBJC_LIBRARY}) - - # target_link_libraries(wasp-app PUBLIC webview) - # target_include_directories(wasp-app PUBLIC ${webview_SOURCE_DIR}/core/include) if (CURL) target_link_libraries(wasp-app PUBLIC ${CURL_LIBRARIES}) diff --git a/docs/assets/script/wasp_tests.js b/docs/assets/script/wasp_tests.js index 0e5f0159..51e6c670 100644 --- a/docs/assets/script/wasp_tests.js +++ b/docs/assets/script/wasp_tests.js @@ -26,7 +26,8 @@ onerror = (err) => { function check(ok) { if (!ok) backtrace_line("⚠️ TEST FAILED") - if (!ok) throw "⚠️ TEST FAILED" + if (!ok) + throw "⚠️ TEST FAILED" } diff --git a/source/Node.cpp b/source/Node.cpp index f82f823c..b177f6a8 100644 --- a/source/Node.cpp +++ b/source/Node.cpp @@ -320,6 +320,7 @@ bool Node::operator==(wchar_t other) { if (kind == codepoint1)return other == value.longy; if (kind == longs)return other == value.longy; error1("Node::operator==(wchar_t other) must be kind codepoint or longs"); + return false; } bool Node::operator==(int other) { diff --git a/source/Util.h b/source/Util.h index f5ed99b0..7875bc3e 100644 --- a/source/Util.h +++ b/source/Util.h @@ -17,7 +17,8 @@ #define debug_line() printf("\nfile://%s\n%s:%d\n",__FILE__,__FILE__,__LINE__); #define backtrace_line() {printf("\n%s:%d\n",__FILE__,__LINE__);proc_exit(0);} #else -#define backtrace_line() {printf("\n%s:%d\n",__FILE__,__LINE__);exit(0);} +#define backtrace_line() {printf("\n%s:%d\n",__FILE__,__LINE__);} +//exit(0); #define debug_line() printf("\n%s:%d\n",__FILE__,__LINE__); #endif @@ -108,9 +109,9 @@ typedef byte *bytes; #include "String.h" // AFTER defines! #include "smart_types.h" -//#if …// sometimes needed sometimes not !? +#if not WEBAPP +#endif [[noreturn]] -//#endif extern void error1(chars message, chars file = 0, int line = 0); extern void info(chars); diff --git a/source/WebApp.cpp b/source/WebApp.cpp index a1e44f8d..362d0e75 100644 --- a/source/WebApp.cpp +++ b/source/WebApp.cpp @@ -272,7 +272,7 @@ int64 open_webview(String url = "") { // add [w] to closure to make it local view.set_title("Example"); - view.set_html(""); +// view.set_html(""); // w.value("alert('js injected into every page')"); view.set_size(480 * 4, 320 * 4, WEBVIEW_HINT_NONE);// default view.set_size(480, 320, WEBVIEW_HINT_MIN);// minimum size, also: MAX, FIXED @@ -296,10 +296,10 @@ int64 open_webview(String url = "") { teste.detach(); return s; }); - view.bind("close", [](std::string s) -> std::string { - view.terminate(); - exit(0); - }); +// view.bind("close", [](std::string s) -> std::string { +// view.terminate(); +// exit(0); +// }); view.bind("destroy", [](std::string s) -> std::string { view.terminate(); return s; diff --git a/source/WebView.cmake b/source/WebView.cmake index 01366369..f0104d79 100644 --- a/source/WebView.cmake +++ b/source/WebView.cmake @@ -19,7 +19,7 @@ if (NOT webview_POPULATED) # We have to do it ourselves FetchContent_Populate(webview) add_library(webview INTERFACE) - target_sources(webview INTERFACE ${webview_SOURCE_DIR}/webview.h) + target_sources(webview INTERFACE ${webview_SOURCE_DIR}/core/include/webview.h) target_include_directories(webview INTERFACE ${webview_SOURCE_DIR}) # Set compile options diff --git a/source/tests.cpp b/source/tests.cpp index 739c3820..10a93d22 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -3218,8 +3218,8 @@ void assurances() { void testAllEmit() { // WASM emit tests under the hood: assert_emit("42", 42);// basics - assert_emit("√ π ²", pi); - assert_emit("√π²", pi); +// assert_emit("√ π ²", pi); +// assert_emit("√π²", pi); testEmitBasics(); testSinus(); @@ -3272,6 +3272,7 @@ void testEmitBasics() { assert_emit("true", true); assert_emit("false", false) assert_emit("8.33333333332248946124e-03", 8.33333333332248946124e-03); + assert_emit("42", 42) assert_emit("-42", -42) assert_emit("3.1415", 3.1415); assert_emit("-3.1415", -3.1415); @@ -3391,8 +3392,9 @@ void tests() { warn("Normal tests ALL PASSING in wasm!"); warn("WASM emit tests CURRENTLY __ALL__ SKIPPED or asynchroneous!"); return; +#else + testAllEmit(); #endif - testAllEmit(); // todo: split in test_wasp test_angle test_emit.cpp } @@ -3417,10 +3419,10 @@ void pleaseFix() { // 2022-12-28 : 3 sec WITH runtime_emit, wasmedge on M1 WOW ALL TESTS PASSING // ⚠️ CANNOT USE assert_emit in WASM! ONLY via void testRun(); void testCurrent() { - testInclude(); +// testInclude(); // check_is("τ≈6.2831853",true); // assert_emit("τ≈6.2831853",1); - testExceptions(); +// testExceptions(); // assert_emit("√ π ²", pi); // assert_emit("√π²", pi); @@ -3444,7 +3446,7 @@ void testCurrent() { // testReplaceAll(); // testFetch(); // return; - testDomProperty(); +// testDomProperty(); // testInnerHtml(); // return; #if WEBAPP diff --git a/source/wasm_helpers.cpp b/source/wasm_helpers.cpp index 789d5cb4..c79fc7d3 100644 --- a/source/wasm_helpers.cpp +++ b/source/wasm_helpers.cpp @@ -70,6 +70,7 @@ int isalnum0(int c) { [[noreturn]] //#endif void error1(chars message, chars file, int line) { + #ifdef _Backtrace_ // Backtrace(2);// later, in raise #endif @@ -89,10 +90,12 @@ void error1(chars message, chars file, int line) { if (file)printf("\n%s:%d\n", file, line); raise(message); #endif -//#if not WEBAPP +#if not WEBAPP // if (throwing) throw message; // [[noreturn]] should not return -//#endif +#else + proc_exit(-1); +#endif } diff --git a/source/wasm_helpers.h b/source/wasm_helpers.h index f7be1f6f..3b76edc8 100644 --- a/source/wasm_helpers.h +++ b/source/wasm_helpers.h @@ -14,9 +14,9 @@ typedef char32_t codepoint;// 'letter' ☃ is a single code point but 3 UTF-8 co typedef const char *chars; typedef unsigned char *bytes; -//#if not WEBAPP +#if not WEBAPP [[noreturn]] -//#endif +#endif extern void error1(chars message, chars file, int line); // there are two aspects of wasm memory: the internal memory starting at 0 and the external c-pointer *wasm_memory if the VM provides it diff --git a/test/test.html b/test/test.html index d0ff8475..568d777c 100644 --- a/test/test.html +++ b/test/test.html @@ -8,7 +8,11 @@
- + + + + + @@ -94,6 +98,7 @@ $ = id => document.getElementById(id), // .bind(document); for debugging ignore = x => x nop = x => ignore(x) + const string_mask_64 = 0xFF10000000000000n // n means BigInt("…") const string_header_64 = 0x0010000000000000n // n means BigInt("…") const double_mask_64 = 0x7F00000000000000n const negative_mask_64 = 0xFF00000000000000n @@ -105,14 +110,13 @@ // let table_size = 294 let memory = new WebAssembly.Memory({initial: memory_size, maximum: 65336}); + const hex = x => x >= 0 ? x.toString(16) : `0x${((BigInt(1) << BigInt(64)) + BigInt(x)).toString(16)}` - // todo negative bigint! - let hex = x => x >= 0 ? x.toString(16) : (BigInt(0xFFFFFFFF) + BigInt(x) + BigInt(1)).toString(16); - + // (BigInt(1) << (BigInt(x.toString(2).length))) + BigInt(x).toString(16); function is_smart_pointer(result) { let got_smart_pointer = Number.isInteger(result) && (result >= 0x10000000 || result <= -0x10000000); - if (typeof result === "bigint") got_smart_pointer = result >= BigInt(0x4000000000000000) - if (typeof result === "bigint") got_smart_pointer ||= (result & string_header_64) + if (typeof result === "bigint") got_smart_pointer = result >= BigInt(0x4000000000000000) && result <= BigInt(0x7FFFFFFFFFFFFFFF); + if (typeof result === "bigint") got_smart_pointer ||= ((result & string_mask_64) == string_header_64) if (typeof result === "bigint" || got_smart_pointer) console.log(">>> 0x", hex(result), got_smart_pointer ? " SMART " : ""); if (Array.isArray(result)) got_smart_pointer = true;// multivalue of length 2 always assumed smart pair @@ -278,6 +282,7 @@ // let table = new WebAssembly.Table({initial: table_size, maximum: table_size, element: "anyfunc"}); let imports = { wasi_unstable: {proc_exit: terminate, fd_write: log, fd_read: nop, fd_seek: nop, fd_close: nop}, + wasi_snapshot_preview1: {proc_exit: terminate, fd_write: log, fd_read: nop, fd_seek: nop, fd_close: nop}, env: { memory, // table,