language

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 8749c60f93b58f010decbd126686d4b09f9f93d2
parent d8072402b929b1ba16dd247d1493cfdfd26d09d6
Author: Paul Longtine <paul@nanner.co>
Date:   Sun, 24 Sep 2017 22:19:30 -0400

Updated doc/SPECIFICATION a bit

lc/interpeter.py:
 - Fixed issue where instantiating an object with arguements would not parse
arguements

Diffstat:
Mdoc/SPECIFICATION | 25+++++++++++++++----------
Msrc/lc/interpreter.py | 21+++++++++++++++++----
Msrc/lc/parser.py | 3+--
Msrc/lc/test_files/example.ti | 27+++++++++++++++------------
Msrc/vm/src/ins_def.c | 10++++++++--
5 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/doc/SPECIFICATION b/doc/SPECIFICATION @@ -9,8 +9,13 @@ The goal is not to innovate, but to see if _I_ can. This is a personal refuge before my inevitable contributions to large group projects where individuals are deemed inferior. - SYNTAX - #TO BE DETERMINED# + PARSER + The syntax and semantics of the language are defined by the cryptic parser +implemented under /src/lc/parser.py, where each type of statement is built from +atomic definitions of various token types, static expressions, and dynamic +expressions. Each one of the matched statments in the parser has a method +"action" -> returns a list of other objects with an "action" method or bytes, +until all that is left is raw bytes in the list. TYPES @@ -103,16 +108,17 @@ function calls, you can traverse n instances of previous namespaces. For example, take this namespace level graphic, where each Level is a namespace instance: - Level 0: Global namespace, LSB == '1'. - Level 1: Namespace level, where Local Level is at 1, LSB == '0'. + Level 0: Global namespace, LSB == '1'. Raw: 00000001 + Level 1: Namespace level, LSB == '0'. Raw: 00000000 When a function is called, another namespace level is created and the local level increases, like so: - Level 0: Global namespace, LSB == '1'. - Level 1: Namespace level. - Level 2: Namespace level, where Local Level is at 2, LSB == '0'. - + Level 0: Global namespace, LSB == '1'. Raw: 00000001 + <function call> + Level 1: Namespace level, where Local Level is at 1, LSB == '0'. Raw: 00000000 + <function call> + Level 2: Namespace level, where Local Level is at 2, LSB == '0'. Raw: 00000000 Global scope names (LSB == 1 in the scope arguement) are persistient through the runtime as they handle all function definitions, objects, and @@ -121,8 +127,7 @@ that have a scope arguement of '0' refer to when accessing names. The Namespace arguement refers to which Namespace the variable exists in. When the namespace arguement equals 0, the current namespace is referenced. -The global namespace is 1 by default, and any other namespaces must be declared -by using the +The global namespace is 1 by default VARIABLE DEFINITION diff --git a/src/lc/interpreter.py b/src/lc/interpreter.py @@ -35,19 +35,22 @@ class Label(AbstractToken): if len(names) > 1: self.is_property = True self.parent = Label(self.i, names[0]) - self.parent.update() self.name = names[1] - t = self.i.ns.resolve_with_obj(self.parent, names[1]) + print("RESOLVING {}".format(self.name)) + t = self.i.ns.resolve_with_obj(self.parent, self.name) + print("RESOLVED {}: {}".format(self.name, t)) self.expr = t[0] else: self.name = names[0] + print("RESOLVING {}".format(self.name)) t = self.i.ns.resolve(self.name) + print("RESOLVED {}: {}".format(self.name, t)) self.scope = t[0] self.expr = t[1] @@ -60,9 +63,18 @@ class Label(AbstractToken): class Arguements(AbstractToken): def update(self): - tokens = token_split(self.data[1:], + if len(self.data) > 0: + if self.data[0] == "(": + t = self.data[1:] + else: + t = self.data + else: + t = self.data + + tokens = token_split(t, [["[", "("], ["]", ")"]], [","], include_splitter = False) + for t in tokens: self.expr.insert(0, Expression(self.i, t)) @@ -138,7 +150,7 @@ class Expression(AbstractToken): "func_call", expression=[ self.i.p.label_def, - self.i.p.paramlist_def, + self.i.p.paramlist_def ], init=(lambda x,y: FunctionCall(Label(x,y[0]), Arguements(x,y[1:]))) @@ -176,6 +188,7 @@ class Expression(AbstractToken): t = token_split(self.data, self.group_char, self.operator_names) + if len(t) == 0: t = self.data if len(t) > 2: diff --git a/src/lc/parser.py b/src/lc/parser.py @@ -288,7 +288,7 @@ class Parser(): x.new_name(1), x.ns_persist(1), ClassDef(x.eval_label(1), - None), + x.eval_param(2)), x.add_directive(lambda x: [x.ns_save(), x.op(OP_ENDCLASS)]) ]) @@ -311,7 +311,6 @@ class Parser(): ]) ) - self.statement_new = Statement( "new", expression=[ diff --git a/src/lc/test_files/example.ti b/src/lc/test_files/example.ti @@ -2,27 +2,30 @@ class Object(int init_args): { int property = init_args * 2; - func method (int arg1, int arg2) -> string: + func method (int arg1, int arg2) -> void: { property = (arg1 * arg2) / property; - - return "Unrelated string literal"; } - func init_method -> void: + func init_method() -> void: { - print "Initalized Object"; + print "Initialized Object"; } - init_method(); - } + init_method(); +} -func main -> void: +func main(int arg) -> void: { - Object new_object = new Object(3); + Object new_object = new Object(arg); + + print new_object.property; + + new_object.method(2,4); - print object.property; - print object.method; + print new_object.property; } -main(); +print "Calling main()"; +main(2); +print "Called main()"; diff --git a/src/vm/src/ins_def.c b/src/vm/src/ins_def.c @@ -282,7 +282,7 @@ void _ins_def_DIV (rt_t* ctx, bc_cont* line) var_cont* A = stk_pop(ctx->stack); var_cont* B = stk_pop(ctx->stack); - var_cont* var = var_mult(A, B); + var_cont* var = var_div(A, B); stk_push(ctx->stack, var); @@ -782,10 +782,11 @@ void _ins_def_DEFUN (rt_t* ctx, bc_cont* line) /* Determine the namespace size by finding variable declarations in the functions body, Along with determining the end of the function. */ - for (nsize = 0; pc_safe(ctx->pc); pc_update(ctx->pc)) + for (nsize = 0; pc_safe(ctx->pc);) { // Increment the program counter pc_inc(ctx->pc, 1); + pc_update(ctx->pc); // Is this the end? if (ctx->pc->line->op == 0xF0) @@ -799,6 +800,11 @@ void _ins_def_DEFUN (rt_t* ctx, bc_cont* line) nsize++; } } + + pc_inc(ctx->pc, 1); + pc_update(ctx->pc); + + // Set all the values. data->end = ctx->pc->line->real_addr; // This is the end! data->size = nsize + alen + 1; // How many names will this