diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-04 23:29:57 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-04 23:29:57 -0500 |
| commit | c2245c85700d5854bb323ffda8dd767c57786dd9 (patch) | |
| tree | ac57639dd963c3a26a854b752ae5b38ba205d45a | |
| parent | adde91636f04ae7544dba1ca5c6c1a40c074edb9 (diff) | |
Misc changes
| -rw-r--r-- | foo.c | 9 | ||||
| -rw-r--r-- | nextlang.h | 14 |
2 files changed, 3 insertions, 20 deletions
@@ -1,18 +1,9 @@ #include "nextlang.h" -static void foo(Int64 x); - - -void foo(Int64 x) -{ - say("Hello world!"); -} - int main(int argc, const char *argv[]) { (void) argc; (void) argv; - foo(((Int64_t) 5)); return 0; } @@ -26,15 +26,7 @@ #define Void_t void -typedef struct __array_s { - void *data; - int64_t length:42; - uint8_t free:4; - bool copy_on_write:1, atomic:1; - int16_t stride:16; -} __array_t; - -#define __Array(t) __array_t +#define __Array(t) array_t #define CORD_asprintf(...) ({ CORD __c; CORD_sprintf(&__c, __VA_ARGS__); __c; }) #define __declare(var, val) __typeof(val) var = val @@ -46,12 +38,12 @@ typedef struct __array_s { default: "???") #define __heap(x) (__typeof(x)*)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x)) #define __stack(x) (&(__typeof(x)){x}) -#define __length(x) _Generic(x, array_t: (x).length) +#define __length(x) _Generic(x, default: (x).length) // Convert negative indices to back-indexed without branching: index0 = index + (index < 0)*(len+1)) - 1 #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_t){.length=sizeof(__items)/sizeof(__items[0]), \ + (__Array(__typeof(x))){.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}; }) |
