#ifndef OBERON_INTERNALS_H #define OBERON_INTERNALS_H #include #include typedef struct gen_module_t gen_module_t; typedef struct gen_proc_t gen_proc_t; typedef struct gen_type_t gen_type_t; typedef struct gen_var_t gen_var_t; typedef struct gen_label_t gen_label_t; typedef struct gen_context_t gen_context_t; typedef struct oberon_type_t oberon_type_t; typedef struct oberon_object_t oberon_object_t; typedef struct oberon_module_t oberon_module_t; typedef struct oberon_context_t oberon_context_t; typedef struct oberon_scope_t oberon_scope_t; typedef struct oberon_location_t oberon_location_t; typedef struct oberon_scanner_t oberon_scanner_t; typedef struct oberon_item_t oberon_item_t; typedef struct oberon_oper_t oberon_oper_t; typedef union oberon_expr_t oberon_expr_t; struct oberon_scope_t { oberon_context_t * ctx; oberon_object_t * list; oberon_scope_t * up; int local; oberon_object_t * parent; oberon_type_t * parent_type; gen_label_t * exit_label; }; enum oberon_type_kind { OBERON_TYPE_NOTYPE, OBERON_TYPE_INTEGER, OBERON_TYPE_BOOLEAN, OBERON_TYPE_PROCEDURE, OBERON_TYPE_ARRAY, OBERON_TYPE_RECORD, OBERON_TYPE_POINTER, OBERON_TYPE_REAL, OBERON_TYPE_CHAR, OBERON_TYPE_STRING, OBERON_TYPE_SET, OBERON_TYPE_NIL, OBERON_TYPE_SYSTEM_BYTE, OBERON_TYPE_SYSTEM_PTR }; typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *); typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *); struct oberon_type_t { enum oberon_type_kind class; int size; oberon_type_t * shorter; oberon_type_t * longer; int num_decl; oberon_type_t * base; oberon_object_t * decl; oberon_scope_t * scope; bool sysproc; GenerateFuncCallback genfunc; GenerateProcCallback genproc; oberon_module_t * module; int recursive; int initialized; gen_type_t * gen_type; }; enum oberon_object_kind { OBERON_CLASS_VAR, OBERON_CLASS_TYPE, OBERON_CLASS_PROC, OBERON_CLASS_PARAM, OBERON_CLASS_VAR_PARAM, OBERON_CLASS_CONST, OBERON_CLASS_FIELD, OBERON_CLASS_MODULE }; struct oberon_object_t { char * name; enum oberon_object_kind class; int export; int read_only; int local; int linked; int initialized; oberon_object_t * parent; oberon_type_t * parent_type; oberon_scope_t * scope; // for proc int has_return; // for proc oberon_type_t * type; oberon_item_t * value; oberon_object_t * next; oberon_module_t * module; gen_var_t * gen_var; gen_proc_t * gen_proc; }; struct oberon_module_t { char * name; bool ready; bool intrinsic; oberon_scope_t * decl; oberon_module_t * next; gen_module_t * gen_mod; }; struct oberon_location_t { const char * source; int line; int col; }; struct oberon_scanner_t { char * source; char * code; }; typedef oberon_scanner_t * (*ModuleImportCallback)(const char * name); struct oberon_context_t { /*** SCANER DATA ***/ const char * code; int code_index; oberon_location_t loc; oberon_location_t xloc; char c; int token; char * string; int64_t integer; double real; bool longmode; /*** END SCANER DATA ***/ /*** PARSER DATA ***/ oberon_scope_t * decl; oberon_module_t * mod; /*** END PARSER DATA ***/ oberon_scope_t * world_scope; oberon_type_t * notype_type; oberon_type_t * nil_type; oberon_type_t * bool_type; oberon_type_t * byte_type; oberon_type_t * shortint_type; oberon_type_t * int_type; oberon_type_t * longint_type; oberon_type_t * real_type; oberon_type_t * longreal_type; oberon_type_t * char_type; oberon_type_t * string_type; oberon_type_t * set_type; oberon_module_t * system_module; oberon_type_t * system_byte_type; oberon_type_t * system_ptr_type; oberon_module_t * module_list; ModuleImportCallback import_module; gen_context_t * gen_context; }; enum oberon_mode_kind { MODE_VAR, MODE_INTEGER, MODE_BOOLEAN, MODE_CALL, MODE_INDEX, MODE_FIELD, MODE_DEREF, MODE_NIL, MODE_NEW, MODE_REAL, MODE_CHAR, MODE_STRING, MODE_TYPE, MODE_SET, MODE_LEN, MODE_SYSBYTE, MODE_AS }; enum oberon_operator_kind { OP_UNARY_MINUS, OP_LOGIC_NOT, OP_ABS, OP_CAP, OP_ENTIER, OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_LOGIC_AND, OP_LOGIC_OR, OP_EQ, OP_NEQ, OP_LSS, OP_LEQ, OP_GRT, OP_GEQ, OP_CAST, OP_HARDCAST, OP_IS, OP_RANGE, OP_UNION, OP_INTERSECTION, OP_DIFFERENCE, OP_SYM_DIFFERENCE, OP_COMPLEMENTATION, OP_IN, OP_ASH, OP_LSH, OP_ROT }; struct oberon_item_t { bool is_item; // == 1 oberon_type_t * result; oberon_expr_t * next; bool read_only; enum oberon_mode_kind mode; long integer; double real; char * string; oberon_object_t * var; oberon_item_t * parent; int num_args; oberon_expr_t * args; }; struct oberon_oper_t { bool is_item; // == 0 oberon_type_t * result; oberon_expr_t * next; bool read_only; enum oberon_operator_kind op; oberon_expr_t * left; oberon_expr_t * right; }; union oberon_expr_t { struct { bool is_item; oberon_type_t * result; oberon_expr_t * next; bool read_only; }; oberon_item_t item; oberon_oper_t oper; }; extern oberon_context_t * oberon_create_context(ModuleImportCallback import_module); extern void oberon_destroy_context(oberon_context_t * ctx); extern oberon_module_t * oberon_compile_module(oberon_context_t * ctx, oberon_scanner_t * s); #endif // OBERON_INTERNALS_H