Classes fixes.
This commit is contained in:
parent
8797d5cc0c
commit
ef7b77e5da
|
|
@ -485,7 +485,7 @@ Future plans
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
- add `observe` modificator.
|
||||||
- static typing
|
- static typing
|
||||||
- `@use` expressions
|
- `@use` expressions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ Cola._ColaRuntime$$updateProperty.i = 14;
|
||||||
Cola._ColaRuntime$$proto = function _ColaRuntime$$proto(_proto) {
|
Cola._ColaRuntime$$proto = function _ColaRuntime$$proto(_proto) {
|
||||||
function proto(){}
|
function proto(){}
|
||||||
proto.prototype = _proto.prototype;
|
proto.prototype = _proto.prototype;
|
||||||
return new c();
|
return new proto();
|
||||||
};
|
};
|
||||||
Cola._ColaRuntime$$proto.i = 15;
|
Cola._ColaRuntime$$proto.i = 15;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1339,8 +1339,15 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
body : []
|
body : []
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var has_main_constr = false;
|
||||||
node.body.forEach(function(member){
|
node.body.forEach(function(member){
|
||||||
if(member instanceof Cola.AST_Defun && member.name instanceof Cola.AST_SymbolDefun && member.name.name == node.name.name){
|
if(member instanceof Cola.AST_Defun && member.name instanceof Cola.AST_SymbolDefun && member.name.name == node.name.name){
|
||||||
|
if(member.type != "dynamic")
|
||||||
|
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Constructor can't have returned type.");
|
||||||
|
|
||||||
|
if(member.mods.length != 0)
|
||||||
|
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Constructor can't have modificators.");
|
||||||
|
|
||||||
if(main_constructors.some(function(constr){ return constr.name instanceof Cola.AST_Dot; }))
|
if(main_constructors.some(function(constr){ return constr.name instanceof Cola.AST_Dot; }))
|
||||||
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Main constructor must be defined before named constructors");
|
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Main constructor must be defined before named constructors");
|
||||||
|
|
||||||
|
|
@ -1350,6 +1357,8 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
main_constructors.push(member);
|
main_constructors.push(member);
|
||||||
newNode.push(member);
|
newNode.push(member);
|
||||||
|
|
||||||
|
has_main_constr = true;
|
||||||
|
|
||||||
if(node.extends){
|
if(node.extends){
|
||||||
_ColaRuntime$$hash[Cola._ColaRuntime$$proto.i] = true;
|
_ColaRuntime$$hash[Cola._ColaRuntime$$proto.i] = true;
|
||||||
newNode.push(new Cola.AST_Assign({
|
newNode.push(new Cola.AST_Assign({
|
||||||
|
|
@ -1370,6 +1379,12 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
|
|
||||||
if(member instanceof Cola.AST_Defun && member.name instanceof Cola.AST_Dot &&
|
if(member instanceof Cola.AST_Defun && member.name instanceof Cola.AST_Dot &&
|
||||||
member.name.expression instanceof Cola.AST_SymbolDefun && member.name.expression.name == node.name.name){
|
member.name.expression instanceof Cola.AST_SymbolDefun && member.name.expression.name == node.name.name){
|
||||||
|
if(member.type != "dynamic")
|
||||||
|
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Constructor can't have returned type.");
|
||||||
|
|
||||||
|
if(member.mods.length != 0)
|
||||||
|
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Constructor can't have modificators.");
|
||||||
|
|
||||||
if(main_constructors.some(function(constr){ return constr.name instanceof Cola.AST_Dot && constr.name.property == member.name.property; }))
|
if(main_constructors.some(function(constr){ return constr.name instanceof Cola.AST_Dot && constr.name.property == member.name.property; }))
|
||||||
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Constructor can be defined only one time");
|
Cola.Parser.prototype.token_error.call(Cola.Parser.prototype, member.start, "Constructor can be defined only one time");
|
||||||
|
|
||||||
|
|
@ -1420,6 +1435,40 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(!has_main_constr){
|
||||||
|
newNode.push(new Cola.AST_Defun({
|
||||||
|
mods : [],
|
||||||
|
type : "dynamic",
|
||||||
|
name : new Cola.AST_SymbolDefun(node.name),
|
||||||
|
argnames : [],
|
||||||
|
body : []
|
||||||
|
}));
|
||||||
|
|
||||||
|
main_constructors.push(newNode[newNode.length - 1]);
|
||||||
|
|
||||||
|
if(node.extends){
|
||||||
|
newNode[newNode.length - 1].body.push(new Cola.AST_SimpleStatement({
|
||||||
|
body : new Cola.AST_Call({
|
||||||
|
expression : new Cola.AST_SymbolRef({ name: "super" }),
|
||||||
|
args : []
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
|
_ColaRuntime$$hash[Cola._ColaRuntime$$proto.i] = true;
|
||||||
|
newNode.push(new Cola.AST_Assign({
|
||||||
|
left : new Cola.AST_Dot({ expression: node.name, property: "prototype" }),
|
||||||
|
operator : "=",
|
||||||
|
right : new Cola.AST_Call({
|
||||||
|
expression : new Cola.AST_SymbolRef({ name: "_ColaRuntime$$proto" }),
|
||||||
|
args : [node.extends]
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
newNode[newNode.length - 1] = new Cola.AST_SimpleStatement({
|
||||||
|
body : newNode[newNode.length - 1]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(pre_constructor.body.length != 0){
|
if(pre_constructor.body.length != 0){
|
||||||
newNode.push(pre_constructor);
|
newNode.push(pre_constructor);
|
||||||
main_constructors.forEach(function(constr){
|
main_constructors.forEach(function(constr){
|
||||||
|
|
@ -1470,7 +1519,15 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
scope = (lvl++, member);
|
scope = (lvl++, member);
|
||||||
else
|
else
|
||||||
|
|
||||||
if(member instanceof Cola.AST_Call && member.expression instanceof Cola.AST_Symbol && member.expression.name == "super"){
|
if(member instanceof Cola.AST_Call && member.expression instanceof Cola.AST_Symbol && member.expression.name == "super" && node.extends){
|
||||||
|
member.expression = new Cola.AST_Dot({
|
||||||
|
expression : node.extends,
|
||||||
|
property : "call"
|
||||||
|
});
|
||||||
|
member.args.unshift(new Cola.AST_This);
|
||||||
|
} else
|
||||||
|
|
||||||
|
if(member instanceof Cola.AST_Call && member.expression instanceof Cola.AST_Dot && member.expression.expression.name == "super" && node.extends){
|
||||||
member.expression = new Cola.AST_Dot({
|
member.expression = new Cola.AST_Dot({
|
||||||
expression : member.expression,
|
expression : member.expression,
|
||||||
property : "call"
|
property : "call"
|
||||||
|
|
@ -1478,15 +1535,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
member.args.unshift(new Cola.AST_This);
|
member.args.unshift(new Cola.AST_This);
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if(member instanceof Cola.AST_Call && member.expression instanceof Cola.AST_Dot && member.expression.expression.name == "super"){
|
if(member instanceof Cola.AST_SymbolRef && hmembers.indexOf(member.name) != -1 && node.extends){
|
||||||
member.expression = new Cola.AST_Dot({
|
|
||||||
expression : member.expression,
|
|
||||||
property : "call"
|
|
||||||
});
|
|
||||||
member.args.unshift(new Cola.AST_This);
|
|
||||||
} else
|
|
||||||
|
|
||||||
if(member instanceof Cola.AST_SymbolRef && hmembers.indexOf(member.name) != -1){
|
|
||||||
if(member.name == "super"){
|
if(member.name == "super"){
|
||||||
with_super = true;
|
with_super = true;
|
||||||
member.name = "$uper";
|
member.name = "$uper";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user