Update compiler.c
added switch
@@ -1446,7 +1446,7 @@ ParseRule rules[] = {
{NULL, and_, PREC_AND}, // TOKEN_AND
{NULL, NULL, PREC_NONE}, // TOKEN_ELSE
{NULL, or_, PREC_OR}, // TOKEN_OR
- {NULL, NULL, PREC_NONE}, // TOKEN_MATCH
+ {NULL, NULL, PREC_NONE}, // TOKEN_SWITCH
{NULL, NULL, PREC_NONE}, // TOKEN_CASE
{NULL, NULL, PREC_NONE}, // TOKEN_VAR
{NULL, NULL, PREC_NONE}, // TOKEN_CONST
@@ -1891,6 +1891,7 @@ static int getArgCount(uint8_t *code, const ValueArray constants, int ip) {
case OP_DEFINE_OPTIONAL:
case OP_JUMP:
+ case OP_COMPARE_JUMP:
case OP_JUMP_IF_NIL:
case OP_JUMP_IF_FALSE:
case OP_LOOP:
@@ -2074,11 +2075,11 @@ static void ifStatement(Compiler *compiler) {
patchJump(compiler, endJump);
}
-static void matchStatement(Compiler *compiler) {
- consume(compiler, TOKEN_LEFT_PAREN, "Expect '(' after 'match'.");
+static void switchStatement(Compiler *compiler) {
+ consume(compiler, TOKEN_LEFT_PAREN, "Expect '(' after 'switch'.");
expression(compiler);
consume(compiler, TOKEN_RIGHT_PAREN, "Expect ')' after expression.");
- consume(compiler, TOKEN_LEFT_BRACE, "Expect '{' before match body.");
+ consume(compiler, TOKEN_LEFT_BRACE, "Expect '{' before switch body.");
consume(compiler, TOKEN_CASE, "Expect atleast one 'case' block.");
do {
expression(compiler);
@@ -2087,7 +2088,7 @@ static void matchStatement(Compiler *compiler) {
statement(compiler);
patchJump(compiler, compareJump);
} while(match(compiler, TOKEN_CASE));
- consume(compiler, TOKEN_RIGHT_BRACE, "Expect '}' end matchbody.");
+ consume(compiler, TOKEN_RIGHT_BRACE, "Expect '}' end switch body.");
emitByte(compiler, OP_POP); // expression.
}
static void withStatement(Compiler *compiler) {
@@ -2327,7 +2328,7 @@ static void synchronize(Parser *parser) {
case TOKEN_CONST:
case TOKEN_FOR:
case TOKEN_IF:
- case TOKEN_MATCH:
+ case TOKEN_SWITCH:
case TOKEN_WHILE:
case TOKEN_BREAK:
case TOKEN_RETURN:
@@ -2371,8 +2372,8 @@ static void statement(Compiler *compiler) {
forStatement(compiler);
} else if (match(compiler, TOKEN_IF)) {
ifStatement(compiler);
- } else if (match(compiler, TOKEN_MATCH)) {
- matchStatement(compiler);
+ } else if (match(compiler, TOKEN_SWITCH)) {
+ switchStatement(compiler);
} else if (match(compiler, TOKEN_RETURN)) {
returnStatement(compiler);
} else if (match(compiler, TOKEN_WITH)) {
