Initial code commit.
This commit is contained in:
parent
7aa60fe930
commit
6a7add3e56
13 changed files with 891 additions and 0 deletions
39
src/value.h
Normal file
39
src/value.h
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue