DEADSOFTWARE

Добавлены процедуры и проверка результата в выражениях
[dsw-obn.git] / oberon.h
1 #ifndef EMBEDED_OBERON_SCRIPT_H
2 #define EMBEDED_OBERON_SCRIPT_H
4 typedef struct oberon_var_s oberon_var_t;
5 typedef struct oberon_type_s oberon_type_t;
6 typedef struct oberon_proc_s oberon_proc_t;
7 typedef struct oberon_module_s oberon_module_t;
8 typedef struct oberon_context_s oberon_context_t;
10 enum {
11 OBERON_TYPE_INTEGER,
12 OBERON_TYPE_BOOLEAN,
13 };
15 struct oberon_type_s
16 {
17 char * name;
18 int class;
19 int size;
20 oberon_type_t * next;
22 void * gen_type;
23 };
25 struct oberon_var_s
26 {
27 char * name;
28 oberon_type_t * type;
29 oberon_var_t * next;
31 void * gen_var;
32 };
34 struct oberon_proc_s
35 {
36 char * name;
38 oberon_proc_t * next;
40 void * gen_proc;
41 };
43 struct oberon_module_s
44 {
45 char * name;
47 oberon_var_t * vars;
48 oberon_proc_t * procs;
50 void (* begin)();
51 };
53 struct oberon_context_s
54 {
55 const char * code;
56 int code_index;
58 char c;
59 int token;
60 char * string;
61 int integer;
63 oberon_module_t * mod;
64 oberon_type_t * types;
66 oberon_type_t * int_type;
67 oberon_type_t * bool_type;
69 void * gen_context;
70 };
72 enum {
73 MODE_VAR,
74 MODE_INTEGER,
75 MODE_BOOLEAN
76 };
78 enum {
79 OP_LOGIC_NOT,
80 OP_UNARY_MINUS,
81 OP_ADD,
82 OP_SUB,
83 OP_MUL,
84 OP_DIV,
85 OP_MOD,
86 OP_LOGIC_AND,
87 OP_LOGIC_OR,
88 OP_EQ,
89 OP_NEQ,
90 OP_LSS,
91 OP_LEQ,
92 OP_GRT,
93 OP_GEQ
94 };
96 typedef struct oberon_item_s oberon_item_t;
97 typedef struct oberon_oper_s oberon_oper_t;
98 typedef union oberon_expr_u oberon_expr_t;
100 struct oberon_item_s
102 int is_item;
103 oberon_type_t * result;
105 int mode;
106 int integer;
107 int boolean;
108 oberon_var_t * var;
109 };
111 struct oberon_oper_s
113 int is_item;
114 oberon_type_t * result;
116 int op;
117 oberon_expr_t * left;
118 oberon_expr_t * right;
119 };
121 union oberon_expr_u
123 struct {
124 int is_item;
125 oberon_type_t * result;
126 };
128 oberon_item_t item;
129 oberon_oper_t oper;
130 };
132 oberon_context_t * oberon_create_context();
133 void oberon_destroy_context(oberon_context_t * ctx);
134 void oberon_register_global_type(oberon_context_t * ctx, oberon_type_t * type);
135 oberon_module_t * oberon_compile_module(oberon_context_t * ctx, const char * code);
136 void oberon_error(oberon_context_t * ctx, const char * fmt, ...);
138 #endif // EMBEDED_OBERON_SCRIPT_H