summaryrefslogtreecommitdiff
path: root/src/runner/runner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runner/runner.c')
-rw-r--r--src/runner/runner.c706
1 files changed, 48 insertions, 658 deletions
diff --git a/src/runner/runner.c b/src/runner/runner.c
index 4f788e7..dc3e655 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -506,668 +506,56 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
}
return ret;
}
+ case AST_TREE_TOKEN_OPERATOR_LOGICAL_NOT:
+ case AST_TREE_TOKEN_OPERATOR_MINUS:
case AST_TREE_TOKEN_OPERATOR_PLUS: {
- AstTreeSingleChild *operand =
- runExpression(expr->metadata, scope, shouldRet, false, isComptime);
- if (operand->type == &AST_TREE_U64_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, u64);
- } else if (operand->type == &AST_TREE_I64_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, i64);
- } else if (operand->type == &AST_TREE_U32_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, u32);
- } else if (operand->type == &AST_TREE_I32_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, i32);
- } else if (operand->type == &AST_TREE_U16_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, u16);
- } else if (operand->type == &AST_TREE_I16_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, i16);
- } else if (operand->type == &AST_TREE_U8_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, u8);
- } else if (operand->type == &AST_TREE_I8_TYPE) {
- doLeftOperation(operand, +, AstTreeInt, i8);
- } else if (operand->type == &AST_TREE_F128_TYPE) {
- doLeftOperation(operand, +, AstTreeFloat, f128);
- } else if (operand->type == &AST_TREE_F64_TYPE) {
- doLeftOperation(operand, +, AstTreeFloat, f64);
- } else if (operand->type == &AST_TREE_F32_TYPE) {
- doLeftOperation(operand, +, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (operand->type == &AST_TREE_F16_TYPE) {
- doLeftOperation(operand, +, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- return operand;
- }
- case AST_TREE_TOKEN_OPERATOR_MINUS: {
- AstTreeSingleChild *operand =
- runExpression(expr->metadata, scope, shouldRet, false, isComptime);
- if (operand->type == &AST_TREE_U64_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, u64);
- } else if (operand->type == &AST_TREE_I64_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, i64);
- } else if (operand->type == &AST_TREE_U32_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, u32);
- } else if (operand->type == &AST_TREE_I32_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, i32);
- } else if (operand->type == &AST_TREE_U16_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, u16);
- } else if (operand->type == &AST_TREE_I16_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, i16);
- } else if (operand->type == &AST_TREE_U8_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, u8);
- } else if (operand->type == &AST_TREE_I8_TYPE) {
- doLeftOperation(operand, -, AstTreeInt, i8);
- } else if (operand->type == &AST_TREE_F128_TYPE) {
- doLeftOperation(operand, -, AstTreeFloat, f128);
- } else if (operand->type == &AST_TREE_F64_TYPE) {
- doLeftOperation(operand, -, AstTreeFloat, f64);
- } else if (operand->type == &AST_TREE_F32_TYPE) {
- doLeftOperation(operand, -, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (operand->type == &AST_TREE_F16_TYPE) {
- doLeftOperation(operand, -, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- return operand;
- }
- case AST_TREE_TOKEN_OPERATOR_LOGICAL_NOT: {
- AstTreeSingleChild *operand =
- runExpression(expr->metadata, scope, shouldRet, false, isComptime);
-
- *(AstTreeBool *)operand->metadata = !*((AstTreeBool *)operand->metadata);
- return operand;
- }
- case AST_TREE_TOKEN_OPERATOR_SUM: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doOperation(left, right, +, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doOperation(left, right, +, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doOperation(left, right, +, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doOperation(left, right, +, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doOperation(left, right, +, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doOperation(left, right, +, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doOperation(left, right, +, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doOperation(left, right, +, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doOperation(left, right, +, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doOperation(left, right, +, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doOperation(left, right, +, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doOperation(left, right, +, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_SUB: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doOperation(left, right, -, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doOperation(left, right, -, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doOperation(left, right, -, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doOperation(left, right, -, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doOperation(left, right, -, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doOperation(left, right, -, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doOperation(left, right, -, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doOperation(left, right, -, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doOperation(left, right, -, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doOperation(left, right, -, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doOperation(left, right, -, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doOperation(left, right, -, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_MULTIPLY: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doOperation(left, right, *, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doOperation(left, right, *, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doOperation(left, right, *, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doOperation(left, right, *, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doOperation(left, right, *, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doOperation(left, right, *, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doOperation(left, right, *, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doOperation(left, right, *, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doOperation(left, right, *, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doOperation(left, right, *, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doOperation(left, right, *, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doOperation(left, right, *, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_DIVIDE: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doOperation(left, right, /, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doOperation(left, right, /, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doOperation(left, right, /, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doOperation(left, right, /, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doOperation(left, right, /, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doOperation(left, right, /, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doOperation(left, right, /, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doOperation(left, right, /, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doOperation(left, right, /, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doOperation(left, right, /, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doOperation(left, right, /, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doOperation(left, right, /, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_MODULO: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doOperation(left, right, %, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doOperation(left, right, %, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doOperation(left, right, %, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doOperation(left, right, %, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doOperation(left, right, %, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doOperation(left, right, %, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doOperation(left, right, %, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doOperation(left, right, %, AstTreeInt, i8);
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported %s",
- AST_TREE_TOKEN_STRINGS[right->type->token]);
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_EQUAL: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doLogicalOperation(left, right, ==, AstTreeFloat, f16);
-#endif
- } else if (left->type == &AST_TREE_TYPE_TYPE) {
- bool *res = a404m_malloc(sizeof(*res));
- *res = typeIsEqual(left, right);
- astTreeDelete(left);
- left = newAstTree(AST_TREE_TOKEN_VALUE_BOOL, res, &AST_TREE_BOOL_TYPE,
- NULL, NULL);
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_NOT_EQUAL: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doLogicalOperation(left, right, !=, AstTreeFloat, f16);
-#endif
- } else if (left->type == &AST_TREE_TYPE_TYPE) {
- bool *res = a404m_malloc(sizeof(*res));
- *res = !typeIsEqual(left, right);
- astTreeDelete(left);
- left = newAstTree(AST_TREE_TOKEN_VALUE_BOOL, res, &AST_TREE_BOOL_TYPE,
- NULL, NULL);
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_GREATER: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doLogicalOperation(left, right, >, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doLogicalOperation(left, right, >, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doLogicalOperation(left, right, >, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doLogicalOperation(left, right, >, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doLogicalOperation(left, right, >, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_SMALLER: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doLogicalOperation(left, right, <, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doLogicalOperation(left, right, <, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doLogicalOperation(left, right, <, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doLogicalOperation(left, right, <, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doLogicalOperation(left, right, <, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_GREATER_OR_EQUAL: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doLogicalOperation(left, right, >=, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_SMALLER_OR_EQUAL: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- if (left->type == &AST_TREE_U64_TYPE && right->type == &AST_TREE_U64_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, u64);
- } else if (left->type == &AST_TREE_I64_TYPE &&
- right->type == &AST_TREE_I64_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, i64);
- } else if (left->type == &AST_TREE_U32_TYPE &&
- right->type == &AST_TREE_U32_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, u32);
- } else if (left->type == &AST_TREE_I32_TYPE &&
- right->type == &AST_TREE_I32_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, i32);
- } else if (left->type == &AST_TREE_U16_TYPE &&
- right->type == &AST_TREE_U16_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, u16);
- } else if (left->type == &AST_TREE_I16_TYPE &&
- right->type == &AST_TREE_I16_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, i16);
- } else if (left->type == &AST_TREE_U8_TYPE &&
- right->type == &AST_TREE_U8_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, u8);
- } else if (left->type == &AST_TREE_I8_TYPE &&
- right->type == &AST_TREE_I8_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeInt, i8);
- } else if (left->type == &AST_TREE_F128_TYPE &&
- right->type == &AST_TREE_F128_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeFloat, f128);
- } else if (left->type == &AST_TREE_F64_TYPE &&
- right->type == &AST_TREE_F64_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeFloat, f64);
- } else if (left->type == &AST_TREE_F32_TYPE &&
- right->type == &AST_TREE_F32_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeFloat, f32);
-#ifdef FLOAT_16_SUPPORT
- } else if (left->type == &AST_TREE_F16_TYPE &&
- right->type == &AST_TREE_F16_TYPE) {
- doLogicalOperation(left, right, <=, AstTreeFloat, f16);
-#endif
- } else {
- printError(expr->str_begin, expr->str_end, "Not supported");
- UNREACHABLE;
- }
- astTreeDelete(right);
- return left;
- }
- case AST_TREE_TOKEN_OPERATOR_LOGICAL_AND: {
- AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- *(AstTreeBool *)left->metadata =
- *(AstTreeBool *)left->metadata && *(AstTreeBool *)right->metadata;
-
- astTreeDelete(right);
- return left;
+ AstTreeUnary *metadata = expr->metadata;
+ AstTree *function = runExpression(metadata->function->value, scope,
+ shouldRet, false, isComptime);
+ AstTreeFunctionCallParam arguments[] = {
+ (AstTreeFunctionCallParam){
+ .nameBegin = NULL,
+ .nameEnd = NULL,
+ .value = metadata->operand,
+ },
+ };
+ AstTree *ret = runAstTreeFunction(function, arguments, 1, isComptime);
+ astTreeDelete(function);
+ return ret;
}
+ case AST_TREE_TOKEN_OPERATOR_SUM:
+ case AST_TREE_TOKEN_OPERATOR_SUB:
+ case AST_TREE_TOKEN_OPERATOR_MULTIPLY:
+ case AST_TREE_TOKEN_OPERATOR_DIVIDE:
+ case AST_TREE_TOKEN_OPERATOR_MODULO:
+ case AST_TREE_TOKEN_OPERATOR_EQUAL:
+ case AST_TREE_TOKEN_OPERATOR_NOT_EQUAL:
+ case AST_TREE_TOKEN_OPERATOR_GREATER:
+ case AST_TREE_TOKEN_OPERATOR_SMALLER:
+ case AST_TREE_TOKEN_OPERATOR_GREATER_OR_EQUAL:
+ case AST_TREE_TOKEN_OPERATOR_SMALLER_OR_EQUAL:
+ case AST_TREE_TOKEN_OPERATOR_LOGICAL_AND:
case AST_TREE_TOKEN_OPERATOR_LOGICAL_OR: {
AstTreeInfix *metadata = expr->metadata;
- AstTree *left =
- runExpression(metadata->left, scope, shouldRet, false, isComptime);
- AstTree *right =
- runExpression(metadata->right, scope, shouldRet, false, isComptime);
-
- *(AstTreeBool *)left->metadata =
- *(AstTreeBool *)left->metadata || *(AstTreeBool *)right->metadata;
-
- astTreeDelete(right);
- return left;
+ AstTree *function = runExpression(metadata->function->value, scope,
+ shouldRet, false, isComptime);
+
+ AstTreeFunctionCallParam arguments[] = {
+ (AstTreeFunctionCallParam){
+ .nameBegin = NULL,
+ .nameEnd = NULL,
+ .value = metadata->left,
+ },
+ (AstTreeFunctionCallParam){
+ .nameBegin = NULL,
+ .nameEnd = NULL,
+ .value = metadata->right,
+ },
+ };
+
+ AstTree *ret = runAstTreeFunction(function, arguments, 2, isComptime);
+ astTreeDelete(function);
+ return ret;
}
case AST_TREE_TOKEN_TYPE_TYPE:
case AST_TREE_TOKEN_TYPE_FUNCTION:
@@ -1200,6 +588,8 @@ AstTree *runExpression(AstTree *expr, AstTreeScope *scope, bool *shouldRet,
case AST_TREE_TOKEN_BUILTIN_CAST:
case AST_TREE_TOKEN_BUILTIN_TYPE_OF:
case AST_TREE_TOKEN_BUILTIN_IMPORT:
+ case AST_TREE_TOKEN_BUILTIN_STACK_ALLOC:
+ case AST_TREE_TOKEN_BUILTIN_HEAP_ALLOC:
return copyAstTree(expr);
case AST_TREE_TOKEN_BUILTIN_IS_COMPTIME: {
AstTreeBool *metadata = a404m_malloc(sizeof(*metadata));