54 lines
1002 B
C
54 lines
1002 B
C
#pragma once
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <assert.h>
|
|
|
|
#include "vmstring.h"
|
|
#include "vm.h"
|
|
|
|
enum vm_type {
|
|
VT_CONS,
|
|
VT_STRING,
|
|
};
|
|
|
|
struct vm_value {
|
|
enum vm_type type;
|
|
size_t refcount;
|
|
union {
|
|
struct {
|
|
uintptr_t fat_ar, fat_dr;
|
|
} v_cons;
|
|
struct vm_string v_string;
|
|
};
|
|
};
|
|
|
|
static inline int ref_q(uint64_t w) {
|
|
return (w & FLAG_REF) != 0;
|
|
}
|
|
|
|
static inline int null_q(uint64_t w) {
|
|
return w == FLAG_REF;
|
|
}
|
|
|
|
static inline struct vm_value *getref(uint64_t w) {
|
|
assert(ref_q(w));
|
|
return (struct vm_value *) (w << 1);
|
|
}
|
|
|
|
static inline int cons_q(uint64_t w) {
|
|
if (ref_q(w)) {
|
|
return null_q(w) || getref(w)->type == VT_CONS;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
static inline int pair_q(uint64_t w) {
|
|
return ref_q(w) && (!null_q(w) && getref(w)->type == VT_CONS);
|
|
}
|
|
|
|
struct vm_value *vm_cons(uint64_t w0, uint64_t w1);
|
|
struct vm_value *vm_makestr(const char *str);
|
|
|
|
void vm_print(uint64_t w);
|