mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added negate opcode to equality opcode, in the second byte
This commit is contained in:
@@ -16,7 +16,6 @@ SRC_SOURCEFILES=$(wildcard $(SRC_SOURCEDIR)/*.c)
|
||||
SRC_OBJFILES=$(addprefix $(SRC_OBJDIR)/,$(notdir $(SRC_SOURCEFILES:.c=.o)))
|
||||
SRC_TARGETNAME=Toy
|
||||
|
||||
#TODO: fix windows & macos
|
||||
#SRC_LIBLINE is a fancy way of making the linker work correctly
|
||||
ifeq ($(shell uname),Linux)
|
||||
SRC_TARGETEXT=.so
|
||||
|
||||
@@ -42,7 +42,6 @@ void Toy_private_emitAstValue(Toy_Bucket** bucket, Toy_Ast** handle, Toy_Value v
|
||||
(*handle) = tmp;
|
||||
}
|
||||
|
||||
//TODO: flag range checks
|
||||
void Toy_private_emitAstUnary(Toy_Bucket** bucket, Toy_Ast** handle, Toy_AstFlag flag) {
|
||||
Toy_Ast* tmp = (Toy_Ast*)Toy_partitionBucket(bucket, sizeof(Toy_Ast));
|
||||
|
||||
|
||||
@@ -167,12 +167,7 @@ static void writeInstructionBinary(Toy_Routine** rt, Toy_AstBinary ast) {
|
||||
}
|
||||
else if (ast.flag == TOY_AST_FLAG_COMPARE_NOT) {
|
||||
EMIT_BYTE(rt, TOY_OPCODE_COMPARE_EQUAL);
|
||||
EMIT_BYTE(rt, 0);
|
||||
EMIT_BYTE(rt, 0);
|
||||
EMIT_BYTE(rt, 0);
|
||||
|
||||
EMIT_BYTE(rt, TOY_OPCODE_NEGATE); //TODO: squeeze these into one word
|
||||
EMIT_BYTE(rt, 0);
|
||||
EMIT_BYTE(rt, TOY_OPCODE_NEGATE); //squeezed into one word
|
||||
EMIT_BYTE(rt, 0);
|
||||
EMIT_BYTE(rt, 0);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ Toy_String* Toy_deepCopyString(Toy_Bucket** bucket, Toy_String* str) {
|
||||
}
|
||||
Toy_String* ret = (Toy_String*)Toy_partitionBucket(bucket, sizeof(Toy_String) + str->length + 1); //TODO: compensate for partitioning more space than bucket capacity
|
||||
|
||||
//TODO
|
||||
//
|
||||
ret->type = TOY_STRING_LEAF;
|
||||
ret->length = str->length;
|
||||
ret->refCount = 1;
|
||||
|
||||
@@ -165,7 +165,16 @@ static void processComparison(Toy_VM* vm, Toy_OpcodeType opcode) {
|
||||
|
||||
//most things can be equal, so handle it separately
|
||||
if (opcode == TOY_OPCODE_COMPARE_EQUAL) {
|
||||
Toy_pushStack(&vm->stack, TOY_VALUE_TO_BOOLEAN(TOY_VALUE_IS_EQUAL(left, right)) );
|
||||
bool equal = TOY_VALUE_IS_EQUAL(left, right);
|
||||
|
||||
//equality has an optional "negate" opcode within it's word
|
||||
if (READ_BYTE(vm) != TOY_OPCODE_NEGATE) {
|
||||
Toy_pushStack(&vm->stack, TOY_VALUE_TO_BOOLEAN(equal) );
|
||||
}
|
||||
else {
|
||||
Toy_pushStack(&vm->stack, TOY_VALUE_TO_BOOLEAN(!equal) );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -254,7 +263,7 @@ static void process(Toy_VM* vm) {
|
||||
case TOY_OPCODE_AND:
|
||||
case TOY_OPCODE_OR:
|
||||
case TOY_OPCODE_TRUTHY:
|
||||
case TOY_OPCODE_NEGATE: //TODO: squeeze into !=
|
||||
case TOY_OPCODE_NEGATE:
|
||||
processLogical(vm, opcode);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user