X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Foberon.c;h=365f47d6a107ac047dbe13e5f3293a5ea138123d;hb=7b989fe6cfb3cf6e529b888bb6827714c45c62c6;hp=8b94271a6033d4675f4c8026d316980139a85d18;hpb=2985d77f3ee4af98761b28b4ce1e57582d8c8619;p=dsw-obn.git diff --git a/src/oberon.c b/src/oberon.c index 8b94271..365f47d 100644 --- a/src/oberon.c +++ b/src/oberon.c @@ -8,6 +8,8 @@ #include #include +#include + #include "../include/oberon.h" #include "oberon-internals.h" @@ -25,7 +27,7 @@ oberon_make_copy_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list static oberon_type_t * oberon_new_type_ptr(int class) { - oberon_type_t * x = malloc(sizeof *x); + oberon_type_t * x = GC_MALLOC(sizeof *x); memset(x, 0, sizeof *x); x -> class = class; return x; @@ -88,7 +90,7 @@ static oberon_expr_t * oberon_new_operator(int op, oberon_type_t * result, oberon_expr_t * left, oberon_expr_t * right) { oberon_oper_t * operator; - operator = malloc(sizeof *operator); + operator = GC_MALLOC(sizeof *operator); memset(operator, 0, sizeof *operator); operator -> is_item = 0; @@ -105,7 +107,7 @@ static oberon_expr_t * oberon_new_item(int mode, oberon_type_t * result, int read_only) { oberon_item_t * item; - item = malloc(sizeof *item); + item = GC_MALLOC(sizeof *item); memset(item, 0, sizeof *item); item -> is_item = 1; @@ -224,8 +226,11 @@ oberon_make_set_range(oberon_context_t * ctx, int64_t x, int64_t y) static oberon_scope_t * oberon_open_scope(oberon_context_t * ctx) { - oberon_scope_t * scope = calloc(1, sizeof *scope); - oberon_object_t * list = calloc(1, sizeof *list); + oberon_scope_t * scope = GC_MALLOC(sizeof *scope); + memset(scope, 0, sizeof *scope); + + oberon_object_t * list = GC_MALLOC(sizeof *list); + memset(list, 0, sizeof *list); scope -> ctx = ctx; scope -> list = list; @@ -256,6 +261,7 @@ oberon_find_object_in_list(oberon_object_t * list, char * name) oberon_object_t * x = list; while(x -> next && strcmp(x -> next -> name, name) != 0) { + printf("inlist: '%s' != '%s'\n", x -> next -> name, name); x = x -> next; } return x -> next; @@ -284,7 +290,8 @@ oberon_find_object(oberon_scope_t * scope, char * name, bool check_it) static oberon_object_t * oberon_create_object(oberon_scope_t * scope, char * name, int class, bool export, bool read_only) { - oberon_object_t * newvar = malloc(sizeof *newvar); + printf("oberon_create_object: '%s'\n", name); + oberon_object_t * newvar = GC_MALLOC(sizeof *newvar); memset(newvar, 0, sizeof *newvar); newvar -> name = name; newvar -> class = class; @@ -311,6 +318,7 @@ oberon_define_object(oberon_scope_t * scope, char * name, int class, bool export oberon_object_t * x = scope -> list; while(x -> next && strcmp(x -> next -> name, name) != 0) { + printf("inlist: '%s' != '%s'\n", x -> next -> name, name); x = x -> next; } @@ -372,7 +380,7 @@ oberon_read_ident(oberon_context_t * ctx) c = ctx -> code[i]; } - char * ident = malloc(len + 1); + char * ident = GC_MALLOC(len + 1); memcpy(ident, &ctx->code[ctx->code_index], len); ident[len] = 0; @@ -631,7 +639,7 @@ oberon_read_number(oberon_context_t * ctx) } int len = end_i - start_i; - ident = malloc(len + 1); + ident = GC_MALLOC(len + 1); memcpy(ident, &ctx -> code[start_i], len); ident[len] = 0; @@ -741,8 +749,9 @@ static void oberon_read_string(oberon_context_t * ctx) oberon_get_char(ctx); - char * string = calloc(1, end - start + 1); + char * string = GC_MALLOC(end - start + 1); strncpy(string, &ctx -> code[start], end - start); + string[end] = 0; ctx -> token = STRING; ctx -> string = string; @@ -1041,10 +1050,14 @@ oberon_cast_expr(oberon_context_t * ctx, oberon_expr_t * expr, oberon_type_t * p cast = oberon_new_item(MODE_CHAR, ctx -> char_type, true); cast -> item.integer = expr -> item.string[0]; } - else + else if(!oberon_is_some_types(expr -> result, pref)) { cast = oberon_new_operator(OP_CAST, pref, expr, NULL); } + else + { + cast = expr; + } return cast; } @@ -1248,7 +1261,7 @@ oberno_make_dereferencing(oberon_context_t * ctx, oberon_expr_t * expr) assert(expr -> is_item); oberon_expr_t * selector; - selector = oberon_new_item(MODE_DEREF, expr -> result -> base, expr -> read_only); + selector = oberon_new_item(MODE_DEREF, expr -> result -> base, false); selector -> item.parent = (oberon_item_t *) expr; return selector; @@ -1958,11 +1971,6 @@ oberon_simple_expr(oberon_context_t * ctx) expr = oberon_term_expr(ctx); - if(minus) - { - expr = oberon_make_unary_op(ctx, MINUS, expr); - } - while(ISADDOP(ctx -> token)) { int token = ctx -> token; @@ -1972,6 +1980,11 @@ oberon_simple_expr(oberon_context_t * ctx) expr = oberon_make_bin_op(ctx, token, expr, inter); } + if(minus) + { + expr = oberon_make_unary_op(ctx, MINUS, expr); + } + return expr; } @@ -2940,9 +2953,10 @@ oberon_initialize_type(oberon_context_t * ctx, oberon_type_t * type) oberon_object_t * field = type -> decl; for(int i = 0; i < num_fields; i++) { - oberon_initialize_object(ctx, field); + //oberon_initialize_object(ctx, field); + oberon_initialize_type(ctx, field -> type); field = field -> next; - } + } oberon_generator_init_type(ctx, type); } @@ -4523,7 +4537,8 @@ oberon_new_intrinsic(oberon_context_t * ctx, char * name, GenerateFuncCallback f oberon_context_t * oberon_create_context(ModuleImportCallback import_module) { - oberon_context_t * ctx = calloc(1, sizeof *ctx); + oberon_context_t * ctx = GC_MALLOC(sizeof *ctx); + memset(ctx, 0, sizeof *ctx); oberon_scope_t * world_scope; world_scope = oberon_open_scope(ctx); @@ -4571,7 +4586,6 @@ void oberon_destroy_context(oberon_context_t * ctx) { oberon_generator_destroy_context(ctx); - free(ctx); } oberon_module_t * @@ -4592,7 +4606,8 @@ oberon_compile_module(oberon_context_t * ctx, const char * newcode) module_scope = oberon_open_scope(ctx); oberon_module_t * module; - module = calloc(1, sizeof *module); + module = GC_MALLOC(sizeof *module); + memset(module, 0, sizeof *module); module -> decl = module_scope; module -> next = ctx -> module_list;