diff --git a/Makefile b/Makefile
index 64a14de..6a00160 100644
--- a/Makefile
+++ b/Makefile
@@ -9,8 +9,8 @@ all: wl
wl: wl.c wl.h main.c
gcc main.c wl.c -o wl -g3 -O0
-test: wl.c wl.h test.c
- gcc test.c wl.c -o test -g3 -O0
+test: wl.c wl.h tests/test.c
+ gcc tests/test.c wl.c -o test -g3 -O0
coverage:
gcc main.c wl.c -o wl_cov -g3 -O0 --coverage -fprofile-arcs -ftest-coverage
@@ -22,8 +22,8 @@ coverage_report:
lcov --remove coverage.info '/usr/*' --output-file coverage_filtered.info
genhtml coverage_filtered.info --output-directory coverage_html --title "WL Template Engine Coverage"
-fuzz: fuzz.c wl.c wl.h
- $(AFL_CC) fuzz.c wl.c -o fuzz \
+fuzz: tests/fuzz.c wl.c wl.h
+ $(AFL_CC) tests/fuzz.c wl.c -o fuzz \
-g -O3 -Wall \
-fsanitize=address,undefined \
-fno-omit-frame-pointer
diff --git a/TODO.md b/TODO.md
index dddb01c..feb7920 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,2 +1,4 @@
* Don't allow [] selections to go over newlines
-* Make sure maps and arrays can be keys of a map
+* Make sure maps and arrays can't be keys of a map
+* Decide and document how comments work
+* Improve the formatting of the output
diff --git a/examples/loop.wl b/examples/loop.wl
new file mode 100644
index 0000000..6dbe761
--- /dev/null
+++ b/examples/loop.wl
@@ -0,0 +1,17 @@
+let items = ['Apple', 'Orange', 'Strawberry']
+
+let list =
+
+ \for item in items:
+ - \{escape item}
+
+
+
+
+ Fruit List
+
+
+ My list:
+ \{list}
+
+
diff --git a/examples/procedure.wl b/examples/procedure.wl
new file mode 100644
index 0000000..d914ea6
--- /dev/null
+++ b/examples/procedure.wl
@@ -0,0 +1,13 @@
+
+procedure my_page_template(title, content) {
+
+
+ \{escape title}
+
+
+ \{content}
+
+
+}
+
+my_page_template("Welcome to my webpage!", Content of my page)
diff --git a/examples/procedure_2.wl b/examples/procedure_2.wl
new file mode 100644
index 0000000..bd54483
--- /dev/null
+++ b/examples/procedure_2.wl
@@ -0,0 +1,73 @@
+
+let comments = [
+ {
+ 'content': 'Cool post!',
+ 'children': [
+ {
+ 'content': 'True!',
+ 'children': []
+ }
+ ]
+ },
+ {
+ 'content': 'I don\'t agree with the second section..',
+ 'children': [
+ {
+ 'content': 'You\'re wrong!',
+ 'children': [
+ {
+ 'content': 'No, YOU are wrong!',
+ 'children' : []
+ }
+ ]
+ }
+ ]
+ },
+]
+
+procedure render_comment_subtree(comment) {
+
+}
+
+
+
+
+
+
+
+
+
+ A Very Cool Post
+
+ Section 1
+
+
+ This language is cool
+
+
+ Section 2
+
+
+ You should try it out
+
+
+
+
+
+
+
+
diff --git a/file.wl b/file.wl
deleted file mode 100644
index 7fd74f0..0000000
--- a/file.wl
+++ /dev/null
@@ -1,7 +0,0 @@
-
-procedure page(title, lang)
-
- \{title}
-
-
-page("Hello, world!", "it")
\ No newline at end of file
diff --git a/fuzz.c b/tests/fuzz.c
similarity index 92%
rename from fuzz.c
rename to tests/fuzz.c
index a615897..4895ea6 100644
--- a/fuzz.c
+++ b/tests/fuzz.c
@@ -2,7 +2,7 @@
#include
#include
#include
-#include "wl.h"
+#include "../wl.h"
#define MAX_INPUT_SIZE (64 * 1024) // 64KB max input
#define ARENA_SIZE (1 << 20) // 1MB arena
@@ -29,33 +29,33 @@ int main(int argc, char **argv)
// AFL persistent mode: loop up to 1000 times per process
while (__AFL_LOOP(1000)) {
int len = __AFL_FUZZ_TESTCASE_LEN;
-
+
// Limit input size
if (len > MAX_INPUT_SIZE) {
len = MAX_INPUT_SIZE;
}
-
+
// Reset arena for each iteration
WL_Arena arena = { mem, ARENA_SIZE, 0 };
-
+
// Initialize compiler
WL_Compiler *c = wl_compiler_init(&arena);
if (c == NULL) {
continue; // Out of memory, skip this input
}
-
+
// Try to compile the input
WL_AddResult res = wl_compiler_add(
- c,
+ c,
(WL_String) { "", 0 }, // empty path
(WL_String) { (char*)buf, len }
);
-
+
// If compilation succeeded, try to link
if (res.type == WL_ADD_LINK) {
WL_Program program;
int ret = wl_compiler_link(c, &program);
-
+
// If linking succeeded, optionally execute (for deeper fuzzing)
if (ret == 0) {
WL_Runtime *rt = wl_runtime_init(&arena, program);
@@ -63,12 +63,12 @@ int main(int argc, char **argv)
// Execute up to 1000 steps to avoid infinite loops
for (int i = 0; i < 1000; i++) {
WL_EvalResult eval_res = wl_runtime_eval(rt);
-
- if (eval_res.type == WL_EVAL_DONE ||
+
+ if (eval_res.type == WL_EVAL_DONE ||
eval_res.type == WL_EVAL_ERROR) {
break;
}
-
+
// Handle syscalls/sysvars by pushing dummy values
if (eval_res.type == WL_EVAL_SYSVAR) {
wl_push_s64(rt, 42);
@@ -79,10 +79,10 @@ int main(int argc, char **argv)
}
}
}
-
+
// Arena is automatically reset on next iteration
}
free(mem);
return 0;
-}
\ No newline at end of file
+}
diff --git a/fuzz_input/000.wl b/tests/fuzz_input/000.wl
similarity index 100%
rename from fuzz_input/000.wl
rename to tests/fuzz_input/000.wl
diff --git a/fuzz_input/001.wl b/tests/fuzz_input/001.wl
similarity index 100%
rename from fuzz_input/001.wl
rename to tests/fuzz_input/001.wl
diff --git a/fuzz_input/002.wl b/tests/fuzz_input/002.wl
similarity index 100%
rename from fuzz_input/002.wl
rename to tests/fuzz_input/002.wl
diff --git a/fuzz_input/003.wl b/tests/fuzz_input/003.wl
similarity index 100%
rename from fuzz_input/003.wl
rename to tests/fuzz_input/003.wl
diff --git a/fuzz_input/004.wl b/tests/fuzz_input/004.wl
similarity index 100%
rename from fuzz_input/004.wl
rename to tests/fuzz_input/004.wl
diff --git a/fuzz_input/005.wl b/tests/fuzz_input/005.wl
similarity index 100%
rename from fuzz_input/005.wl
rename to tests/fuzz_input/005.wl
diff --git a/fuzz_input/006.wl b/tests/fuzz_input/006.wl
similarity index 100%
rename from fuzz_input/006.wl
rename to tests/fuzz_input/006.wl
diff --git a/fuzz_input/007.wl b/tests/fuzz_input/007.wl
similarity index 100%
rename from fuzz_input/007.wl
rename to tests/fuzz_input/007.wl
diff --git a/fuzz_input/008.wl b/tests/fuzz_input/008.wl
similarity index 100%
rename from fuzz_input/008.wl
rename to tests/fuzz_input/008.wl
diff --git a/fuzz_input/009.wl b/tests/fuzz_input/009.wl
similarity index 100%
rename from fuzz_input/009.wl
rename to tests/fuzz_input/009.wl
diff --git a/fuzz_input/010.wl b/tests/fuzz_input/010.wl
similarity index 100%
rename from fuzz_input/010.wl
rename to tests/fuzz_input/010.wl
diff --git a/fuzz_input/011.wl b/tests/fuzz_input/011.wl
similarity index 100%
rename from fuzz_input/011.wl
rename to tests/fuzz_input/011.wl
diff --git a/fuzz_input/012.wl b/tests/fuzz_input/012.wl
similarity index 100%
rename from fuzz_input/012.wl
rename to tests/fuzz_input/012.wl
diff --git a/fuzz_input/013.wl b/tests/fuzz_input/013.wl
similarity index 100%
rename from fuzz_input/013.wl
rename to tests/fuzz_input/013.wl
diff --git a/fuzz_input/014.wl b/tests/fuzz_input/014.wl
similarity index 100%
rename from fuzz_input/014.wl
rename to tests/fuzz_input/014.wl
diff --git a/fuzz_input/015.wl b/tests/fuzz_input/015.wl
similarity index 100%
rename from fuzz_input/015.wl
rename to tests/fuzz_input/015.wl
diff --git a/fuzz_input/016.wl b/tests/fuzz_input/016.wl
similarity index 100%
rename from fuzz_input/016.wl
rename to tests/fuzz_input/016.wl
diff --git a/fuzz_input/017.wl b/tests/fuzz_input/017.wl
similarity index 100%
rename from fuzz_input/017.wl
rename to tests/fuzz_input/017.wl
diff --git a/fuzz_input/018.wl b/tests/fuzz_input/018.wl
similarity index 100%
rename from fuzz_input/018.wl
rename to tests/fuzz_input/018.wl
diff --git a/fuzz_input/019.wl b/tests/fuzz_input/019.wl
similarity index 100%
rename from fuzz_input/019.wl
rename to tests/fuzz_input/019.wl
diff --git a/fuzz_input/020.wl b/tests/fuzz_input/020.wl
similarity index 100%
rename from fuzz_input/020.wl
rename to tests/fuzz_input/020.wl
diff --git a/fuzz_input/021.wl b/tests/fuzz_input/021.wl
similarity index 100%
rename from fuzz_input/021.wl
rename to tests/fuzz_input/021.wl
diff --git a/fuzz_input/022.wl b/tests/fuzz_input/022.wl
similarity index 100%
rename from fuzz_input/022.wl
rename to tests/fuzz_input/022.wl
diff --git a/fuzz_input/023.wl b/tests/fuzz_input/023.wl
similarity index 100%
rename from fuzz_input/023.wl
rename to tests/fuzz_input/023.wl
diff --git a/fuzz_input/024.wl b/tests/fuzz_input/024.wl
similarity index 100%
rename from fuzz_input/024.wl
rename to tests/fuzz_input/024.wl
diff --git a/fuzz_input/025.wl b/tests/fuzz_input/025.wl
similarity index 100%
rename from fuzz_input/025.wl
rename to tests/fuzz_input/025.wl
diff --git a/fuzz_input/026.wl b/tests/fuzz_input/026.wl
similarity index 100%
rename from fuzz_input/026.wl
rename to tests/fuzz_input/026.wl
diff --git a/fuzz_input/027.wl b/tests/fuzz_input/027.wl
similarity index 100%
rename from fuzz_input/027.wl
rename to tests/fuzz_input/027.wl
diff --git a/fuzz_input/028.wl b/tests/fuzz_input/028.wl
similarity index 100%
rename from fuzz_input/028.wl
rename to tests/fuzz_input/028.wl
diff --git a/fuzz_input/029.wl b/tests/fuzz_input/029.wl
similarity index 100%
rename from fuzz_input/029.wl
rename to tests/fuzz_input/029.wl
diff --git a/fuzz_input/030.wl b/tests/fuzz_input/030.wl
similarity index 100%
rename from fuzz_input/030.wl
rename to tests/fuzz_input/030.wl
diff --git a/fuzz_input/031.wl b/tests/fuzz_input/031.wl
similarity index 100%
rename from fuzz_input/031.wl
rename to tests/fuzz_input/031.wl
diff --git a/fuzz_input/032.wl b/tests/fuzz_input/032.wl
similarity index 100%
rename from fuzz_input/032.wl
rename to tests/fuzz_input/032.wl
diff --git a/fuzz_input/033.wl b/tests/fuzz_input/033.wl
similarity index 100%
rename from fuzz_input/033.wl
rename to tests/fuzz_input/033.wl
diff --git a/fuzz_input/034.wl b/tests/fuzz_input/034.wl
similarity index 100%
rename from fuzz_input/034.wl
rename to tests/fuzz_input/034.wl
diff --git a/fuzz_input/035.wl b/tests/fuzz_input/035.wl
similarity index 100%
rename from fuzz_input/035.wl
rename to tests/fuzz_input/035.wl
diff --git a/fuzz_input/036.wl b/tests/fuzz_input/036.wl
similarity index 100%
rename from fuzz_input/036.wl
rename to tests/fuzz_input/036.wl
diff --git a/fuzz_input/037.wl b/tests/fuzz_input/037.wl
similarity index 100%
rename from fuzz_input/037.wl
rename to tests/fuzz_input/037.wl
diff --git a/fuzz_input/038.wl b/tests/fuzz_input/038.wl
similarity index 100%
rename from fuzz_input/038.wl
rename to tests/fuzz_input/038.wl
diff --git a/fuzz_input/039.wl b/tests/fuzz_input/039.wl
similarity index 100%
rename from fuzz_input/039.wl
rename to tests/fuzz_input/039.wl
diff --git a/fuzz_input/040.wl b/tests/fuzz_input/040.wl
similarity index 100%
rename from fuzz_input/040.wl
rename to tests/fuzz_input/040.wl
diff --git a/fuzz_input/041.wl b/tests/fuzz_input/041.wl
similarity index 100%
rename from fuzz_input/041.wl
rename to tests/fuzz_input/041.wl
diff --git a/fuzz_input/042.wl b/tests/fuzz_input/042.wl
similarity index 100%
rename from fuzz_input/042.wl
rename to tests/fuzz_input/042.wl
diff --git a/fuzz_input/043.wl b/tests/fuzz_input/043.wl
similarity index 100%
rename from fuzz_input/043.wl
rename to tests/fuzz_input/043.wl
diff --git a/fuzz_input/044.wl b/tests/fuzz_input/044.wl
similarity index 100%
rename from fuzz_input/044.wl
rename to tests/fuzz_input/044.wl
diff --git a/fuzz_input/045.wl b/tests/fuzz_input/045.wl
similarity index 100%
rename from fuzz_input/045.wl
rename to tests/fuzz_input/045.wl
diff --git a/fuzz_input/046.wl b/tests/fuzz_input/046.wl
similarity index 100%
rename from fuzz_input/046.wl
rename to tests/fuzz_input/046.wl
diff --git a/fuzz_input/047.wl b/tests/fuzz_input/047.wl
similarity index 100%
rename from fuzz_input/047.wl
rename to tests/fuzz_input/047.wl
diff --git a/fuzz_input/048.wl b/tests/fuzz_input/048.wl
similarity index 100%
rename from fuzz_input/048.wl
rename to tests/fuzz_input/048.wl
diff --git a/fuzz_input/049.wl b/tests/fuzz_input/049.wl
similarity index 100%
rename from fuzz_input/049.wl
rename to tests/fuzz_input/049.wl
diff --git a/fuzz_input/050.wl b/tests/fuzz_input/050.wl
similarity index 100%
rename from fuzz_input/050.wl
rename to tests/fuzz_input/050.wl
diff --git a/fuzz_input/051.wl b/tests/fuzz_input/051.wl
similarity index 100%
rename from fuzz_input/051.wl
rename to tests/fuzz_input/051.wl
diff --git a/fuzz_input/052.wl b/tests/fuzz_input/052.wl
similarity index 100%
rename from fuzz_input/052.wl
rename to tests/fuzz_input/052.wl
diff --git a/fuzz_input/053.wl b/tests/fuzz_input/053.wl
similarity index 100%
rename from fuzz_input/053.wl
rename to tests/fuzz_input/053.wl
diff --git a/fuzz_input/054.wl b/tests/fuzz_input/054.wl
similarity index 100%
rename from fuzz_input/054.wl
rename to tests/fuzz_input/054.wl
diff --git a/fuzz_input/055.wl b/tests/fuzz_input/055.wl
similarity index 100%
rename from fuzz_input/055.wl
rename to tests/fuzz_input/055.wl
diff --git a/fuzz_input/056.wl b/tests/fuzz_input/056.wl
similarity index 100%
rename from fuzz_input/056.wl
rename to tests/fuzz_input/056.wl
diff --git a/fuzz_input/057.wl b/tests/fuzz_input/057.wl
similarity index 100%
rename from fuzz_input/057.wl
rename to tests/fuzz_input/057.wl
diff --git a/fuzz_input/058.wl b/tests/fuzz_input/058.wl
similarity index 100%
rename from fuzz_input/058.wl
rename to tests/fuzz_input/058.wl
diff --git a/fuzz_input/059.wl b/tests/fuzz_input/059.wl
similarity index 100%
rename from fuzz_input/059.wl
rename to tests/fuzz_input/059.wl
diff --git a/fuzz_input/060.wl b/tests/fuzz_input/060.wl
similarity index 100%
rename from fuzz_input/060.wl
rename to tests/fuzz_input/060.wl
diff --git a/fuzz_input/061.wl b/tests/fuzz_input/061.wl
similarity index 100%
rename from fuzz_input/061.wl
rename to tests/fuzz_input/061.wl
diff --git a/fuzz_input/062.wl b/tests/fuzz_input/062.wl
similarity index 100%
rename from fuzz_input/062.wl
rename to tests/fuzz_input/062.wl
diff --git a/fuzz_input/063.wl b/tests/fuzz_input/063.wl
similarity index 100%
rename from fuzz_input/063.wl
rename to tests/fuzz_input/063.wl
diff --git a/fuzz_input/064.wl b/tests/fuzz_input/064.wl
similarity index 100%
rename from fuzz_input/064.wl
rename to tests/fuzz_input/064.wl
diff --git a/fuzz_input/065.wl b/tests/fuzz_input/065.wl
similarity index 100%
rename from fuzz_input/065.wl
rename to tests/fuzz_input/065.wl
diff --git a/fuzz_input/066.wl b/tests/fuzz_input/066.wl
similarity index 100%
rename from fuzz_input/066.wl
rename to tests/fuzz_input/066.wl
diff --git a/fuzz_input/067.wl b/tests/fuzz_input/067.wl
similarity index 100%
rename from fuzz_input/067.wl
rename to tests/fuzz_input/067.wl
diff --git a/fuzz_input/068.wl b/tests/fuzz_input/068.wl
similarity index 100%
rename from fuzz_input/068.wl
rename to tests/fuzz_input/068.wl
diff --git a/fuzz_input/069.wl b/tests/fuzz_input/069.wl
similarity index 100%
rename from fuzz_input/069.wl
rename to tests/fuzz_input/069.wl
diff --git a/fuzz_input/070.wl b/tests/fuzz_input/070.wl
similarity index 100%
rename from fuzz_input/070.wl
rename to tests/fuzz_input/070.wl
diff --git a/fuzz_input/071.wl b/tests/fuzz_input/071.wl
similarity index 100%
rename from fuzz_input/071.wl
rename to tests/fuzz_input/071.wl
diff --git a/fuzz_input/072.wl b/tests/fuzz_input/072.wl
similarity index 100%
rename from fuzz_input/072.wl
rename to tests/fuzz_input/072.wl
diff --git a/fuzz_input/073.wl b/tests/fuzz_input/073.wl
similarity index 100%
rename from fuzz_input/073.wl
rename to tests/fuzz_input/073.wl
diff --git a/fuzz_input/074.wl b/tests/fuzz_input/074.wl
similarity index 100%
rename from fuzz_input/074.wl
rename to tests/fuzz_input/074.wl
diff --git a/fuzz_input/075.wl b/tests/fuzz_input/075.wl
similarity index 100%
rename from fuzz_input/075.wl
rename to tests/fuzz_input/075.wl
diff --git a/fuzz_input/076.wl b/tests/fuzz_input/076.wl
similarity index 100%
rename from fuzz_input/076.wl
rename to tests/fuzz_input/076.wl
diff --git a/fuzz_input/077.wl b/tests/fuzz_input/077.wl
similarity index 100%
rename from fuzz_input/077.wl
rename to tests/fuzz_input/077.wl
diff --git a/fuzz_input/078.wl b/tests/fuzz_input/078.wl
similarity index 100%
rename from fuzz_input/078.wl
rename to tests/fuzz_input/078.wl
diff --git a/fuzz_input/079.wl b/tests/fuzz_input/079.wl
similarity index 100%
rename from fuzz_input/079.wl
rename to tests/fuzz_input/079.wl
diff --git a/fuzz_input/080.wl b/tests/fuzz_input/080.wl
similarity index 100%
rename from fuzz_input/080.wl
rename to tests/fuzz_input/080.wl
diff --git a/fuzz_input/081.wl b/tests/fuzz_input/081.wl
similarity index 100%
rename from fuzz_input/081.wl
rename to tests/fuzz_input/081.wl
diff --git a/fuzz_input/082.wl b/tests/fuzz_input/082.wl
similarity index 100%
rename from fuzz_input/082.wl
rename to tests/fuzz_input/082.wl
diff --git a/fuzz_input/083.wl b/tests/fuzz_input/083.wl
similarity index 100%
rename from fuzz_input/083.wl
rename to tests/fuzz_input/083.wl
diff --git a/fuzz_input/084.wl b/tests/fuzz_input/084.wl
similarity index 100%
rename from fuzz_input/084.wl
rename to tests/fuzz_input/084.wl
diff --git a/fuzz_input/085.wl b/tests/fuzz_input/085.wl
similarity index 100%
rename from fuzz_input/085.wl
rename to tests/fuzz_input/085.wl
diff --git a/fuzz_input/086.wl b/tests/fuzz_input/086.wl
similarity index 100%
rename from fuzz_input/086.wl
rename to tests/fuzz_input/086.wl
diff --git a/fuzz_input/087.wl b/tests/fuzz_input/087.wl
similarity index 100%
rename from fuzz_input/087.wl
rename to tests/fuzz_input/087.wl
diff --git a/fuzz_input/088.wl b/tests/fuzz_input/088.wl
similarity index 100%
rename from fuzz_input/088.wl
rename to tests/fuzz_input/088.wl
diff --git a/fuzz_input/089.wl b/tests/fuzz_input/089.wl
similarity index 100%
rename from fuzz_input/089.wl
rename to tests/fuzz_input/089.wl
diff --git a/fuzz_input/090.wl b/tests/fuzz_input/090.wl
similarity index 100%
rename from fuzz_input/090.wl
rename to tests/fuzz_input/090.wl
diff --git a/fuzz_input/091.wl b/tests/fuzz_input/091.wl
similarity index 100%
rename from fuzz_input/091.wl
rename to tests/fuzz_input/091.wl
diff --git a/fuzz_input/092.wl b/tests/fuzz_input/092.wl
similarity index 100%
rename from fuzz_input/092.wl
rename to tests/fuzz_input/092.wl
diff --git a/fuzz_input/093.wl b/tests/fuzz_input/093.wl
similarity index 100%
rename from fuzz_input/093.wl
rename to tests/fuzz_input/093.wl
diff --git a/fuzz_input/094.wl b/tests/fuzz_input/094.wl
similarity index 100%
rename from fuzz_input/094.wl
rename to tests/fuzz_input/094.wl
diff --git a/fuzz_input/095.wl b/tests/fuzz_input/095.wl
similarity index 100%
rename from fuzz_input/095.wl
rename to tests/fuzz_input/095.wl
diff --git a/fuzz_input/096.wl b/tests/fuzz_input/096.wl
similarity index 100%
rename from fuzz_input/096.wl
rename to tests/fuzz_input/096.wl
diff --git a/fuzz_input/097.wl b/tests/fuzz_input/097.wl
similarity index 100%
rename from fuzz_input/097.wl
rename to tests/fuzz_input/097.wl
diff --git a/fuzz_input/098.wl b/tests/fuzz_input/098.wl
similarity index 100%
rename from fuzz_input/098.wl
rename to tests/fuzz_input/098.wl
diff --git a/fuzz_input/099.wl b/tests/fuzz_input/099.wl
similarity index 100%
rename from fuzz_input/099.wl
rename to tests/fuzz_input/099.wl
diff --git a/fuzz_input/100.wl b/tests/fuzz_input/100.wl
similarity index 100%
rename from fuzz_input/100.wl
rename to tests/fuzz_input/100.wl
diff --git a/fuzz_input/101.wl b/tests/fuzz_input/101.wl
similarity index 100%
rename from fuzz_input/101.wl
rename to tests/fuzz_input/101.wl
diff --git a/fuzz_input/102.wl b/tests/fuzz_input/102.wl
similarity index 100%
rename from fuzz_input/102.wl
rename to tests/fuzz_input/102.wl
diff --git a/fuzz_input/103.wl b/tests/fuzz_input/103.wl
similarity index 100%
rename from fuzz_input/103.wl
rename to tests/fuzz_input/103.wl
diff --git a/fuzz_input/104.wl b/tests/fuzz_input/104.wl
similarity index 100%
rename from fuzz_input/104.wl
rename to tests/fuzz_input/104.wl
diff --git a/fuzz_input/105.wl b/tests/fuzz_input/105.wl
similarity index 100%
rename from fuzz_input/105.wl
rename to tests/fuzz_input/105.wl
diff --git a/fuzz_input/106.wl b/tests/fuzz_input/106.wl
similarity index 100%
rename from fuzz_input/106.wl
rename to tests/fuzz_input/106.wl
diff --git a/fuzz_input/107.wl b/tests/fuzz_input/107.wl
similarity index 100%
rename from fuzz_input/107.wl
rename to tests/fuzz_input/107.wl
diff --git a/fuzz_input/108.wl b/tests/fuzz_input/108.wl
similarity index 100%
rename from fuzz_input/108.wl
rename to tests/fuzz_input/108.wl
diff --git a/fuzz_input/109.wl b/tests/fuzz_input/109.wl
similarity index 100%
rename from fuzz_input/109.wl
rename to tests/fuzz_input/109.wl
diff --git a/fuzz_input/110.wl b/tests/fuzz_input/110.wl
similarity index 100%
rename from fuzz_input/110.wl
rename to tests/fuzz_input/110.wl
diff --git a/fuzz_input/111.wl b/tests/fuzz_input/111.wl
similarity index 100%
rename from fuzz_input/111.wl
rename to tests/fuzz_input/111.wl
diff --git a/fuzz_input/112.wl b/tests/fuzz_input/112.wl
similarity index 100%
rename from fuzz_input/112.wl
rename to tests/fuzz_input/112.wl
diff --git a/test.c b/tests/test.c
similarity index 99%
rename from test.c
rename to tests/test.c
index 4357dde..3ccd2cd 100644
--- a/test.c
+++ b/tests/test.c
@@ -3,7 +3,7 @@
#include
#include
#include
-#include "wl.h"
+#include "../wl.h"
#define COUNT(X) (int) (sizeof(X) / sizeof((X)[0]))
diff --git a/wl.c b/wl.c
index 76e9e09..5042502 100644
--- a/wl.c
+++ b/wl.c
@@ -197,14 +197,8 @@ static void write_raw_mem(Writer *w, void *ptr, int len)
}
static void write_raw_u8 (Writer *w, uint8_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
-//static void write_raw_u16(Writer *w, uint16_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
static void write_raw_u32(Writer *w, uint32_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
-//static void write_raw_u64(Writer *w, uint64_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
-//static void write_raw_s8 (Writer *w, int8_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
-//static void write_raw_s16(Writer *w, int16_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
-//static void write_raw_s32(Writer *w, int32_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
static void write_raw_s64(Writer *w, int64_t x) { write_raw_mem(w, &x, SIZEOF(x)); }
-//static void write_raw_f32(Writer *w, float x) { write_raw_mem(w, &x, SIZEOF(x)); }
static void write_raw_f64(Writer *w, double x) { write_raw_mem(w, &x, SIZEOF(x)); }
static void write_text(Writer *w, String str)
@@ -426,47 +420,47 @@ static void write_token(Writer *w, Token token)
{
switch (token.type) {
- default : write_text(w, S("???")); break;
- case TOKEN_END : write_text(w, S("")); break;
- case TOKEN_ERROR : write_text(w, S("")); break;
- case TOKEN_IDENT : write_text(w, token.sval); break;
- case TOKEN_KWORD_IF : write_text(w, S("if")); break;
- case TOKEN_KWORD_ELSE : write_text(w, S("else")); break;
- case TOKEN_KWORD_WHILE : write_text(w, S("while")); break;
- case TOKEN_KWORD_FOR : write_text(w, S("for")); break;
- case TOKEN_KWORD_IN : write_text(w, S("in")); break;
+ default : write_text(w, S("???")); break;
+ case TOKEN_END : write_text(w, S("")); break;
+ case TOKEN_ERROR : write_text(w, S("")); break;
+ case TOKEN_IDENT : write_text(w, token.sval); break;
+ case TOKEN_KWORD_IF : write_text(w, S("if")); break;
+ case TOKEN_KWORD_ELSE : write_text(w, S("else")); break;
+ case TOKEN_KWORD_WHILE : write_text(w, S("while")); break;
+ case TOKEN_KWORD_FOR : write_text(w, S("for")); break;
+ case TOKEN_KWORD_IN : write_text(w, S("in")); break;
case TOKEN_KWORD_PROCEDURE: write_text(w, S("procedure")); break;
- case TOKEN_KWORD_LET : write_text(w, S("let")); break;
- case TOKEN_KWORD_NONE : write_text(w, S("none")); break;
- case TOKEN_KWORD_TRUE : write_text(w, S("true")); break;
- case TOKEN_KWORD_FALSE : write_text(w, S("false")); break;
- case TOKEN_KWORD_INCLUDE: write_text(w, S("include")); break;
- case TOKEN_KWORD_LEN : write_text(w, S("len")); break;
- case TOKEN_KWORD_ESCAPE: write_text(w, S("escape")); break;
- case TOKEN_VALUE_FLOAT : write_text_f64(w, token.fval); break;
- case TOKEN_VALUE_INT : write_text_s64(w, token.ival); break;
- case TOKEN_OPER_ASS : write_text(w, S("=")); break;
- case TOKEN_OPER_EQL : write_text(w, S("==")); break;
- case TOKEN_OPER_NQL : write_text(w, S("!=")); break;
- case TOKEN_OPER_LSS : write_text(w, S("<")); break;
- case TOKEN_OPER_GRT : write_text(w, S(">")); break;
- case TOKEN_OPER_ADD : write_text(w, S("+")); break;
- case TOKEN_OPER_SUB : write_text(w, S("-")); break;
- case TOKEN_OPER_MUL : write_text(w, S("*")); break;
- case TOKEN_OPER_DIV : write_text(w, S("/")); break;
- case TOKEN_OPER_MOD : write_text(w, S("%")); break;
- case TOKEN_OPER_SHOVEL : write_text(w, S("<<")); break;
- case TOKEN_PAREN_OPEN : write_text(w, S("(")); break;
- case TOKEN_PAREN_CLOSE : write_text(w, S(")")); break;
- case TOKEN_BRACKET_OPEN : write_text(w, S("[")); break;
- case TOKEN_BRACKET_CLOSE: write_text(w, S("]")); break;
- case TOKEN_CURLY_OPEN : write_text(w, S("{")); break;
- case TOKEN_CURLY_CLOSE : write_text(w, S("}")); break;
- case TOKEN_DOT : write_text(w, S(".")); break;
- case TOKEN_COMMA : write_text(w, S(",")); break;
- case TOKEN_COLON : write_text(w, S(":")); break;
- case TOKEN_DOLLAR : write_text(w, S("$")); break;
- case TOKEN_NEWLINE : write_text(w, S("\\n")); break;
+ case TOKEN_KWORD_LET : write_text(w, S("let")); break;
+ case TOKEN_KWORD_NONE : write_text(w, S("none")); break;
+ case TOKEN_KWORD_TRUE : write_text(w, S("true")); break;
+ case TOKEN_KWORD_FALSE : write_text(w, S("false")); break;
+ case TOKEN_KWORD_INCLUDE : write_text(w, S("include")); break;
+ case TOKEN_KWORD_LEN : write_text(w, S("len")); break;
+ case TOKEN_KWORD_ESCAPE : write_text(w, S("escape")); break;
+ case TOKEN_VALUE_FLOAT : write_text_f64(w, token.fval); break;
+ case TOKEN_VALUE_INT : write_text_s64(w, token.ival); break;
+ case TOKEN_OPER_ASS : write_text(w, S("=")); break;
+ case TOKEN_OPER_EQL : write_text(w, S("==")); break;
+ case TOKEN_OPER_NQL : write_text(w, S("!=")); break;
+ case TOKEN_OPER_LSS : write_text(w, S("<")); break;
+ case TOKEN_OPER_GRT : write_text(w, S(">")); break;
+ case TOKEN_OPER_ADD : write_text(w, S("+")); break;
+ case TOKEN_OPER_SUB : write_text(w, S("-")); break;
+ case TOKEN_OPER_MUL : write_text(w, S("*")); break;
+ case TOKEN_OPER_DIV : write_text(w, S("/")); break;
+ case TOKEN_OPER_MOD : write_text(w, S("%")); break;
+ case TOKEN_OPER_SHOVEL : write_text(w, S("<<")); break;
+ case TOKEN_PAREN_OPEN : write_text(w, S("(")); break;
+ case TOKEN_PAREN_CLOSE : write_text(w, S(")")); break;
+ case TOKEN_BRACKET_OPEN : write_text(w, S("[")); break;
+ case TOKEN_BRACKET_CLOSE : write_text(w, S("]")); break;
+ case TOKEN_CURLY_OPEN : write_text(w, S("{")); break;
+ case TOKEN_CURLY_CLOSE : write_text(w, S("}")); break;
+ case TOKEN_DOT : write_text(w, S(".")); break;
+ case TOKEN_COMMA : write_text(w, S(",")); break;
+ case TOKEN_COLON : write_text(w, S(":")); break;
+ case TOKEN_DOLLAR : write_text(w, S("$")); break;
+ case TOKEN_NEWLINE : write_text(w, S("\\n")); break;
case TOKEN_VALUE_STR:
write_text(w, S("\""));
@@ -547,19 +541,19 @@ static Token next_token(Parser *p)
p->s.cur - start
};
- if (streq(kword, S("if"))) return (Token) { .type=TOKEN_KWORD_IF };
- if (streq(kword, S("else"))) return (Token) { .type=TOKEN_KWORD_ELSE };
- if (streq(kword, S("while"))) return (Token) { .type=TOKEN_KWORD_WHILE };
- if (streq(kword, S("for"))) return (Token) { .type=TOKEN_KWORD_FOR };
- if (streq(kword, S("in"))) return (Token) { .type=TOKEN_KWORD_IN };
+ if (streq(kword, S("if"))) return (Token) { .type=TOKEN_KWORD_IF };
+ if (streq(kword, S("else"))) return (Token) { .type=TOKEN_KWORD_ELSE };
+ if (streq(kword, S("while"))) return (Token) { .type=TOKEN_KWORD_WHILE };
+ if (streq(kword, S("for"))) return (Token) { .type=TOKEN_KWORD_FOR };
+ if (streq(kword, S("in"))) return (Token) { .type=TOKEN_KWORD_IN };
if (streq(kword, S("procedure"))) return (Token) { .type=TOKEN_KWORD_PROCEDURE };
- if (streq(kword, S("let"))) return (Token) { .type=TOKEN_KWORD_LET };
- if (streq(kword, S("none"))) return (Token) { .type=TOKEN_KWORD_NONE };
- if (streq(kword, S("true"))) return (Token) { .type=TOKEN_KWORD_TRUE };
- if (streq(kword, S("false"))) return (Token) { .type=TOKEN_KWORD_FALSE };
- if (streq(kword, S("include"))) return (Token) { .type=TOKEN_KWORD_INCLUDE };
- if (streq(kword, S("len"))) return (Token) { .type=TOKEN_KWORD_LEN };
- if (streq(kword, S("escape"))) return (Token) { .type=TOKEN_KWORD_ESCAPE };
+ if (streq(kword, S("let"))) return (Token) { .type=TOKEN_KWORD_LET };
+ if (streq(kword, S("none"))) return (Token) { .type=TOKEN_KWORD_NONE };
+ if (streq(kword, S("true"))) return (Token) { .type=TOKEN_KWORD_TRUE };
+ if (streq(kword, S("false"))) return (Token) { .type=TOKEN_KWORD_FALSE };
+ if (streq(kword, S("include"))) return (Token) { .type=TOKEN_KWORD_INCLUDE };
+ if (streq(kword, S("len"))) return (Token) { .type=TOKEN_KWORD_LEN };
+ if (streq(kword, S("escape"))) return (Token) { .type=TOKEN_KWORD_ESCAPE };
return (Token) { .type=TOKEN_IDENT, .sval=kword };
}
@@ -695,28 +689,27 @@ static Token next_token(Parser *p)
return (Token) { .type=TOKEN_VALUE_STR, .sval=(String) { .ptr=buf, .len=len } };
}
- if (consume_str(&p->s, S("<<"))) return (Token) { .type=TOKEN_OPER_SHOVEL };
- if (consume_str(&p->s, S("=="))) return (Token) { .type=TOKEN_OPER_EQL };
- if (consume_str(&p->s, S("!="))) return (Token) { .type=TOKEN_OPER_NQL };
- if (consume_str(&p->s, S("<"))) return (Token) { .type=TOKEN_OPER_LSS };
- if (consume_str(&p->s, S(">"))) return (Token) { .type=TOKEN_OPER_GRT };
- if (consume_str(&p->s, S("+"))) return (Token) { .type=TOKEN_OPER_ADD };
- if (consume_str(&p->s, S("-"))) return (Token) { .type=TOKEN_OPER_SUB };
- if (consume_str(&p->s, S("*"))) return (Token) { .type=TOKEN_OPER_MUL };
- if (consume_str(&p->s, S("/"))) return (Token) { .type=TOKEN_OPER_DIV };
- if (consume_str(&p->s, S("%"))) return (Token) { .type=TOKEN_OPER_MOD };
- if (consume_str(&p->s, S("="))) return (Token) { .type=TOKEN_OPER_ASS };
-
- if (consume_str(&p->s, S("("))) return (Token) { .type=TOKEN_PAREN_OPEN };
- if (consume_str(&p->s, S(")"))) return (Token) { .type=TOKEN_PAREN_CLOSE };
- if (consume_str(&p->s, S("["))) return (Token) { .type=TOKEN_BRACKET_OPEN };
+ if (consume_str(&p->s, S("<<"))) return (Token) { .type=TOKEN_OPER_SHOVEL };
+ if (consume_str(&p->s, S("=="))) return (Token) { .type=TOKEN_OPER_EQL };
+ if (consume_str(&p->s, S("!="))) return (Token) { .type=TOKEN_OPER_NQL };
+ if (consume_str(&p->s, S("<"))) return (Token) { .type=TOKEN_OPER_LSS };
+ if (consume_str(&p->s, S(">"))) return (Token) { .type=TOKEN_OPER_GRT };
+ if (consume_str(&p->s, S("+"))) return (Token) { .type=TOKEN_OPER_ADD };
+ if (consume_str(&p->s, S("-"))) return (Token) { .type=TOKEN_OPER_SUB };
+ if (consume_str(&p->s, S("*"))) return (Token) { .type=TOKEN_OPER_MUL };
+ if (consume_str(&p->s, S("/"))) return (Token) { .type=TOKEN_OPER_DIV };
+ if (consume_str(&p->s, S("%"))) return (Token) { .type=TOKEN_OPER_MOD };
+ if (consume_str(&p->s, S("="))) return (Token) { .type=TOKEN_OPER_ASS };
+ if (consume_str(&p->s, S("("))) return (Token) { .type=TOKEN_PAREN_OPEN };
+ if (consume_str(&p->s, S(")"))) return (Token) { .type=TOKEN_PAREN_CLOSE };
+ if (consume_str(&p->s, S("["))) return (Token) { .type=TOKEN_BRACKET_OPEN };
if (consume_str(&p->s, S("]"))) return (Token) { .type=TOKEN_BRACKET_CLOSE };
- if (consume_str(&p->s, S("{"))) return (Token) { .type=TOKEN_CURLY_OPEN };
- if (consume_str(&p->s, S("}"))) return (Token) { .type=TOKEN_CURLY_CLOSE };
- if (consume_str(&p->s, S("."))) return (Token) { .type=TOKEN_DOT };
- if (consume_str(&p->s, S(","))) return (Token) { .type=TOKEN_COMMA };
- if (consume_str(&p->s, S(":"))) return (Token) { .type=TOKEN_COLON };
- if (consume_str(&p->s, S("$"))) return (Token) { .type=TOKEN_DOLLAR };
+ if (consume_str(&p->s, S("{"))) return (Token) { .type=TOKEN_CURLY_OPEN };
+ if (consume_str(&p->s, S("}"))) return (Token) { .type=TOKEN_CURLY_CLOSE };
+ if (consume_str(&p->s, S("."))) return (Token) { .type=TOKEN_DOT };
+ if (consume_str(&p->s, S(","))) return (Token) { .type=TOKEN_COMMA };
+ if (consume_str(&p->s, S(":"))) return (Token) { .type=TOKEN_COLON };
+ if (consume_str(&p->s, S("$"))) return (Token) { .type=TOKEN_DOLLAR };
parser_report(p, "Invalid character '%c'", c);
return (Token) { .type=TOKEN_ERROR };
@@ -977,7 +970,7 @@ static Node *parse_map(Parser *p)
saved = p->s;
t = next_token(p);
if (t.type == TOKEN_IDENT) {
-
+
key = alloc_node(p);
if (key == NULL)
return NULL;
@@ -2568,7 +2561,7 @@ static void cg_pop_scope(Codegen *cg)
return;
}
call->next = parent_scope->calls;
- parent_scope->calls = call;
+ parent_scope->calls = call;
continue;
}
@@ -2656,9 +2649,6 @@ static void walk_node(Codegen *cg, Node *node, bool inside_html);
static void walk_expr_node(Codegen *cg, Node *node, bool one)
{
- // TODO: remove
- ASSERT(cg->scopes[cg->num_scopes-1].calls == NULL || (cg->scopes[cg->num_scopes-1].calls - cg->calls >= 0 && cg->scopes[cg->num_scopes-1].calls - cg->calls < MAX_UNPATCHED_CALLS));
-
switch (node->type) {
case NODE_NESTED:
@@ -2942,7 +2932,7 @@ static void walk_expr_node(Codegen *cg, Node *node, bool one)
Node *proc = node->left;
if (proc->type == NODE_VALUE_VAR) {
-
+
cg_write_opcode(cg, OPCODE_CALL);
cg_write_u8(cg, count);
int p = cg_write_u32(cg, 0);
@@ -2968,9 +2958,6 @@ static void walk_expr_node(Codegen *cg, Node *node, bool one)
static void walk_node(Codegen *cg, Node *node, bool inside_html)
{
- // TODO: remove
- ASSERT(cg->scopes[cg->num_scopes-1].calls == NULL || (cg->scopes[cg->num_scopes-1].calls - cg->calls >= 0 && cg->scopes[cg->num_scopes-1].calls - cg->calls < MAX_UNPATCHED_CALLS));
-
switch (node->type) {
case NODE_GLOBAL:
@@ -3666,8 +3653,6 @@ WL_AddResult wl_compiler_add(WL_Compiler *compiler, WL_String path, WL_String co
ASSERT(0); // TODO
}
- // TODO: Make the path relative to the compiled file
-
compiler->waiting_file = include->include_path;
return (WL_AddResult) { .type=WL_ADD_AGAIN, .path={ include->include_path.ptr, include->include_path.len } };
}
@@ -3841,45 +3826,6 @@ static String value_to_str(Value v)
return (String) { p->data, p->len };
}
-/*
-
-2 bits -> 2^2 = 4
-
-00000 0 .
-00001 1 .
-00010 2 .
-00011 3 .
-00100 4 .
-00101 5 .
-00110 6 .
-00111 7 .
-01000 8
-01001 9
-01010 10
-01011 11
-01100 12
-01101 13
-01110 14
-01111 15
-10000 -16
-10001 -15
-10010 -14
-10011 -13
-10100 -12
-10101 -11
-10110 -10
-10111 -9
-11000 -8 .
-11001 -7 .
-11010 -6 .
-11011 -5 .
-11100 -4 .
-11101 -3 .
-11110 -2 .
-11111 -1 .
-
-*/
-
static Value value_from_s64(int64_t x, WL_Arena *arena, Error *err)
{
Value v = (Value) x;
@@ -4008,7 +3954,7 @@ static Value *aggregate_select(AggregateValue *agg, Value key)
}
return NULL;
-
+
} else {
ASSERT(agg->type == TYPE_ARRAY);
@@ -4260,7 +4206,7 @@ static Value value_neg(Value v, WL_Arena *arena, Error *err)
Type t = value_type(v);
if (t == TYPE_INT)
return value_from_s64(-value_to_s64(v), arena, err); // TODO: overflow
-
+
if (t == TYPE_FLOAT)
return value_from_f64(-value_to_f64(v), arena, err);
@@ -5906,7 +5852,7 @@ void wl_runtime_dump(WL_Runtime *rt)
{
for (int i = 0; i < rt->num_frames; i++) {
printf("=== frame %d ===\n", i);
-
+
Frame *frame = &rt->frames[i];
int num_vars;
\{escape comment.content}
+