library.m4
1.4 KB
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
_divert_(-1) // -- For Emacs: this is -*-C-*- code. --------------------------
NOTE: diversions used:
5 ->
_define_(`_function_info_', `// (declarations for function $1)')
_divert_(0)_dnl_
goto lib_init; // skip library code!
print_int: // print_int (int) -> ()
printf ("%ld\n", M[SP+1]);
goto * ((void *) M[SP++]);
print_char: // print_char (int) -> ()
putchar (M[SP+1]);
goto * ((void *) M[SP++]);
read_int: // read_int () -> int
scanf ("%ld", &M[SP+1]);
goto * ((void *) M[SP++]);
read_char: // read_char () -> int
M[SP+1] = getchar ();
goto * ((void *) M[SP++]);
halt: // halt () -> ()
return 0;
dump_regs: // dump_regs () -> ()
{
printf ("-- Register dump --\n");
printf ("SP = 0x%lx (%ld)\n", (long) SP, (long) SP);
printf ("FP = 0x%lx (%ld)\n", (long) FP, (long) FP);
printf ("SR = 0x%lx (%ld)\n", (long) SR, (long) SR);
printf ("PC = (unused)\n");
}
goto * ((void *) M[SP++]);
dump_stack: // dump_stack () -> ()
{
printf ("-- Stack dump --\n");
}
goto * ((void *) M[SP++]);
stack_trace: // stack_trace () -> ()
{
printf ("-- Stack trace --\n");
}
goto * ((void *) M[SP++]);
lib_init:
{
_function_info_ (print_int);
_function_info_ (print_char);
_function_info_ (read_int);
_function_info_ (read_char);
_function_info_ (halt);
_function_info_ (dump_regs);
_function_info_ (dump_stack);
_function_info_ (stack_trace);
}