wip: working on variables

This commit is contained in:
samsonium
2026-10-11 19:11:49 +03:00
parent 01afe2e972
commit 2c76277a68
8 changed files with 215 additions and 72 deletions
+44 -2
View File
@@ -1,6 +1,6 @@
#include "common/fzl_types.h"
#include <common/fzl_builtins.h>
#include <common/fzl_opcodes.h>
#include <common/fzl_types.h>
#include <compiler/fzl_parser.h>
#include <compiler/fzl_token.h>
#include <compiler/fzl_walker.h>
@@ -94,15 +94,28 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
if (!walker || !node)
return (fzl_walk_res_t){.error = true, .error_msg = "walker is null"};
push_op(walker, FZL_OPCODE_MK_ENVTABLE);
fzl_walk_res_t current_res;
while (node != NULL)
{
switch (node->type)
{
case FZL_NODETYPE_UNARY_PLUS:
case FZL_NODETYPE_IDENTIFIER:
break;
case FZL_NODETYPE_IDENTIFIER:
{
size_t n = add_const(
walker, (fzl_const_t){.type = FZL_CONSTTYPE_STRING,
.as.string.chars = node->token->value,
.as.string.length = node->token->value_sz});
push_op(walker, FZL_OPCODE_LOADCONST);
push_word(walker, n);
current_res = (fzl_walk_res_t){.type = FZL_TYPE_STRING, .error = false};
}
case FZL_NODETYPE_BLOCK:
if (node->list.entry_count > 0)
for (size_t i = 0; i < node->list.entry_count; i++)
@@ -248,6 +261,35 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
push_op(walker, FZL_OPCODE_NEG);
current_res = (fzl_walk_res_t){.type = res.type, .error = false};
}
case FZL_NODETYPE_DECLARATION:
{
fzl_walk_res_t rres = walk(walker, node->var.identifier);
if (rres.error)
return rres;
push_op(walker, FZL_OPCODE_STORE);
// NOTE: ignoring type field for now
current_res = (fzl_walk_res_t){.type = FZL_TYPE_NULL, .error = false};
}
case FZL_NODETYPE_ASSIGN:
{
fzl_walk_res_t lres = walk(walker, node->binary_op.left);
if (lres.error)
return lres;
push_op(walker, FZL_OPCODE_LOOKUP_ENV);
fzl_walk_res_t rres = walk(walker, node->binary_op.right);
if (rres.error)
return rres;
push_op(walker, FZL_OPCODE_WRITE);
current_res = (fzl_walk_res_t){.type = rres.type, .error = false};
}
}
node = node->next;