From 98752831dc061590acffee7e68a075f8c18cb132 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Fri, 18 Aug 2017 23:06:05 +0300 Subject: [PATCH] =?utf8?q?=D0=9C=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=B7=D0=B0?= =?utf8?q?=D0=B4=D0=B0=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B4=D0=B8=D1=80=D0=B5?= =?utf8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=20=D0=B4=D0=BB=D1=8F=20?= =?utf8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BC=D0=BE=D0=B4=D1=83?= =?utf8?q?=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- obn-compile.sh | 2 +- obn-run-tests.sh | 13 ++--- src/main.c | 65 ++++++++++++++++++---- Test1.obn => tests/Test1.obn | 0 Test10.obn => tests/Test10.obn | 0 Test11.obn => tests/Test11.obn | 0 Test12.obn => tests/Test12.obn | 0 Test13.obn => tests/Test13.obn | 0 Test14.obn => tests/Test14.obn | 0 Test15.obn => tests/Test15.obn | 0 Test16.obn => tests/Test16.obn | 0 Test17A.obn => tests/Test17A.obn | 0 Test17B.obn => tests/Test17B.obn | 0 Test17C.obn => tests/Test17C.obn | 0 Test17Common.obn => tests/Test17Common.obn | 0 Test17D.obn => tests/Test17D.obn | 0 Test17E.obn => tests/Test17E.obn | 0 Test17F.obn => tests/Test17F.obn | 0 Test18A.obn => tests/Test18A.obn | 0 Test18B.obn => tests/Test18B.obn | 0 Test18C.obn => tests/Test18C.obn | 0 Test19.obn => tests/Test19.obn | 2 +- Test2.obn => tests/Test2.obn | 0 Test20.obn => tests/Test20.obn | 0 Test3.obn => tests/Test3.obn | 0 Test4.obn => tests/Test4.obn | 0 Test5.obn => tests/Test5.obn | 0 Test6.obn => tests/Test6.obn | 0 Test7.obn => tests/Test7.obn | 0 Test8.obn => tests/Test8.obn | 0 Test9.obn => tests/Test9.obn | 0 31 files changed, 61 insertions(+), 21 deletions(-) rename Test1.obn => tests/Test1.obn (100%) rename Test10.obn => tests/Test10.obn (100%) rename Test11.obn => tests/Test11.obn (100%) rename Test12.obn => tests/Test12.obn (100%) rename Test13.obn => tests/Test13.obn (100%) rename Test14.obn => tests/Test14.obn (100%) rename Test15.obn => tests/Test15.obn (100%) rename Test16.obn => tests/Test16.obn (100%) rename Test17A.obn => tests/Test17A.obn (100%) rename Test17B.obn => tests/Test17B.obn (100%) rename Test17C.obn => tests/Test17C.obn (100%) rename Test17Common.obn => tests/Test17Common.obn (100%) rename Test17D.obn => tests/Test17D.obn (100%) rename Test17E.obn => tests/Test17E.obn (100%) rename Test17F.obn => tests/Test17F.obn (100%) rename Test18A.obn => tests/Test18A.obn (100%) rename Test18B.obn => tests/Test18B.obn (100%) rename Test18C.obn => tests/Test18C.obn (100%) rename Test19.obn => tests/Test19.obn (91%) rename Test2.obn => tests/Test2.obn (100%) rename Test20.obn => tests/Test20.obn (100%) rename Test3.obn => tests/Test3.obn (100%) rename Test4.obn => tests/Test4.obn (100%) rename Test5.obn => tests/Test5.obn (100%) rename Test6.obn => tests/Test6.obn (100%) rename Test7.obn => tests/Test7.obn (100%) rename Test8.obn => tests/Test8.obn (100%) rename Test9.obn => tests/Test9.obn (100%) diff --git a/obn-compile.sh b/obn-compile.sh index 85b71c5..4ad5c3d 100755 --- a/obn-compile.sh +++ b/obn-compile.sh @@ -5,7 +5,7 @@ set -e rm -rf classes tmp mkdir -p classes tmp -./a.out -d tmp $1 +./a.out -d tmp $* jasmin -d classes tmp/*.j diff --git a/obn-run-tests.sh b/obn-run-tests.sh index fa1d728..faaf6ea 100755 --- a/obn-run-tests.sh +++ b/obn-run-tests.sh @@ -2,12 +2,14 @@ set -e +TEST_DIR=tests + # Тест: компиляция и исполнение maketest() { local OK=1 local LOG="" - if ! LOG="$(./obn-compile.sh $1)"; then + if ! LOG="$(./obn-compile.sh -I $TEST_DIR $1)"; then OK=0; echo "==============================" echo "Test fail: $1 compile-time $?:" @@ -18,11 +20,6 @@ maketest() if [ $OK = 1 ]; then if ! ./obn-run.sh $1; then OK=0 - echo "==============================" - echo "Test fail: $1 run-time $?:" - echo "$LOG" - echo "==============================" - echo fi fi if [ $OK = 1 ]; then @@ -34,7 +31,7 @@ maketest() makecomp() { local LOG="" - if ! LOG="$(./obn-compile.sh $1)"; then + if ! LOG="$(./obn-compile.sh -I $TEST_DIR $1)"; then echo "==============================" echo "Test fail: $1 compile-time $?:" echo "$LOG" @@ -50,7 +47,7 @@ makecomp() makefail() { local LOG="" - if ! LOG="$(./obn-compile.sh $1)"; then + if ! LOG="$(./obn-compile.sh -I $TEST_DIR $1)"; then echo "Test ok: $1" else echo "==============================" diff --git a/src/main.c b/src/main.c index 994ae80..754d90a 100644 --- a/src/main.c +++ b/src/main.c @@ -5,24 +5,48 @@ #include "../include/oberon.h" +struct string_stack +{ + char * string; + struct string_stack * next; +}; + static oberon_context_t * ctx; static oberon_module_t * mod; static const char * module; static const char * out_path; +static struct string_stack * path_list; + +static void +add_to_stack(struct string_stack ** stack, char * string) +{ + struct string_stack * p = malloc(sizeof *p); + p -> string = string; + p -> next = *stack; + *stack = p; +} + +static FILE * +open_file(struct string_stack * path, const char * ext, const char * name, const char * mode) +{ + 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; + } + return fp; +} static const char * import_module(const char * name) { - assert(name); - FILE * fp; - char fname[256]; - snprintf(fname, 256, "%s.obn", name); - fp = fopen(fname, "r"); + fp = open_file(path_list, "obn", name, "r"); if(fp == NULL) { - printf("can't open file %s\n", fname); - exit(1); return NULL; } @@ -43,13 +67,27 @@ static void init(int argc, char ** argv) { int i = 1; + add_to_stack(&path_list, "."); out_path = "."; - if(argc > 2 && strcmp(argv[i], "-d") == 0) + while(argc > 2) { - out_path = argv[i + 1]; - argc -= 2; - i += 2; + if(argc > 2 && strcmp(argv[i], "-d") == 0) + { + out_path = argv[i + 1]; + argc -= 2; + i += 2; + } + else if(argc > 2 && strcmp(argv[i], "-I") == 0) + { + add_to_stack(&path_list, argv[i + 1]); + argc -= 2; + i += 2; + } + else + { + break; + } } if(argc != 2 || argv[i][0] == '-') @@ -69,6 +107,11 @@ main(int argc, char ** argv) init(argc, argv); code = import_module(module); + if(code == 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); diff --git a/Test1.obn b/tests/Test1.obn similarity index 100% rename from Test1.obn rename to tests/Test1.obn diff --git a/Test10.obn b/tests/Test10.obn similarity index 100% rename from Test10.obn rename to tests/Test10.obn diff --git a/Test11.obn b/tests/Test11.obn similarity index 100% rename from Test11.obn rename to tests/Test11.obn diff --git a/Test12.obn b/tests/Test12.obn similarity index 100% rename from Test12.obn rename to tests/Test12.obn diff --git a/Test13.obn b/tests/Test13.obn similarity index 100% rename from Test13.obn rename to tests/Test13.obn diff --git a/Test14.obn b/tests/Test14.obn similarity index 100% rename from Test14.obn rename to tests/Test14.obn diff --git a/Test15.obn b/tests/Test15.obn similarity index 100% rename from Test15.obn rename to tests/Test15.obn diff --git a/Test16.obn b/tests/Test16.obn similarity index 100% rename from Test16.obn rename to tests/Test16.obn diff --git a/Test17A.obn b/tests/Test17A.obn similarity index 100% rename from Test17A.obn rename to tests/Test17A.obn diff --git a/Test17B.obn b/tests/Test17B.obn similarity index 100% rename from Test17B.obn rename to tests/Test17B.obn diff --git a/Test17C.obn b/tests/Test17C.obn similarity index 100% rename from Test17C.obn rename to tests/Test17C.obn diff --git a/Test17Common.obn b/tests/Test17Common.obn similarity index 100% rename from Test17Common.obn rename to tests/Test17Common.obn diff --git a/Test17D.obn b/tests/Test17D.obn similarity index 100% rename from Test17D.obn rename to tests/Test17D.obn diff --git a/Test17E.obn b/tests/Test17E.obn similarity index 100% rename from Test17E.obn rename to tests/Test17E.obn diff --git a/Test17F.obn b/tests/Test17F.obn similarity index 100% rename from Test17F.obn rename to tests/Test17F.obn diff --git a/Test18A.obn b/tests/Test18A.obn similarity index 100% rename from Test18A.obn rename to tests/Test18A.obn diff --git a/Test18B.obn b/tests/Test18B.obn similarity index 100% rename from Test18B.obn rename to tests/Test18B.obn diff --git a/Test18C.obn b/tests/Test18C.obn similarity index 100% rename from Test18C.obn rename to tests/Test18C.obn diff --git a/Test19.obn b/tests/Test19.obn similarity index 91% rename from Test19.obn rename to tests/Test19.obn index 323d528..c5e684d 100644 --- a/Test19.obn +++ b/tests/Test19.obn @@ -9,7 +9,7 @@ VAR x : POINTER TO ARRAY OF CHAR; BEGIN - f := Files.Old("Test19.obn"); + f := Files.Old("tests/Test19.obn"); ASSERT(f # NIL); Files.Set(r, f, 0); diff --git a/Test2.obn b/tests/Test2.obn similarity index 100% rename from Test2.obn rename to tests/Test2.obn diff --git a/Test20.obn b/tests/Test20.obn similarity index 100% rename from Test20.obn rename to tests/Test20.obn diff --git a/Test3.obn b/tests/Test3.obn similarity index 100% rename from Test3.obn rename to tests/Test3.obn diff --git a/Test4.obn b/tests/Test4.obn similarity index 100% rename from Test4.obn rename to tests/Test4.obn diff --git a/Test5.obn b/tests/Test5.obn similarity index 100% rename from Test5.obn rename to tests/Test5.obn diff --git a/Test6.obn b/tests/Test6.obn similarity index 100% rename from Test6.obn rename to tests/Test6.obn diff --git a/Test7.obn b/tests/Test7.obn similarity index 100% rename from Test7.obn rename to tests/Test7.obn diff --git a/Test8.obn b/tests/Test8.obn similarity index 100% rename from Test8.obn rename to tests/Test8.obn diff --git a/Test9.obn b/tests/Test9.obn similarity index 100% rename from Test9.obn rename to tests/Test9.obn -- 2.29.2