diff --git a/CHANGELOG.md b/CHANGELOG.md index eb6817d14e..56299b5967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,10 +122,12 @@ - [Added overloaded `from` conversions.][3227] - [Upgraded to Graal VM 21.3.0][3258] - [Added the ability to decorate values with warnings.][3248] +- [Fixed issues related to constructors' default arguments][3330] [3227]: https://github.com/enso-org/enso/pull/3227 [3248]: https://github.com/enso-org/enso/pull/3248 [3258]: https://github.com/enso-org/enso/pull/3258 +[3330]: https://github.com/enso-org/enso/pull/3330 # Enso 2.0.0-alpha.18 (2021-10-12) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/EnsoRootNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/EnsoRootNode.java index 13a7be1dcf..3919fe4ccf 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/EnsoRootNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/EnsoRootNode.java @@ -128,4 +128,5 @@ public abstract class EnsoRootNode extends RootNode { public boolean isCloningAllowed() { return true; } + } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/atom/InstantiateNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/atom/InstantiateNode.java index e830d8b532..d51f2f5123 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/atom/InstantiateNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/atom/InstantiateNode.java @@ -44,7 +44,7 @@ public class InstantiateNode extends ExpressionNode { * Creates an instance of this node. * * @param constructor the {@link AtomConstructor} this node will be instantiating - * @param arguments the expressions for field values + * @param arguments the expressions that produce field values * @return a node that instantiates {@code constructor} */ public static InstantiateNode build(AtomConstructor constructor, ExpressionNode[] arguments) { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/InstantiateAtomNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/InstantiateAtomNode.java deleted file mode 100644 index 58e632878d..0000000000 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/InstantiateAtomNode.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.enso.interpreter.node.expression.builtin; - -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.NodeInfo; -import com.oracle.truffle.api.nodes.RootNode; -import org.enso.interpreter.Language; -import org.enso.interpreter.node.ExpressionNode; -import org.enso.interpreter.runtime.callable.function.Function; -import org.enso.interpreter.runtime.state.Stateful; - -/** This node represents the process of instantiating an atom at runtime. */ -@NodeInfo(shortName = "constructor::", description = "An atom instantiation at runtime.") -public class InstantiateAtomNode extends RootNode { - private @Child ExpressionNode instantiator; - private final String name; - - private InstantiateAtomNode(Language language, String name, ExpressionNode instantiator) { - super(language); - this.name = name; - this.instantiator = instantiator; - } - - /** - * Executes this node. - * - * @param frame the language frame being executed - * @return the result of executing this node - */ - @Override - public Stateful execute(VirtualFrame frame) { - return new Stateful( - Function.ArgumentsHelper.getState(frame.getArguments()), - instantiator.executeGeneric(frame)); - } - - /** - * Returns a string representation of this node. - * - * @return a string representation of this node - */ - @Override - public String getName() { - return name; - } - - /** - * Creates an instance of this node. - * - * @param language the language for which the node is created - * @param name the name of the atom being instantated - * @param instantiator the expression used to instantiate the atom - * @return an instance of this node - */ - public static InstantiateAtomNode build( - Language language, String name, ExpressionNode instantiator) { - return new InstantiateAtomNode(language, name, instantiator); - } -} diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java index 54dd225ba8..7b031d9285 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/atom/AtomConstructor.java @@ -11,12 +11,13 @@ import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.api.library.ExportLibrary; import com.oracle.truffle.api.library.ExportMessage; import com.oracle.truffle.api.nodes.RootNode; +import org.enso.interpreter.node.ClosureRootNode; import org.enso.interpreter.node.ExpressionNode; import org.enso.interpreter.node.callable.argument.ReadArgumentNode; +import org.enso.interpreter.node.callable.function.BlockNode; import org.enso.interpreter.node.expression.atom.GetFieldNode; import org.enso.interpreter.node.expression.atom.InstantiateNode; import org.enso.interpreter.node.expression.atom.QualifiedAccessorNode; -import org.enso.interpreter.node.expression.builtin.InstantiateAtomNode; import org.enso.interpreter.runtime.Context; import org.enso.interpreter.runtime.callable.UnresolvedConversion; import org.enso.interpreter.runtime.callable.UnresolvedSymbol; @@ -24,6 +25,7 @@ import org.enso.interpreter.runtime.callable.argument.ArgumentDefinition; import org.enso.interpreter.runtime.callable.function.Function; import org.enso.interpreter.runtime.callable.function.FunctionSchema; import org.enso.interpreter.runtime.library.dispatch.MethodDispatchLibrary; +import org.enso.interpreter.runtime.scope.LocalScope; import org.enso.interpreter.runtime.scope.ModuleScope; import org.enso.pkg.QualifiedName; @@ -39,7 +41,7 @@ public final class AtomConstructor implements TruffleObject { /** * Creates a new Atom constructor for a given name. The constructor is not valid until {@link - * AtomConstructor#initializeFields(ArgumentDefinition...)} is called. + * AtomConstructor#initializeFields(LocalScope,ExpressionNode[],ExpressionNode[],ArgumentDefinition...)} is called. * * @param name the name of the Atom constructor * @param definitionScope the scope in which this constructor was defined @@ -49,15 +51,37 @@ public final class AtomConstructor implements TruffleObject { this.definitionScope = definitionScope; } + /** - * Sets the fields of this {@link AtomConstructor} and generates a constructor function. + * Generates a constructor function for this {@link AtomConstructor}. + * Note that such manually constructed argument definitions must not have default arguments. * - * @param args the arguments this constructor will take * @return {@code this}, for convenience */ public AtomConstructor initializeFields(ArgumentDefinition... args) { + ExpressionNode[] reads = new ExpressionNode[args.length]; + for (int i=0; i