From 6905791c60a43d45fd0d3784d06120de2073bf98 Mon Sep 17 00:00:00 2001 From: mtardy Date: Wed, 12 Aug 2020 22:31:48 +0200 Subject: [PATCH] Add tests and update todo --- TODO.txt | 27 +++++++++++++++++++++++++++ test-object.txt | 39 +++++++++++++++++++++++++++++++++++++-- test3.txt | 20 ++++++++++++-------- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/TODO.txt b/TODO.txt index 7bf42e8..ccc98a4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,3 +3,30 @@ return break in switch, loops continue in loops + +getFunction(Object.print) +{ + __proto__ : { __name__ : Function }, + body: anAst, + parameters: aMap, + scope: aMap, +} + +makeFunction({ + __proto__ : { __name__ : Function }, + body: anAst, + parameters: aMap, + scope: aMap, +}) + + +var num = `4; // THESE ARE THE +var ast = `(3+@num); // IMPORTANT 2 LINES + +println(3 + @ast); // -> 10 +println(3 + (3+4)); // -> 10 + +syntax for () { + if (__arguments__[1] == #in) { } + else if (__arguments__[1] == #on) { } +} diff --git a/test-object.txt b/test-object.txt index b48b3db..5ebae4b 100644 --- a/test-object.txt +++ b/test-object.txt @@ -11,7 +11,7 @@ Object.new = fun () { var obj= { __proto__ : this }; var init= this.init; print("INIT is ", init); - init && invoke(null, obj, init, __arguments__); + init && invoke(obj, init, __arguments__); obj; }; @@ -26,4 +26,39 @@ Point.init = fun (x, y) { this.y = y; } -print("Point.new(3, 4) is ", Point.new(3, 4)); +var p = Point.new(3, 4); + +print("Point.new(3, 4) is ", p); + + + +Object.clone = fun () { clone(this) } + +var q = p.clone(); + +print("clone is ", q); + +Object.println = fun () { this.print(); print('\n'); this; } + +Object.print = fun () { + var proto= this.__proto__; + if (!proto) print(this); + else { + var name= proto.__name__; + if (!name) print(this); + else { + print(name, "{"); + var keys= keys(this); + for (var i= 0; i < length(keys); ++i) { + var key= keys[i]; + var val= this[key]; + if (i) print(", "); + print(" ", key, ": ", val); + } + print(" }"); + } + } + this; +} + +p.println() \ No newline at end of file diff --git a/test3.txt b/test3.txt index 7a52b60..f2bd8e1 100644 --- a/test3.txt +++ b/test3.txt @@ -1,8 +1,12 @@ -fun f(n) { - if (n < 2) { - return 1 - } else { - return 1 + f(n-1) + f(n-2) - } -} -f(27) \ No newline at end of file +var o = {} +o.a = 12 +o.b = "salut" +var c = clone(o, "12"); + +c.a = 24 +c.b = "au revoir" +c.chips = "on va manger, des chips!!!" + + +o +c \ No newline at end of file