aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-17 23:27:02 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-17 23:27:02 -0500
commit86f3a8054445ffe8650b7da7450234414b5b1789 (patch)
tree7dd6b1a278d85ca821eb608caf22231a773b2ea1
parent20b4c6f4973adf52ed3eef57df3aa8d19fef554c (diff)
Split out parts into appropriate headers
-rw-r--r--builtins/bool.h4
-rw-r--r--builtins/integers.h10
-rw-r--r--builtins/nums.h4
-rw-r--r--builtins/string.h3
-rw-r--r--compile.c6
-rw-r--r--nextlang.h25
6 files changed, 25 insertions, 27 deletions
diff --git a/builtins/bool.h b/builtins/bool.h
index 2e13c3c5..bbe67dba 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 2843951e..d4679a81 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 2b8387b9..83299ccf 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 51862520..48c39ae5 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 08193f38..10701866 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 29ff4465..a7e45935 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}; })