AST
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

110 rivejä
1.7 KiB

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();