This commit is contained in:
2026-05-13 07:19:33 -05:00
parent 15f2794133
commit 19bff9b32f
9 changed files with 377 additions and 132 deletions

View File

@@ -1,25 +1,15 @@
#include "tyche.h"
#include "priv.h"
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct {
TYC_TYPE type;
union {
int32_t i;
float f;
uint32_t idx;
} v;
} VALUE;
static TYC_TYPE value_type(VALUE v)
TYC_TYPE value_type(VALUE v)
{
return v.type;
}
static int32_t value_integer(VALUE v)
int32_t value_integer(VALUE v)
{
#ifdef CHECK_TYCHE_BUGS
if (v.type != TT_INTEGER)
@@ -28,7 +18,7 @@ static int32_t value_integer(VALUE v)
return v.v.i;
}
static float value_real(VALUE v)
float value_real(VALUE v)
{
#ifdef CHECK_TYCHE_BUGS
if (v.type != TT_REAL)
@@ -37,7 +27,7 @@ static float value_real(VALUE v)
return v.v.f;
}
static uint32_t value_idx(VALUE v)
uint32_t value_idx(VALUE v)
{
#ifdef CHECK_TYCHE_BUGS
if (v.type != TT_FUNCTION && v.type != TT_NATIVE_PTR && v.type != TT_ARRAY && v.type != TT_TABLE && v.type != TT_STRING && v.type != TT_STRING_CONST)
@@ -46,22 +36,22 @@ static uint32_t value_idx(VALUE v)
return v.v.idx;
}
static VALUE create_value_nil()
VALUE create_value_nil()
{
return (VALUE) { .type = TT_NIL };
}
static VALUE create_value_integer(int32_t v)
VALUE create_value_integer(int32_t v)
{
return (VALUE) { .type = TT_INTEGER, .v = { .i = v } };
}
static VALUE create_value_real(float f)
VALUE create_value_real(float f)
{
return (VALUE) { .type = TT_REAL, .v = { .f = f } };
}
static VALUE create_value_idx(TYC_TYPE type, uint32_t idx)
VALUE create_value_idx(TYC_TYPE type, uint32_t idx)
{
#ifdef CHECK_TYCHE_BUGS
if (type != TT_FUNCTION && type != TT_NATIVE_PTR && type != TT_ARRAY && type != TT_TABLE && type != TT_STRING && type != TT_STRING_CONST)
@@ -70,7 +60,7 @@ static VALUE create_value_idx(TYC_TYPE type, uint32_t idx)
return (VALUE) { .type = type, .v = { .idx = idx } };
}
static bool value_is_zero(VALUE v)
bool value_is_zero(VALUE v)
{
return v.type == TT_NIL || (v.type == TT_INTEGER && v.v.i == 0);
}