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
|
#include <emscripten.h>
void print(const char *prefix, int v) {
int *x = (int*)8; // XXX this order is wrong!
*x = (int)prefix;
int *y = (int*)16;
*y = v;
EM_ASM({
Module.print("print: " + Pointer_stringify(HEAP32[8>>2]) + " : " + HEAP32[16>>2]);
});
}
void something() {
print("something", 12);
}
void more() {
print("more", -1);
}
void other(int x) {
print("other", x + 40);
}
void yet(int x) {
print("yet", x + 99);
}
typedef void (*v)();
typedef void (*vi)(int);
int main(int argc, char **argv) {
print("argc", argc);
v f1[4] = { something, more, something, more };
print("addr of something", (int)&something);
print("addr of more", (int)&more);
for (int i = 0; i < 4 && i < argc*4; i++) {
print("i", i);
v curr = f1[i];
//print("curr address to call", (int)curr);
curr();
}
vi f2[4] = { other, yet, other, yet };
for (int i = 0; i < 4 && i < argc*4; i++) {
vi curr = f2[i];
//print("curr", (int)curr);
curr(i);
}
}
|