@@ -1,3+1,4@@ |
||
1 |
+#include <stdint.h> |
|
1 | 2 |
#include <stdio.h> |
2 | 3 |
|
3 | 4 |
#define ASIZE(x) (sizeof((x)) / sizeof((x)[0])) |
@@ -10,18+11,15@@unsigned stack_p; |
||
10 | 11 |
void push(int value) { stack[stack_p++] = value; } |
11 | 12 |
int pop(void) { return stack[--stack_p]; } |
12 | 13 |
|
13 |
-instruction put_0; |
|
14 |
-instruction increment; |
|
14 |
+instruction lit; |
|
15 | 15 |
|
16 | 16 |
instruction *prog[] = { |
17 |
- &put_0, |
|
18 |
- &increment, |
|
17 |
+ &lit, |
|
18 |
+ (instruction *)2, |
|
19 | 19 |
}; |
20 | 20 |
int pc = 0; |
21 | 21 |
|
22 |
-void put_0(void) { push(0); } |
|
23 |
- |
|
24 |
-void increment(void) { push(pop() + 1); } |
|
22 |
+void lit(void) { push((int)(intptr_t)prog[++pc]); } |
|
25 | 23 |
|
26 | 24 |
int main(int argc, char *argv[]) { |
27 | 25 |
for (pc = 0; pc < ASIZE(prog); pc++) { |