-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhoc.h
More file actions
97 lines (80 loc) · 1.92 KB
/
hoc.h
File metadata and controls
97 lines (80 loc) · 1.92 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef _HOC_INCLUDE_H_
#define _HOC_INCLUDE_H_
#ifndef NULL
# define NULL (0L)
#endif
typedef void (*Inst)(); // machine instruction
#define STOP (Inst)0
struct Symbol;
typedef struct Env {
struct Symbol* symlist;
struct Env* prev;
} Env;
typedef struct Func {
Inst* defn;
struct Symbol* params; // point to the last parameter; NULL if no parameter
} Func;
/**
* symbol table entry
*/
typedef struct Symbol {
char* name;
short type; // VAR, CONST, BLTIN, UNDEF
union {
double val; // if VAR
double (*ptr)(double); // if BLTIN
Func func; // FUNCTION, PROCEDURE
char* str; // STRING
} u;
struct Symbol* next; // link to another Symbol
struct Env* env; // only function / procedure has env
} Symbol;
/**
* install s in symbol table
* @param s - name
* @param t - type
* @param d - data
*/
Symbol* install(const char* s, int t, double d);
/**
* find s in a symbol table
* @param s - name
*/
Symbol* lookup(const char* s);
/**
* push local env
*/
void pushLocalEnv(Symbol* sp);
/**
* pop current env, restore to global env
*/
void popEnv();
/**
* debug output all symbol in current env
*/
void debugDumpEnv();
/**
* alloc buffer
*/
void* emalloc(unsigned int n);
/**
* interpreter stack type
*/
typedef union Datum {
double val;
Symbol* sym;
} Datum;
extern Datum pop();
extern Inst prog[];
extern Inst* progp;
extern Inst* progbase;
extern Inst* code();
extern void eval(), add(), sub(), mul(), hocDiv(), negate(), power();
extern void assign(), bltin(), varpush(), constpush(), print(), varread();
extern void printexpr(), printstr();
extern void gt(), lt(), eq(), ge(), le(), ne(), hocAnd(), hocOr(), hocNot();
extern void ifcode(), whilecode(), call(), arg(), argassign();
extern void funcret(), procret();
void debugInitSymbolTable();
const char* debugLookupBuiltinFuncName(void* addr);
#endif