more tests for the runtime
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
- talk about how functions are variables in the docs
|
||||
- tests for MUL and DIV bytecodes
|
||||
@@ -0,0 +1 @@
|
||||
1 + 2 , 3 * 4 * 5;
|
||||
@@ -189,7 +189,16 @@ static bool parseIntegerOperand(Context *ctx, Error *error, Operand *op)
|
||||
// pointing to a sequence of one or more digits
|
||||
// NOT followed by a dot and a digit after that
|
||||
// (so this is an integer for sure, not a float).
|
||||
assert(ctx->cur < ctx->len && isdigit(ctx->str[ctx->cur]));
|
||||
// Also, the sequence may be preceded by a '+' or
|
||||
// '-'.
|
||||
|
||||
int sign = 1;
|
||||
if (ctx->str[ctx->cur] == '+')
|
||||
ctx->cur++;
|
||||
else if (ctx->str[ctx->cur] == '-') {
|
||||
sign = -1;
|
||||
ctx->cur++;
|
||||
}
|
||||
|
||||
long long int buffer = 0;
|
||||
do {
|
||||
@@ -209,9 +218,9 @@ static bool parseIntegerOperand(Context *ctx, Error *error, Operand *op)
|
||||
} while(ctx->cur < ctx->len && isdigit(ctx->str[ctx->cur]));
|
||||
|
||||
// Not a float!
|
||||
|
||||
|
||||
op->type = OPTP_INT;
|
||||
op->as_int = buffer;
|
||||
op->as_int = sign * buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -224,7 +233,16 @@ static bool parseFloatingOperand(Context *ctx, Error *error, Operand *op)
|
||||
// It's ensured by the caller that the cursor is
|
||||
// pointing to a sequence of one or more digits
|
||||
// followed by a dot and a digit after that.
|
||||
assert(ctx->cur < ctx->len && isdigit(ctx->str[ctx->cur]));
|
||||
// Also, the sequence may be preceded by a '+' or
|
||||
// '-'.
|
||||
|
||||
int sign = 1;
|
||||
if (ctx->str[ctx->cur] == '+')
|
||||
ctx->cur++;
|
||||
else if (ctx->str[ctx->cur] == '-') {
|
||||
sign = -1;
|
||||
ctx->cur++;
|
||||
}
|
||||
|
||||
double buffer = 0;
|
||||
do {
|
||||
@@ -256,7 +274,7 @@ static bool parseFloatingOperand(Context *ctx, Error *error, Operand *op)
|
||||
} while(ctx->cur < ctx->len && isdigit(ctx->str[ctx->cur]));
|
||||
|
||||
op->type = OPTP_FLOAT;
|
||||
op->as_float = buffer;
|
||||
op->as_float = sign * buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -277,11 +295,21 @@ static bool parseOperands(Context *ctx, BPAlloc *alloc, Error *error,
|
||||
if(!parseStringOperand(ctx, error, alloc, &op))
|
||||
return false;
|
||||
|
||||
} else if(isdigit(c)) {
|
||||
|
||||
} else if(isdigit(c) || c == '-' || c == '+') {
|
||||
|
||||
/* Integer or float operand */
|
||||
|
||||
size_t k = ctx->cur;
|
||||
|
||||
if (c == '-' || c == '+') {
|
||||
k++;
|
||||
if (k == ctx->len || !isdigit(ctx->str[k])) {
|
||||
*ctx->error_offset = k;
|
||||
Error_Report(error, ErrorType_SYNTAX, "Invalid character '%c' not followed by a digit", c);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
while(k < ctx->len && isdigit(ctx->str[k]))
|
||||
k += 1;
|
||||
|
||||
|
||||
@@ -1758,7 +1758,8 @@ static Node *parse_expression_2(Context *ctx, Node *left_expr, int min_prec, _Bo
|
||||
|
||||
while(isbinop(ctx->token) && (precedenceof(ctx->token) > precedenceof(op) || (precedenceof(ctx->token) == precedenceof(op) && isrightassoc(ctx->token))))
|
||||
{
|
||||
right_expr = parse_expression_2(ctx, right_expr, precedenceof(op) + 1, allow_toplev_tuples, allow_assignments);
|
||||
int new_prec = precedenceof(op) + (precedenceof(op) < precedenceof(ctx->token));
|
||||
right_expr = parse_expression_2(ctx, right_expr, new_prec, allow_toplev_tuples, allow_assignments);
|
||||
|
||||
if(right_expr == NULL)
|
||||
return NULL;
|
||||
|
||||
+1
-1
@@ -884,7 +884,7 @@ static _Bool runInstruction(Runtime *runtime, Error *error)
|
||||
|
||||
return Runtime_Push(runtime, error, obj);
|
||||
}
|
||||
|
||||
|
||||
case OPCODE_PUSHFLT:
|
||||
{
|
||||
ASSERT(opc == 1);
|
||||
|
||||
@@ -114,10 +114,6 @@ ErrorID findField(NojaTestScanner *scanner)
|
||||
return ErrorID_VOID;
|
||||
}
|
||||
|
||||
// Returns:
|
||||
// 0 if there are no more fields
|
||||
// -1 on error
|
||||
// 1 if a field was parsed
|
||||
ErrorID parseField(NojaTestScanner *scanner, NojaTestField *field)
|
||||
{
|
||||
ErrorID error;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
@type [compiler]
|
||||
|
||||
@source
|
||||
|
||||
fun nop(a = 1)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
@type [compiler]
|
||||
|
||||
@source
|
||||
|
||||
if true:
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.22;
|
||||
PUSHFLT 700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.22;
|
||||
PUSHFLT 700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [610.17]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.22;
|
||||
PUSHFLT -700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-610.17]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.22;
|
||||
PUSHFLT -700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.39;
|
||||
PUSHINT 700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.39;
|
||||
PUSHINT 700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [609.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.39;
|
||||
PUSHINT -700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-609.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.39;
|
||||
PUSHINT -700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHFLT 700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHFLT -700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-610.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHFLT 700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [610.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHFLT -700.39;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHINT 700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHINT 700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [610]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHINT -700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-610]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHINT -700;
|
||||
ADD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 100;
|
||||
PUSHINT 8;
|
||||
MOD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [4]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 8;
|
||||
PUSHINT 100;
|
||||
MOD;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [8]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.22;
|
||||
PUSHFLT 700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-610.17]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.22;
|
||||
PUSHFLT 700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.22;
|
||||
PUSHFLT -700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.22;
|
||||
PUSHFLT -700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [610.17]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.39;
|
||||
PUSHINT 700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-609.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.39;
|
||||
PUSHINT 700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 90.39;
|
||||
PUSHINT -700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -90.39;
|
||||
PUSHINT -700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [609.61]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHFLT 700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-610.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHFLT -700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHFLT 700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHFLT -700.39;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [610.39]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHINT 700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-610]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHINT 700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-790]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 90;
|
||||
PUSHINT -700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [790]
|
||||
@@ -0,0 +1,14 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -90;
|
||||
PUSHINT -700;
|
||||
SUB;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [610]
|
||||
@@ -0,0 +1,13 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT 23;
|
||||
NEG;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-23]
|
||||
@@ -0,0 +1,13 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHINT -23;
|
||||
NEG;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [23]
|
||||
@@ -0,0 +1,13 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT 2.3;
|
||||
NEG;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [-2.30]
|
||||
@@ -0,0 +1,13 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLT -2.3;
|
||||
NEG;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [2.30]
|
||||
@@ -0,0 +1,13 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHTRU;
|
||||
NOT;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [false]
|
||||
@@ -0,0 +1,13 @@
|
||||
@type [runtime]
|
||||
|
||||
@bytecode
|
||||
|
||||
PUSHFLS;
|
||||
NOT;
|
||||
|
||||
PUSHVAR "print";
|
||||
CALL 1, 1;
|
||||
POP 1;
|
||||
EXIT;
|
||||
|
||||
@output [true]
|
||||
Reference in New Issue
Block a user