diff options
-rw-r--r-- | sources/scala/tools/scalai/Compiler.java | 29 | ||||
-rw-r--r-- | sources/scala/tools/scalai/Environment.java | 8 | ||||
-rw-r--r-- | sources/scala/tools/scalai/Evaluator.java | 15 | ||||
-rw-r--r-- | sources/scala/tools/scalai/ExpressionCompiler.java | 39 | ||||
-rw-r--r-- | sources/scala/tools/scalai/Variable.java | 6 |
5 files changed, 37 insertions, 60 deletions
diff --git a/sources/scala/tools/scalai/Compiler.java b/sources/scala/tools/scalai/Compiler.java index 6a6f34e4e8..2de32e3f6d 100644 --- a/sources/scala/tools/scalai/Compiler.java +++ b/sources/scala/tools/scalai/Compiler.java @@ -292,9 +292,6 @@ public class Compiler { case ClassDef(_, _, _, _, _, _): sources.put(tree, source); environment.insertClassDef(symbol, (Tree.ClassDef)tree); - if (symbol.isModuleClass() && symbol.isStatic()) { - environment.insertVariable(symbol.module(), Variable.Module(new CodePromise(new ModuleBuilder(this, source, symbol.module())), null)); - } return; // !!! these could be removed @@ -410,30 +407,4 @@ public class Compiler { } //######################################################################## - // !!! - - public static class ModuleBuilder extends CodeGenerator { - - private final Compiler compiler; - private final SourceFile source; - private final Symbol symbol; - - public ModuleBuilder(Compiler compiler, SourceFile source, Symbol symbol) { - this.compiler = compiler; - this.source = source; - this.symbol = symbol; - } - - public CodeContainer generate() { - TreeGen gen = compiler.global.treeGen; - Symbol clasz = symbol.moduleClass(); - Symbol initializer = clasz.lookup(Names.INITIALIZER); - compiler.global.prevPhase(); - Tree code = gen.mkNew__(symbol.pos, Tree.Empty, initializer); - compiler.global.nextPhase(); - return compiler.compile(source, symbol, code, Symbol.EMPTY_ARRAY); - } - } - - //######################################################################## } diff --git a/sources/scala/tools/scalai/Environment.java b/sources/scala/tools/scalai/Environment.java index f9a883d0a0..1a1a056975 100644 --- a/sources/scala/tools/scalai/Environment.java +++ b/sources/scala/tools/scalai/Environment.java @@ -161,6 +161,14 @@ public class Environment { } else if (symbol.isExternal()) { Variable variable = Variable.JavaField(mirror.getField(symbol)); return insertVariable(symbol, variable); + } else if (symbol.isModule() && symbol.isStatic()) { + switch (lookupTemplate(symbol.moduleClass())) { + case Global(ScalaTemplate template): + Variable variable = Variable.Module(template, null); + return insertVariable(symbol, variable); + default: + throw Debug.abort("illegal case", symbol); + } } else { return (Variable)loadOwnerThenGet("variable", symbol, variables); } diff --git a/sources/scala/tools/scalai/Evaluator.java b/sources/scala/tools/scalai/Evaluator.java index 3c04ad7060..604919ba38 100644 --- a/sources/scala/tools/scalai/Evaluator.java +++ b/sources/scala/tools/scalai/Evaluator.java @@ -30,6 +30,7 @@ import scalac.symtab.Symbol; import scalac.symtab.SymbolNameWriter; import scalac.symtab.Type; import scalac.util.Debug; +import scalac.util.Names; public class Evaluator { @@ -445,11 +446,17 @@ public class Evaluator { case Global(Object value): return value; - case Module(CodePromise body, Object value): + case Module(ScalaTemplate template, Object value): if (value != null) return value; - ((Variable.Module)variable).body = null; - evaluate(body, null, new Object[0]); - return load(object, variable); + value = evaluate(Code.Create(template)); + ((Variable.Module)variable).template = null; + ((Variable.Module)variable).value = value; + Symbol clasz = template.getSymbol(); + Symbol initializer = clasz.lookup(Names.INITIALIZER); + CodePromise promise = template.getMethod(initializer); + assert promise != null: Debug.show(clasz, " - ", initializer); + evaluate(promise, value, new Object[0]); + return value; case Member(int index): return getScalaObject(object).variables[index]; diff --git a/sources/scala/tools/scalai/ExpressionCompiler.java b/sources/scala/tools/scalai/ExpressionCompiler.java index 2ecd93a733..f2442df655 100644 --- a/sources/scala/tools/scalai/ExpressionCompiler.java +++ b/sources/scala/tools/scalai/ExpressionCompiler.java @@ -137,33 +137,24 @@ public class ExpressionCompiler { return Code.Switch( compute(test), tags, compute(bodies), compute(otherwise)); - case New(Tree init): // !!! - Symbol symbol = Symbol.NONE.newTerm(tree.pos, 0, Name.fromString("new")); // !!! should be newVariable - Variable variable = Variable.Local(context.push()); - Code code = compute(init); + case New(Tree init): switch (context.lookupTemplate(tree.getType().symbol())) { case Global(ScalaTemplate template): - assert code instanceof Code.Invoke : Debug.show(code); - Code.Invoke invoke = (Code.Invoke)code; - // !!! correct ? - assert invoke.target == Code.Self | invoke.target == Code.Null : Debug.show(code); - invoke.target = Code.Load(Code.Null, variable); - context.insertVariable(symbol, variable); - Code module = template.getSymbol().isModuleClass() - && template.getSymbol().isStatic() - ? Code.Store( - Code.Null, - context.lookupVariable(template.getSymbol().module()), - Code.Load(Code.Null, variable)) - : Code.Null; - code = Code.Block( - new Code[] { - Code.Store(Code.Null, variable, Code.Create(template)), - module, - invoke}, - Code.Load(Code.Null, variable)); + Variable local = Variable.Local(context.push()); + Code create = Code.Create(template); + Code store = Code.Store(Code.Null, local, create); + Code load = Code.Load(Code.Null, local); + Code code = compute(init); + switch (code) { + case Invoke(Null, Function fun, Code[] args, int pos): + Code initialize = Code.Invoke(load, fun, args, pos); + return Code.Block(new Code[] {store, initialize}, load); + default: + throw Debug.abort("illegal case", code); + } + default: + return compute(init); } - return code; case Apply(TypeApply(Tree tfun, Tree[] targs), Tree[] vargs): return tapply(tfun, tfun.symbol(), targs, vargs); diff --git a/sources/scala/tools/scalai/Variable.java b/sources/scala/tools/scalai/Variable.java index 8dc17bcb5e..72b9f7c10f 100644 --- a/sources/scala/tools/scalai/Variable.java +++ b/sources/scala/tools/scalai/Variable.java @@ -19,7 +19,7 @@ public class Variable { // Public Cases public case Global(Object value); - public case Module(CodePromise body, Object value); + public case Module(ScalaTemplate template, Object value); public case Member(int index); public case Argument(int index); public case Local(int index); @@ -34,8 +34,8 @@ public class Variable { case Global(Object value): return "Global(" + Debug.show(value) + ")"; - case Module(CodePromise body, Object value): - return "Module(" + body + "," + Debug.show(value) + ")"; + case Module(ScalaTemplate template, Object value): + return "Module(" + template + "," + Debug.show(value) + ")"; case Member(int index): return "Member(" + index + ")"; |