-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.c
49 lines (37 loc) · 881 Bytes
/
runner.c
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
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "src/stack_cpu.h"
#include "src/asmr.h"
extern bool debug;
int
main(int argc, char *argv[])
{
int ch;
char *fn = "progs/forth.asmr";
while ((ch = getopt(argc, argv, "vf:")) != -1) {
switch (ch) {
case 'v':
debug = true;
break;
case 'f':
fn = optarg;
break;
}
}
// init cpu
stack_cpu_t *cpu = init_stack_cpu();
// assemble it
asmr_t *asmr = init_asmr();
stack_cpu_asm(asmr, fn);
load_prog(cpu, asmr->prog, asmr->prog_len);
free(asmr);
if (debug) {
printf("Press enter to step through the code.\n");
printf("^D to step through as fast as possible.\n");
}
// run program
run_prog(cpu);
print_state(cpu);
return 0;
}