Skip to content

Commit

Permalink
[WIP] use a typeless long array behind MStack
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Jul 29, 2024
1 parent fd90dc2 commit 7e4ba06
Show file tree
Hide file tree
Showing 10 changed files with 515 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static Value computeConstantValue(Instance instance, List<Instruction> ex
"constant expression required, initializer expression"
+ " cannot reference a mutable global");
}
return instance.readGlobal(idx);
return instance.readGlobalValue(idx);
} else {
throw new InvalidException(
"unknown global "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public void setValue(Value value) {
this.value = value;
}

public void setValue(long value) {
this.value = new Value(this.value.type(), value);
}

public Instance getInstance() {
return instance;
}
Expand Down
10 changes: 7 additions & 3 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public ExportFunction export(String name) {
@Override
public Value[] apply(Value... args) throws ChicoryException {
assert (args.length == 0);
return new Value[] {readGlobal(export.index())};
return new Value[] {readGlobalValue(export.index())};
}
};
}
Expand Down Expand Up @@ -329,14 +329,14 @@ public GlobalInstance global(int idx) {
return globals[idx - importedGlobalsOffset];
}

public void writeGlobal(int idx, Value val) {
public void writeGlobal(int idx, long val) {
if (idx < importedGlobalsOffset) {
imports.global(idx).instance().setValue(val);
}
globals[idx - importedGlobalsOffset].setValue(val);
}

public Value readGlobal(int idx) {
public Value readGlobalValue(int idx) {
if (idx < importedGlobalsOffset) {
return imports.global(idx).instance().getValue();
}
Expand All @@ -347,6 +347,10 @@ public Value readGlobal(int idx) {
return globals[idx - importedGlobalsOffset].getValue();
}

public long readGlobal(int idx) {
return readGlobalValue(idx).raw();
}

public Global globalInitializer(int idx) {
if (idx < importedGlobalsOffset) {
return null;
Expand Down
Loading

0 comments on commit 7e4ba06

Please sign in to comment.