-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-object.txt
110 lines (80 loc) · 1.73 KB
/
test-object.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var Object = { __name__: #"Object" };
println("Object is ", Object);
var Point = { __name__: #"Point", __proto__ : Object };
println("Point is ", Point);
Object.new = fun () {
println("ARGS are ", __arguments__);
var obj= { __proto__ : this };
var init= this.init;
println("INIT is ", init);
init && invoke(obj, init, __arguments__);
obj;
};
println("Object.new is ", Object.new);
println("Point.new is ", Point.new);
println("Object.new() is ", Object.new());
Point.init = fun (x, y) {
this.x = x;
this.y = y;
}
var p = Point.new(3, 4);
println("Point.new(3, 4) is ", p);
Object.clone = fun () { clone(this) }
var q = p.clone();
println("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()
fun println() {
apply(print, __arguments__)
print("\n")
}
fun makeAst() {
println("Making an AST!")
return t
}
var t = `(3+4)
println(t)
var a = 333
syntax double(a) {
return `(@a+@a)
}
println(double(21))
syntax until (c) b {
return `(while (!@c) @b)
}
var x = 0;
until (x==10) {
println(x++)
}
println(`x);
AST.__proto__ = Object;
for (key in AST) AST[key].__proto__ = AST;
/*
{
var k= keys(AST);
var n= length(k);
for (i = 0; i < n; ++i)
AST[k[i]].__proto__ = AST;
};
*/
(`x).println();