Skip to content

Commit

Permalink
fix(compiler): locals are also case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Dec 29, 2023
1 parent eeacf28 commit 81f29db
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import javassist.CtClass;
import javassist.bytecode.Bytecode;
import org.jetbrains.annotations.NotNull;
import team.unnamed.mocha.util.CaseInsensitiveStringHashMap;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import static java.util.Objects.requireNonNull;
Expand All @@ -42,10 +42,9 @@ final class FunctionCompileState {
private final Bytecode bytecode;
private final Method method;

private final Map<String, Object> requirements = new HashMap<>();
private final Map<String, Object> requirements = new CaseInsensitiveStringHashMap<>();
private final GlobalScope scope;
private final Map<String, Integer> argumentParameterIndexes;
private final Map<String, Integer> localsByName = new HashMap<>();
private int maxLocals = 0;

FunctionCompileState(
Expand Down Expand Up @@ -100,8 +99,4 @@ public int maxLocals() {
public void maxLocals(int maxLocals) {
this.maxLocals = maxLocals;
}

public Map<String, Integer> getLocalsByName() {
return localsByName;
}
}
4 changes: 2 additions & 2 deletions src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
import team.unnamed.mocha.parser.ast.Expression;
import team.unnamed.mocha.runtime.compiled.MochaCompiledFunction;
import team.unnamed.mocha.runtime.compiled.Named;
import team.unnamed.mocha.util.CaseInsensitiveStringHashMap;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand Down Expand Up @@ -99,7 +99,7 @@ public MolangCompiler(final @NotNull ClassLoader classLoader, final @NotNull Glo
throw new IllegalArgumentException("Target type must have a method to implement: " + clazz.getName());
}

final Map<String, Integer> argumentParameterIndexes = new HashMap<>();
final Map<String, Integer> argumentParameterIndexes = new CaseInsensitiveStringHashMap<>();
final CtClass[] ctParameters;

// check method parameter types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import team.unnamed.mocha.runtime.value.NumberValue;
import team.unnamed.mocha.runtime.value.ObjectValue;
import team.unnamed.mocha.runtime.value.Value;
import team.unnamed.mocha.util.CaseInsensitiveStringHashMap;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -75,7 +75,7 @@ final class MolangCompilingVisitor implements ExpressionVisitor<CompileVisitResu
private final Map<String, Object> requirements;
private final Map<String, Integer> argumentParameterIndexes;

private final Map<String, Integer> localsByName = new HashMap<>();
private final Map<String, Integer> localsByName = new CaseInsensitiveStringHashMap<>();

private final CtClass stringCtType;
/**
Expand Down

0 comments on commit 81f29db

Please sign in to comment.