more tests for the runtime

This commit is contained in:
Francesco Cozzuto
2023-01-23 01:06:29 +01:00
parent 1780826a97
commit f7a2cb0611
48 changed files with 597 additions and 14 deletions
+35 -7
View File
@@ -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;
+2 -1
View File
@@ -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
View File
@@ -884,7 +884,7 @@ static _Bool runInstruction(Runtime *runtime, Error *error)
return Runtime_Push(runtime, error, obj);
}
case OPCODE_PUSHFLT:
{
ASSERT(opc == 1);
-4
View File
@@ -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;