Fixed equality behavior.
This commit is contained in:
1 parent
f1d5f13322
commit
d68d4401af
1 file changed
+13
-2
+13
-2
@@ -167,19 +167,30 @@ AST* builtin_if(size_t argc, AST** argv, Scope* parent) {
|
||||
else return exec_exp(alt, parent);
|
||||
}
|
||||
|
||||
// Helper to force references.
|
||||
static AST* equality_arg(AST* expr, Scope* scope) {
|
||||
if (expr->type == AST_TYPE_REF) {
|
||||
expr = exec_ref(expr, scope);
|
||||
if (expr->type == AST_TYPE_EXC)
|
||||
return expr;
|
||||
}
|
||||
|
||||
return exec_exp(expr, scope);
|
||||
}
|
||||
|
||||
AST* builtin_eq(size_t argc, AST** argv, Scope* parent) {
|
||||
if (argc < 1) return ast_init(AST_TYPE_EXC, ast_exc_data_init("bad", NULL));
|
||||
// Return true for eq(anything)
|
||||
if (argc == 1) return ast_init(AST_TYPE_LIT_BOOL, ast_bool_data_init(1));
|
||||
|
||||
AST* first = exec_exp(argv[0], parent);
|
||||
AST* first = equality_arg(argv[0], parent);
|
||||
if (first->type == AST_TYPE_EXC)
|
||||
return ast_init(
|
||||
AST_TYPE_EXC, ast_exc_data_init("`eq` encountered an exception.", first)
|
||||
);
|
||||
|
||||
for (size_t i = 1; i < argc; i++) {
|
||||
AST* next = exec_exp(argv[i], parent);
|
||||
AST* next = equality_arg(argv[i], parent);
|
||||
if (next->type == AST_TYPE_EXC)
|
||||
return ast_init(
|
||||
AST_TYPE_EXC, ast_exc_data_init("`eq` encountered an exception.", next)
|
||||
|
||||
Reference in new issue
Block a user