Skip to content

Commit

Permalink
CURRENT TESTS PASSED
Browse files Browse the repository at this point in the history
  • Loading branch information
pannous committed Sep 30, 2024
1 parent c1bfd4a commit 404b68a
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 41 deletions.
26 changes: 11 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
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
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:
Expand Down Expand Up @@ -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 !?
Expand Down Expand Up @@ -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})
Expand Down
3 changes: 2 additions & 1 deletion docs/assets/script/wasp_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand Down
1 change: 1 addition & 0 deletions source/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions source/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions source/WebApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int64 open_webview(String url = "") {

// add [w] to closure to make it local
view.set_title("Example");
view.set_html("<script>alert('js injected into every page')</script>");
// view.set_html("<script>alert('js injected into every page')</script>");
// 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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/WebView.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}

Expand All @@ -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);

Expand All @@ -3444,7 +3446,7 @@ void testCurrent() {
// testReplaceAll();
// testFetch();
// return;
testDomProperty();
// testDomProperty();
// testInnerHtml();
// return;
#if WEBAPP
Expand Down
7 changes: 5 additions & 2 deletions source/wasm_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}


Expand Down
4 changes: 2 additions & 2 deletions source/wasm_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
</head>
<!--onclick='test().then(_=>terminate0())' -->
<body onload="test()" style='height: 1000px;'>
<script src='webgl.js'></script><!--not allowed to access local resource--> <!-- start wasp in server mode!-->
<script src='../samples/webgl.js'></script><!--not allowed to access local resource-->
<!-- start wasp in server mode!-->
<!--<script src='../docs/wasp.js'></script>-->
<!--<script src='https://wasp.pannous.com/wasp.js'></script>-->


<!-- http://dataurl.net/#dataurlmaker -->

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 404b68a

Please sign in to comment.