summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0f382f6)
raw | patch | inline | side by side (parent: 0f382f6)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sat, 19 Aug 2017 09:27:16 +0000 (12:27 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sat, 19 Aug 2017 09:27:16 +0000 (12:27 +0300) |
12 files changed:
Test.obn | patch | blob | history | |
notes | patch | blob | history | |
src/backends/jvm/generator-jvm-abi.c | patch | blob | history | |
src/backends/jvm/generator-jvm-asm.c | patch | blob | history | |
src/backends/jvm/generator-jvm-basic.c | patch | blob | history | |
src/backends/jvm/generator-jvm.c | patch | blob | history | |
src/main.c | patch | blob | history | |
src/oberon-common.c | patch | blob | history | |
src/oberon-internals.h | patch | blob | history | |
src/oberon-type-compat.c | patch | blob | history | |
src/oberon.c | patch | blob | history | |
src/oberon.h | [moved from include/oberon.h with 100% similarity] | patch | blob | history |
diff --git a/Test.obn b/Test.obn
index f47edbbb416fd2154a0f16c7bfbaf310923269bc..6fae5299c4ceb508ddf3708622d39e419e562a12 100644 (file)
--- a/Test.obn
+++ b/Test.obn
MODULE Test;
-IMPORT Files;
-
-TYPE
- String = POINTER TO ARRAY OF CHAR;
- R* = RECORD ch : CHAR END;
-
-VAR
- f : Files.File;
- r : Files.Rider;
- m : R;
- s : String;
-
-BEGIN
- f := Files.Old("Test.obn");
- ASSERT(f # NIL);
- Files.Set(r, f, 0);
-
- Files.Read(r, m.ch);
-
- ASSERT(s = NIL);
END Test.
index 0fa3ba8caf13b9cb0c4c90fad00bebecd77c053f..71fcaf3866a440c895be254c267961ed0f61be79 100644 (file)
--- a/notes
+++ b/notes
+- Нужно передавать информацию о файле и строках в кодогенератор.
- Нет процедур привязанных к типм (10.2)
- Не полная реализация модуля Files
* Не реализована запись в файл
+- Нужно передлать кодогенератор что бы складировать код в структурах а не напрямую срать в файлы
+
- Не полная реализация модуля Strings
* Не реализованы процедуры Insert Append Delete Replace Extract Pos
- Сделать проверку повторов в CASE.
- Сделать нормальную проверку наличия RETURN.
-- Нет счёта строк / столбцов (хрен с ними - у меня есть утилита tail!)
- Нужны средства создания биндингов. (oakwood 3.5)
- Любая ошибка фатальна
index 2889ae3c718437b3220ae308ba0e446a9fec55bc..d1e87f16a964bbb76f69eefe6c550081abda82cb 100644 (file)
#include <gc.h>
-#include "../../../include/oberon.h"
#include "../../oberon-internals.h"
#include "generator-jvm.h"
#include "generator-jvm-abi.h"
index 1d1220d0ecac4b99f7e81d2eee7e96deb241a54e..bd1812c00d0d74309faee20c12301a3102675f42 100644 (file)
#include <gc.h>
-#include "../../../include/oberon.h"
#include "../../oberon-internals.h"
#include "generator-jvm.h"
#include "generator-jvm-abi.h"
index 2baed6556849dc01aa1d61d9fda6836cccf7642c..e4c6c15635a591cefe9800074670bd34dc29f4cb 100644 (file)
#include <gc.h>
-#include "../../../include/oberon.h"
#include "../../oberon-internals.h"
#include "generator-jvm.h"
#include "generator-jvm-basic.h"
index eb445918fa5e20d462300e1da7cd23defe5824eb..e4ea3833027a6d27cd502cf3be21e98191cfc4b7 100644 (file)
#include <gc.h>
-#include "../../../include/oberon.h"
#include "../../oberon-internals.h"
#include "generator-jvm.h"
#include "generator-jvm-abi.h"
diff --git a/src/main.c b/src/main.c
index 754d90aa7f216863d6f6337c0c3d41bd3def2afc..9d471e6baa33ed44cddced222fba5c25d81869c8 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include <string.h>
#include <assert.h>
-#include "../include/oberon.h"
+#include "oberon-internals.h"
+#include "generator.h"
struct string_stack
{
}
static FILE *
-open_file(struct string_stack * path, const char * ext, const char * name, const char * mode)
+open_file(struct string_stack * path, const char * ext, const char * name, const char * mode, oberon_scanner_t * res)
{
+ char fname[256];
+ memset(fname, 0, 256);
+
FILE * fp = NULL;
while(fp == NULL && path != NULL)
{
- char fname[256];
snprintf(fname, 256, "%s/%s.%s", path -> string, name, ext);
fp = fopen(fname, mode);
path = path -> next;
}
+
+ if(fp == NULL)
+ {
+ snprintf(fname, 256, "%s.%s", name, ext);
+ fp = fopen(fname, mode);
+ }
+
+ size_t len = strlen(fname);
+ res -> source = malloc(len + 1);
+ memcpy(res -> source, fname, len);
+
return fp;
}
-static const char *
+static oberon_scanner_t *
import_module(const char * name)
{
+ oberon_scanner_t * res = malloc(sizeof *res);
+ memset(res, 0, sizeof *res);
+
FILE * fp;
- fp = open_file(path_list, "obn", name, "r");
+ fp = open_file(path_list, "obn", name, "r", res);
if(fp == NULL)
{
return NULL;
}
- char * source;
size_t len;
fseek(fp, 0, SEEK_END);
len = ftell(fp);
fseek(fp, 0, SEEK_SET);
- source = calloc(1, len + 1);
- fread(source, len, 1, fp);
+ res -> code = calloc(1, len + 1);
+ fread(res -> code, len, 1, fp);
- return source;
+ return res;
}
static void
init(int argc, char ** argv)
{
int i = 1;
- add_to_stack(&path_list, ".");
out_path = ".";
while(argc > 2)
int
main(int argc, char ** argv)
{
- const char * code;
+ oberon_scanner_t * s;
init(argc, argv);
- code = import_module(module);
- if(code == NULL)
+ s = import_module(module);
+ if(s == NULL)
{
printf("can't open module source %s\n", module);
return 0;
ctx = oberon_create_context(import_module);
oberon_set_out_directory(ctx, out_path);
- mod = oberon_compile_module(ctx, code);
+ mod = oberon_compile_module(ctx, s);
oberon_destroy_context(ctx);
diff --git a/src/oberon-common.c b/src/oberon-common.c
index 01f2c9e5aab0ab553f2c527349c5731d4802daa4..997b7d250bc9d8f8fe5b21af8ac50513f824b7e7 100644 (file)
--- a/src/oberon-common.c
+++ b/src/oberon-common.c
#include <stdlib.h>
#include <stdarg.h>
-#include "../include/oberon.h"
-
#include "oberon-internals.h"
void
{
va_list ptr;
va_start(ptr, fmt);
- printf("error: ");
+ printf("%s: (%i:%i) ", ctx -> loc.source, ctx -> loc.line, ctx -> loc.col);
vprintf(fmt, ptr);
printf("\n");
- printf(" code_index = %i\n", ctx -> code_index);
- printf(" c = %c\n", ctx -> c);
- printf(" token = %i\n", ctx -> token);
va_end(ptr);
exit(1);
}
diff --git a/src/oberon-internals.h b/src/oberon-internals.h
index ad2ecc654b1dfc66fd744ddab31a7ef26f05a515..d4f3cf211f02eb8411f06093b19043b1cfb8d1b1 100644 (file)
--- a/src/oberon-internals.h
+++ b/src/oberon-internals.h
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;
gen_module_t * gen_mod;
};
-typedef const char * (*ModuleImportCallback)(const char * name);
+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;
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
index a30849986c45fa9d2054587864c280b9e7a5cc23..964f0a0e4797875c123aae905c700bab23f17a9f 100644 (file)
--- a/src/oberon-type-compat.c
+++ b/src/oberon-type-compat.c
#include <stdbool.h>
#include <math.h>
-#include "../include/oberon.h"
-
-#include "oberon-common.h"
#include "oberon-internals.h"
#include "oberon-type-compat.h"
+#include "oberon-common.h"
bool
oberon_is_array_type(oberon_type_t * t)
diff --git a/src/oberon.c b/src/oberon.c
index 29c40cb974b5a822bb89c18cfe567a2d464aa966..e684e655df644a277dbc65955983efcc62d08b27 100644 (file)
--- a/src/oberon.c
+++ b/src/oberon.c
#include <gc.h>
-#include "../include/oberon.h"
-
#include "oberon-internals.h"
#include "oberon-type-compat.h"
#include "oberon-common.h"
if(ctx -> code[ctx -> code_index])
{
ctx -> code_index += 1;
+ ctx -> xloc.col += 1;
ctx -> c = ctx -> code[ctx -> code_index];
}
}
static void
-oberon_init_scaner(oberon_context_t * ctx, const char * code)
+oberon_init_scaner(oberon_context_t * ctx, oberon_scanner_t * s)
{
- ctx -> code = code;
+ ctx -> code = s -> code;
ctx -> code_index = 0;
+ ctx -> xloc.source = s -> source;
+ ctx -> xloc.line = 1;
+ ctx -> xloc.col = 1;
+ ctx -> loc = ctx -> xloc;
ctx -> c = ctx -> code[ctx -> code_index];
}
{
while(isspace(ctx -> c))
{
- oberon_get_char(ctx);
+ if(ctx -> c == 0xD)
+ {
+ oberon_get_char(ctx);
+ if(ctx -> c == 0xA)
+ {
+ oberon_get_char(ctx);
+ }
+ ctx -> xloc.line += 1;
+ ctx -> xloc.col = 1;
+ }
+ else if(ctx -> c == 0xA)
+ {
+ oberon_get_char(ctx);
+ ctx -> xloc.line += 1;
+ ctx -> xloc.col = 1;
+ }
+ else
+ {
+ oberon_get_char(ctx);
+ }
}
}
{
oberon_skip_space(ctx);
+ ctx -> loc = ctx -> xloc;
+
int c = ctx -> c;
if(isalpha(c) || c == '_')
{
if(m == NULL)
{
- const char * code;
- code = ctx -> import_module(name);
- if(code == NULL)
+ oberon_scanner_t * s;
+ s = ctx -> import_module(name);
+ if(s == NULL)
{
- oberon_error(ctx, "no such module");
+ oberon_error(ctx, "no such module %s", name);
}
- m = oberon_compile_module(ctx, code);
+ m = oberon_compile_module(ctx, s);
assert(m);
}
}
oberon_module_t *
-oberon_compile_module(oberon_context_t * ctx, const char * newcode)
+oberon_compile_module(oberon_context_t * ctx, oberon_scanner_t * s)
{
const char * code = ctx -> code;
int code_index = ctx -> code_index;
+ oberon_location_t loc = ctx -> loc;
+ oberon_location_t xloc = ctx -> xloc;
char c = ctx -> c;
int token = ctx -> token;
char * string = ctx -> string;
ctx -> mod = module;
ctx -> module_list = module;
- oberon_init_scaner(ctx, newcode);
+ oberon_init_scaner(ctx, s);
oberon_parse_module(ctx);
module -> ready = 1;
ctx -> code = code;
ctx -> code_index = code_index;
+ ctx -> loc = loc;
+ ctx -> xloc = xloc;
ctx -> c = c;
ctx -> token = token;
ctx -> string = string;
diff --git a/include/oberon.h b/src/oberon.h