Skip to content

Commit

Permalink
CURRENT TESTS PASSED
Browse files Browse the repository at this point in the history
next: canvas
  • Loading branch information
pannous committed Dec 27, 2023
1 parent d5222e7 commit 9dd022c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(X86_64 1)
endif ()

# ⚠️ SET these configurations via CLion Preferences… Build->CMake->Profiles
# ⚠️ 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:
#set(NO_TESTS 1) # no tests
#set(RUNTIME_ONLY 1) # no Angle eval emit merge etc! ≠ NO_TESTS
#set(VERBOSE 1)
#set(DEBUG 1)
#set(TRACE 1)
set(STRICT 1)
#set(SDL 1) # Graphics
#set(WASM 1) # no WebView, duh SET VIA TOOLCHAIN!
#set(WASM 1) # SET VIA TOOLCHAIN!
#set(INCLUDE_MERGER 0) # include wasm_linker.cpp
#set(WABT_MERGE 1) # not the whole WABT though, heavy
#ADD_DEFINITIONS(-DMULTI_VALUE) # change ABI to always return (value, type) tuple
Expand Down Expand Up @@ -193,7 +194,10 @@ endif ()
ADD_COMPILE_FLAG("-fno-inline") # why not? debug?

# ENABLE:
#ADD_COMPILE_FLAG("-Werror") # WARNINGS AS ERRORS! use -Wno-error=… for exceptions
if (STRICT)
ADD_COMPILE_FLAG("-Wall")
ADD_COMPILE_FLAG("-Werror") # WARNINGS AS ERRORS! use -Wno-error=… for exceptions
endif ()
ADD_COMPILE_FLAG("-Wformat") # essential !! print("%s",string) => memory corruption!
ADD_COMPILE_FLAG("-Wreturn-type") # VERY USEFUL : non-void function does not return a value
ADD_COMPILE_FLAG("-Wunused-result") # VERY USEFUL : check for nodiscard, e.g. in non-self-modifying replace()
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ <h2>A new programming language for wasm</h2>
<script type="text/javascript">
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
// draw a red rectangle
ctx.fillStyle = 'red';
ctx.fillRect(10, 10, 150, 100);
</script>

</body>
Expand Down
19 changes: 12 additions & 7 deletions source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@

#define assert_parses(marka) result=assert_parsesx(marka);if(result==ERROR){printf("NOT PARSING %s\n",marka);backtrace_line();}

void testDom() {

void testCanvas() {
result = analyze(parse("$canvas"));
assert_equals(result.kind, (int64) externref);
auto nod = eval("$canvas;123");
auto nod = eval(" ctx = $canvas.getContext('2d');\n"
" ctx.fillStyle = 'red';\n"
" ctx.fillRect(10, 10, 150, 100);");
print(nod);
}

void testDom() {
result = analyze(parse("$canvas"));
assert_equals(result.kind, (int64) externref);
// embedder.trace('canvas = document.getElementById("canvas");')
// print(nod);
}

void testTypes() {
Expand Down Expand Up @@ -668,7 +677,7 @@ void testHyphenUnits() {
}

void testHypenVersusMinus() {
const char *code = "a=1 b=2 b-a";
const char *code = "a=-1 b=2 b-a";
assert_emit(code, 3);
// kebab case
const char *data = "a-b:2 c-d:4 a-b";
Expand Down Expand Up @@ -3273,15 +3282,11 @@ void testCurrent() {


// exit(1);
assert_emit("(2 4 3)[1]", 4);
assert_eval("if (0) {3}", false);

testSubGroupingFlatten();
testTypedFunctions();
testTypes();
testPolymorphism();
// assert_emit("√3^2", 3)
// testSinus();
testDom();
// testKebabCase();
skip(
Expand Down
2 changes: 1 addition & 1 deletion source/wasm_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ Code emitOperator(Node &node, Function &context) {
code.add(0x01); // todo: memory index argument!?
if (last_type == none or last_type == voids)
last_type = i32t;
if (opcode >= 0x45 and opcode <= 0x78 or opcode == string_eq)
if ((opcode >= 0x45 and opcode <= 0x78) or opcode == string_eq)
last_type = i32;// int ops (also f64.eqz …)
} else if (name == "²") {
// error("this should be handled universally in analyse: x² => x*x no matter what!");
Expand Down

0 comments on commit 9dd022c

Please sign in to comment.