package org.mozartoz.truffle.translator;

import org.mozartoz.truffle.nodes.OzNode;
import org.mozartoz.truffle.nodes.OzRootNode;
import org.mozartoz.truffle.nodes.builtins.BuiltinsManager;
import org.mozartoz.truffle.nodes.builtins.ValueBuiltinsFactory.DotNodeFactory;
import org.mozartoz.truffle.nodes.call.CallNode;
import org.mozartoz.truffle.nodes.literal.LiteralNode;
import org.mozartoz.truffle.runtime.Arity;
import org.mozartoz.truffle.runtime.OzRecord;
import org.mozartoz.truffle.runtime.OzVar;

import com.oracle.truffle.api.RootCallTarget;

public abstract class InitFunctor {

	public static RootCallTarget apply(Object initFunctor) {
		Object imports = OzRecord.buildRecord(
				Arity.build("import", "Boot"),
				BuiltinsManager.getBootModule("Boot_Boot"));

		OzNode node = CallNode.create(
				DotNodeFactory.create(new LiteralNode(initFunctor), new LiteralNode("apply")),
				new LiteralNode(new Object[] { imports, new OzVar() }));

		return OzRootNode.createTopRootNode("Init.apply", node).toCallTarget();
	}

}

@@ -31,24 +31,69 @@
 ranslator;%0A%0A
+import org.mozartoz.truffle.nodes.DerefNode;%0A
 import org.m
@@ -118,24 +118,24 @@
 des.OzNode;%0A
-
 import org.m
@@ -353,24 +353,80 @@
 l.CallNode;%0A
+import org.mozartoz.truffle.nodes.control.SequenceNode;%0A
 import org.m
@@ -877,17 +877,48 @@
 %09%09Oz
-Node node
+Var result = new OzVar();%0A%09%09OzNode apply
  = C
@@ -1064,26 +1064,110 @@
 ts, 
-new OzVar() %7D
+result %7D));%0A%0A%09%09OzNode node = SequenceNode.sequence(apply, DerefNode.create(new LiteralNode(result)
 ));%0A
-%0A
 %09%09re

Use a result variable in InitFunctor#apply()