DEADSOFTWARE

Добавлен тип SYSTEM.PTR
[dsw-obn.git] / src / oberon.c
index 0bbeec188b3d5b4e7fafe506285a9d096cb809b7..07c83c28643623df555292ca429fa5eba776ae9d 100644 (file)
@@ -356,23 +356,20 @@ oberon_init_scaner(oberon_context_t * ctx, const char * code)
 static void
 oberon_read_ident(oberon_context_t * ctx)
 {
-       int len = 0;
-       int i = ctx -> code_index;
+       int start = ctx -> code_index;
 
-       int c = ctx -> code[i];
-       while(isalnum(c))
+       oberon_get_char(ctx);
+       while(isalnum(ctx -> c) || ctx -> c == '_')
        {
-               i += 1;
-               len += 1;
-               c = ctx -> code[i];
+               oberon_get_char(ctx);
        }
 
-       char * ident = GC_MALLOC(len + 1);
-       memcpy(ident, &ctx->code[ctx->code_index], len);
-       ident[len] = 0;
+       int end = ctx -> code_index;
+
+       char * ident = GC_MALLOC(end - start + 1);
+       memcpy(ident, &ctx -> code[start], end - start);
+       ident[end - start] = 0;
 
-       ctx -> code_index = i;
-       ctx -> c = ctx -> code[i];
        ctx -> string = ident;
        ctx -> token = IDENT;
 
@@ -738,7 +735,7 @@ static void oberon_read_string(oberon_context_t * ctx)
 
        char * string = GC_MALLOC(end - start + 1);
        strncpy(string, &ctx -> code[start], end - start);
-       string[end] = 0;
+       string[end - start] = 0;
 
        ctx -> token = STRING;
        ctx -> string = string;
@@ -893,7 +890,7 @@ oberon_read_token(oberon_context_t * ctx)
        oberon_skip_space(ctx);
 
        int c = ctx -> c;
-       if(isalpha(c))
+       if(isalpha(c) || c == '_')
        {
                oberon_read_ident(ctx);
        }
@@ -4493,6 +4490,9 @@ register_default_types(oberon_context_t * ctx)
        ctx -> system_byte_type = oberon_new_type_ptr(OBERON_TYPE_SYSTEM_BYTE);
        oberon_generator_init_type(ctx, ctx -> system_byte_type);
 
+       ctx -> system_ptr_type = oberon_new_type_ptr(OBERON_TYPE_SYSTEM_PTR);
+       oberon_generator_init_type(ctx, ctx -> system_ptr_type);
+
        /* LONG / SHORT support */
        ctx -> byte_type -> shorter = NULL;
        ctx -> byte_type -> longer = ctx -> shortint_type;
@@ -4621,6 +4621,7 @@ oberon_create_context(ModuleImportCallback import_module)
 
                /* Types */
                oberon_new_intrinsic_type(ctx, "BYTE", ctx -> system_byte_type);
+               oberon_new_intrinsic_type(ctx, "PTR", ctx -> system_ptr_type);
 
        oberon_end_intrinsic_module(ctx, ctx -> system_module);