-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemscripten_debug_shell.html
140 lines (115 loc) · 3.39 KB
/
emscripten_debug_shell.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!doctype html>
<html Module="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
textarea.emscripten { font-family: monospace; width: 80%; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 1px solid black; }
</style>
</head>
<body>
<textarea class="emscripten" id="output" rows="12"></textarea>
<script type='text/javascript'>
var Module = {
preRun: [],
postRun: [],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})()
};
let path = "input.wil";
let test_data =
`
extern fn printf(str: char*, variadic) : int
extern fn assert(condition: bool)
const static_array_length = 12
struct list_holder
{
list: int[]
}
fn print_list_stats(list: int[])
{
let len := list.length()
let cap := list.capacity()
printf("\nlist:\nlength: %d,\ncapacity:%d", len, cap)
}
fn append_twice(list: int[], element: int)
{
list.add(element)
list.add(element)
}
fn main ()
{
let some_list := new int[]
let some_list_pointer_copy := some_list
let holder_one := new list_holder
holder_one.list = some_list
let holder_two := new list_holder
holder_two.list = some_list
some_list.add(1)
some_list.add(2)
some_list.add(3)
holder_one.list.add(4)
holder_two.list.add(5)
assert(some_list[0] == 1)
assert(some_list[1] == 2)
assert(some_list[2] == 3)
assert(some_list[3] == 4)
assert(some_list[4] == 5)
assert(holder_one.list[0] == 1)
assert(holder_one.list[1] == 2)
assert(holder_one.list[2] == 3)
assert(holder_one.list[3] == 4)
assert(holder_one.list[4] == 5)
print_list_stats(holder_one.list)
print_list_stats(holder_two.list)
append_twice(holder_one.list, 6)
append_twice(holder_two.list, 6)
print_list_stats(some_list_pointer_copy)
if (some_list.add(4))
{
printf("\ntest if", 0)
}
for (let x := new int[], x.capacity() < 5, x.add(2))
{
printf("\ntest for", 0)
}
let auto_list := auto int[]
auto_list[0] = 1
auto_list[1] = 2
auto_list[2] = 3
assert(auto_list[0] == 1)
assert(auto_list[1] == 2)
assert(auto_list[2] == 3)
}
`;
let main_called = false;
function run_test(){
FS.writeFile(path, test_data);
if ((FS.stat("input.wil").size == test_data.length)){
if (false == main_called){
Module.callMain();
main_called = true;
}
Module._compile_input(COMPILER_OPTION_RUN | COMPILER_OPTION_SHOW_AST);
} else{
console.error("file length is not equal")
}
}
</script>
{{{ SCRIPT }}}
</body>
</html>