1
0
Fork 0
forked from fun/fun

Initial code commit.

This commit is contained in:
Johannes Findeisen 2025-09-13 05:09:20 +02:00
commit 6a7add3e56
13 changed files with 891 additions and 0 deletions

39
src/value.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef FUN_VALUE_H
#define FUN_VALUE_H
#include <inttypes.h>
struct Bytecode; /* forward */
typedef enum {
VAL_INT,
VAL_STRING,
VAL_FUNCTION,
VAL_NIL
} ValueType;
typedef struct {
ValueType type;
union {
int64_t i;
char *s;
struct Bytecode *fn;
};
} Value;
/* constructors / helpers */
Value make_int(int64_t v);
Value make_string(const char *s);
Value make_function(struct Bytecode *fn);
Value make_nil(void);
/* copy (deep for strings), free (free string only) */
Value copy_value(const Value *v);
void free_value(Value v);
/* utilities */
void print_value(const Value *v);
int value_is_truthy(const Value *v);
#endif