1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 13:55:55 +03:00

[java-truffle] propagate step B code thru C-E

This commit is contained in:
mmcgill 2021-03-10 09:30:18 -05:00 committed by Joel Martin
parent 66144016ee
commit 068512559e
3 changed files with 51 additions and 0 deletions

View File

@ -381,6 +381,9 @@ public class stepC_slots {
@Child private MalNode fnNode;
@Children private MalNode[] argNodes;
@Child private InvokeNode invokeNode;
@CompilationFinal private boolean initialized = false;
@CompilationFinal private boolean usingCachedFn;
@CompilationFinal private MalFunction cachedFn;
ApplyNode(MalLanguage language, MalList list, boolean tailPosition, LexicalScope scope) {
super(list);
@ -415,6 +418,20 @@ public class stepC_slots {
@Override
public Object executeGeneric(VirtualFrame frame, MalEnv env) {
var fn = (MalFunction)fnNode.executeGeneric(frame, env);
if (!initialized) {
CompilerDirectives.transferToInterpreterAndInvalidate();
initialized = true;
cachedFn = fn;
usingCachedFn = true;
}
if (usingCachedFn) {
if (fn != cachedFn) {
CompilerDirectives.transferToInterpreterAndInvalidate();
usingCachedFn = false;
} else {
fn = cachedFn;
}
}
if (fn.isMacro) {
// Mal's macro semantics are... interesting. To preserve them in the
// general case, we must re-expand a macro each time it's applied.

View File

@ -393,6 +393,9 @@ public class stepD_caching {
@Child private MalNode fnNode;
@Children private MalNode[] argNodes;
@Child private InvokeNode invokeNode;
@CompilationFinal private boolean initialized = false;
@CompilationFinal private boolean usingCachedFn;
@CompilationFinal private MalFunction cachedFn;
ApplyNode(MalLanguage language, MalList list, boolean tailPosition, LexicalScope scope) {
super(list);
@ -427,6 +430,20 @@ public class stepD_caching {
@Override
public Object executeGeneric(VirtualFrame frame, MalEnv env) {
var fn = (MalFunction)fnNode.executeGeneric(frame, env);
if (!initialized) {
CompilerDirectives.transferToInterpreterAndInvalidate();
initialized = true;
cachedFn = fn;
usingCachedFn = true;
}
if (usingCachedFn) {
if (fn != cachedFn) {
CompilerDirectives.transferToInterpreterAndInvalidate();
usingCachedFn = false;
} else {
fn = cachedFn;
}
}
if (fn.isMacro) {
// Mal's macro semantics are... interesting. To preserve them in the
// general case, we must re-expand a macro each time it's applied.

View File

@ -420,6 +420,9 @@ public class stepE_macros {
@Child private MalNode fnNode;
@Children private MalNode[] argNodes;
@Child private InvokeNode invokeNode;
@CompilationFinal private boolean initialized = false;
@CompilationFinal private boolean usingCachedFn;
@CompilationFinal private MalFunction cachedFn;
ApplyNode(MalLanguage language, MalList list, boolean tailPosition, LexicalScope scope) {
super(list);
@ -464,6 +467,20 @@ public class stepE_macros {
@Override
public Object executeGeneric(VirtualFrame frame, MalEnv env) {
var fn = (MalFunction)fnNode.executeGeneric(frame, env);
if (!initialized) {
CompilerDirectives.transferToInterpreterAndInvalidate();
initialized = true;
cachedFn = fn;
usingCachedFn = true;
}
if (usingCachedFn) {
if (fn != cachedFn) {
CompilerDirectives.transferToInterpreterAndInvalidate();
usingCachedFn = false;
} else {
fn = cachedFn;
}
}
if (fn.isMacro) {
var expanded = applyMacro(env, fn);
if (isInlinableMacro(fn)) {