commit 9714eedc94447ca125c5986d5a96219cdbd6d75f parent d63d34e130a52e7c988a9326e3ad84323f8a6dbd Author: Paul Longtine <paullongtine@gmail.com> Date: Wed May 4 23:52:21 2016 . Diffstat: src/lc/parser.py | 2 +- src/lc/test_files/class.ti | 19 +++---------------- src/lc/test_files/example.ti | 28 ++++++++++++++++++++++++++++ src/vm/src/ins_def.c | 10 +++------- src/vm/src/proc.c | 10 ---------- 5 files changed, 35 insertions(+), 34 deletions(-)
diff --git a/src/lc/parser.py b/src/lc/parser.py @@ -284,9 +284,9 @@ class Parser(): ], init=(lambda x: [ x.new_name(1), - x.ns_persist(1), ClassDef(x.eval_label(1), x.eval_param(2)), + x.ns_persist(1), x.add_directive(lambda x: [x.ns_save(), x.pop_scope(), x.op(OP_ENDCLASS)]), diff --git a/src/lc/test_files/class.ti b/src/lc/test_files/class.ti @@ -1,23 +1,9 @@ -class Counter: -{ - int val = 0; - int inc = 1; - - func increment -> int: - { - val = val + inc; - return val; - } -} - class ObjectFibb: { int a = 0; int b = 1; int c = 0; - Counter counter = new Counter(); - func next -> void: { if c == 0: @@ -40,9 +26,10 @@ class ObjectFibb: func run (int count) -> void: { - counter.val = 0; - while counter.increment() < count: + int x = 0; + while x < count: { + x = x + 1; next(); display(); } diff --git a/src/lc/test_files/example.ti b/src/lc/test_files/example.ti @@ -0,0 +1,28 @@ +class Object(int init_args): +{ + int property = init_args * 2; + + func method (int arg1, int arg2) -> string: + { + property = (arg1 * arg2) / property; + + return "Unrelated string literal"; + } + + func init_method -> void: + { + print "Initalized Object"; + } + + init_method(); + } + +func main -> void: +{ + Object new_object = new Object(3); + + print object.property; + print object.method; +} + +main(); diff --git a/src/vm/src/ins_def.c b/src/vm/src/ins_def.c @@ -598,7 +598,7 @@ void _ins_def_CALLM (rt_t* ctx, bc_cont* line) var_data_func* func = var_data_get_FUNC(var); // Push current namespace context ns_ctx_push(ctx->varctx, ctx->vars); - if (ctx->db) printf("PUSHED NAMESPACE CONTEXT\n"); + // Set current namespace to objects namespace ctx->vars = object->names; // Call the function @@ -609,7 +609,6 @@ void _ins_def_CALLM (rt_t* ctx, bc_cont* line) proc_run_to_return(ctx); // Pop the namespace context ctx->vars = ns_ctx_pop(ctx->varctx); - if (ctx->db) printf("POPPED NAMESPACE CONTEXT\n"); pc_inc(ctx->pc, 1); } @@ -630,7 +629,7 @@ void _ins_def_RETURN (rt_t* ctx, bc_cont* line) // Pop the namespace and get the return value var_cont* return_value = ns_pop(ctx->vars); - if (ctx->db) printf("RETURN VALUE TYPE (%i)\n", return_value->type); + // Push the return value to the stack stk_push(ctx->stack, return_value); @@ -640,7 +639,7 @@ void _ins_def_RETURN (rt_t* ctx, bc_cont* line) void _ins_def_NEW (rt_t* ctx, bc_cont* line) { int scope = var_data_get_G_INT(line->varg[0]); - int name = var_data_get_G_INT(line->varg[0]); + int name = var_data_get_G_INT(line->varg[1]); // Get the object builder var_cont* var = proc_getvar(ctx, scope, name); @@ -651,7 +650,6 @@ void _ins_def_NEW (rt_t* ctx, bc_cont* line) // Push current namespace to namespace context ns_ctx_push(ctx->varctx, ctx->vars); - if (ctx->db) printf("NEW: PUSHED NEW NAMESPACE CONTEXT\n"); // Set the current namespace to new namespace ctx->vars = new_ns; @@ -678,7 +676,6 @@ void _ins_def_NEW (rt_t* ctx, bc_cont* line) } void _ins_def_ENDCLASS (rt_t* ctx, bc_cont* line) { - if (ctx->db) printf("NEW: CREATING NEW OBJECT\n"); var_cont* new = var_new(OBJECT); var_data_object* data = var_data_alloc_OBJECT(object_del); @@ -692,7 +689,6 @@ void _ins_def_ENDCLASS (rt_t* ctx, bc_cont* line) stk_poplevel(&ctx->stack); stk_poplevel(&ctx->argstk); - if (ctx->db) printf("NEW: POPPED NAMESPACE\n"); ctx->vars = ns_ctx_pop(ctx->varctx); stk_push(ctx->stack, new); diff --git a/src/vm/src/proc.c b/src/vm/src/proc.c @@ -53,8 +53,6 @@ void proc_run_to_return(rt_t* ctx) { N_ASSERT(ctx, "proc_run\n"); - if (ctx->db) printf("START proc_run_to_return\n"); - int n; for (n = 0; pc_safe(ctx->pc); pc_update(ctx->pc)) { @@ -67,7 +65,6 @@ void proc_run_to_return(rt_t* ctx) if (ctx->pc->line->op == 0x7F) { - if (ctx->db) printf("FUNCTION CALL proc_run_to_return\n"); n++; } @@ -79,16 +76,13 @@ void proc_run_to_return(rt_t* ctx) { if (n > 0) { - if (ctx->db) printf("FUNCTION CALL RETURN proc_run_to_return\n"); n--; } else { - if (ctx->db) printf("RETURNING FROM proc_run_to_return\n"); break; } } } - if (ctx->db) printf("END proc_run_to_return\n"); } /* Calls runtime context elements to free memory and terminate @@ -174,7 +168,6 @@ var_cont* proc_getvar(rt_t* ctx, int scope, ns_addr name) rv = ns_get(ns, s, name); } - return rv; } @@ -183,7 +176,6 @@ var_cont* proc_getvar(rt_t* ctx, int scope, ns_addr name) void proc_function_call(rt_t* ctx, int scope, ns_addr name) { N_ASSERT(ctx, "proc_function_call\n"); - if (ctx->db) printf("FUNCTION CALL (%i)\n", name); int x = (scope & 0xFE) >> 1; @@ -212,8 +204,6 @@ void proc_function_call(rt_t* ctx, int scope, ns_addr name) { ctx->vars = ns_ctx_pop(ctx->varctx); } - - if (ctx->db) printf("RETURN (%i)\n", name); } /* Handles arguements and namespace procedures for a given