fixed SP restoration.
[bugg-scheme-compiler.git] / src / c / arch.h~
blobc0d18c1c6e95eaf3d78a71fded919d62ca79bfb7
1 /* Architecture */
3 #ifndef __ARCH_H
4 #define __ARCH_H
6 void initArchitecture(int stackSize, int regsCount);
8 /* Stack */
9 extern int* stack;
10 extern int sp;
11 extern int fp;
13 void push(int x);
14 int pop();
16 /* The stack when in a user procedure:
17      fp -> |      |
18            | fp   |  - the old fp (before this application)
19            | ret  |  - return address
20            | sp   |  - the old sp (before entering this procedure)
21            | env  |  - points to the enviroment vector
22            | n    |  - number of arguments
23            | A0   |  - argument 0
24            | A1   |  - argument 1
25            | ...  |  - ...
26            | An-1 |  - argument n-1
28    Note: sp does NOT have to be equal to fp - for example if we are in the
29          middle of applying a procedure and already pushed some arguments
30          on to the stack (then sp has changed, but fp has not).
32    Macros for user procedures:
34 #define ST_ARG(n) (stack[fp-6-(n)])
35 #define ST_ARG_COUNT() (stack[fp-5])
36 #define ST_OLDFP() (stack[fp-1])
37 #define ST_RET() (stack[fp-2])
38 #define ST_ENV() (stack[fp-4])
39 #define RETURN() goto *pop()
41 /* General Purpose Registers */
42 extern int* r;
43 extern int r_res;
45 #endif