Added dictionaries {}

Objects are now separate from {} dictionaries

the . operator now only indexes fields on objects, the [] operator can only be used on objects if the __index or __newindex functions are defined

Additionally 4 new instructions have been added to the VM: OP_NEWDICT, OP_INDEX, OP_INCINDEX, and OP_NEWINDEX.

The syntax to create a dictionary is as follows { <key> : <value>, <otherkey> : <othervalue> } eg. { "hello" : "world", "foo" : 1337 }

The Lexer & Parser was extended to add the TOKEN_COLON ':' token.
This commit is contained in:
2020-12-09 20:32:42 -06:00
parent 6445dae04c
commit 181ef8a18c
11 changed files with 290 additions and 90 deletions

View File

@@ -118,6 +118,12 @@ int disasmInstr(CChunk *chunk, int offset, int indent) {
}
case OP_CLOSE:
return simpleInstruction("OP_CLOSE", offset);
case OP_NEWDICT:
return u16OperandInstruction("OP_NEWDICT", chunk, offset);
case OP_INDEX:
return simpleInstruction("OP_INDEX", offset);
case OP_NEWINDEX:
return simpleInstruction("OP_NEWINDEX", offset);
case OP_NEWOBJECT:
return u16OperandInstruction("OP_NEWOBJECT", chunk, offset);
case OP_GETOBJECT:
@@ -164,6 +170,8 @@ int disasmInstr(CChunk *chunk, int offset, int indent) {
return u8u16OperandInstruction("OP_INCGLOBAL", chunk, offset);
case OP_INCUPVAL:
return u8u8OperandInstruction("OP_INCLOCAL", chunk, offset);
case OP_INCINDEX:
return u8OperandInstruction("OP_INCINDEX", chunk, offset);
case OP_INCOBJECT:
return u8u16OperandInstruction("OP_INCOBJECT", chunk, offset);
case OP_RETURN: