Split out parts into appropriate headers

This commit is contained in:
Bruce Hill 2024-02-17 23:27:02 -05:00
parent 20b4c6f497
commit 86f3a80544
6 changed files with 25 additions and 27 deletions

View File

@ -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 {

View File

@ -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); \

View File

@ -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);

View File

@ -5,6 +5,9 @@
#include "types.h"
#define String_t CORD
#define Str_t CORD
typedef struct {
CORD *data;
unsigned long int length:42;

View File

@ -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);

View File

@ -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}; })