This commit is contained in:
2026-05-10 16:10:44 -05:00
parent 3a40eda575
commit f12d1f01da
2 changed files with 87 additions and 0 deletions

View File

@@ -1,2 +1,78 @@
#include "value.c"
#include <stdlib.h>
typedef struct {
VALUE* stack;
size_t stack_n;
size_t stack_cap;
uint32_t* fp;
size_t fp_n;
size_t fp_cap;
} Stack;
static void stack_init(Stack* s)
{
s->stack_n = s->fp_n = 0;
s->stack_cap = 64;
s->fp_cap = 8;
s->stack = malloc(s->stack_cap * sizeof s->stack[0]);
s->fp = malloc(s->stack_cap * sizeof s->fp[0]);
assert(s->stack);
assert(s->fp);
}
static void stack_destroy(Stack* s)
{
free(s->stack);
free(s->fp);
}
static void stack_push(Stack* s, VALUE v)
{
if (s->stack_n == s->stack_cap) {
s->stack_cap *= 2;
s->stack = realloc(s->stack, s->stack_cap * sizeof s->stack[0]);
assert(s->stack);
}
s->stack[s->stack_n] = v;
++s->stack_n;
}
static VALUE stack_pop(Stack* s)
{
}
static VALUE stack_peek(Stack* s)
{
}
static uint32_t stack_len(Stack* s)
{
}
static VALUE stack_get(Stack* s, int32_t key)
{
}
static void stack_set(Stack* s, int32_t key, VALUE v)
{
}
static void stack_push_fp(Stack* s)
{
}
static void stack_pop_fp(Stack* s)
{
}
static uint32_t stack_top_fp(Stack* s)
{
}
static uint32_t stack_fp_level(Stack* s)
{
}

View File

@@ -1,6 +1,7 @@
#include "tyche.h"
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
@@ -47,6 +48,11 @@ static uint32_t value_idx(VALUE v)
return v.idx;
}
static VALUE create_value_nil()
{
return (VALUE) { .type = TT_NIL };
}
static VALUE create_value_integer(int32_t v)
{
return (VALUE) { .type = TT_INTEGER, .i = v };
@@ -65,3 +71,8 @@ static VALUE create_value_idx(TYC_TYPE type, uint32_t idx)
#endif
return (VALUE) { .type = type, .idx = idx };
}
static bool value_is_zero(VALUE v)
{
return v.type == TT_NIL || (v.type == TT_INTEGER && v.i == 0);
}