For loop on arrays working, untested, read more

Needed: break and continue support, extensive tests, other iterables
This commit is contained in:
2026-05-24 18:13:18 +10:00
parent 813da3e1aa
commit f11bc95833
10 changed files with 241 additions and 58 deletions
+28 -9
View File
@@ -195,9 +195,24 @@ int inspect_instruction(unsigned char* bytecode, unsigned int pc, unsigned int j
return 4;
case TOY_OPCODE_ELIMINATE:
printf(MARKER "ELIMINATE\n", MARKER_VALUE(pc, unsigned char));
printf(MARKER "ELIMINATE %u\n", MARKER_VALUE(pc, unsigned char), (unsigned int)bytecode[pc + 1]);
return 4;
case TOY_OPCODE_ITERATE:
printf(MARKER TOY_CC_DEBUG "ITERATE on [-2] based on type, with [-1] as counter, then delegate to: JUMP %s%s (%s%d) (GOTO %u)\n" TOY_CC_RESET, MARKER_VALUE(pc, unsigned char),
bytecode[pc + 1] == TOY_OP_PARAM_JUMP_ABSOLUTE ? "absolute" : "relative",
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_ALWAYS ? "" :
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_TRUE ? " if true" :
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_FALSE ? " if false" :
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_NULL ? " if null" :
"if <unknown>"
,
(*(int*)(bytecode + pc + 4)) > 0 ? "+" : "", //show a + sign when positive
(*(int*)(bytecode + pc + 4)),
(*(int*)(bytecode + pc + 4)) + pc + 8
);
return 8;
case TOY_OPCODE_ADD:
printf(MARKER "ADD %s\n", MARKER_VALUE(pc, unsigned char), bytecode[pc + 1] == TOY_OPCODE_ASSIGN ? "and ASSIGN" : "");
return 4;
@@ -262,18 +277,22 @@ int inspect_instruction(unsigned char* bytecode, unsigned int pc, unsigned int j
printf(MARKER TOY_CC_DEBUG "JUMP %s%s (%s%d) (GOTO %u)\n" TOY_CC_RESET, MARKER_VALUE(pc, unsigned char),
bytecode[pc + 1] == TOY_OP_PARAM_JUMP_ABSOLUTE ? "absolute" : "relative",
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_ALWAYS ? "" :
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_TRUE ? " if true" : " if false",
bytecode[pc + 4] > 0 ? "+" : "", //show a + sign when positive
bytecode[pc + 4],
bytecode[pc + 4] + pc + 8
);
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_TRUE ? " if true" :
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_FALSE ? " if false" :
bytecode[pc + 2] == TOY_OP_PARAM_JUMP_IF_NULL ? " if null" :
"if <unknown>"
,
(*(int*)(bytecode + pc + 4)) > 0 ? "+" : "", //show a + sign when positive
(*(int*)(bytecode + pc + 4)),
(*(int*)(bytecode + pc + 4)) + pc + 8
);
return 8;
case TOY_OPCODE_ESCAPE:
printf(MARKER TOY_CC_DEBUG "ESCAPE relative %s%d (GOTO %u) and pop %d\n" TOY_CC_RESET, MARKER_VALUE(pc, unsigned char),
bytecode[pc + 4] > 0 ? "+" : "", //show a + sign when positive
bytecode[pc + 4],
bytecode[pc + 4] + pc + 12,
(*(int*)(bytecode + pc + 4)) > 0 ? "+" : "", //show a + sign when positive
(*(int*)(bytecode + pc + 4)),
(*(int*)(bytecode + pc + 4)) + pc + 12,
bytecode[pc + 8]
);
return 12;