#include <assert.h>
#include <string.h>
-#if (UINTPTR_MAX == 0xFFFFFFFFu)
-#error "32-bit machines are not supported at this time"
-#endif
-
-//# Nil X
-//# Bool X
-//# Int X
-//# Real X
-//# Record .
-//# Array
-//# Hashmap
-//# String
-
-//#define VALUE_NIL 0x0llu
-//#define VALUE_UNDEFINED 0x1llu
-//#define VALUE_FALSE 0x2llu
-//#define VALUE_TRUE 0x3llu
-
-#define NAN_TAG_DICT 0x0000000000000000llu
-#define NAN_TAG_ARRAY 0x0001000000000000llu
-#define NAN_TAG_STRING 0x0002000000000000llu
-//#define NAN_TAG_BLOCK 0x0003000000000000llu
-//#define NAN_TAG_NATIVE 0x0004000000000000llu
-//#define NAN_TAG_SYMBOL 0x0005000000000000llu
-#define NAN_TAG_INTEGER 0x0006000000000000llu
-#define NAN_TAG_DOUBLE 0x0007000000000000llu
-
-#define MASK_POINTER 0x0000fffffffffffcllu
-#define HIGH16_TAG 0xffff000000000000llu
-//#define IMM_TAG 0x0000000000000003llu
-//#define TAG_BITS (HIGH16_TAG | IMM_TAG)
-
-
-#define VALUE_NIL 0x0llu
-#define VALUE_UNUSED 0x1llu
-#define VALUE_FALSE 0x2llu
-#define VALUE_TRUE 0x3llu
-
-typedef union {
- uint64_t as_uint64;
- double as_double;
-} Value;
+typedef intptr_t _value;
typedef struct string {
uint64_t length;
uint8_t bytes[];
}* string;
-typedef struct {
+typedef struct array {
uint64_t length;
uint64_t capacity;
- Value* values;
-} Array;
-
-typedef struct DictNode {
- struct DictNode* left;
- struct DictNode* right;
- Value key;
- Value value;
+ _value* values;
+}* _array;
+
+typedef struct dict_node {
+ struct dict_node* left;
+ struct dict_node* right;
+ _value key;
+ _value value;
uint32_t hash;
-} DictNode;
+}* dict_node;
-typedef struct {
+typedef struct dict {
uint64_t length;
- DictNode* root;
-} Dict;
-
-
-/* Value Tests
- *************************************************/
-
-static inline bool IsNil(Value val) {
- return val.as_uint64 == VALUE_NIL;
-}
-
-static inline bool IsFalse(Value val) {
- return val.as_uint64 == VALUE_FALSE;
-}
-
-static inline bool IsTrue(Value val) {
- return val.as_uint64 == VALUE_TRUE;
-}
-
-static inline bool IsBool(Value val) {
- return (IsTrue(val) || IsFalse(val));
-}
-
-static inline bool IsNumber(Value val) {
- return val.as_uint64 >= NAN_TAG_INTEGER;
-}
-
-static inline bool IsInt(Value val) {
- return (val.as_uint64 & HIGH16_TAG) == NAN_TAG_INTEGER;
-}
-
-static inline bool IsReal(Value val) {
- return IsNumber(val) && !IsInt(val);
-}
-
-static inline bool IsString(Value val) {
- return (val.as_uint64 & HIGH16_TAG) == NAN_TAG_STRING;
-}
-
-static inline bool IsArray(Value val) {
- return (val.as_uint64 & HIGH16_TAG) == NAN_TAG_ARRAY;
-}
-
-static inline bool IsDict(Value val) {
- return (val.as_uint64 & HIGH16_TAG) == NAN_TAG_DICT;
-}
-
-
-/* C Type Conversions
- *************************************************/
-
-static inline bool ValueAsBool(Value val) {
- assert(IsBool(val));
- return (bool)(val.as_uint64 == VALUE_TRUE);
-}
-
-static inline int32_t ValueAsInt(Value val) {
- assert(IsInt(val));
- return (int32_t)val.as_uint64;
-}
-
-static inline double ValueAsReal(Value val) {
- assert(IsReal(val));
- val.as_uint64 -= NAN_TAG_DOUBLE;
- return val.as_double;
-}
-
-//static String* ValueAsString(Value val) {
-// assert(IsString(val));
-// return (String*)(val.as_uint64 & MASK_POINTER);
-//}
-//
-static Array* ValueAsArray(Value val) {
- assert(IsArray(val));
- return (Array*)(val.as_uint64 & MASK_POINTER);
-}
-
-static Dict* ValueAsDict(Value val) {
- assert(IsDict(val));
- return (Dict*)(val.as_uint64 & MASK_POINTER);
-}
-
-
-//static Array* to_array(Value val) {
-// assert(is_array(val));
-// return (Array*)(val.as_pointer);
-//}
-//
-//
-//static Block* to_block(Value val) {
-// assert(is_block(val));
-// return (Block*)(val.as_pointer);
-//}
-
-//static NativeBlock* to_native(Value val) {
-// assert(is_native(val));
-// return (NativeBlock*)(val.as_pointer);
-//}
-//
-//static Symbol* to_symbol(Value val) {
-// assert(is_symbol(val));
-// return (Symbol*)(val.as_pointer);
-//}
-
-
-/* Value Constructors
- *************************************************/
-
-static inline Value MakeNil(void) {
- return (Value){ .as_uint64 = VALUE_NIL };
-}
-
-static inline Value MakeBool(bool b) {
- return (Value){ .as_uint64 = (b ? VALUE_TRUE : VALUE_FALSE) };
-}
-
-static inline Value MakeInt(int32_t i) {
- return (Value){ .as_uint64 = NAN_TAG_INTEGER | (uint32_t)i };
-}
-
-static inline Value MakeReal(double d) {
- Value val = { .as_double = d };
- val.as_uint64 += NAN_TAG_DOUBLE;
- assert(IsReal(val));
- return val;
-}
+ dict_node root;
+}* _dict;
string MakeString(char* s);
-Value MakeArray(int32_t nslots);
-Value MakeDict(int32_t nslots);
-
-
-/* Value Type Conversions
- *************************************************/
-
-Value ToString(Value val);
-
-
-/* Builtin Functions
- *************************************************/
-
-Value Error(Value val);
-void RuntimeError(char* s);
+_array MakeArray(int32_t nslots);
+_dict MakeDict(int32_t nslots);
void Assert(char* file, int lineno, bool val);
-Value Length(Value val);
-
-/* Binary Operators
- *************************************************/
-
-Value OpAdd(Value left, Value right);
-Value OpSub(Value left, Value right);
-Value OpMul(Value left, Value right);
-Value OpDiv(Value left, Value right);
-Value OpMod(Value left, Value right);
-Value OpLt(Value left, Value right);
-Value OpLtEq(Value left, Value right);
-Value OpGt(Value left, Value right);
-Value OpGtEq(Value left, Value right);
-Value OpEq(Value left, Value right);
-Value OpNeq(Value left, Value right);
-
-/* Arrays And Hashes
- *************************************************/
-
-void String_Set(Value array, int index, Value value);
-Value String_Get(Value array, int index);
-
-void Array_Set(Value array, int index, Value value);
-Value Array_Get(Value array, int index);
-
-void Dict_Set(Value hash, Value key, Value value);
-Value Dict_Get(Value hash, Value key);
-
-Value Object_Get(Value object, Value key);
-void Object_Set(Value object, Value key, Value value);
+static inline void Array_Set(_array ary, int index, _value val)
+{
+}
/* Garbage Collection
*************************************************/
#define ENTRYPOINT(func) \
int main(int argc, char** argv) { \
- extern Value func(); \
- (void)func(); \
+ extern void func(); \
+ func(); \
return 0; \
}