lang: ast: replace var keyword with global

local variables are now created automatically when they are first assigned to.

the global keyword can be used to declare that a name refers to a global variable instead,
at which point, assigning to the name results in the assignment referencing the global variable
instead of allocating a new global variable.
This commit is contained in:
2025-09-08 15:50:50 +01:00
parent 5ea544692b
commit 84e52b1649
5 changed files with 39 additions and 41 deletions

View File

@@ -16,7 +16,7 @@ extern struct ast_node_type expr_node_ops;
extern struct ast_node_type block_node_ops;
extern struct ast_node_type msg_node_ops;
extern struct ast_node_type op_node_ops;
extern struct ast_node_type var_node_ops;
extern struct ast_node_type global_node_ops;
extern struct ast_node_type ident_node_ops;
extern struct ast_node_type int_node_ops;
extern struct ast_node_type double_node_ops;
@@ -52,7 +52,7 @@ static const struct ast_node_type *node_ops[] = {
[IVY_AST_BLOCK] = &block_node_ops,
[IVY_AST_MSG] = &msg_node_ops,
[IVY_AST_OP] = &op_node_ops,
[IVY_AST_VAR] = &var_node_ops,
[IVY_AST_GLOBAL] = &global_node_ops,
[IVY_AST_IDENT] = &ident_node_ops,
[IVY_AST_INT] = &int_node_ops,
[IVY_AST_DOUBLE] = &double_node_ops,
@@ -349,7 +349,7 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v)
ENUM_STR(IVY_AST_UNIT_IMPORT);
ENUM_STR(IVY_AST_DISCARD);
ENUM_STR(IVY_AST_INT);
ENUM_STR(IVY_AST_VAR);
ENUM_STR(IVY_AST_GLOBAL);
ENUM_STR(IVY_AST_DOUBLE);
ENUM_STR(IVY_AST_STRING);
ENUM_STR(IVY_AST_FSTRING);