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