Skip to content

Commit

Permalink
More lookup tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Sep 27, 2024
1 parent 703927a commit d9a8199
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions convex-core/src/main/java/convex/core/lang/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ private Address getParentAddress(AccountStatus as) {
*/
@SuppressWarnings("unchecked")
public <T extends ACell> T lookupValue(String symName) {
return (T) lookupValue(Symbol.create(symName));
return (T) lookupValue(getAddress(),Symbol.create(symName));
}

/**
Expand All @@ -648,17 +648,7 @@ public <T extends ACell> T lookupValue(String symName) {
* @return Value for the given symbol or null if undeclared
*/
public ACell lookupValue(Symbol sym) {
AHashMap<Symbol, ACell> env=getEnvironment();

// Lookup in current environment first
MapEntry<Symbol,ACell> me=env.getEntry(sym);
if (me!=null) {
return me.getValue();
}

AccountStatus as = getAliasedAccount(env);
if (as==null) return null;
return as.getEnvironment().get(sym);
return lookupValue(getAddress(),sym);
}

/**
Expand All @@ -668,11 +658,9 @@ public ACell lookupValue(Symbol sym) {
* @return Value for the given symbol or null if undeclared
*/
public ACell lookupValue(Address address,Symbol sym) {
if (address==null) return lookupValue(sym);
AccountStatus as=getAccountStatus(address);
if (as==null) return null;
AHashMap<Symbol, ACell> env=as.getEnvironment();
return env.get(sym);
MapEntry<Symbol,ACell> entry=lookupDynamicEntry(address,sym);
if (entry==null) return null;
return entry.getValue();
}

/**
Expand All @@ -683,6 +671,7 @@ public ACell lookupValue(Address address,Symbol sym) {
* @return Environment entry
*/
public MapEntry<Symbol,ACell> lookupDynamicEntry(Address address,Symbol sym) {
if (address==null) address=getAddress();
AccountStatus as=getAccountStatus(address);
if (as==null) return null;
return lookupDynamicEntry(as,sym);
Expand Down

0 comments on commit d9a8199

Please sign in to comment.