diff --git a/builtins/bool.h b/builtins/bool.h index 2e13c3c..bbe67db 100644 --- a/builtins/bool.h +++ b/builtins/bool.h @@ -5,6 +5,10 @@ #include "types.h" +#define Bool_t bool +#define yes (Bool_t)true +#define no (Bool_t)false + CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type); typedef struct { diff --git a/builtins/integers.h b/builtins/integers.h index 2843951..d4679a8 100644 --- a/builtins/integers.h +++ b/builtins/integers.h @@ -5,6 +5,16 @@ #include "types.h" +#define Int64_t int64_t +#define Int32_t int32_t +#define Int16_t int16_t +#define Int8_t int8_t +#define Int_t int64_t +#define I64(x) ((int64_t)x) +#define I32(x) ((int32_t)x) +#define I16(x) ((int16_t)x) +#define I8(x) ((int8_t)x) + #define DEFINE_INT_TYPE(c_type, type_name) \ CORD type_name ## __as_str(const c_type *i, bool colorize, const TypeInfo *type); \ int32_t type_name ## __compare(const c_type *x, const c_type *y, const TypeInfo *type); \ diff --git a/builtins/nums.h b/builtins/nums.h index 2b8387b..83299cc 100644 --- a/builtins/nums.h +++ b/builtins/nums.h @@ -5,6 +5,10 @@ #include "types.h" +#define Num64_t double +#define Num32_t float +#define Num_t double + CORD Num64__as_str(const double *f, bool colorize, const TypeInfo *type); int32_t Num64__compare(const double *x, const double *y, const TypeInfo *type); bool Num64__equal(const double *x, const double *y, const TypeInfo *type); diff --git a/builtins/string.h b/builtins/string.h index 5186252..48c39ae 100644 --- a/builtins/string.h +++ b/builtins/string.h @@ -5,6 +5,9 @@ #include "types.h" +#define String_t CORD +#define Str_t CORD + typedef struct { CORD *data; unsigned long int length:42; diff --git a/compile.c b/compile.c index 08193f3..1070186 100644 --- a/compile.c +++ b/compile.c @@ -74,9 +74,9 @@ CORD compile(env_t *env, ast_t *ast) return CORD_from_char_star(buf); } case Not: return CORD_asprintf("not(%r)", compile(env, Match(ast, Not)->value)); - case Negative: return CORD_asprintf("-(%r)", compile(env, Match(ast, Not)->value)); - case HeapAllocate: return CORD_asprintf("$heap(%r)", compile(env, Match(ast, Not)->value)); - case StackReference: return CORD_asprintf("$stack(%r)", compile(env, Match(ast, Not)->value)); + case Negative: return CORD_asprintf("-(%r)", compile(env, Match(ast, Negative)->value)); + case HeapAllocate: return CORD_asprintf("$heap(%r)", compile(env, Match(ast, HeapAllocate)->value)); + case StackReference: return CORD_asprintf("$stack(%r)", compile(env, Match(ast, StackReference)->value)); case BinaryOp: { auto binop = Match(ast, BinaryOp); CORD lhs = compile(env, binop->lhs); diff --git a/nextlang.h b/nextlang.h index 29ff446..a7e4593 100644 --- a/nextlang.h +++ b/nextlang.h @@ -24,31 +24,8 @@ #include "builtins/table.h" #include "builtins/types.h" -#define Int64_t int64_t -#define Int32_t int32_t -#define Int16_t int16_t -#define Int8_t int8_t -#define Int_t int64_t -#define I64(x) ((int64_t)x) -#define I32(x) ((int32_t)x) -#define I16(x) ((int16_t)x) -#define I8(x) ((int8_t)x) - -#define Num64_t double -#define Num32_t float -#define Num_t double - -#define String_t CORD -#define Str_t CORD - -#define Bool_t bool -#define yes (Bool_t)true -#define no (Bool_t)false - #define Void_t void -#define $Array(t) array_t - CORD as_cord(void *x, bool use_color, const char *fmt, ...); #define StrF(...) ({ CORD $c; CORD_sprintf(&$c, __VA_ARGS__); $c; }) @@ -68,7 +45,7 @@ CORD as_cord(void *x, bool use_color, const char *fmt, ...); #define $index(x, i) _Generic(x, array_t: ({ __typeof(x) $obj; int64_t $offset = i; $offset += ($offset < 0) * ($obj.length + 1) - 1; assert($offset >= 0 && offset < $obj.length); $obj.data + $obj.stride * $offset;})) #define $safe_index(x, i) _Generic(x, array_t: ({ __typeof(x) $obj; int64_t $offset = i - 1; $obj.data + $obj.stride * $offset;})) #define $array(x, ...) ({ __typeof(x) $items[] = {x, __VA_ARGS__}; \ - ($Array(__typeof(x))){.length=sizeof($items)/sizeof($items[0]), \ + (array_t){.length=sizeof($items)/sizeof($items[0]), \ .stride=(int64_t)&$items[1] - (int64_t)&$items[0], \ .data=memcpy(GC_MALLOC(sizeof($items)), $items, sizeof($items)), \ .copy_on_write=1}; })