Skip to content

Commit

Permalink
work on #750
Browse files Browse the repository at this point in the history
  • Loading branch information
chochos committed Sep 30, 2015
1 parent 48a5751 commit 80c45ba
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 10 deletions.
2 changes: 1 addition & 1 deletion runtime-js/jsint/AppliedCallableConstructor/container.js
@@ -1 +1 @@
return null;
return this.fakeConstr$?this.type:null;
2 changes: 1 addition & 1 deletion runtime-js/jsint/AppliedCallableConstructor/type.js
@@ -1,5 +1,5 @@
if (this.cont$===undefined) {
var cc=getrtmm$$(this.tipo).$cont;
var cc=this.fakeConstr$?this.tipo:getrtmm$$(this.tipo).$cont;
this.cont$=AppliedClass$jsint(cc,{Type$AppliedClass:this.$$targs$$.Type$AppliedCallableConstructor,Arguments$AppliedClass:{t:Nothing}},undefined,this.$targs);
}
return this.cont$;
9 changes: 9 additions & 0 deletions runtime-js/jsint/AppliedClass/defaultConstructor.js
Expand Up @@ -2,13 +2,22 @@ if (this.$defcons$===undefined) {
var mm=getrtmm$$(this.tipo);
var fn=mm.d[mm.d.length-1]+'_$c$';
var cn=this.tipo[fn];
var fc=false;
if (!cn) {
var m2=get_model(mm);
if (m2 && m2.$cn===undefined) {
cn=this.tipo;
fc=true;
}
}
if (cn) {
mm=getrtmm$$(cn).ps;
var args=tupleize$params(getrtmm$$(cn).ps,this.$$targs$$.Target$Type.a);
var r=AppliedCallableConstructor$jsint(cn,{Type$AppliedCallableConstructor:this.$$targs$$.Type$AppliedClass,
Arguments$AppliedCallableConstructor:args},undefined,this.$targs);
r.cont$=this;
this.$defcons$=r;
if(fc)r.fakeConstr$=true;
return r;
}
this.$defcons$=null;
Expand Down
2 changes: 1 addition & 1 deletion runtime-js/jsint/OpenCallableConstructor.js
Expand Up @@ -15,7 +15,7 @@ function OpenCallableConstructor$jsint(pkg, meta, that){
that.meta_ = get_model(_mm);
}
that.name_=(that.meta&&that.meta.nm)||_mm.d[_mm.d.length-1];
if (that.name_==='$def') {
if (that.name_==='$def' || that.name_==='$c' || _mm.d.length<3) {
that.name_='';
} else if (that.name_.indexOf('$')>0) {
that.name_=that.name_.substring(0,that.name_.indexOf('$'));
Expand Down
4 changes: 3 additions & 1 deletion runtime-js/jsint/OpenCallableConstructor/invoke.js
Expand Up @@ -3,8 +3,10 @@ function invoke(targs,args) {
for (var i=0;i<args.size;i++) {
a$.push(args.$_get(i));
}
var mm=getrtmm$$(this.tipo);
var fc=mm.d[mm.d.length-1]!=='$def';
if (targs.size) {
a$.push(tparms2targs$(getrtmm$$(this.tipo).$cont,targs));
a$.push(tparms2targs$(fc?this.tipo:mm.$cont,targs));
}
return this.tipo.apply(undefined,a$);
}
18 changes: 14 additions & 4 deletions runtime-js/jsint/OpenCallableConstructor/memberApply.js
@@ -1,6 +1,16 @@
function memberApply(ctype,targs,$mpt) {
return AppliedMemberClassCallableConstructor$jsint(this.tipo,
{Type$AppliedMemberClassCallableConstructor:$mpt.Result$memberApply,
Container$AppliedMemberClassCallableConstructor:$mpt.Container$memberApply,
Arguments$AppliedMemberClassCallableConstructor:$mpt.Arguments$memberApply});
var fakeConstructor=false;
if (this.defaultConstructor) {
var mm=getrtmm$$(this.tipo);
fakeConstructor=mm.d[mm.d.length-1]!=='$def';
if (fakeConstructor && mm.d[mm.d.length-1]!=='$c') {
throw TypeApplicationException$meta$model("Not a member constructor");
}
}
var c=AppliedMemberClassCallableConstructor$jsint(this.tipo,
{Type$AppliedMemberClassCallableConstructor:$mpt.Result$memberApply,
Container$AppliedMemberClassCallableConstructor:$mpt.Container$memberApply,
Arguments$AppliedMemberClassCallableConstructor:$mpt.Arguments$memberApply});
if (fakeConstructor)c.fakeConstr$=true;
return c;
}
7 changes: 6 additions & 1 deletion runtime-js/jsint/OpenCallableConstructor/memberInvoke.js
@@ -1,10 +1,15 @@
function memberInvoke(o,targs,args) {
var mm=getrtmm$$(this.tipo);
var fc=mm.d[mm.d.length-1]!=='$def';
if (fc && mm.d[mm.d.length-1]!=='$c') {
throw TypeApplicationException$meta$model("Not a member constructor");
}
var a$=[];
for (var i=0;i<args.size;i++) {
a$.push(args.$_get(i));
}
if (targs.size) {
a$.push(tparms2targs$(getrtmm$$(this.tipo).$cont,targs));
a$.push(tparms2targs$(fc?this.tipo:mm.$cont,targs));
}
return this.tipo.apply(o,a$);
}
17 changes: 16 additions & 1 deletion runtime-js/metamodel_functions_coi.js
Expand Up @@ -690,7 +690,7 @@ function coiclsannconstrs$(coi,anntypes,prefix,mt,arg$,tipo) {
var cs=[];
for (var cn in coi.tipo) {
if (cn.startsWith(prefix)) {
mm=getrtmm$$(coi.tipo[cn]);
var mm=getrtmm$$(coi.tipo[cn]);
if (mm.d[mm.d.length-2]===mt && coi$is$anns(allann$(mm),ats)) {
var parms=mm.ps;
if (parms && arg$.t!==Nothing && tipo.a) {
Expand All @@ -705,5 +705,20 @@ function coiclsannconstrs$(coi,anntypes,prefix,mt,arg$,tipo) {
}
}
}
if (cs.length===0 && this.defaultConstructor && this.defaultConstructor.fakeConstr$) {
mm=getrtmm$$(coi.tipo);
if (coi$is$anns(allann$(mm),ats)) {
var parms=mm.ps;
if (parms && arg$.t!==Nothing && tipo.a) {
for (var i=0;i<parms.length;i++) {
parms[i] = {$t:restype$(tipo,parms[i].$t)};
}
}
if (validate$params(parms,arg$,"",1)) {
var args=parms?tupleize$params(parms,coi.$targs):empty();
cs.push({tipo:coi.tipo,args:args});
}
}
}
return cs;
}

0 comments on commit 80c45ba

Please sign in to comment.