DEADSOFTWARE

f29aa4d4a780b18af1a526bcbc9556580f3d94ff
[dsw-obn.git] / oberon.h
1 #ifndef EMBEDED_OBERON_SCRIPT_H
2 #define EMBEDED_OBERON_SCRIPT_H
4 typedef struct oberon_type_s oberon_type_t;
5 typedef struct oberon_object_s oberon_object_t;
6 typedef struct oberon_module_s oberon_module_t;
7 typedef struct oberon_context_s oberon_context_t;
8 typedef struct oberon_scope_s oberon_scope_t;
10 struct oberon_scope_s
11 {
12 oberon_context_t * ctx;
13 oberon_object_t * list;
14 oberon_scope_t * up;
15 };
17 enum
18 {
19 OBERON_TYPE_INTEGER,
20 OBERON_TYPE_BOOLEAN,
21 };
23 struct oberon_type_s
24 {
25 int class;
26 int size;
28 void * gen_type;
29 };
31 enum
32 {
33 OBERON_CLASS_VAR,
34 OBERON_CLASS_TYPE,
35 OBERON_CLASS_PROC
36 };
38 struct oberon_object_s
39 {
40 char * name;
41 int class;
43 oberon_type_t * type;
45 void * gen_var;
46 void * gen_proc;
48 oberon_object_t * next;
49 };
51 struct oberon_module_s
52 {
53 char * name;
55 oberon_scope_t * decl;
57 void (* begin)();
58 };
60 struct oberon_context_s
61 {
62 const char * code;
63 int code_index;
65 char c;
66 int token;
67 char * string;
68 int integer;
70 oberon_scope_t * decl;
71 oberon_module_t * mod;
73 oberon_type_t * int_type;
74 oberon_type_t * bool_type;
75 oberon_scope_t * world_scope;
77 void * gen_context;
78 };
80 enum {
81 MODE_VAR,
82 MODE_INTEGER,
83 MODE_BOOLEAN,
84 MODE_CALL
85 };
87 enum {
88 OP_LOGIC_NOT,
89 OP_UNARY_MINUS,
90 OP_ADD,
91 OP_SUB,
92 OP_MUL,
93 OP_DIV,
94 OP_MOD,
95 OP_LOGIC_AND,
96 OP_LOGIC_OR,
97 OP_EQ,
98 OP_NEQ,
99 OP_LSS,
100 OP_LEQ,
101 OP_GRT,
102 OP_GEQ
103 };
105 typedef struct oberon_item_s oberon_item_t;
106 typedef struct oberon_oper_s oberon_oper_t;
107 typedef union oberon_expr_u oberon_expr_t;
109 struct oberon_item_s
111 int is_item;
112 oberon_type_t * result;
114 int mode;
115 int integer;
116 int boolean;
117 oberon_object_t * var;
118 };
120 struct oberon_oper_s
122 int is_item;
123 oberon_type_t * result;
125 int op;
126 oberon_expr_t * left;
127 oberon_expr_t * right;
128 };
130 union oberon_expr_u
132 struct {
133 int is_item;
134 oberon_type_t * result;
135 };
137 oberon_item_t item;
138 oberon_oper_t oper;
139 };
141 oberon_context_t * oberon_create_context();
142 void oberon_destroy_context(oberon_context_t * ctx);
143 void oberon_register_global_type(oberon_context_t * ctx, oberon_type_t * type);
144 oberon_module_t * oberon_compile_module(oberon_context_t * ctx, const char * code);
145 void oberon_error(oberon_context_t * ctx, const char * fmt, ...);
147 #endif // EMBEDED_OBERON_SCRIPT_H