feat: implement environment table for vm

This commit is contained in:
samsonium
2026-10-12 17:20:41 +03:00
parent 2c76277a68
commit e7573743aa
5 changed files with 164 additions and 18 deletions
+3 -1
View File
@@ -5,6 +5,7 @@
#include <compiler/utils/fzl_const_pool.h> // NOTE: move outside compiler scope to common
#include <stddef.h>
#include <stdint.h>
#include <vm/fzl_vm_env.h>
// VM descriptor
typedef struct
@@ -26,7 +27,8 @@ typedef struct
size_t ctop;
// Environment stack
// TODO: implement `estack` and `etop`
fzl_vm_env_t estack[256];
size_t etop;
} fzl_vm_t;
// Allocate FZL VM
+52
View File
@@ -0,0 +1,52 @@
#ifndef FZL_VM_ENV_H
#define FZL_VM_ENV_H
#include <common/fzl_value.h>
#include <stdbool.h>
#include <stddef.h>
typedef enum
{
FZL_VM_ENV_WRESULT_OK,
FZL_VM_ENV_WRESULT_ERR,
FZL_VM_ENV_WRESULT_ERR_EXISTS,
FZL_VM_ENV_WRESULT_ERR_NOT_FOUND
} fzl_vm_env_wresult_t;
// Environment table entry descriptor
typedef struct
{
char *name;
fzl_value_t value;
} fzl_vm_env_entry_t;
// Environment table descriptor
typedef struct
{
size_t size;
size_t remainder;
fzl_vm_env_entry_t *table;
} fzl_vm_env_t;
// Allocate env table
fzl_vm_env_t *fzl_mkenv();
// Try get value by name
fzl_value_t fzl_env_lookup(fzl_vm_env_t *env, char *name);
// Check name in env table
bool fzl_env_contains(fzl_vm_env_t *env, char *name);
// Store new value
fzl_vm_env_wresult_t fzl_env_storevalue(fzl_vm_env_t *env, char *name,
fzl_value_t val);
// Overwrite existing value
fzl_vm_env_wresult_t fzl_env_writevalue(fzl_vm_env_t *env, char *name,
fzl_value_t newval);
// Free env table
void fzl_freeenv(fzl_vm_env_t *env);
#endif // FZL_VM_ENV_H