mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Constants access priority
This commit is contained in:
parent
cdf0219ca1
commit
f6c3f3fe17
@ -76,12 +76,19 @@ public final class ScopeHandler {
|
||||
|
||||
|
||||
public static boolean isVariableOrConstantExists(String name) {
|
||||
if (rootScope().containsConstant(name)) {
|
||||
return true;
|
||||
}
|
||||
synchronized (lock) {
|
||||
return findScope(name).isFound;
|
||||
}
|
||||
}
|
||||
|
||||
public static Value getVariableOrConstant(String name) {
|
||||
Value constant = rootScope().getConstant(name);
|
||||
if (constant != null) {
|
||||
return constant;
|
||||
}
|
||||
synchronized (lock) {
|
||||
final ScopeFindData scopeData = findScope(name);
|
||||
if (scopeData.isFound) {
|
||||
|
@ -44,13 +44,12 @@ public final class MatchExpression extends InterruptableNode implements Expressi
|
||||
return evalResult(p.result);
|
||||
}
|
||||
} else {
|
||||
ScopeHandler.defineVariableInCurrentScope(pattern.variable, value);
|
||||
if (optMatches(p)) {
|
||||
final Value result = evalResult(p.result);
|
||||
ScopeHandler.removeVariable(pattern.variable);
|
||||
return result;
|
||||
try (final var ignored = ScopeHandler.closeableScope()) {
|
||||
ScopeHandler.defineVariableInCurrentScope(pattern.variable, value);
|
||||
if (optMatches(p)) {
|
||||
return evalResult(p.result);
|
||||
}
|
||||
}
|
||||
ScopeHandler.removeVariable(pattern.variable);
|
||||
}
|
||||
}
|
||||
if ((value.type() == Types.ARRAY) && (p instanceof ListPattern pattern)) {
|
||||
|
Loading…
Reference in New Issue
Block a user