language

some fools attempt at an interpreted language
Log | Files | Refs | README

commit af508dd43a9e6e755a4a44582eb3f4b0dd73bff0
parent dd4b49f2738ff071951e45725617129394199f67
Author: Paul Longtine <paul@nanner.co>
Date:   Sun, 27 Sep 2020 01:41:28 -0400

Fixed tests

Diffstat:
Msrc/lc/test_files/out | 0
Msrc/vm/inc/ns.h | 4++--
Msrc/vm/inc/var.h | 2+-
Msrc/vm/src/ns.c | 2+-
Msrc/vm/tests/cases/bc/Makefile | 4++++
Msrc/vm/tests/cases/ns/Makefile | 2++
Dsrc/vm/tests/cases/ns/test | 0
Msrc/vm/tests/cases/ns/test.c | 27+++++++++++++--------------
Msrc/vm/tests/cases/pc/Makefile | 4++++
Msrc/vm/tests/cases/pc/test.c | 6+++---
Msrc/vm/tests/cases/stk/Makefile | 4++++
11 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/src/lc/test_files/out b/src/lc/test_files/out Binary files differ. diff --git a/src/vm/inc/ns.h b/src/vm/inc/ns.h @@ -12,14 +12,14 @@ typedef unsigned int ns_addr; typedef struct ns_cont { - unsigned long level; + long level; ns_addr size; var_cont** names; struct ns_cont* next; } ns_cont; typedef struct ns_t { - unsigned long id; + long id; ns_cont* root; ns_cont* last; } ns_t; diff --git a/src/vm/inc/var.h b/src/vm/inc/var.h @@ -32,7 +32,7 @@ typedef enum { } b_type; typedef struct var_cont { - unsigned long ownership; + long ownership; b_type type; void* data; } var_cont; diff --git a/src/vm/src/ns.c b/src/vm/src/ns.c @@ -119,7 +119,7 @@ var_cont* ns_cont_del(ns_cont* container, ns_addr to_return) if (i != to_return && container->names[i] != NULL) { if (container->names[i]->ownership == container->level && - container->names[i]->data != rv->data) + (rv == NULL || container->names[i]->data != rv->data)) { var_del(container->names[i]); } diff --git a/src/vm/tests/cases/bc/Makefile b/src/vm/tests/cases/bc/Makefile @@ -9,12 +9,16 @@ DEPS = $(INC_DIR)/is_mdata.h \ fh.h \ bc.h \ is.h \ + ns.h \ + object.h \ var.h OBJ = test.o \ $(SRC_DIR)/fh.o \ $(SRC_DIR)/bc.o \ $(SRC_DIR)/is.o \ + $(SRC_DIR)/object.o \ + $(SRC_DIR)/ns.o \ $(SRC_DIR)/var.o OUT = test diff --git a/src/vm/tests/cases/ns/Makefile b/src/vm/tests/cases/ns/Makefile @@ -5,10 +5,12 @@ CC = gcc CFLAGS = -ggdb -std=c99 -Wall -I$(INC_DIR) DEPS = i$(INC_DIR)/helper.h \ + object.h \ ns.h \ var.h \ OBJ = test.o \ + $(SRC_DIR)/object.o \ $(SRC_DIR)/ns.o \ $(SRC_DIR)/var.o diff --git a/src/vm/tests/cases/ns/test b/src/vm/tests/cases/ns/test Binary files differ. diff --git a/src/vm/tests/cases/ns/test.c b/src/vm/tests/cases/ns/test.c @@ -6,19 +6,18 @@ int main( void ) { ns_t* test = ns_init(10); - var_cont* testing_on_namespace; var_cont* testing = var_new(G_INT); var_set(testing, var_data_alloc_G_INT(42), G_INT); printf("testing: %li, %i\n", testing->ownership, - var_data_get_G_INT(testing)); + var_data_get_G_INT(testing)); ns_dec(test, G_INT, 0, 2); ns_set(test, 0, 2, testing); - testing_on_namespace = ns_get(test, 0, 2); + var_cont* testing_on_namespace = ns_get(test, 0, 2); printf("testing_on_namespace: %li, %i\n", testing_on_namespace->ownership, - var_data_get_G_INT(testing)); + var_data_get_G_INT(testing)); ns_push(test, 5); @@ -28,15 +27,15 @@ int main( void ) ns_dec(test, G_INT, 0, 1); ns_set(test, 0, 1, testing_2); - testing_on_namespace = ns_get(test, 0, 1); - printf("testing_on_namespace: %li, %i\n", testing_on_namespace->ownership, + var_cont* testing_on_namespace_1 = ns_get(test, 0, 1); + printf("testing_on_namespace: %li, %i\n", testing_on_namespace_1->ownership, var_data_get_G_INT(testing)); ns_dec(test, G_INT, 0, 2); ns_set(test, 0, 2, testing); - testing_on_namespace = ns_get(test, 0, 2); - printf("testing_on_namespace: %li, %i\n", testing_on_namespace->ownership, + var_cont* testing_on_namespace_2 = ns_get(test, 0, 2); + printf("testing_on_namespace: %li, %i\n", testing_on_namespace_2->ownership, var_data_get_G_INT(testing)); ns_push(test, 5); @@ -44,24 +43,24 @@ int main( void ) ns_dec(test, G_INT, 0, 2); ns_set(test, 0, 2, testing); - testing_on_namespace = ns_get(test, 0, 2); - printf("testing_on_namespace: %li, %i\n", testing_on_namespace->ownership, + var_cont* testing_on_namespace_3 = ns_get(test, 0, 2); + printf("testing_on_namespace: %li, %i\n", testing_on_namespace_3->ownership, var_data_get_G_INT(testing)); printf("Namespace info: %d, %li\n", test->last->size, test->last->level); ns_pop(test); - testing_on_namespace = ns_get(test, 0, 2); - printf("testing_on_namespace: %li, %i\n", testing_on_namespace->ownership, + var_cont* testing_on_namespace_4 = ns_get(test, 0, 2); + printf("testing_on_namespace: %li, %i\n", testing_on_namespace_4->ownership, var_data_get_G_INT(testing)); printf("Namespace info: %d, %li\n", test->last->size, test->last->level); ns_pop(test); - testing_on_namespace = ns_get(test, 0, 2); - printf("testing_on_namespace: %li, %i\n", testing_on_namespace->ownership, + var_cont* testing_on_namespace_5 = ns_get(test, 0, 2); + printf("testing_on_namespace: %li, %i\n", testing_on_namespace_5->ownership, var_data_get_G_INT(testing)); printf("Namespace info: %d, %li\n", test->last->size, test->last->level); diff --git a/src/vm/tests/cases/pc/Makefile b/src/vm/tests/cases/pc/Makefile @@ -9,6 +9,8 @@ DEPS = i$(INC_DIR)/is_mdata.h \ fh.h \ is.h \ bc.h \ + object.h \ + ns.h \ var.h \ pc.h @@ -16,6 +18,8 @@ OBJ = test.o \ $(SRC_DIR)/fh.o \ $(SRC_DIR)/is.o \ $(SRC_DIR)/bc.o \ + $(SRC_DIR)/ns.o \ + $(SRC_DIR)/object.o \ $(SRC_DIR)/var.o\ $(SRC_DIR)/pc.o diff --git a/src/vm/tests/cases/pc/test.c b/src/vm/tests/cases/pc/test.c @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) while (pc_safe(pc)) { - printf("ADDR: %x, OP: %x\n", pc->address, pc->line->op); + printf("ADDR: %lx, OP: %x\n", pc->address, pc->line->op); pc_inc(pc, 1); pc_update(pc); } @@ -26,14 +26,14 @@ int main(int argc, char *argv[]) while (pc_safe(pc)) { - printf("ADDR: %x, OP: %x\n", pc->address, pc->line->op); + printf("ADDR: %lx, OP: %x\n", pc->address, pc->line->op); pc_inc(pc, 1); pc_update(pc); } pc_return(pc); pc_update(pc); - printf("ADDR: %x, OP: %x\n", pc->address, pc->line->op); + printf("ADDR: %lx, OP: %x\n", pc->address, pc->line->op); pc_del(pc); return 0; diff --git a/src/vm/tests/cases/stk/Makefile b/src/vm/tests/cases/stk/Makefile @@ -5,11 +5,15 @@ CC = gcc CFLAGS = -std=c99 -Wall -I$(INC_DIR) DEPS = i$(INC_DIR)/helper.h \ + ns.h \ + object.h \ stk.h \ var.h \ OBJ = test.o \ $(SRC_DIR)/stk.o \ + $(SRC_DIR)/object.o \ + $(SRC_DIR)/ns.o \ $(SRC_DIR)/var.o OUT = test