Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzerntev committed Jan 13, 2024
1 parent 810dac1 commit b38093b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 36 deletions.
6 changes: 3 additions & 3 deletions client/src/main/scala/raw/client/api/CompilerService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ object CompilerService {
if (engine == null) {
val options = new java.util.HashMap[String, String]()
if (settings.onTrainingWheels) {
// options.put("engine.CompileImmediately", "true")
// options.put("engine.TraceCompilation", "true")
// options.put("engine.BackgroundCompilation", "false")
options.put("engine.CompileImmediately", "true")
options.put("engine.TraceCompilation", "true")
options.put("engine.BackgroundCompilation", "false")
// options.put("engine.CompilationFailureAction", "Throw")
// options.put("engine.CompilationFailureAction", "Diagnose")
// options.put("compiler.LogInlinedTargets", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand All @@ -42,7 +44,6 @@ public class Closure implements TruffleObject {
private final MaterializedFrame frame;
private final Object[] defaultArguments;
private String[] namedArgNames = null;
private final Map<String, Object> namedArgs = new HashMap<>();
private static final String GET_DEFAULT_PREFIX = "default_";

// for regular closures. The 'frame' has to be a materialized one to make sure it can be stored
Expand All @@ -52,11 +53,6 @@ public Closure(Function function, Object[] defaultArguments, MaterializedFrame f
this.function = function;
this.frame = frame;
this.defaultArguments = defaultArguments;
for (int i = 0; i < defaultArguments.length; i++) {
if (defaultArguments[i] != null) {
putNamedArg(function.getArgNames()[i], defaultArguments[i]);
}
}
}

// for top-level functions. The internal 'frame' is null because it's never used to fetch values
Expand Down Expand Up @@ -142,17 +138,25 @@ final boolean hasMembers() {
final boolean isMemberInvocable(String member) {
if (member.startsWith(GET_DEFAULT_PREFIX)) {
String argName = member.substring(GET_DEFAULT_PREFIX.length());
return containsKey(argName);
} else {
return false;
for (int i = 0; i < defaultArguments.length; i++) {
if (defaultArguments[i] != null && argName.equals(function.getArgNames()[i])) {
return true;
}
}
}
return false;
}

@ExportMessage
@CompilerDirectives.TruffleBoundary
final Object getMembers(boolean includeInternal) {
return new StringList(
namedArgs.keySet().stream().map(s -> GET_DEFAULT_PREFIX + s).toArray(String[]::new));
ArrayList<String> keys = new ArrayList<>();
for (int i = 0; i < defaultArguments.length; i++) {
if (defaultArguments[i] != null) {
keys.add(GET_DEFAULT_PREFIX + function.getArgNames()[i]);
}
}
return new StringList(keys.toArray(String[]::new));
}

@ExportMessage
Expand All @@ -163,10 +167,14 @@ final Object invokeMember(String member, Object... arguments)
throw ArityException.create(0, 0, arguments.length);
}
String argName = substring(member, GET_DEFAULT_PREFIX.length());
return getNamedArg(argName);
} else {
throw UnknownIdentifierException.create(member);

for (int i = 0; i < defaultArguments.length; i++) {
if (defaultArguments[i] != null && argName.equals(function.getArgNames()[i])) {
return defaultArguments[i];
}
}
}
throw UnknownIdentifierException.create(member);
}

@CompilerDirectives.TruffleBoundary
Expand All @@ -179,21 +187,6 @@ private String substring(String member, int from) {
return member.substring(from);
}

@CompilerDirectives.TruffleBoundary
private Object getNamedArg(String argName) {
return namedArgs.get(argName);
}

@CompilerDirectives.TruffleBoundary
private void putNamedArg(String argName, Object value) {
namedArgs.put(argName, value);
}

@CompilerDirectives.TruffleBoundary
private boolean containsKey(String argName) {
return namedArgs.containsKey(argName);
}

@NodeInfo(shortName = "Closure.Execute")
@GenerateUncached
@GenerateInline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.interop.TruffleObject;
import java.util.HashMap;
import java.util.Map;

public final class Function implements TruffleObject {

Expand All @@ -25,8 +23,6 @@ public final class Function implements TruffleObject {

public final String[] argNames;

public final Map<Integer, Map<String, Object>> namedArgsCache = new HashMap<>();

public Function(RootCallTarget rootCallTarget, String[] argNames) {
this.name = rootCallTarget.getRootNode().getName();
this.rootCallTarget = rootCallTarget;
Expand Down

0 comments on commit b38093b

Please sign in to comment.