.
This commit is contained in:
76
lib/stack.c
76
lib/stack.c
@@ -1,2 +1,78 @@
|
|||||||
#include "value.c"
|
#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)
|
||||||
|
{
|
||||||
|
}
|
||||||
11
lib/value.c
11
lib/value.c
@@ -1,6 +1,7 @@
|
|||||||
#include "tyche.h"
|
#include "tyche.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -47,6 +48,11 @@ static uint32_t value_idx(VALUE v)
|
|||||||
return v.idx;
|
return v.idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE create_value_nil()
|
||||||
|
{
|
||||||
|
return (VALUE) { .type = TT_NIL };
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE create_value_integer(int32_t v)
|
static VALUE create_value_integer(int32_t v)
|
||||||
{
|
{
|
||||||
return (VALUE) { .type = TT_INTEGER, .i = v };
|
return (VALUE) { .type = TT_INTEGER, .i = v };
|
||||||
@@ -64,4 +70,9 @@ static VALUE create_value_idx(TYC_TYPE type, uint32_t idx)
|
|||||||
abort();
|
abort();
|
||||||
#endif
|
#endif
|
||||||
return (VALUE) { .type = type, .idx = idx };
|
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);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user