Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul implementation of for-generators #844

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pkl-core/src/main/java/org/pkl/core/ast/MemberNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package org.pkl.core.ast;

import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import java.util.function.Function;
import org.pkl.core.ast.member.DefaultPropertyBodyNode;
import org.pkl.core.runtime.VmExceptionBuilder;
import org.pkl.core.runtime.VmLanguage;
Expand All @@ -44,14 +42,6 @@ public final ExpressionNode getBodyNode() {
return bodyNode;
}

public final void replaceBody(Function<ExpressionNode, ExpressionNode> replacer) {
bodyNode = insert(replacer.apply(bodyNode));
}

protected final Object executeBody(VirtualFrame frame) {
return executeBody(frame, bodyNode);
}

protected final VmExceptionBuilder exceptionBuilder() {
return new VmExceptionBuilder().withSourceSection(getHeaderSection());
}
Expand Down
12 changes: 10 additions & 2 deletions pkl-core/src/main/java/org/pkl/core/ast/PklRootNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.type.VmTypeMismatchException;
import org.pkl.core.runtime.*;
import org.pkl.core.util.Nullable;

Expand All @@ -36,9 +37,16 @@ protected PklRootNode(@Nullable VmLanguage language, FrameDescriptor descriptor)

public abstract @Nullable String getName();

protected final Object executeBody(VirtualFrame frame, ExpressionNode bodyNode) {
// name must start with `execute` (see Javadoc of @Specialization)
protected abstract Object executeImpl(VirtualFrame frame);

@Override
public final Object execute(VirtualFrame frame) {
try {
return bodyNode.executeGeneric(frame);
return executeImpl(frame);
} catch (VmTypeMismatchException e) {
CompilerDirectives.transferToInterpreter();
throw e.toVmException();
} catch (VmException e) {
CompilerDirectives.transferToInterpreter();
throw e;
Expand Down
4 changes: 2 additions & 2 deletions pkl-core/src/main/java/org/pkl/core/ast/SimpleRootNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getName() {
}

@Override
public Object execute(VirtualFrame frame) {
return executeBody(frame, bodyNode);
protected Object executeImpl(VirtualFrame frame) {
return bodyNode.executeGeneric(frame);
}
}
7 changes: 0 additions & 7 deletions pkl-core/src/main/java/org/pkl/core/ast/VmModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ private VmModifier() {}

public static final int GLOB = 0x1000;

// To be removed when https://github.com/apple/pkl/issues/741 is fixed
public static final int IS_IN_ITERABLE = 0x100000;

// modifier sets

public static final int NONE = 0;
Expand Down Expand Up @@ -137,10 +134,6 @@ public static boolean isEntry(int modifiers) {
return (modifiers & ENTRY) != 0;
}

public static boolean isInIterable(int modifiers) {
return (modifiers & IS_IN_ITERABLE) != 0;
}

public static boolean isType(int modifiers) {
return (modifiers & (CLASS | TYPE_ALIAS | IMPORT)) != 0 && (modifiers & GLOB) == 0;
}
Expand Down
Loading