Skip to content

Commit

Permalink
slight vm improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SenkJu committed Jan 21, 2021
1 parent 92f364a commit 2c37d40
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/vm/VirtualMachine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ class VirtualMachine {
final cIndex = cast(index, StringObj);

target.getMembers().value.set(cIndex.value, value);
default:
error.error("index operator cannot be used on this datatype");
default: error.error("index operator cannot be used on this datatype");
}
case OpCode.ConcatString:
final right = stack.pop().toString();
Expand All @@ -211,7 +210,7 @@ class VirtualMachine {
final left = stack.pop();

if (left.type != ObjectType.Number || right.type != ObjectType.Number) {
error.error("cannot perform operation");
error.error('cannot perform operation (left: ${left.type}, right: ${right.type})');
}

final cLeft = cast(left, NumberObj).value;
Expand Down Expand Up @@ -245,7 +244,7 @@ class VirtualMachine {
final constantIndex = instructions.readInt32();

final constant = switch (constantPool[constantIndex].type) {
case ObjectType.UserFunction: new ClosureObj(cast(constantPool[constantIndex], UserFunctionObj), currentFrame,this);
case ObjectType.UserFunction: new ClosureObj(cast(constantPool[constantIndex], UserFunctionObj), currentFrame, this);
default: constantPool[constantIndex];
}

Expand All @@ -254,12 +253,7 @@ class VirtualMachine {
final localIndex = instructions.readInt32();

final value = stack.pop();

if (value == null) {
currentFrame.setVariable(localIndex, new NullObj(this));
} else {
currentFrame.setVariable(localIndex, value);
}
currentFrame.setVariable(localIndex, value);
case OpCode.Load:
final localIndex = instructions.readInt32();
final value = currentFrame.getVariable(localIndex);
Expand Down

0 comments on commit 2c37d40

Please sign in to comment.