Skip to content

Commit

Permalink
Perlito5 - misc/Java-Asm-Interpreter/MethodExecutorAsm eval string
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jul 31, 2024
1 parent 50bccd4 commit 4f18eda
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions misc/Java-Asm-Interpreter/MethodExecutorAsm/Runtime.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.*;

public class Runtime {
long i;
Expand Down Expand Up @@ -51,6 +50,18 @@ public static Runtime eval_string(Runtime code, String evalTag) throws Exception
// retrieve the context that was saved at compile-time
EmitterContext evalCtx = Runtime.evalContext.get(evalTag);

// retrieve closure variable list
// alternately, scan the AST for variables and capture only the ones that are used
Map<Integer, String> visibleVariables = evalCtx.symbolTable.getAllVisibleVariables();
String[] newEnv = new String[visibleVariables.size()];
System.out.println(" ctx.symbolTable.getAllVisibleVariables");
for (Integer index : visibleVariables.keySet()) {
String variableName = visibleVariables.get(index);
System.out.println(" " + index + " " + variableName);
newEnv[index] = variableName;
}


// Create the Token list
Lexer lexer = new Lexer(code.toString());
List<Token> tokens = lexer.tokenize(); // Tokenize the Perl code
Expand All @@ -64,7 +75,7 @@ public static Runtime eval_string(Runtime code, String evalTag) throws Exception
evalCtx.errorUtil = new ErrorMessageUtil(evalCtx.fileName, tokens);
Class<?> generatedClass = ASMMethodCreator.createClassWithMethod(
evalCtx,
new String[] {}, // Closure variables
newEnv, // Closure variables
ast
);

Expand Down

0 comments on commit 4f18eda

Please sign in to comment.