aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/bools.c18
-rw-r--r--src/stdlib/bools.h18
-rw-r--r--src/stdlib/bytes.c48
-rw-r--r--src/stdlib/bytes.h30
-rw-r--r--src/stdlib/c_strings.c40
-rw-r--r--src/stdlib/c_strings.h10
-rw-r--r--src/stdlib/datatypes.h2
-rw-r--r--src/stdlib/enums.c22
-rw-r--r--src/stdlib/enums.h46
-rw-r--r--src/stdlib/functiontype.c8
-rw-r--r--src/stdlib/functiontype.h18
-rw-r--r--src/stdlib/integers.c324
-rw-r--r--src/stdlib/integers.h282
-rw-r--r--src/stdlib/lists.c132
-rw-r--r--src/stdlib/lists.h116
-rw-r--r--src/stdlib/memory.c8
-rw-r--r--src/stdlib/memory.h4
-rw-r--r--src/stdlib/metamethods.c4
-rw-r--r--src/stdlib/nums.c108
-rw-r--r--src/stdlib/nums.h96
-rw-r--r--src/stdlib/optionals.c18
-rw-r--r--src/stdlib/optionals.h32
-rw-r--r--src/stdlib/paths.c390
-rw-r--r--src/stdlib/paths.h118
-rw-r--r--src/stdlib/pointers.c46
-rw-r--r--src/stdlib/pointers.h30
-rw-r--r--src/stdlib/print.h12
-rw-r--r--src/stdlib/stacktrace.c2
-rw-r--r--src/stdlib/stdlib.c64
-rw-r--r--src/stdlib/structs.c48
-rw-r--r--src/stdlib/structs.h50
-rw-r--r--src/stdlib/tables.c194
-rw-r--r--src/stdlib/tables.h120
-rw-r--r--src/stdlib/text.c424
-rw-r--r--src/stdlib/text.h136
-rw-r--r--src/stdlib/types.c12
-rw-r--r--src/stdlib/types.h10
-rw-r--r--src/stdlib/util.h2
38 files changed, 1521 insertions, 1521 deletions
diff --git a/src/stdlib/bools.c b/src/stdlib/bools.c
index 85de0621..fd669579 100644
--- a/src/stdlib/bools.c
+++ b/src/stdlib/bools.c
@@ -12,7 +12,7 @@
#include "text.h"
#include "util.h"
-PUREFUNC public Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t *info)
+PUREFUNC public Text_t Boolヽas_text(const void *b, bool colorize, const TypeInfo_t *info)
{
(void)info;
if (!b) return Text("Bool");
@@ -26,9 +26,9 @@ static bool try_parse(Text_t text, Text_t target, bool target_value, Text_t *rem
{
static const Text_t lang = Text("C");
if (text.length < target.length) return false;
- Text_t prefix = Text$to(text, Int$from_int64(target.length));
- if (Text$equal_ignoring_case(prefix, target, lang)) {
- if (remainder) *remainder = Text$from(text, Int$from_int64(target.length + 1));
+ Text_t prefix = Textヽto(text, Intヽfrom_int64(target.length));
+ if (Textヽequal_ignoring_case(prefix, target, lang)) {
+ if (remainder) *remainder = Textヽfrom(text, Intヽfrom_int64(target.length + 1));
else if (text.length > target.length) return false;
*result = target_value;
return true;
@@ -37,7 +37,7 @@ static bool try_parse(Text_t text, Text_t target, bool target_value, Text_t *rem
}
}
-PUREFUNC public OptionalBool_t Bool$parse(Text_t text, Text_t *remainder)
+PUREFUNC public OptionalBool_t Boolヽparse(Text_t text, Text_t *remainder)
{
bool result;
if (try_parse(text, Text("yes"), true, remainder, &result)
@@ -53,18 +53,18 @@ PUREFUNC public OptionalBool_t Bool$parse(Text_t text, Text_t *remainder)
return NONE_BOOL;
}
-static bool Bool$is_none(const void *b, const TypeInfo_t *info)
+static bool Boolヽis_none(const void *b, const TypeInfo_t *info)
{
(void)info;
return *(OptionalBool_t*)b == NONE_BOOL;
}
-public const TypeInfo_t Bool$info = {
+public const TypeInfo_t Boolヽinfo = {
.size=sizeof(bool),
.align=__alignof__(bool),
.metamethods={
- .as_text=Bool$as_text,
- .is_none=Bool$is_none,
+ .as_text=Boolヽas_text,
+ .is_none=Boolヽis_none,
},
};
diff --git a/src/stdlib/bools.h b/src/stdlib/bools.h
index ae6c5feb..db282b12 100644
--- a/src/stdlib/bools.h
+++ b/src/stdlib/bools.h
@@ -12,15 +12,15 @@
#define yes (Bool_t)true
#define no (Bool_t)false
-PUREFUNC Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t *type);
-OptionalBool_t Bool$parse(Text_t text, Text_t *remainder);
-MACROLIKE Bool_t Bool$from_int(Int_t i) { return (i.small != 0); }
-MACROLIKE Bool_t Bool$from_int64(Int64_t i) { return (i != 0); }
-MACROLIKE Bool_t Bool$from_int32(Int32_t i) { return (i != 0); }
-MACROLIKE Bool_t Bool$from_int16(Int16_t i) { return (i != 0); }
-MACROLIKE Bool_t Bool$from_int8(Int8_t i) { return (i != 0); }
-MACROLIKE Bool_t Bool$from_byte(uint8_t b) { return (b != 0); }
+PUREFUNC Text_t Boolヽas_text(const void *b, bool colorize, const TypeInfo_t *type);
+OptionalBool_t Boolヽparse(Text_t text, Text_t *remainder);
+MACROLIKE Bool_t Boolヽfrom_int(Int_t i) { return (i.small != 0); }
+MACROLIKE Bool_t Boolヽfrom_int64(Int64_t i) { return (i != 0); }
+MACROLIKE Bool_t Boolヽfrom_int32(Int32_t i) { return (i != 0); }
+MACROLIKE Bool_t Boolヽfrom_int16(Int16_t i) { return (i != 0); }
+MACROLIKE Bool_t Boolヽfrom_int8(Int8_t i) { return (i != 0); }
+MACROLIKE Bool_t Boolヽfrom_byte(uint8_t b) { return (b != 0); }
-extern const TypeInfo_t Bool$info;
+extern const TypeInfo_t Boolヽinfo;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c
index 130a645f..9492c14c 100644
--- a/src/stdlib/bytes.c
+++ b/src/stdlib/bytes.c
@@ -8,10 +8,10 @@
#include "text.h"
#include "util.h"
-public const Byte_t Byte$min = 0;
-public const Byte_t Byte$max = UINT8_MAX;
+public const Byte_t Byteヽmin = 0;
+public const Byte_t Byteヽmax = UINT8_MAX;
-PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo_t *info)
+PUREFUNC public Text_t Byteヽas_text(const void *b, bool colorize, const TypeInfo_t *info)
{
(void)info;
if (!b) return Text("Byte");
@@ -21,28 +21,28 @@ PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo
(byte & 15) <= 9 ? '0' + (byte & 15) : 'a' + (byte & 15) - 10,
'\0',
};
- Text_t text = Text$from_str(digits);
+ Text_t text = Textヽfrom_str(digits);
if (colorize) text = Texts(Text("\x1b[35m"), text, Text("\x1b[m"));
return text;
}
-public CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const Byte_t high) {
+public CONSTFUNC bool Byteヽis_between(const Byte_t x, const Byte_t low, const Byte_t high) {
return low <= x && x <= high;
}
-public OptionalByte_t Byte$parse(Text_t text, Text_t *remainder)
+public OptionalByte_t Byteヽparse(Text_t text, Text_t *remainder)
{
- OptionalInt_t full_int = Int$parse(text, remainder);
+ OptionalInt_t full_int = Intヽparse(text, remainder);
if (full_int.small != 0L
- && Int$compare_value(full_int, I(0)) >= 0
- && Int$compare_value(full_int, I(255)) <= 0) {
- return (OptionalByte_t){.value=Byte$from_int(full_int, true)};
+ && Intヽcompare_value(full_int, I(0)) >= 0
+ && Intヽcompare_value(full_int, I(255)) <= 0) {
+ return (OptionalByte_t){.value=Byteヽfrom_int(full_int, true)};
} else {
return NONE_BYTE;
}
}
-public Text_t Byte$hex(Byte_t byte, bool uppercase, bool prefix) {
+public Text_t Byteヽhex(Byte_t byte, bool uppercase, bool prefix) {
struct Text_s text = {.tag=TEXT_ASCII};
text.ascii = GC_MALLOC_ATOMIC(8);
char *p = (char*)text.ascii;
@@ -62,12 +62,12 @@ public Text_t Byte$hex(Byte_t byte, bool uppercase, bool prefix) {
return text;
}
-public bool Byte$get_bit(Byte_t x, Int_t bit_index) {
- if (Int$compare_value(bit_index, I(1)) < 0)
+public bool Byteヽget_bit(Byte_t x, Int_t bit_index) {
+ if (Intヽcompare_value(bit_index, I(1)) < 0)
fail("Invalid bit index (expected 1 or higher): ", bit_index);
- if (Int$compare_value(bit_index, I(8)) > 0)
+ if (Intヽcompare_value(bit_index, I(8)) > 0)
fail("Bit index is too large! There are only 8 bits in a byte, but index is: ", bit_index);
- return ((x & (Byte_t)(1L << (Int64$from_int(bit_index, true)-1L))) != 0);
+ return ((x & (Byte_t)(1L << (Int64ヽfrom_int(bit_index, true)-1L))) != 0);
}
#ifdef __TINYC__
@@ -91,7 +91,7 @@ static OptionalByte_t _next_Byte(ByteRange_t *info) {
return i;
}
-public CONSTFUNC Closure_t Byte$to(Byte_t first, Byte_t last, OptionalInt8_t step) {
+public CONSTFUNC Closure_t Byteヽto(Byte_t first, Byte_t last, OptionalInt8_t step) {
ByteRange_t *range = GC_MALLOC(sizeof(ByteRange_t));
range->current = (OptionalByte_t){.value=first};
range->last = (OptionalByte_t){.value=last};
@@ -99,34 +99,34 @@ public CONSTFUNC Closure_t Byte$to(Byte_t first, Byte_t last, OptionalInt8_t ste
return (Closure_t){.fn=_next_Byte, .userdata=range};
}
-public PUREFUNC Byte_t Byte$from_int(Int_t i, bool truncate) {
- if unlikely (!truncate && Int$compare_value(i, I_small(0xFF)) > 0)
+public PUREFUNC Byte_t Byteヽfrom_int(Int_t i, bool truncate) {
+ if unlikely (!truncate && Intヽcompare_value(i, I_small(0xFF)) > 0)
fail("This value is too large to convert to a byte without truncation: ", i);
- else if unlikely (!truncate && Int$compare_value(i, I_small(0)) < 0)
+ else if unlikely (!truncate && Intヽcompare_value(i, I_small(0)) < 0)
fail("Negative values can't be converted to bytes: ", i);
return (Byte_t)(i.small >> 2);
}
-public PUREFUNC Byte_t Byte$from_int64(Int64_t i, bool truncate) {
+public PUREFUNC Byte_t Byteヽfrom_int64(Int64_t i, bool truncate) {
if unlikely (!truncate && i != (Int64_t)(Byte_t)i)
fail("This value can't be converted to a byte without truncation: ", i);
return (Byte_t)i;
}
-public PUREFUNC Byte_t Byte$from_int32(Int32_t i, bool truncate) {
+public PUREFUNC Byte_t Byteヽfrom_int32(Int32_t i, bool truncate) {
if unlikely (!truncate && i != (Int32_t)(Byte_t)i)
fail("This value can't be converted to a byte without truncation: ", i);
return (Byte_t)i;
}
-public PUREFUNC Byte_t Byte$from_int16(Int16_t i, bool truncate) {
+public PUREFUNC Byte_t Byteヽfrom_int16(Int16_t i, bool truncate) {
if unlikely (!truncate && i != (Int16_t)(Byte_t)i)
fail("This value can't be converted to a byte without truncation: ", i);
return (Byte_t)i;
}
-public const TypeInfo_t Byte$info = {
+public const TypeInfo_t Byteヽinfo = {
.size=sizeof(Byte_t),
.align=__alignof__(Byte_t),
.metamethods={
- .as_text=Byte$as_text,
+ .as_text=Byteヽas_text,
},
};
diff --git a/src/stdlib/bytes.h b/src/stdlib/bytes.h
index ab88b5bc..669303d4 100644
--- a/src/stdlib/bytes.h
+++ b/src/stdlib/bytes.h
@@ -13,24 +13,24 @@
#define Byte(b) ((Byte_t)(b))
-PUREFUNC Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo_t *type);
+PUREFUNC Text_t Byteヽas_text(const void *b, bool colorize, const TypeInfo_t *type);
-Byte_t Byte$from_int(Int_t i, bool truncate);
-Byte_t Byte$from_int64(int64_t i, bool truncate);
-Byte_t Byte$from_int32(int32_t i, bool truncate);
-Byte_t Byte$from_int16(int16_t i, bool truncate);
-OptionalByte_t Byte$parse(Text_t text, Text_t *remainder);
-Closure_t Byte$to(Byte_t first, Byte_t last, OptionalInt8_t step);
-MACROLIKE Byte_t Byte$from_int8(int8_t i) { return (Byte_t)i; }
-MACROLIKE Byte_t Byte$from_bool(bool b) { return (Byte_t)b; }
-CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const Byte_t high);
+Byte_t Byteヽfrom_int(Int_t i, bool truncate);
+Byte_t Byteヽfrom_int64(int64_t i, bool truncate);
+Byte_t Byteヽfrom_int32(int32_t i, bool truncate);
+Byte_t Byteヽfrom_int16(int16_t i, bool truncate);
+OptionalByte_t Byteヽparse(Text_t text, Text_t *remainder);
+Closure_t Byteヽto(Byte_t first, Byte_t last, OptionalInt8_t step);
+MACROLIKE Byte_t Byteヽfrom_int8(int8_t i) { return (Byte_t)i; }
+MACROLIKE Byte_t Byteヽfrom_bool(bool b) { return (Byte_t)b; }
+CONSTFUNC bool Byteヽis_between(const Byte_t x, const Byte_t low, const Byte_t high);
-extern const Byte_t Byte$min;
-extern const Byte_t Byte$max;
+extern const Byte_t Byteヽmin;
+extern const Byte_t Byteヽmax;
-extern const TypeInfo_t Byte$info;
+extern const TypeInfo_t Byteヽinfo;
-Text_t Byte$hex(Byte_t byte, bool uppercase, bool prefix);
-bool Byte$get_bit(Byte_t x, Int_t bit_index);
+Text_t Byteヽhex(Byte_t byte, bool uppercase, bool prefix);
+bool Byteヽget_bit(Byte_t x, Int_t bit_index);
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c
index 860a69ff..e4836ffe 100644
--- a/src/stdlib/c_strings.c
+++ b/src/stdlib/c_strings.c
@@ -11,15 +11,15 @@
#include "siphash.h"
#include "util.h"
-public Text_t CString$as_text(const void *c_string, bool colorize, const TypeInfo_t *info)
+public Text_t CStringヽas_text(const void *c_string, bool colorize, const TypeInfo_t *info)
{
(void)info;
if (!c_string) return Text("CString");
- Text_t text = Text$from_str(*(const char**)c_string);
- return Text$concat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("), Text$quoted(text, colorize, Text("\"")), Text(")"));
+ Text_t text = Textヽfrom_str(*(const char**)c_string);
+ return Textヽconcat(colorize ? Text("\x1b[34mCString\x1b[m(") : Text("CString("), Textヽquoted(text, colorize, Text("\"")), Text(")"));
}
-PUREFUNC public int32_t CString$compare(const void *x, const void *y, const TypeInfo_t *info)
+PUREFUNC public int32_t CStringヽcompare(const void *x, const void *y, const TypeInfo_t *info)
{
(void)info;
if (x == y)
@@ -31,38 +31,38 @@ PUREFUNC public int32_t CString$compare(const void *x, const void *y, const Type
return strcmp(*(const char**)x, *(const char**)y);
}
-PUREFUNC public bool CString$equal(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public bool CStringヽequal(const void *x, const void *y, const TypeInfo_t *type)
{
- return CString$compare(x, y, type) == 0;
+ return CStringヽcompare(x, y, type) == 0;
}
-PUREFUNC public uint64_t CString$hash(const void *c_str, const TypeInfo_t *info)
+PUREFUNC public uint64_t CStringヽhash(const void *c_str, const TypeInfo_t *info)
{
(void)info;
if (!*(const char**)c_str) return 0;
return siphash24(*(void**)c_str, strlen(*(const char**)c_str));
}
-PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t *info)
+PUREFUNC public bool CStringヽis_none(const void *c_str, const TypeInfo_t *info)
{
(void)info;
return *(const char**)c_str == NULL;
}
-static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
+static void CStringヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
{
(void)info;
const char *str = *(const char **)obj;
int64_t len = (int64_t)strlen(str);
- Int64$serialize(&len, out, pointers, &Int64$info);
+ Int64ヽserialize(&len, out, pointers, &Int64ヽinfo);
fwrite(str, sizeof(char), (size_t)len, out);
}
-static void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info)
+static void CStringヽdeserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info)
{
(void)info;
int64_t len = -1;
- Int64$deserialize(in, &len, pointers, &Int64$info);
+ Int64ヽdeserialize(in, &len, pointers, &Int64ヽinfo);
char *str = GC_MALLOC_ATOMIC((size_t)len+1);
if (fread(str, sizeof(char), (size_t)len, in) != (size_t)len)
fail("Not enough data in stream to deserialize");
@@ -70,17 +70,17 @@ static void CString$deserialize(FILE *in, void *out, List_t *pointers, const Typ
*(const char**)out = str;
}
-public const TypeInfo_t CString$info = {
+public const TypeInfo_t CStringヽinfo = {
.size=sizeof(const char*),
.align=__alignof__(const char*),
.metamethods={
- .hash=CString$hash,
- .compare=CString$compare,
- .equal=CString$equal,
- .as_text=CString$as_text,
- .is_none=CString$is_none,
- .serialize=CString$serialize,
- .deserialize=CString$deserialize,
+ .hash=CStringヽhash,
+ .compare=CStringヽcompare,
+ .equal=CStringヽequal,
+ .as_text=CStringヽas_text,
+ .is_none=CStringヽis_none,
+ .serialize=CStringヽserialize,
+ .deserialize=CStringヽdeserialize,
},
};
diff --git a/src/stdlib/c_strings.h b/src/stdlib/c_strings.h
index 4df5c3ac..d9e871de 100644
--- a/src/stdlib/c_strings.h
+++ b/src/stdlib/c_strings.h
@@ -8,11 +8,11 @@
#include "types.h"
#include "util.h"
-Text_t CString$as_text(const char **str, bool colorize, const TypeInfo_t *info);
-PUREFUNC int CString$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool CString$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC uint64_t CString$hash(const void *str, const TypeInfo_t *type);
+Text_t CStringヽas_text(const char **str, bool colorize, const TypeInfo_t *info);
+PUREFUNC int CStringヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool CStringヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC uint64_t CStringヽhash(const void *str, const TypeInfo_t *type);
-extern const TypeInfo_t CString$info;
+extern const TypeInfo_t CStringヽinfo;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h
index fce1ea74..f786598b 100644
--- a/src/stdlib/datatypes.h
+++ b/src/stdlib/datatypes.h
@@ -100,7 +100,7 @@ typedef struct Text_s {
} Text_t;
typedef struct {
- enum { PATH_NONE, PATH_RELATIVE, PATH_ABSOLUTE, PATH_HOME } $tag;
+ enum { PATH_NONE, PATH_RELATIVE, PATH_ABSOLUTE, PATH_HOME } ヽtag;
} PathType_t;
#define OptionalPathType_t PathType_t
diff --git a/src/stdlib/enums.c b/src/stdlib/enums.c
index ae9f440f..57c4a2b4 100644
--- a/src/stdlib/enums.c
+++ b/src/stdlib/enums.c
@@ -24,7 +24,7 @@ CONSTFUNC static ptrdiff_t value_offset(const TypeInfo_t *type) {
return offset;
}
-PUREFUNC public uint64_t Enum$hash(const void *obj, const TypeInfo_t *type)
+PUREFUNC public uint64_t Enumヽhash(const void *obj, const TypeInfo_t *type)
{
int32_t tag = *(int32_t*)obj;
uint32_t components[2] = {(uint32_t)tag, 0};
@@ -36,7 +36,7 @@ PUREFUNC public uint64_t Enum$hash(const void *obj, const TypeInfo_t *type)
return siphash24((void*)components, sizeof(components));
}
-PUREFUNC public int32_t Enum$compare(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public int32_t Enumヽcompare(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y) return 0;
@@ -53,7 +53,7 @@ PUREFUNC public int32_t Enum$compare(const void *x, const void *y, const TypeInf
return 0;
}
-PUREFUNC public bool Enum$equal(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public bool Enumヽequal(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y) return true;
@@ -70,30 +70,30 @@ PUREFUNC public bool Enum$equal(const void *x, const void *y, const TypeInfo_t *
return true;
}
-public Text_t Enum$as_text(const void *obj, bool colorize, const TypeInfo_t *type)
+public Text_t Enumヽas_text(const void *obj, bool colorize, const TypeInfo_t *type)
{
- if (!obj) return Text$from_str(type->EnumInfo.name);
+ if (!obj) return Textヽfrom_str(type->EnumInfo.name);
int32_t tag = *(int32_t*)obj;
NamedType_t value = type->EnumInfo.tags[tag-1];
if (!value.type || value.type->size == 0) {
- Text_t text = Text$from_str(value.name);
+ Text_t text = Textヽfrom_str(value.name);
return colorize ? Texts(Text("\x1b[1m"), text, Text("\x1b[m")) : text;
}
return generic_as_text(obj + value_offset(type), colorize, value.type);
}
-PUREFUNC public bool Enum$is_none(const void *x, const TypeInfo_t *info)
+PUREFUNC public bool Enumヽis_none(const void *x, const TypeInfo_t *info)
{
(void)info;
return *(int32_t*)x == 0;
}
-public void Enum$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Enumヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
int32_t tag = *(int32_t*)obj;
- Int32$serialize(&tag, out, pointers, &Int32$info);
+ Int32ヽserialize(&tag, out, pointers, &Int32ヽinfo);
NamedType_t value = type->EnumInfo.tags[tag-1];
if (value.type && value.type->size > 0) {
@@ -101,10 +101,10 @@ public void Enum$serialize(const void *obj, FILE *out, Table_t *pointers, const
}
}
-public void Enum$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
+public void Enumヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
{
int32_t tag = 0;
- Int32$deserialize(in, &tag, pointers, &Int32$info);
+ Int32ヽdeserialize(in, &tag, pointers, &Int32ヽinfo);
*(int32_t*)outval = tag;
NamedType_t value = type->EnumInfo.tags[tag-1];
diff --git a/src/stdlib/enums.h b/src/stdlib/enums.h
index 8345c527..c5e38953 100644
--- a/src/stdlib/enums.h
+++ b/src/stdlib/enums.h
@@ -7,32 +7,32 @@
#include "types.h"
#include "util.h"
-PUREFUNC uint64_t Enum$hash(const void *obj, const TypeInfo_t *type);
-PUREFUNC int32_t Enum$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Enum$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC Text_t Enum$as_text(const void *obj, bool colorize, const TypeInfo_t *type);
-PUREFUNC bool Enum$is_none(const void *obj, const TypeInfo_t *type);
-void Enum$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void Enum$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
+PUREFUNC uint64_t Enumヽhash(const void *obj, const TypeInfo_t *type);
+PUREFUNC int32_t Enumヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Enumヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC Text_t Enumヽas_text(const void *obj, bool colorize, const TypeInfo_t *type);
+PUREFUNC bool Enumヽis_none(const void *obj, const TypeInfo_t *type);
+void Enumヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Enumヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
-#define Enum$metamethods { \
- .as_text=Enum$as_text, \
- .compare=Enum$compare, \
- .equal=Enum$equal, \
- .hash=Enum$hash, \
- .is_none=Enum$is_none, \
- .serialize=Enum$serialize, \
- .deserialize=Enum$deserialize, \
+#define Enumヽmetamethods { \
+ .as_text=Enumヽas_text, \
+ .compare=Enumヽcompare, \
+ .equal=Enumヽequal, \
+ .hash=Enumヽhash, \
+ .is_none=Enumヽis_none, \
+ .serialize=Enumヽserialize, \
+ .deserialize=Enumヽdeserialize, \
}
-#define PackedDataEnum$metamethods { \
- .hash=PackedData$hash, \
- .compare=Enum$compare, \
- .equal=PackedData$equal, \
- .as_text=Enum$as_text, \
- .is_none=Enum$is_none, \
- .serialize=Enum$serialize, \
- .deserialize=Enum$deserialize, \
+#define PackedDataEnumヽmetamethods { \
+ .hash=PackedDataヽhash, \
+ .compare=Enumヽcompare, \
+ .equal=PackedDataヽequal, \
+ .as_text=Enumヽas_text, \
+ .is_none=Enumヽis_none, \
+ .serialize=Enumヽserialize, \
+ .deserialize=Enumヽdeserialize, \
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/functiontype.c b/src/stdlib/functiontype.c
index b0fff1a7..ef7b7b5b 100644
--- a/src/stdlib/functiontype.c
+++ b/src/stdlib/functiontype.c
@@ -11,15 +11,15 @@
#include "types.h"
#include "util.h"
-public Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo_t *type)
+public Text_t Funcヽas_text(const void *fn, bool colorize, const TypeInfo_t *type)
{
- Text_t text = Text$from_str(type->FunctionInfo.type_str);
+ Text_t text = Textヽfrom_str(type->FunctionInfo.type_str);
if (fn && colorize)
- text = Text$concat(Text("\x1b[32;1m"), text, Text("\x1b[m"));
+ text = Textヽconcat(Text("\x1b[32;1m"), text, Text("\x1b[m"));
return text;
}
-public PUREFUNC bool Func$is_none(const void *obj, const TypeInfo_t *info)
+public PUREFUNC bool Funcヽis_none(const void *obj, const TypeInfo_t *info)
{
(void)info;
return *(void**)obj == NULL;
diff --git a/src/stdlib/functiontype.h b/src/stdlib/functiontype.h
index d308be96..02345c6b 100644
--- a/src/stdlib/functiontype.h
+++ b/src/stdlib/functiontype.h
@@ -14,21 +14,21 @@ void register_function(void *fn, Text_t filename, int64_t line_num, Text_t name)
OptionalText_t get_function_name(void *fn);
OptionalText_t get_function_filename(void *fn);
int64_t get_function_line_num(void *fn);
-Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo_t *type);
-PUREFUNC bool Func$is_none(const void *obj, const TypeInfo_t*);
+Text_t Funcヽas_text(const void *fn, bool colorize, const TypeInfo_t *type);
+PUREFUNC bool Funcヽis_none(const void *obj, const TypeInfo_t*);
-#define Func$metamethods { \
- .as_text=Func$as_text, \
- .is_none=Func$is_none, \
+#define Funcヽmetamethods { \
+ .as_text=Funcヽas_text, \
+ .is_none=Funcヽis_none, \
.serialize=cannot_serialize, \
.deserialize=cannot_deserialize, \
}
-#define Function$info(typestr) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \
+#define Functionヽinfo(typestr) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \
.tag=FunctionInfo, .FunctionInfo.type_str=typestr, \
- .metamethods=Func$metamethods})
-#define Closure$info(typestr) &((TypeInfo_t){.size=sizeof(void*[2]), .align=__alignof__(void*), \
+ .metamethods=Funcヽmetamethods})
+#define Closureヽinfo(typestr) &((TypeInfo_t){.size=sizeof(void*[2]), .align=__alignof__(void*), \
.tag=FunctionInfo, .FunctionInfo.type_str=typestr, \
- .metamethods=Func$metamethods})
+ .metamethods=Funcヽmetamethods})
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/integers.c b/src/stdlib/integers.c
index 037aba0f..6b5f55c4 100644
--- a/src/stdlib/integers.c
+++ b/src/stdlib/integers.c
@@ -18,7 +18,7 @@
#include "text.h"
#include "types.h"
-public int Int$print(FILE *f, Int_t i) {
+public int Intヽprint(FILE *f, Int_t i) {
if (likely(i.small & 1L)) {
return _print_int(f, (int64_t)((i.small)>>2L));
} else {
@@ -44,33 +44,33 @@ static inline Text_t _int64_to_text(int64_t n)
if (negative)
*(p--) = '-';
- return Text$from_strn(p + 1, (size_t)(&buf[19] - p));
+ return Textヽfrom_strn(p + 1, (size_t)(&buf[19] - p));
}
-public Text_t Int$value_as_text(Int_t i) {
+public Text_t Intヽvalue_as_text(Int_t i) {
if (likely(i.small & 1L)) {
return _int64_to_text(i.small >> 2L);
} else {
char *str = mpz_get_str(NULL, 10, *i.big);
- return Text$from_str(str);
+ return Textヽfrom_str(str);
}
}
-public Text_t Int$as_text(const void *i, bool colorize, const TypeInfo_t *info) {
+public Text_t Intヽas_text(const void *i, bool colorize, const TypeInfo_t *info) {
(void)info;
if (!i) return Text("Int");
- Text_t text = Int$value_as_text(*(Int_t*)i);
- if (colorize) text = Text$concat(Text("\x1b[35m"), text, Text("\x1b[m"));
+ Text_t text = Intヽvalue_as_text(*(Int_t*)i);
+ if (colorize) text = Textヽconcat(Text("\x1b[35m"), text, Text("\x1b[m"));
return text;
}
-static bool Int$is_none(const void *i, const TypeInfo_t *info)
+static bool Intヽis_none(const void *i, const TypeInfo_t *info)
{
(void)info;
return ((Int_t*)i)->small == 0L;
}
-public PUREFUNC int32_t Int$compare_value(const Int_t x, const Int_t y) {
+public PUREFUNC int32_t Intヽcompare_value(const Int_t x, const Int_t y) {
if (likely(x.small & y.small & 1L))
return (x.small > y.small) - (x.small < y.small);
else if (x.small & 1)
@@ -81,32 +81,32 @@ public PUREFUNC int32_t Int$compare_value(const Int_t x, const Int_t y) {
return x.big == y.big ? 0 : mpz_cmp(*x.big, *y.big);
}
-public PUREFUNC int32_t Int$compare(const void *x, const void *y, const TypeInfo_t *info) {
+public PUREFUNC int32_t Intヽcompare(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
- return Int$compare_value(*(Int_t*)x, *(Int_t*)y);
+ return Intヽcompare_value(*(Int_t*)x, *(Int_t*)y);
}
-public PUREFUNC bool Int$equal_value(const Int_t x, const Int_t y) {
+public PUREFUNC bool Intヽequal_value(const Int_t x, const Int_t y) {
if (likely((x.small | y.small) & 1L))
return x.small == y.small;
else
return x.big == y.big ? 0 : (mpz_cmp(*x.big, *y.big) == 0);
}
-public PUREFUNC bool Int$equal(const void *x, const void *y, const TypeInfo_t *info) {
+public PUREFUNC bool Intヽequal(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
- return Int$equal_value(*(Int_t*)x, *(Int_t*)y);
+ return Intヽequal_value(*(Int_t*)x, *(Int_t*)y);
}
-public CONSTFUNC Int_t Int$clamped(Int_t x, Int_t low, Int_t high) {
- return (Int$compare(&x, &low, &Int$info) <= 0) ? low : (Int$compare(&x, &high, &Int$info) >= 0 ? high : x);
+public CONSTFUNC Int_t Intヽclamped(Int_t x, Int_t low, Int_t high) {
+ return (Intヽcompare(&x, &low, &Intヽinfo) <= 0) ? low : (Intヽcompare(&x, &high, &Intヽinfo) >= 0 ? high : x);
}
-public CONSTFUNC bool Int$is_between(const Int_t x, const Int_t low, const Int_t high) {
- return Int$compare_value(low, x) <= 0 && Int$compare_value(x, high) <= 0;
+public CONSTFUNC bool Intヽis_between(const Int_t x, const Int_t low, const Int_t high) {
+ return Intヽcompare_value(low, x) <= 0 && Intヽcompare_value(x, high) <= 0;
}
-public PUREFUNC uint64_t Int$hash(const void *vx, const TypeInfo_t *info) {
+public PUREFUNC uint64_t Intヽhash(const void *vx, const TypeInfo_t *info) {
(void)info;
Int_t *x = (Int_t*)vx;
if (likely(x->small & 1L)) {
@@ -117,57 +117,57 @@ public PUREFUNC uint64_t Int$hash(const void *vx, const TypeInfo_t *info) {
}
}
-public Text_t Int$hex(Int_t i, Int_t digits_int, bool uppercase, bool prefix) {
- if (Int$is_negative(i))
- return Text$concat(Text("-"), Int$hex(Int$negative(i), digits_int, uppercase, prefix));
+public Text_t Intヽhex(Int_t i, Int_t digits_int, bool uppercase, bool prefix) {
+ if (Intヽis_negative(i))
+ return Textヽconcat(Text("-"), Intヽhex(Intヽnegative(i), digits_int, uppercase, prefix));
if (likely(i.small & 1L)) {
uint64_t u64 = (uint64_t)(i.small >> 2);
- return Text$from_str(String(hex(u64, .no_prefix=!prefix, .digits=Int32$from_int(digits_int, false), .uppercase=uppercase)));
+ return Textヽfrom_str(String(hex(u64, .no_prefix=!prefix, .digits=Int32ヽfrom_int(digits_int, false), .uppercase=uppercase)));
} else {
char *str = mpz_get_str(NULL, 16, *i.big);
if (uppercase) {
for (char *c = str; *c; c++)
*c = (char)toupper(*c);
}
- int64_t digits = Int64$from_int(digits_int, false);
+ int64_t digits = Int64ヽfrom_int(digits_int, false);
int64_t needed_zeroes = digits - (int64_t)strlen(str);
if (needed_zeroes <= 0)
- return prefix ? Text$concat(Text("0x"), Text$from_str(str)) : Text$from_str(str);
+ return prefix ? Textヽconcat(Text("0x"), Textヽfrom_str(str)) : Textヽfrom_str(str);
char *zeroes = GC_MALLOC_ATOMIC((size_t)(needed_zeroes));
memset(zeroes, '0', (size_t)(needed_zeroes));
if (prefix)
- return Text$concat(Text("0x"), Text$from_str(zeroes), Text$from_str(str));
+ return Textヽconcat(Text("0x"), Textヽfrom_str(zeroes), Textヽfrom_str(str));
else
- return Text$concat(Text$from_str(zeroes), Text$from_str(str));
+ return Textヽconcat(Textヽfrom_str(zeroes), Textヽfrom_str(str));
}
}
-public Text_t Int$octal(Int_t i, Int_t digits_int, bool prefix) {
- if (Int$is_negative(i))
- return Text$concat(Text("-"), Int$octal(Int$negative(i), digits_int, prefix));
+public Text_t Intヽoctal(Int_t i, Int_t digits_int, bool prefix) {
+ if (Intヽis_negative(i))
+ return Textヽconcat(Text("-"), Intヽoctal(Intヽnegative(i), digits_int, prefix));
if (likely(i.small & 1L)) {
uint64_t u64 = (uint64_t)(i.small >> 2);
- return Text$from_str(String(oct(u64, .no_prefix=!prefix, .digits=Int32$from_int(digits_int, false))));
+ return Textヽfrom_str(String(oct(u64, .no_prefix=!prefix, .digits=Int32ヽfrom_int(digits_int, false))));
} else {
- int64_t digits = Int64$from_int(digits_int, false);
+ int64_t digits = Int64ヽfrom_int(digits_int, false);
char *str = mpz_get_str(NULL, 8, *i.big);
int64_t needed_zeroes = digits - (int64_t)strlen(str);
if (needed_zeroes <= 0)
- return prefix ? Text$concat(Text("0o"), Text$from_str(str)) : Text$from_str(str);
+ return prefix ? Textヽconcat(Text("0o"), Textヽfrom_str(str)) : Textヽfrom_str(str);
char *zeroes = GC_MALLOC_ATOMIC((size_t)(needed_zeroes));
memset(zeroes, '0', (size_t)(needed_zeroes));
if (prefix)
- return Text$concat(Text("0o"), Text$from_str(zeroes), Text$from_str(str));
+ return Textヽconcat(Text("0o"), Textヽfrom_str(zeroes), Textヽfrom_str(str));
else
- return Text$concat(Text$from_str(zeroes), Text$from_str(str));
+ return Textヽconcat(Textヽfrom_str(zeroes), Textヽfrom_str(str));
}
}
-public Int_t Int$slow_plus(Int_t x, Int_t y) {
+public Int_t Intヽslow_plus(Int_t x, Int_t y) {
mpz_t result;
mpz_init_set_int(result, x);
if (y.small & 1L) {
@@ -178,10 +178,10 @@ public Int_t Int$slow_plus(Int_t x, Int_t y) {
} else {
mpz_add(result, result, *y.big);
}
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_minus(Int_t x, Int_t y) {
+public Int_t Intヽslow_minus(Int_t x, Int_t y) {
mpz_t result;
mpz_init_set_int(result, x);
if (y.small & 1L) {
@@ -192,20 +192,20 @@ public Int_t Int$slow_minus(Int_t x, Int_t y) {
} else {
mpz_sub(result, result, *y.big);
}
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_times(Int_t x, Int_t y) {
+public Int_t Intヽslow_times(Int_t x, Int_t y) {
mpz_t result;
mpz_init_set_int(result, x);
if (y.small & 1L)
mpz_mul_si(result, result, y.small >> 2L);
else
mpz_mul(result, result, *y.big);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_divided_by(Int_t dividend, Int_t divisor) {
+public Int_t Intヽslow_divided_by(Int_t dividend, Int_t divisor) {
// Euclidean division, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
mpz_t quotient, remainder;
mpz_init_set_int(quotient, dividend);
@@ -218,20 +218,20 @@ public Int_t Int$slow_divided_by(Int_t dividend, Int_t divisor) {
else
mpz_add_ui(quotient, quotient, 1);
}
- return Int$from_mpz(quotient);
+ return Intヽfrom_mpz(quotient);
}
-public Int_t Int$slow_modulo(Int_t x, Int_t modulus)
+public Int_t Intヽslow_modulo(Int_t x, Int_t modulus)
{
mpz_t result;
mpz_init_set_int(result, x);
mpz_t divisor;
mpz_init_set_int(divisor, modulus);
mpz_mod(result, result, divisor);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_modulo1(Int_t x, Int_t modulus)
+public Int_t Intヽslow_modulo1(Int_t x, Int_t modulus)
{
mpz_t result;
mpz_init_set_int(result, x);
@@ -240,67 +240,67 @@ public Int_t Int$slow_modulo1(Int_t x, Int_t modulus)
mpz_init_set_int(divisor, modulus);
mpz_mod(result, result, divisor);
mpz_add_ui(result, result, 1);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_left_shifted(Int_t x, Int_t y)
+public Int_t Intヽslow_left_shifted(Int_t x, Int_t y)
{
- mp_bitcnt_t bits = (mp_bitcnt_t)Int64$from_int(y, false);
+ mp_bitcnt_t bits = (mp_bitcnt_t)Int64ヽfrom_int(y, false);
mpz_t result;
mpz_init_set_int(result, x);
mpz_mul_2exp(result, result, bits);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_right_shifted(Int_t x, Int_t y)
+public Int_t Intヽslow_right_shifted(Int_t x, Int_t y)
{
- mp_bitcnt_t bits = (mp_bitcnt_t)Int64$from_int(y, false);
+ mp_bitcnt_t bits = (mp_bitcnt_t)Int64ヽfrom_int(y, false);
mpz_t result;
mpz_init_set_int(result, x);
mpz_tdiv_q_2exp(result, result, bits);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_bit_and(Int_t x, Int_t y)
+public Int_t Intヽslow_bit_and(Int_t x, Int_t y)
{
mpz_t result;
mpz_init_set_int(result, x);
mpz_t y_mpz;
mpz_init_set_int(y_mpz, y);
mpz_and(result, result, y_mpz);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_bit_or(Int_t x, Int_t y)
+public Int_t Intヽslow_bit_or(Int_t x, Int_t y)
{
mpz_t result;
mpz_init_set_int(result, x);
mpz_t y_mpz;
mpz_init_set_int(y_mpz, y);
mpz_ior(result, result, y_mpz);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_bit_xor(Int_t x, Int_t y)
+public Int_t Intヽslow_bit_xor(Int_t x, Int_t y)
{
mpz_t result;
mpz_init_set_int(result, x);
mpz_t y_mpz;
mpz_init_set_int(y_mpz, y);
mpz_xor(result, result, y_mpz);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_negated(Int_t x)
+public Int_t Intヽslow_negated(Int_t x)
{
mpz_t result;
mpz_init_set_int(result, x);
mpz_neg(result, result);
mpz_sub_ui(result, result, 1);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$slow_negative(Int_t x)
+public Int_t Intヽslow_negative(Int_t x)
{
if (likely(x.small & 1L))
return (Int_t){.small=4L*-((x.small)>>2L) + 1L};
@@ -308,10 +308,10 @@ public Int_t Int$slow_negative(Int_t x)
mpz_t result;
mpz_init_set_int(result, x);
mpz_neg(result, result);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$abs(Int_t x)
+public Int_t Intヽabs(Int_t x)
{
if (likely(x.small & 1L))
return (Int_t){.small=4L*labs((x.small)>>2L) + 1L};
@@ -319,24 +319,24 @@ public Int_t Int$abs(Int_t x)
mpz_t result;
mpz_init_set_int(result, x);
mpz_abs(result, result);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$power(Int_t base, Int_t exponent)
+public Int_t Intヽpower(Int_t base, Int_t exponent)
{
- int64_t exp = Int64$from_int(exponent, false);
+ int64_t exp = Int64ヽfrom_int(exponent, false);
if (unlikely(exp < 0))
fail("Cannot take a negative power of an integer!");
mpz_t result;
mpz_init_set_int(result, base);
mpz_pow_ui(result, result, (uint64_t)exp);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public Int_t Int$gcd(Int_t x, Int_t y)
+public Int_t Intヽgcd(Int_t x, Int_t y)
{
if (likely(x.small & y.small & 0x1L))
- return I_small(Int32$gcd(x.small >> 2L, y.small >> 2L));
+ return I_small(Int32ヽgcd(x.small >> 2L, y.small >> 2L));
mpz_t result;
mpz_init(result);
@@ -346,29 +346,29 @@ public Int_t Int$gcd(Int_t x, Int_t y)
mpz_gcd_ui(result, *x.big, (uint64_t)labs(y.small>>2L));
else
mpz_gcd(result, *x.big, *y.big);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public OptionalInt_t Int$sqrt(Int_t i)
+public OptionalInt_t Intヽsqrt(Int_t i)
{
- if (Int$compare_value(i, I(0)) < 0)
+ if (Intヽcompare_value(i, I(0)) < 0)
return NONE_INT;
mpz_t result;
mpz_init_set_int(result, i);
mpz_sqrt(result, result);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-public bool Int$get_bit(Int_t x, Int_t bit_index)
+public bool Intヽget_bit(Int_t x, Int_t bit_index)
{
mpz_t i;
mpz_init_set_int(i, x);
- if (Int$compare_value(bit_index, I(1)) < 0)
+ if (Intヽcompare_value(bit_index, I(1)) < 0)
fail("Invalid bit index (expected 1 or higher): ", bit_index);
- if (Int$compare_value(bit_index, Int$from_int64(INT64_MAX)) > 0)
+ if (Intヽcompare_value(bit_index, Intヽfrom_int64(INT64_MAX)) > 0)
fail("Bit index is too large! ", bit_index);
- int is_bit_set = mpz_tstbit(i, (mp_bitcnt_t)(Int64$from_int(bit_index, true)-1));
+ int is_bit_set = mpz_tstbit(i, (mp_bitcnt_t)(Int64ヽfrom_int(bit_index, true)-1));
return (bool)is_bit_set;
}
@@ -380,26 +380,26 @@ typedef struct {
static OptionalInt_t _next_int(IntRange_t *info)
{
OptionalInt_t i = info->current;
- if (!Int$is_none(&i, &Int$info)) {
- Int_t next = Int$plus(i, info->step);
- if (!Int$is_none(&info->last, &Int$info) && Int$compare_value(next, info->last) == Int$compare_value(info->step, I(0)))
+ if (!Intヽis_none(&i, &Intヽinfo)) {
+ Int_t next = Intヽplus(i, info->step);
+ if (!Intヽis_none(&info->last, &Intヽinfo) && Intヽcompare_value(next, info->last) == Intヽcompare_value(info->step, I(0)))
next = NONE_INT;
info->current = next;
}
return i;
}
-public PUREFUNC Closure_t Int$to(Int_t first, Int_t last, OptionalInt_t step) {
+public PUREFUNC Closure_t Intヽto(Int_t first, Int_t last, OptionalInt_t step) {
IntRange_t *range = GC_MALLOC(sizeof(IntRange_t));
range->current = first;
range->last = last;
- range->step = Int$is_none(&step, &Int$info) ?
- Int$compare_value(last, first) >= 0 ? (Int_t){.small=(1L<<2L)|1L} : (Int_t){.small=(-1L>>2L)|1L}
+ range->step = Intヽis_none(&step, &Intヽinfo) ?
+ Intヽcompare_value(last, first) >= 0 ? (Int_t){.small=(1L<<2L)|1L} : (Int_t){.small=(-1L>>2L)|1L}
: step;
return (Closure_t){.fn=_next_int, .userdata=range};
}
-public PUREFUNC Closure_t Int$onward(Int_t first, Int_t step) {
+public PUREFUNC Closure_t Intヽonward(Int_t first, Int_t step) {
IntRange_t *range = GC_MALLOC(sizeof(IntRange_t));
range->current = first;
range->last = NONE_INT;
@@ -407,7 +407,7 @@ public PUREFUNC Closure_t Int$onward(Int_t first, Int_t step) {
return (Closure_t){.fn=_next_int, .userdata=range};
}
-public Int_t Int$from_str(const char *str) {
+public Int_t Intヽfrom_str(const char *str) {
mpz_t i;
int result;
if (strncmp(str, "0x", 2) == 0) {
@@ -421,31 +421,31 @@ public Int_t Int$from_str(const char *str) {
}
if (result != 0)
return NONE_INT;
- return Int$from_mpz(i);
+ return Intヽfrom_mpz(i);
}
-public OptionalInt_t Int$parse(Text_t text, Text_t *remainder) {
- const char *str = Text$as_c_string(text);
+public OptionalInt_t Intヽparse(Text_t text, Text_t *remainder) {
+ const char *str = Textヽas_c_string(text);
mpz_t i;
int result;
if (strncmp(str, "0x", 2) == 0) {
const char *end = str + 2 + strspn(str + 2, "0123456789abcdefABCDEF");
- if (remainder) *remainder = Text$from_str(end);
+ if (remainder) *remainder = Textヽfrom_str(end);
else if (*end != '\0') return NONE_INT;
result = mpz_init_set_str(i, str + 2, 16);
} else if (strncmp(str, "0o", 2) == 0) {
const char *end = str + 2 + strspn(str + 2, "01234567");
- if (remainder) *remainder = Text$from_str(end);
+ if (remainder) *remainder = Textヽfrom_str(end);
else if (*end != '\0') return NONE_INT;
result = mpz_init_set_str(i, str + 2, 8);
} else if (strncmp(str, "0b", 2) == 0) {
const char *end = str + 2 + strspn(str + 2, "01");
- if (remainder) *remainder = Text$from_str(end);
+ if (remainder) *remainder = Textヽfrom_str(end);
else if (*end != '\0') return NONE_INT;
result = mpz_init_set_str(i, str + 2, 2);
} else {
const char *end = str + 2 + strspn(str + 2, "0123456789");
- if (remainder) *remainder = Text$from_str(end);
+ if (remainder) *remainder = Textヽfrom_str(end);
else if (*end != '\0') return NONE_INT;
result = mpz_init_set_str(i, str, 10);
}
@@ -453,49 +453,49 @@ public OptionalInt_t Int$parse(Text_t text, Text_t *remainder) {
if (remainder) *remainder = text;
return NONE_INT;
}
- return Int$from_mpz(i);
+ return Intヽfrom_mpz(i);
}
-public bool Int$is_prime(Int_t x, Int_t reps)
+public bool Intヽis_prime(Int_t x, Int_t reps)
{
mpz_t p;
mpz_init_set_int(p, x);
- if (unlikely(Int$compare_value(reps, I(9999)) > 0))
+ if (unlikely(Intヽcompare_value(reps, I(9999)) > 0))
fail("Number of prime-test repetitions should not be above 9999");
- int reps_int = Int32$from_int(reps, false);
+ int reps_int = Int32ヽfrom_int(reps, false);
return (mpz_probab_prime_p(p, reps_int) != 0);
}
-public Int_t Int$next_prime(Int_t x)
+public Int_t Intヽnext_prime(Int_t x)
{
mpz_t p;
mpz_init_set_int(p, x);
mpz_nextprime(p, p);
- return Int$from_mpz(p);
+ return Intヽfrom_mpz(p);
}
#if __GNU_MP_VERSION >= 6
#if __GNU_MP_VERSION_MINOR >= 3
-public OptionalInt_t Int$prev_prime(Int_t x)
+public OptionalInt_t Intヽprev_prime(Int_t x)
{
mpz_t p;
mpz_init_set_int(p, x);
if (unlikely(mpz_prevprime(p, p) == 0))
return NONE_INT;
- return Int$from_mpz(p);
+ return Intヽfrom_mpz(p);
}
#endif
#endif
-public Int_t Int$choose(Int_t n, Int_t k)
+public Int_t Intヽchoose(Int_t n, Int_t k)
{
- if unlikely (Int$compare_value(n, I_small(0)) < 0)
+ if unlikely (Intヽcompare_value(n, I_small(0)) < 0)
fail("Negative inputs are not supported for choose()");
mpz_t ret;
mpz_init(ret);
- int64_t k_i64 = Int64$from_int(k, false);
+ int64_t k_i64 = Int64ヽfrom_int(k, false);
if unlikely (k_i64 < 0)
fail("Negative inputs are not supported for choose()");
@@ -506,28 +506,28 @@ public Int_t Int$choose(Int_t n, Int_t k)
mpz_init_set_int(n_mpz, n);
mpz_bin_ui(ret, n_mpz, (unsigned long)k_i64);
}
- return Int$from_mpz(ret);
+ return Intヽfrom_mpz(ret);
}
-public Int_t Int$factorial(Int_t n)
+public Int_t Intヽfactorial(Int_t n)
{
mpz_t ret;
mpz_init(ret);
- int64_t n_i64 = Int64$from_int(n, false);
+ int64_t n_i64 = Int64ヽfrom_int(n, false);
if unlikely (n_i64 < 0)
fail("Factorials are not defined for negative numbers");
mpz_fac_ui(ret, (unsigned long)n_i64);
- return Int$from_mpz(ret);
+ return Intヽfrom_mpz(ret);
}
-static void Int$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
+static void Intヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
{
(void)info;
Int_t i = *(Int_t*)obj;
if (likely(i.small & 1L)) {
fputc(0, out);
int64_t i64 = i.small >> 2L;
- Int64$serialize(&i64, out, pointers, &Int64$info);
+ Int64ヽserialize(&i64, out, pointers, &Int64ヽinfo);
} else {
fputc(1, out);
mpz_t n;
@@ -536,36 +536,36 @@ static void Int$serialize(const void *obj, FILE *out, Table_t *pointers, const T
}
}
-static void Int$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *info)
+static void Intヽdeserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *info)
{
(void)info;
if (fgetc(in) == 0) {
int64_t i = 0;
- Int64$deserialize(in, &i, pointers, &Int64$info);
+ Int64ヽdeserialize(in, &i, pointers, &Int64ヽinfo);
*(Int_t*)obj = (Int_t){.small=(i<<2L) | 1L};
} else {
mpz_t n;
mpz_init(n);
mpz_inp_raw(n, in);
- *(Int_t*)obj = Int$from_mpz(n);
+ *(Int_t*)obj = Intヽfrom_mpz(n);
}
}
-public const TypeInfo_t Int$info = {
+public const TypeInfo_t Intヽinfo = {
.size=sizeof(Int_t),
.align=__alignof__(Int_t),
.metamethods={
- .compare=Int$compare,
- .equal=Int$equal,
- .hash=Int$hash,
- .as_text=Int$as_text,
- .is_none=Int$is_none,
- .serialize=Int$serialize,
- .deserialize=Int$deserialize,
+ .compare=Intヽcompare,
+ .equal=Intヽequal,
+ .hash=Intヽhash,
+ .as_text=Intヽas_text,
+ .is_none=Intヽis_none,
+ .serialize=Intヽserialize,
+ .deserialize=Intヽdeserialize,
},
};
-public void Int64$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
+public void Int64ヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
{
(void)info, (void)pointers;
int64_t i = *(int64_t*)obj;
@@ -577,7 +577,7 @@ public void Int64$serialize(const void *obj, FILE *out, Table_t *pointers, const
fputc((uint8_t)z, out);
}
-public void Int64$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info)
+public void Int64ヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info)
{
(void)info, (void)pointers;
uint64_t z = 0;
@@ -589,7 +589,7 @@ public void Int64$deserialize(FILE *in, void *outval, List_t *pointers, const Ty
*(int64_t*)outval = (int64_t)((z >> 1L) ^ -(z & 1L)); // Zigzag decode
}
-public void Int32$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
+public void Int32ヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
{
(void)info, (void)pointers;
int32_t i = *(int32_t*)obj;
@@ -601,7 +601,7 @@ public void Int32$serialize(const void *obj, FILE *out, Table_t *pointers, const
fputc((uint8_t)z, out);
}
-public void Int32$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info)
+public void Int32ヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info)
{
(void)info, (void)pointers;
uint32_t z = 0;
@@ -614,45 +614,45 @@ public void Int32$deserialize(FILE *in, void *outval, List_t *pointers, const Ty
}
// The space savings for smaller ints are not worth having:
-#define Int16$serialize NULL
-#define Int16$deserialize NULL
-#define Int8$serialize NULL
-#define Int8$deserialize NULL
+#define Int16ヽserialize NULL
+#define Int16ヽdeserialize NULL
+#define Int8ヽserialize NULL
+#define Int8ヽdeserialize NULL
#ifdef __TINYC__
#define __builtin_add_overflow(x, y, result) ({ *(result) = (x) + (y); false; })
#endif
#define DEFINE_INT_TYPE(c_type, KindOfInt, min_val, max_val, to_attr)\
- public Text_t KindOfInt ## $as_text(const void *i, bool colorize, const TypeInfo_t *info) { \
+ public Text_t KindOfInt ## ヽas_text(const void *i, bool colorize, const TypeInfo_t *info) { \
(void)info; \
if (!i) return Text(#KindOfInt); \
Text_t text = _int64_to_text((int64_t)(*(c_type*)i)); \
return colorize ? Texts(Text("\033[35m"), text, Text("\033[m")) : text; \
} \
- public PUREFUNC int32_t KindOfInt ## $compare(const void *x, const void *y, const TypeInfo_t *info) { \
+ public PUREFUNC int32_t KindOfInt ## ヽcompare(const void *x, const void *y, const TypeInfo_t *info) { \
(void)info; \
return (*(c_type*)x > *(c_type*)y) - (*(c_type*)x < *(c_type*)y); \
} \
- public PUREFUNC bool KindOfInt ## $equal(const void *x, const void *y, const TypeInfo_t *info) { \
+ public PUREFUNC bool KindOfInt ## ヽequal(const void *x, const void *y, const TypeInfo_t *info) { \
(void)info; \
return *(c_type*)x == *(c_type*)y; \
} \
- public CONSTFUNC bool KindOfInt ## $is_between(const c_type x, const c_type low, const c_type high) { \
+ public CONSTFUNC bool KindOfInt ## ヽis_between(const c_type x, const c_type low, const c_type high) { \
return low <= x && x <= high; \
} \
- public CONSTFUNC c_type KindOfInt ## $clamped(c_type x, c_type min, c_type max) { \
+ public CONSTFUNC c_type KindOfInt ## ヽclamped(c_type x, c_type min, c_type max) { \
return x < min ? min : (x > max ? max : x); \
} \
- public Text_t KindOfInt ## $hex(c_type i, Int_t digits_int, bool uppercase, bool prefix) { \
- Int_t as_int = Int$from_int64((int64_t)i); \
- return Int$hex(as_int, digits_int, uppercase, prefix); \
+ public Text_t KindOfInt ## ヽhex(c_type i, Int_t digits_int, bool uppercase, bool prefix) { \
+ Int_t as_int = Intヽfrom_int64((int64_t)i); \
+ return Intヽhex(as_int, digits_int, uppercase, prefix); \
} \
- public Text_t KindOfInt ## $octal(c_type i, Int_t digits_int, bool prefix) { \
- Int_t as_int = Int$from_int64((int64_t)i); \
- return Int$octal(as_int, digits_int, prefix); \
+ public Text_t KindOfInt ## ヽoctal(c_type i, Int_t digits_int, bool prefix) { \
+ Int_t as_int = Intヽfrom_int64((int64_t)i); \
+ return Intヽoctal(as_int, digits_int, prefix); \
} \
- public List_t KindOfInt ## $bits(c_type x) { \
+ public List_t KindOfInt ## ヽbits(c_type x) { \
List_t bit_list = (List_t){.data=GC_MALLOC_ATOMIC(sizeof(bool[8*sizeof(c_type)])), .atomic=1, .stride=sizeof(bool), .length=8*sizeof(c_type)}; \
bool *bits = bit_list.data + sizeof(c_type)*8; \
for (size_t i = 0; i < 8*sizeof(c_type); i++) { \
@@ -661,12 +661,12 @@ public void Int32$deserialize(FILE *in, void *outval, List_t *pointers, const Ty
} \
return bit_list; \
} \
- public bool KindOfInt ## $get_bit(c_type x, Int_t bit_index) { \
- if (Int$compare_value(bit_index, I(1)) < 0) \
+ public bool KindOfInt ## ヽget_bit(c_type x, Int_t bit_index) { \
+ if (Intヽcompare_value(bit_index, I(1)) < 0) \
fail("Invalid bit index (expected 1 or higher): ", bit_index); \
- if (Int$compare_value(bit_index, Int$from_int64(sizeof(c_type)*8)) > 0) \
+ if (Intヽcompare_value(bit_index, Intヽfrom_int64(sizeof(c_type)*8)) > 0) \
fail("Bit index is too large! There are only ", sizeof(c_type)*8, " bits, but index is: ", bit_index); \
- return ((x & (c_type)(1L << (Int64$from_int(bit_index, true)-1L))) != 0); \
+ return ((x & (c_type)(1L << (Int64ヽfrom_int(bit_index, true)-1L))) != 0); \
} \
typedef struct { \
Optional##KindOfInt##_t current, last; \
@@ -684,51 +684,51 @@ public void Int32$deserialize(FILE *in, void *outval, List_t *pointers, const Ty
} \
return i; \
} \
- public to_attr Closure_t KindOfInt ## $to(c_type first, c_type last, Optional ## KindOfInt ## _t step) { \
+ public to_attr Closure_t KindOfInt ## ヽto(c_type first, c_type last, Optional ## KindOfInt ## _t step) { \
KindOfInt##Range_t *range = GC_MALLOC(sizeof(KindOfInt##Range_t)); \
range->current = (Optional##KindOfInt##_t){.value=first}; \
range->last = (Optional##KindOfInt##_t){.value=last}; \
range->step = step.is_none ? (last >= first ? 1 : -1) : step.value; \
return (Closure_t){.fn=_next_##KindOfInt, .userdata=range}; \
} \
- public to_attr Closure_t KindOfInt ## $onward(c_type first, c_type step) { \
+ public to_attr Closure_t KindOfInt ## ヽonward(c_type first, c_type step) { \
KindOfInt##Range_t *range = GC_MALLOC(sizeof(KindOfInt##Range_t)); \
range->current = (Optional##KindOfInt##_t){.value=first}; \
range->last = (Optional##KindOfInt##_t){.is_none=true}; \
range->step = step; \
return (Closure_t){.fn=_next_##KindOfInt, .userdata=range}; \
} \
- public PUREFUNC Optional ## KindOfInt ## _t KindOfInt ## $parse(Text_t text, Text_t *remainder) { \
- OptionalInt_t full_int = Int$parse(text, remainder); \
+ public PUREFUNC Optional ## KindOfInt ## _t KindOfInt ## ヽparse(Text_t text, Text_t *remainder) { \
+ OptionalInt_t full_int = Intヽparse(text, remainder); \
if (full_int.small == 0L) return (Optional ## KindOfInt ## _t){.is_none=true}; \
- if (Int$compare_value(full_int, I(min_val)) < 0) { \
+ if (Intヽcompare_value(full_int, I(min_val)) < 0) { \
return (Optional ## KindOfInt ## _t){.is_none=true}; \
} \
- if (Int$compare_value(full_int, I(max_val)) > 0) { \
+ if (Intヽcompare_value(full_int, I(max_val)) > 0) { \
return (Optional ## KindOfInt ## _t){.is_none=true}; \
} \
- return (Optional ## KindOfInt ## _t){.value=KindOfInt##$from_int(full_int, true)}; \
+ return (Optional ## KindOfInt ## _t){.value=KindOfInt##ヽfrom_int(full_int, true)}; \
} \
- public CONSTFUNC c_type KindOfInt ## $gcd(c_type x, c_type y) { \
+ public CONSTFUNC c_type KindOfInt ## ヽgcd(c_type x, c_type y) { \
if (x == 0 || y == 0) return 0; \
- x = KindOfInt##$abs(x); \
- y = KindOfInt##$abs(y); \
+ x = KindOfInt##ヽabs(x); \
+ y = KindOfInt##ヽabs(y); \
while (x != y) { \
if (x > y) x -= y; \
else y -= x; \
} \
return x; \
} \
- public const c_type KindOfInt##$min = min_val; \
- public const c_type KindOfInt##$max = max_val; \
- public const TypeInfo_t KindOfInt##$info = { \
+ public const c_type KindOfInt##ヽmin = min_val; \
+ public const c_type KindOfInt##ヽmax = max_val; \
+ public const TypeInfo_t KindOfInt##ヽinfo = { \
.size=sizeof(c_type), \
.align=__alignof__(c_type), \
.metamethods={ \
- .compare=KindOfInt##$compare, \
- .as_text=KindOfInt##$as_text, \
- .serialize=KindOfInt##$serialize, \
- .deserialize=KindOfInt##$deserialize, \
+ .compare=KindOfInt##ヽcompare, \
+ .as_text=KindOfInt##ヽas_text, \
+ .serialize=KindOfInt##ヽserialize, \
+ .deserialize=KindOfInt##ヽdeserialize, \
}, \
};
diff --git a/src/stdlib/integers.h b/src/stdlib/integers.h
index 50ca485f..25ccecb3 100644
--- a/src/stdlib/integers.h
+++ b/src/stdlib/integers.h
@@ -23,46 +23,46 @@
c_type value; \
bool is_none:1; \
} Optional ## type_name ## _t; \
- Text_t type_name ## $as_text(const void *i, bool colorize, const TypeInfo_t *type); \
- PUREFUNC int32_t type_name ## $compare(const void *x, const void *y, const TypeInfo_t *type); \
- PUREFUNC bool type_name ## $equal(const void *x, const void *y, const TypeInfo_t *type); \
- Text_t type_name ## $hex(c_type i, Int_t digits, bool uppercase, bool prefix); \
- Text_t type_name ## $octal(c_type i, Int_t digits, bool prefix); \
- List_t type_name ## $bits(c_type x); \
- bool type_name ## $get_bit(c_type x, Int_t bit_index); \
- Closure_t type_name ## $to(c_type first, c_type last, Optional ## type_name ## _t step); \
- Closure_t type_name ## $onward(c_type first, c_type step); \
- PUREFUNC Optional ## type_name ## _t type_name ## $parse(Text_t text, Text_t *remainder); \
- CONSTFUNC bool type_name ## $is_between(const c_type x, const c_type low, const c_type high); \
- CONSTFUNC c_type type_name ## $clamped(c_type x, c_type min, c_type max); \
- MACROLIKE CONSTFUNC c_type type_name ## $from_byte(Byte_t b) { return (c_type)b; } \
- MACROLIKE CONSTFUNC c_type type_name ## $from_bool(Bool_t b) { return (c_type)b; } \
- CONSTFUNC c_type type_name ## $gcd(c_type x, c_type y); \
- extern const c_type type_name ## $min, type_name##$max; \
- extern const TypeInfo_t type_name ## $info; \
- MACROLIKE c_type type_name ## $divided_by(c_type D, c_type d) { \
+ Text_t type_name ## ヽas_text(const void *i, bool colorize, const TypeInfo_t *type); \
+ PUREFUNC int32_t type_name ## ヽcompare(const void *x, const void *y, const TypeInfo_t *type); \
+ PUREFUNC bool type_name ## ヽequal(const void *x, const void *y, const TypeInfo_t *type); \
+ Text_t type_name ## ヽhex(c_type i, Int_t digits, bool uppercase, bool prefix); \
+ Text_t type_name ## ヽoctal(c_type i, Int_t digits, bool prefix); \
+ List_t type_name ## ヽbits(c_type x); \
+ bool type_name ## ヽget_bit(c_type x, Int_t bit_index); \
+ Closure_t type_name ## ヽto(c_type first, c_type last, Optional ## type_name ## _t step); \
+ Closure_t type_name ## ヽonward(c_type first, c_type step); \
+ PUREFUNC Optional ## type_name ## _t type_name ## ヽparse(Text_t text, Text_t *remainder); \
+ CONSTFUNC bool type_name ## ヽis_between(const c_type x, const c_type low, const c_type high); \
+ CONSTFUNC c_type type_name ## ヽclamped(c_type x, c_type min, c_type max); \
+ MACROLIKE CONSTFUNC c_type type_name ## ヽfrom_byte(Byte_t b) { return (c_type)b; } \
+ MACROLIKE CONSTFUNC c_type type_name ## ヽfrom_bool(Bool_t b) { return (c_type)b; } \
+ CONSTFUNC c_type type_name ## ヽgcd(c_type x, c_type y); \
+ extern const c_type type_name ## ヽmin, type_name##ヽmax; \
+ extern const TypeInfo_t type_name ## ヽinfo; \
+ MACROLIKE c_type type_name ## ヽdivided_by(c_type D, c_type d) { \
c_type q = D/d, r = D%d; \
q -= (r < 0) * (2*(d > 0) - 1); \
return q; \
} \
- MACROLIKE c_type type_name ## $modulo(c_type D, c_type d) { \
+ MACROLIKE c_type type_name ## ヽmodulo(c_type D, c_type d) { \
c_type r = D%d; \
r -= (r < 0) * (2*(d < 0) - 1) * d; \
return r; \
} \
- MACROLIKE c_type type_name ## $modulo1(c_type D, c_type d) { \
- return type_name ## $modulo(D-1, d) + 1; \
+ MACROLIKE c_type type_name ## ヽmodulo1(c_type D, c_type d) { \
+ return type_name ## ヽmodulo(D-1, d) + 1; \
} \
- MACROLIKE PUREFUNC c_type type_name ## $wrapping_plus(c_type x, c_type y) { \
+ MACROLIKE PUREFUNC c_type type_name ## ヽwrapping_plus(c_type x, c_type y) { \
return (c_type)((u##c_type)x + (u##c_type)y); \
} \
- MACROLIKE PUREFUNC c_type type_name ## $wrapping_minus(c_type x, c_type y) { \
+ MACROLIKE PUREFUNC c_type type_name ## ヽwrapping_minus(c_type x, c_type y) { \
return (c_type)((u##c_type)x + (u##c_type)y); \
} \
- MACROLIKE PUREFUNC c_type type_name ## $unsigned_left_shifted(c_type x, c_type y) { \
+ MACROLIKE PUREFUNC c_type type_name ## ヽunsigned_left_shifted(c_type x, c_type y) { \
return (c_type)((u##c_type)x << y); \
} \
- MACROLIKE PUREFUNC c_type type_name ## $unsigned_right_shifted(c_type x, c_type y) { \
+ MACROLIKE PUREFUNC c_type type_name ## ヽunsigned_right_shifted(c_type x, c_type y) { \
return (c_type)((u##c_type)x >> y); \
}
@@ -77,41 +77,41 @@ DEFINE_INT_TYPE(int8_t, Int8)
#define NONE_INT16 ((OptionalInt16_t){.is_none=true})
#define NONE_INT8 ((OptionalInt8_t){.is_none=true})
-#define Int64$abs(...) I64(labs(__VA_ARGS__))
-#define Int32$abs(...) I32(abs(__VA_ARGS__))
-#define Int16$abs(...) I16(abs(__VA_ARGS__))
-#define Int8$abs(...) I8(abs(__VA_ARGS__))
-
-void Int64$serialize(const void *obj, FILE *out, Table_t*, const TypeInfo_t*);
-void Int64$deserialize(FILE *in, void *outval, List_t*, const TypeInfo_t*);
-void Int32$serialize(const void *obj, FILE *out, Table_t*, const TypeInfo_t*);
-void Int32$deserialize(FILE *in, void *outval, List_t*, const TypeInfo_t*);
-
-Text_t Int$as_text(const void *i, bool colorize, const TypeInfo_t *type);
-Text_t Int$value_as_text(Int_t i);
-PUREFUNC uint64_t Int$hash(const void *x, const TypeInfo_t *type);
-PUREFUNC int32_t Int$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC int32_t Int$compare_value(const Int_t x, const Int_t y);
-CONSTFUNC bool Int$is_between(const Int_t x, const Int_t low, const Int_t high);
-CONSTFUNC Int_t Int$clamped(Int_t x, Int_t low, Int_t high);
-PUREFUNC bool Int$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Int$equal_value(const Int_t x, const Int_t y);
-Text_t Int$hex(Int_t i, Int_t digits, bool uppercase, bool prefix);
-Text_t Int$octal(Int_t i, Int_t digits, bool prefix);
-PUREFUNC Closure_t Int$to(Int_t first, Int_t last, OptionalInt_t step);
-PUREFUNC Closure_t Int$onward(Int_t first, Int_t step);
-OptionalInt_t Int$from_str(const char *str);
-OptionalInt_t Int$parse(Text_t text, Text_t *remainder);
-Int_t Int$abs(Int_t x);
-Int_t Int$power(Int_t base, Int_t exponent);
-Int_t Int$gcd(Int_t x, Int_t y);
-OptionalInt_t Int$sqrt(Int_t i);
-bool Int$get_bit(Int_t x, Int_t bit_index);
+#define Int64ヽabs(...) I64(labs(__VA_ARGS__))
+#define Int32ヽabs(...) I32(abs(__VA_ARGS__))
+#define Int16ヽabs(...) I16(abs(__VA_ARGS__))
+#define Int8ヽabs(...) I8(abs(__VA_ARGS__))
+
+void Int64ヽserialize(const void *obj, FILE *out, Table_t*, const TypeInfo_t*);
+void Int64ヽdeserialize(FILE *in, void *outval, List_t*, const TypeInfo_t*);
+void Int32ヽserialize(const void *obj, FILE *out, Table_t*, const TypeInfo_t*);
+void Int32ヽdeserialize(FILE *in, void *outval, List_t*, const TypeInfo_t*);
+
+Text_t Intヽas_text(const void *i, bool colorize, const TypeInfo_t *type);
+Text_t Intヽvalue_as_text(Int_t i);
+PUREFUNC uint64_t Intヽhash(const void *x, const TypeInfo_t *type);
+PUREFUNC int32_t Intヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC int32_t Intヽcompare_value(const Int_t x, const Int_t y);
+CONSTFUNC bool Intヽis_between(const Int_t x, const Int_t low, const Int_t high);
+CONSTFUNC Int_t Intヽclamped(Int_t x, Int_t low, Int_t high);
+PUREFUNC bool Intヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Intヽequal_value(const Int_t x, const Int_t y);
+Text_t Intヽhex(Int_t i, Int_t digits, bool uppercase, bool prefix);
+Text_t Intヽoctal(Int_t i, Int_t digits, bool prefix);
+PUREFUNC Closure_t Intヽto(Int_t first, Int_t last, OptionalInt_t step);
+PUREFUNC Closure_t Intヽonward(Int_t first, Int_t step);
+OptionalInt_t Intヽfrom_str(const char *str);
+OptionalInt_t Intヽparse(Text_t text, Text_t *remainder);
+Int_t Intヽabs(Int_t x);
+Int_t Intヽpower(Int_t base, Int_t exponent);
+Int_t Intヽgcd(Int_t x, Int_t y);
+OptionalInt_t Intヽsqrt(Int_t i);
+bool Intヽget_bit(Int_t x, Int_t bit_index);
#define BIGGEST_SMALL_INT 0x3fffffff
#define SMALLEST_SMALL_INT -0x40000000
-#define Int$from_mpz(mpz) (\
+#define Intヽfrom_mpz(mpz) (\
mpz_cmpabs_ui(mpz, BIGGEST_SMALL_INT) <= 0 ? ( \
(Int_t){.small=(mpz_get_si(mpz)<<2L)|1L} \
) : ( \
@@ -124,61 +124,61 @@ bool Int$get_bit(Int_t x, Int_t bit_index);
} while (0)
#define I_small(i) ((Int_t){.small=(int64_t)((uint64_t)(i)<<2L)|1L})
-#define I(i) _Generic(i, int8_t: I_small(i), int16_t: I_small(i), default: Int$from_int64(i))
+#define I(i) _Generic(i, int8_t: I_small(i), int16_t: I_small(i), default: Intヽfrom_int64(i))
#define I_is_zero(i) ((i).small == 1L)
-Int_t Int$slow_plus(Int_t x, Int_t y);
-Int_t Int$slow_minus(Int_t x, Int_t y);
-Int_t Int$slow_times(Int_t x, Int_t y);
-Int_t Int$slow_divided_by(Int_t x, Int_t y);
-Int_t Int$slow_modulo(Int_t x, Int_t y);
-Int_t Int$slow_modulo1(Int_t x, Int_t y);
-Int_t Int$slow_left_shifted(Int_t x, Int_t y);
-Int_t Int$slow_right_shifted(Int_t x, Int_t y);
-Int_t Int$slow_bit_and(Int_t x, Int_t y);
-Int_t Int$slow_bit_or(Int_t x, Int_t y);
-Int_t Int$slow_bit_xor(Int_t x, Int_t y);
-Int_t Int$slow_negative(Int_t x);
-Int_t Int$slow_negated(Int_t x);
-bool Int$is_prime(Int_t x, Int_t reps);
-Int_t Int$next_prime(Int_t x);
+Int_t Intヽslow_plus(Int_t x, Int_t y);
+Int_t Intヽslow_minus(Int_t x, Int_t y);
+Int_t Intヽslow_times(Int_t x, Int_t y);
+Int_t Intヽslow_divided_by(Int_t x, Int_t y);
+Int_t Intヽslow_modulo(Int_t x, Int_t y);
+Int_t Intヽslow_modulo1(Int_t x, Int_t y);
+Int_t Intヽslow_left_shifted(Int_t x, Int_t y);
+Int_t Intヽslow_right_shifted(Int_t x, Int_t y);
+Int_t Intヽslow_bit_and(Int_t x, Int_t y);
+Int_t Intヽslow_bit_or(Int_t x, Int_t y);
+Int_t Intヽslow_bit_xor(Int_t x, Int_t y);
+Int_t Intヽslow_negative(Int_t x);
+Int_t Intヽslow_negated(Int_t x);
+bool Intヽis_prime(Int_t x, Int_t reps);
+Int_t Intヽnext_prime(Int_t x);
#if __GNU_MP_VERSION >= 6
#if __GNU_MP_VERSION_MINOR >= 3
-OptionalInt_t Int$prev_prime(Int_t x);
+OptionalInt_t Intヽprev_prime(Int_t x);
#endif
#endif
-Int_t Int$choose(Int_t n, Int_t k);
-Int_t Int$factorial(Int_t n);
+Int_t Intヽchoose(Int_t n, Int_t k);
+Int_t Intヽfactorial(Int_t n);
-extern const TypeInfo_t Int$info;
+extern const TypeInfo_t Intヽinfo;
// Fast-path inline versions for the common case where integer arithmetic is
// between two small ints.
-MACROLIKE Int_t Int$plus(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽplus(Int_t x, Int_t y) {
const int64_t z = (int64_t)((uint64_t)x.small + (uint64_t)y.small);
if likely ((z|2L) == (int32_t)z)
return (Int_t){.small=(z-1L)};
- return Int$slow_plus(x, y);
+ return Intヽslow_plus(x, y);
}
-MACROLIKE Int_t Int$minus(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽminus(Int_t x, Int_t y) {
const int64_t z = (int64_t)(((uint64_t)x.small ^ 3L) - (uint64_t)y.small);
if likely ((z & ~2L) == (int32_t)z)
return (Int_t){.small=z};
- return Int$slow_minus(x, y);
+ return Intヽslow_minus(x, y);
}
-MACROLIKE Int_t Int$times(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽtimes(Int_t x, Int_t y) {
if likely ((x.small & y.small) & 1L) {
const int64_t z = (x.small>>1L) * (y.small>>1L);
if likely (z == (int32_t)z)
return (Int_t){.small=z+1L};
}
- return Int$slow_times(x, y);
+ return Intヽslow_times(x, y);
}
-MACROLIKE Int_t Int$divided_by(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽdivided_by(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L) {
// Euclidean division, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
const int64_t D = (x.small>>2L);
@@ -188,10 +188,10 @@ MACROLIKE Int_t Int$divided_by(Int_t x, Int_t y) {
if likely (q == (int32_t)q)
return (Int_t){.small=(q<<2L)|1L};
}
- return Int$slow_divided_by(x, y);
+ return Intヽslow_divided_by(x, y);
}
-MACROLIKE Int_t Int$modulo(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽmodulo(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L) {
// Euclidean modulus, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
const int64_t D = (x.small>>2L);
@@ -200,10 +200,10 @@ MACROLIKE Int_t Int$modulo(Int_t x, Int_t y) {
r -= (r < 0L) * (2L*(d < 0L) - 1L) * d;
return (Int_t){.small=(r<<2L)|1L};
}
- return Int$slow_modulo(x, y);
+ return Intヽslow_modulo(x, y);
}
-MACROLIKE Int_t Int$modulo1(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽmodulo1(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L) {
// Euclidean modulus, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
const int64_t D = (x.small>>2L)-1L;
@@ -212,62 +212,62 @@ MACROLIKE Int_t Int$modulo1(Int_t x, Int_t y) {
r -= (r < 0L) * (2L*(d < 0L) - 1L) * d;
return (Int_t){.small=((r+1L)<<2L)|1L};
}
- return Int$slow_modulo1(x, y);
+ return Intヽslow_modulo1(x, y);
}
-MACROLIKE Int_t Int$left_shifted(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽleft_shifted(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L) {
const int64_t z = ((x.small>>2L) << (y.small>>2L))<<2L;
if likely (z == (int32_t)z)
return (Int_t){.small=z+1L};
}
- return Int$slow_left_shifted(x, y);
+ return Intヽslow_left_shifted(x, y);
}
-MACROLIKE Int_t Int$right_shifted(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽright_shifted(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L) {
const int64_t z = ((x.small>>2L) >> (y.small>>2L))<<2L;
if likely (z == (int32_t)z)
return (Int_t){.small=z+1L};
}
- return Int$slow_right_shifted(x, y);
+ return Intヽslow_right_shifted(x, y);
}
-MACROLIKE Int_t Int$bit_and(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽbit_and(Int_t x, Int_t y) {
const int64_t z = x.small & y.small;
if likely (z & 1L)
return (Int_t){.small=z};
- return Int$slow_bit_and(x, y);
+ return Intヽslow_bit_and(x, y);
}
-MACROLIKE Int_t Int$bit_or(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽbit_or(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L)
return (Int_t){.small=(x.small | y.small)};
- return Int$slow_bit_or(x, y);
+ return Intヽslow_bit_or(x, y);
}
-MACROLIKE Int_t Int$bit_xor(Int_t x, Int_t y) {
+MACROLIKE Int_t Intヽbit_xor(Int_t x, Int_t y) {
if likely (x.small & y.small & 1L)
return (Int_t){.small=(x.small ^ y.small) | 1L};
- return Int$slow_bit_xor(x, y);
+ return Intヽslow_bit_xor(x, y);
}
-MACROLIKE Int_t Int$negated(Int_t x) {
+MACROLIKE Int_t Intヽnegated(Int_t x) {
if likely (x.small & 1L)
return (Int_t){.small=(~x.small) ^ 3L};
- return Int$slow_negated(x);
+ return Intヽslow_negated(x);
}
-MACROLIKE Int_t Int$negative(Int_t x) {
+MACROLIKE Int_t Intヽnegative(Int_t x) {
if likely (x.small & 1L)
return (Int_t){.small=((-((x.small)>>2L))<<2L) | 1L};
- return Int$slow_negative(x);
+ return Intヽslow_negative(x);
}
-MACROLIKE PUREFUNC bool Int$is_negative(Int_t x) {
+MACROLIKE PUREFUNC bool Intヽis_negative(Int_t x) {
if likely (x.small & 1L)
return x.small < 0L;
- return Int$compare_value(x, I_small(0)) < 0L;
+ return Intヽcompare_value(x, I_small(0)) < 0L;
}
// Constructors/conversion functions:
@@ -277,147 +277,147 @@ MACROLIKE PUREFUNC bool Int$is_negative(Int_t x) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
-MACROLIKE PUREFUNC Int_t Int$from_num(double n, bool truncate) {
+MACROLIKE PUREFUNC Int_t Intヽfrom_num(double n, bool truncate) {
mpz_t result;
mpz_init_set_d(result, n);
if (!truncate && unlikely(mpz_get_d(result) != n))
fail("Could not convert to an integer without truncation: ", n);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-MACROLIKE PUREFUNC Int_t Int$from_num32(float n, bool truncate) { return Int$from_num((double)n, truncate); }
-MACROLIKE Int_t Int$from_int64(int64_t i) {
+MACROLIKE PUREFUNC Int_t Intヽfrom_num32(float n, bool truncate) { return Intヽfrom_num((double)n, truncate); }
+MACROLIKE Int_t Intヽfrom_int64(int64_t i) {
if likely (i >= SMALLEST_SMALL_INT && i <= BIGGEST_SMALL_INT)
return (Int_t){.small=(i<<2L)|1L};
mpz_t result;
mpz_init_set_si(result, i);
- return Int$from_mpz(result);
+ return Intヽfrom_mpz(result);
}
-MACROLIKE CONSTFUNC Int_t Int$from_int32(Int32_t i) { return Int$from_int64((Int32_t)i); }
-MACROLIKE CONSTFUNC Int_t Int$from_int16(Int16_t i) { return I_small(i); }
-MACROLIKE CONSTFUNC Int_t Int$from_int8(Int8_t i) { return I_small(i); }
-MACROLIKE CONSTFUNC Int_t Int$from_byte(Byte_t b) { return I_small(b); }
-MACROLIKE CONSTFUNC Int_t Int$from_bool(Bool_t b) { return I_small(b); }
+MACROLIKE CONSTFUNC Int_t Intヽfrom_int32(Int32_t i) { return Intヽfrom_int64((Int32_t)i); }
+MACROLIKE CONSTFUNC Int_t Intヽfrom_int16(Int16_t i) { return I_small(i); }
+MACROLIKE CONSTFUNC Int_t Intヽfrom_int8(Int8_t i) { return I_small(i); }
+MACROLIKE CONSTFUNC Int_t Intヽfrom_byte(Byte_t b) { return I_small(b); }
+MACROLIKE CONSTFUNC Int_t Intヽfrom_bool(Bool_t b) { return I_small(b); }
// Int64 constructors
-MACROLIKE PUREFUNC Int64_t Int64$from_num(Num_t n, bool truncate) {
+MACROLIKE PUREFUNC Int64_t Int64ヽfrom_num(Num_t n, bool truncate) {
int64_t i64 = (int64_t)n;
if (!truncate && unlikely((Num_t)i64 != n))
fail("Could not convert Num to Int64 without truncation: ", n);
return i64;
}
-MACROLIKE PUREFUNC Int64_t Int64$from_num32(Num32_t n, bool truncate) {
+MACROLIKE PUREFUNC Int64_t Int64ヽfrom_num32(Num32_t n, bool truncate) {
int64_t i64 = (int64_t)n;
if (!truncate && unlikely((Num32_t)i64 != n))
fail("Could not convert Num32 to Int64 without truncation: ", n);
return i64;
}
-MACROLIKE PUREFUNC Int64_t Int64$from_int(Int_t i, bool truncate) {
+MACROLIKE PUREFUNC Int64_t Int64ヽfrom_int(Int_t i, bool truncate) {
if likely (i.small & 1L)
return (int64_t)(i.small >> 2L);
if (!truncate && unlikely(!mpz_fits_slong_p(*i.big)))
fail("Integer is too big to fit in a 64-bit integer: ", i);
return mpz_get_si(*i.big);
}
-MACROLIKE CONSTFUNC Int64_t Int64$from_int32(Int32_t i) { return (Int64_t)i; }
-MACROLIKE CONSTFUNC Int64_t Int64$from_int16(Int16_t i) { return (Int64_t)i; }
-MACROLIKE CONSTFUNC Int64_t Int64$from_int8(Int8_t i) { return (Int64_t)i; }
+MACROLIKE CONSTFUNC Int64_t Int64ヽfrom_int32(Int32_t i) { return (Int64_t)i; }
+MACROLIKE CONSTFUNC Int64_t Int64ヽfrom_int16(Int16_t i) { return (Int64_t)i; }
+MACROLIKE CONSTFUNC Int64_t Int64ヽfrom_int8(Int8_t i) { return (Int64_t)i; }
// Int32 constructors
-MACROLIKE PUREFUNC Int32_t Int32$from_num(Num_t n, bool truncate) {
+MACROLIKE PUREFUNC Int32_t Int32ヽfrom_num(Num_t n, bool truncate) {
int32_t i32 = (int32_t)n;
if (!truncate && unlikely((Num_t)i32 != n))
fail("Could not convert Num to Int32 without truncation: ", n);
return i32;
}
-MACROLIKE PUREFUNC Int32_t Int32$from_num32(Num32_t n, bool truncate) {
+MACROLIKE PUREFUNC Int32_t Int32ヽfrom_num32(Num32_t n, bool truncate) {
int32_t i32 = (int32_t)n;
if (!truncate && unlikely((Num32_t)i32 != n))
fail("Could not convert Num32 to Int32 without truncation: ", n);
return i32;
}
-MACROLIKE PUREFUNC Int32_t Int32$from_int(Int_t i, bool truncate) {
- int64_t i64 = Int64$from_int(i, truncate);
+MACROLIKE PUREFUNC Int32_t Int32ヽfrom_int(Int_t i, bool truncate) {
+ int64_t i64 = Int64ヽfrom_int(i, truncate);
int32_t i32 = (int32_t)i64;
if (!truncate && unlikely((int64_t)i32 != i64))
fail("Integer is too big to fit in a 32-bit integer: ", i);
return i32;
}
-MACROLIKE PUREFUNC Int32_t Int32$from_int64(Int64_t i64, bool truncate) {
+MACROLIKE PUREFUNC Int32_t Int32ヽfrom_int64(Int64_t i64, bool truncate) {
int32_t i32 = (int32_t)i64;
if (!truncate && unlikely((int64_t)i32 != i64))
fail("Integer is too big to fit in a 32-bit integer: ", i64);
return i32;
}
-MACROLIKE CONSTFUNC Int32_t Int32$from_int16(Int16_t i) { return (Int32_t)i; }
-MACROLIKE CONSTFUNC Int32_t Int32$from_int8(Int8_t i) { return (Int32_t)i; }
+MACROLIKE CONSTFUNC Int32_t Int32ヽfrom_int16(Int16_t i) { return (Int32_t)i; }
+MACROLIKE CONSTFUNC Int32_t Int32ヽfrom_int8(Int8_t i) { return (Int32_t)i; }
// Int16 constructors
-MACROLIKE PUREFUNC Int16_t Int16$from_num(Num_t n, bool truncate) {
+MACROLIKE PUREFUNC Int16_t Int16ヽfrom_num(Num_t n, bool truncate) {
int16_t i16 = (int16_t)n;
if (!truncate && unlikely((Num_t)i16 != n))
fail("Could not convert Num to Int16 without truncation: ", n);
return i16;
}
-MACROLIKE PUREFUNC Int16_t Int16$from_num32(Num32_t n, bool truncate) {
+MACROLIKE PUREFUNC Int16_t Int16ヽfrom_num32(Num32_t n, bool truncate) {
int16_t i16 = (int16_t)n;
if (!truncate && unlikely((Num32_t)i16 != n))
fail("Could not convert Num32 to Int16 without truncation: ", (double)n);
return i16;
}
-MACROLIKE PUREFUNC Int16_t Int16$from_int(Int_t i, bool truncate) {
- int64_t i64 = Int64$from_int(i, truncate);
+MACROLIKE PUREFUNC Int16_t Int16ヽfrom_int(Int_t i, bool truncate) {
+ int64_t i64 = Int64ヽfrom_int(i, truncate);
int16_t i16 = (int16_t)i64;
if (!truncate && unlikely((int64_t)i16 != i64))
fail("Integer is too big to fit in a 16-bit integer!");
return i16;
}
-MACROLIKE PUREFUNC Int16_t Int16$from_int64(Int64_t i64, bool truncate) {
+MACROLIKE PUREFUNC Int16_t Int16ヽfrom_int64(Int64_t i64, bool truncate) {
int16_t i16 = (int16_t)i64;
if (!truncate && unlikely((int64_t)i16 != i64))
fail("Integer is too big to fit in a 16-bit integer: ", i64);
return i16;
}
-MACROLIKE PUREFUNC Int16_t Int16$from_int32(Int32_t i32, bool truncate) {
+MACROLIKE PUREFUNC Int16_t Int16ヽfrom_int32(Int32_t i32, bool truncate) {
int16_t i16 = (int16_t)i32;
if (!truncate && unlikely((int32_t)i16 != i32))
fail("Integer is too big to fit in a 16-bit integer: ", i32);
return i16;
}
-MACROLIKE CONSTFUNC Int16_t Int16$from_int8(Int8_t i) { return (Int16_t)i; }
+MACROLIKE CONSTFUNC Int16_t Int16ヽfrom_int8(Int8_t i) { return (Int16_t)i; }
// Int8 constructors
-MACROLIKE PUREFUNC Int8_t Int8$from_num(Num_t n, bool truncate) {
+MACROLIKE PUREFUNC Int8_t Int8ヽfrom_num(Num_t n, bool truncate) {
int8_t i8 = (int8_t)n;
if (!truncate && unlikely((Num_t)i8 != n))
fail("Could not convert Num to Int8 without truncation: ", n);
return i8;
}
-MACROLIKE PUREFUNC Int8_t Int8$from_num32(Num32_t n, bool truncate) {
+MACROLIKE PUREFUNC Int8_t Int8ヽfrom_num32(Num32_t n, bool truncate) {
int8_t i8 = (int8_t)n;
if (!truncate && unlikely((Num32_t)i8 != n))
fail("Could not convert Num32 to Int8 without truncation: ", n);
return i8;
}
-MACROLIKE PUREFUNC Int8_t Int8$from_int(Int_t i, bool truncate) {
- int64_t i64 = Int64$from_int(i, truncate);
+MACROLIKE PUREFUNC Int8_t Int8ヽfrom_int(Int_t i, bool truncate) {
+ int64_t i64 = Int64ヽfrom_int(i, truncate);
int8_t i8 = (int8_t)i64;
if (!truncate && unlikely((int64_t)i8 != i64))
fail("Integer is too big to fit in an 8-bit integer!");
return i8;
}
-MACROLIKE PUREFUNC Int8_t Int8$from_int64(Int64_t i64, bool truncate) {
+MACROLIKE PUREFUNC Int8_t Int8ヽfrom_int64(Int64_t i64, bool truncate) {
int8_t i8 = (int8_t)i64;
if (!truncate && unlikely((int64_t)i8 != i64))
fail("Integer is too big to fit in a 8-bit integer: ", i64);
return i8;
}
-MACROLIKE PUREFUNC Int8_t Int8$from_int32(Int32_t i32, bool truncate) {
+MACROLIKE PUREFUNC Int8_t Int8ヽfrom_int32(Int32_t i32, bool truncate) {
int8_t i8 = (int8_t)i32;
if (!truncate && unlikely((int32_t)i8 != i32))
fail("Integer is too big to fit in a 8-bit integer: ", i32);
return i8;
}
-MACROLIKE PUREFUNC Int8_t Int8$from_int16(Int16_t i16, bool truncate) {
+MACROLIKE PUREFUNC Int8_t Int8ヽfrom_int16(Int16_t i16, bool truncate) {
int8_t i8 = (int8_t)i16;
if (!truncate && unlikely((int16_t)i8 != i16))
fail("Integer is too big to fit in a 8-bit integer: ", i16);
diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c
index 31e25f15..8ea29081 100644
--- a/src/stdlib/lists.c
+++ b/src/stdlib/lists.c
@@ -28,7 +28,7 @@ PUREFUNC static INLINE int64_t get_padded_item_size(const TypeInfo_t *info)
// Replace the list's .data pointer with a new pointer to a copy of the
// data that is compacted and has a stride of exactly `padded_item_size`
-public void List$compact(List_t *list, int64_t padded_item_size)
+public void Listヽcompact(List_t *list, int64_t padded_item_size)
{
void *copy = NULL;
if (list->length > 0) {
@@ -49,9 +49,9 @@ public void List$compact(List_t *list, int64_t padded_item_size)
};
}
-public void List$insert(List_t *list, const void *item, Int_t int_index, int64_t padded_item_size)
+public void Listヽinsert(List_t *list, const void *item, Int_t int_index, int64_t padded_item_size)
{
- int64_t index = Int64$from_int(int_index, false);
+ int64_t index = Int64ヽfrom_int(int_index, false);
if (index <= 0) index = list->length + index + 1;
if (index < 1) index = 1;
@@ -92,9 +92,9 @@ public void List$insert(List_t *list, const void *item, Int_t int_index, int64_t
memcpy((void*)list->data + (index-1)*padded_item_size, item, (size_t)padded_item_size);
}
-public void List$insert_all(List_t *list, List_t to_insert, Int_t int_index, int64_t padded_item_size)
+public void Listヽinsert_all(List_t *list, List_t to_insert, Int_t int_index, int64_t padded_item_size)
{
- int64_t index = Int64$from_int(int_index, false);
+ int64_t index = Int64ヽfrom_int(int_index, false);
if (to_insert.length == 0)
return;
@@ -174,12 +174,12 @@ public void List$insert_all(List_t *list, List_t to_insert, Int_t int_index, int
}
}
-public void List$remove_at(List_t *list, Int_t int_index, Int_t int_count, int64_t padded_item_size)
+public void Listヽremove_at(List_t *list, Int_t int_index, Int_t int_count, int64_t padded_item_size)
{
- int64_t index = Int64$from_int(int_index, false);
+ int64_t index = Int64ヽfrom_int(int_index, false);
if (index < 1) index = list->length + index + 1;
- int64_t count = Int64$from_int(int_count, false);
+ int64_t count = Int64ヽfrom_int(int_count, false);
if (index < 1 || index > (int64_t)list->length || count < 1) return;
if (count > list->length - index + 1)
@@ -210,7 +210,7 @@ public void List$remove_at(List_t *list, Int_t int_index, Int_t int_count, int64
if (list->length == 0) list->data = NULL;
}
-public void List$remove_item(List_t *list, void *item, Int_t max_removals, const TypeInfo_t *type)
+public void Listヽremove_item(List_t *list, void *item, Int_t max_removals, const TypeInfo_t *type)
{
int64_t padded_item_size = get_padded_item_size(type);
const Int_t ZERO = (Int_t){.small=(0<<2)|1};
@@ -221,15 +221,15 @@ public void List$remove_item(List_t *list, void *item, Int_t max_removals, const
break;
if (generic_equal(item, list->data + i*list->stride, item_type)) {
- List$remove_at(list, I(i+1), ONE, padded_item_size);
- max_removals = Int$minus(max_removals, ONE);
+ Listヽremove_at(list, I(i+1), ONE, padded_item_size);
+ max_removals = Intヽminus(max_removals, ONE);
} else {
i++;
}
}
}
-public OptionalInt_t List$find(List_t list, void *item, const TypeInfo_t *type)
+public OptionalInt_t Listヽfind(List_t list, void *item, const TypeInfo_t *type)
{
const TypeInfo_t *item_type = type->ListInfo.item;
for (int64_t i = 0; i < list.length; i++) {
@@ -239,7 +239,7 @@ public OptionalInt_t List$find(List_t list, void *item, const TypeInfo_t *type)
return NONE_INT;
}
-public OptionalInt_t List$first(List_t list, Closure_t predicate)
+public OptionalInt_t Listヽfirst(List_t list, Closure_t predicate)
{
bool (*is_good)(void*, void*) = (void*)predicate.fn;
for (int64_t i = 0; i < list.length; i++) {
@@ -257,18 +257,18 @@ int _compare_closure(const void *a, const void *b)
return ((comparison_t)_sort_comparison.fn)(a, b, _sort_comparison.userdata);
}
-public void List$sort(List_t *list, Closure_t comparison, int64_t padded_item_size)
+public void Listヽsort(List_t *list, Closure_t comparison, int64_t padded_item_size)
{
if (list->data_refcount != 0 || (int64_t)list->stride != padded_item_size)
- List$compact(list, padded_item_size);
+ Listヽcompact(list, padded_item_size);
_sort_comparison = comparison;
qsort(list->data, (size_t)list->length, (size_t)padded_item_size, _compare_closure);
}
-public List_t List$sorted(List_t list, Closure_t comparison, int64_t padded_item_size)
+public List_t Listヽsorted(List_t list, Closure_t comparison, int64_t padded_item_size)
{
- List$compact(&list, padded_item_size);
+ Listヽcompact(&list, padded_item_size);
_sort_comparison = comparison;
qsort(list.data, (size_t)list.length, (size_t)padded_item_size, _compare_closure);
return list;
@@ -303,10 +303,10 @@ static int64_t _default_random_int64(int64_t min, int64_t max, void *userdata)
return (int64_t)((uint64_t)min + (r % range));
}
-public void List$shuffle(List_t *list, OptionalClosure_t random_int64, int64_t padded_item_size)
+public void Listヽshuffle(List_t *list, OptionalClosure_t random_int64, int64_t padded_item_size)
{
if (list->data_refcount != 0 || (int64_t)list->stride != padded_item_size)
- List$compact(list, padded_item_size);
+ Listヽcompact(list, padded_item_size);
typedef int64_t (*rng_fn_t)(int64_t, int64_t, void*);
rng_fn_t rng_fn = random_int64.fn ? (rng_fn_t)random_int64.fn : _default_random_int64;
@@ -321,14 +321,14 @@ public void List$shuffle(List_t *list, OptionalClosure_t random_int64, int64_t p
}
}
-public List_t List$shuffled(List_t list, Closure_t random_int64, int64_t padded_item_size)
+public List_t Listヽshuffled(List_t list, Closure_t random_int64, int64_t padded_item_size)
{
- List$compact(&list, padded_item_size);
- List$shuffle(&list, random_int64, padded_item_size);
+ Listヽcompact(&list, padded_item_size);
+ Listヽshuffle(&list, random_int64, padded_item_size);
return list;
}
-public void *List$random(List_t list, OptionalClosure_t random_int64)
+public void *Listヽrandom(List_t list, OptionalClosure_t random_int64)
{
if (list.length == 0)
return NULL; // fail("Cannot get a random item from an empty list!");
@@ -341,15 +341,15 @@ public void *List$random(List_t list, OptionalClosure_t random_int64)
return list.data + list.stride*index;
}
-public Table_t List$counts(List_t list, const TypeInfo_t *type)
+public Table_t Listヽcounts(List_t list, const TypeInfo_t *type)
{
Table_t counts = {};
- const TypeInfo_t count_type = *Table$info(type->ListInfo.item, &Int$info);
+ const TypeInfo_t count_type = *Tableヽinfo(type->ListInfo.item, &Intヽinfo);
for (int64_t i = 0; i < list.length; i++) {
void *key = list.data + i*list.stride;
- int64_t *count = Table$get(counts, key, &count_type);
+ int64_t *count = Tableヽget(counts, key, &count_type);
int64_t val = count ? *count + 1 : 1;
- Table$set(&counts, key, &val, &count_type);
+ Tableヽset(&counts, key, &val, &count_type);
}
return counts;
}
@@ -369,9 +369,9 @@ static double _default_random_num(void *userdata)
return r.num - 1.0;
}
-public List_t List$sample(List_t list, Int_t int_n, List_t weights, OptionalClosure_t random_num, int64_t padded_item_size)
+public List_t Listヽsample(List_t list, Int_t int_n, List_t weights, OptionalClosure_t random_num, int64_t padded_item_size)
{
- int64_t n = Int64$from_int(int_n, false);
+ int64_t n = Int64ヽfrom_int(int_n, false);
if (n < 0)
fail("Cannot select a negative number of values");
@@ -459,19 +459,19 @@ public List_t List$sample(List_t list, Int_t int_n, List_t weights, OptionalClos
return selected;
}
-public List_t List$from(List_t list, Int_t first)
+public List_t Listヽfrom(List_t list, Int_t first)
{
- return List$slice(list, first, I_small(-1));
+ return Listヽslice(list, first, I_small(-1));
}
-public List_t List$to(List_t list, Int_t last)
+public List_t Listヽto(List_t list, Int_t last)
{
- return List$slice(list, I_small(1), last);
+ return Listヽslice(list, I_small(1), last);
}
-public List_t List$by(List_t list, Int_t int_stride, int64_t padded_item_size)
+public List_t Listヽby(List_t list, Int_t int_stride, int64_t padded_item_size)
{
- int64_t stride = Int64$from_int(int_stride, false);
+ int64_t stride = Int64ヽfrom_int(int_stride, false);
// In the unlikely event that the stride value would be too large to fit in
// a 15-bit integer, fall back to creating a copy of the list:
if (unlikely(list.stride*stride < LIST_MIN_STRIDE || list.stride*stride > LIST_MAX_STRIDE)) {
@@ -503,14 +503,14 @@ public List_t List$by(List_t list, Int_t int_stride, int64_t padded_item_size)
};
}
-public List_t List$slice(List_t list, Int_t int_first, Int_t int_last)
+public List_t Listヽslice(List_t list, Int_t int_first, Int_t int_last)
{
- int64_t first = Int64$from_int(int_first, false);
+ int64_t first = Int64ヽfrom_int(int_first, false);
if (first < 0)
first = list.length + first + 1;
- int64_t last = Int64$from_int(int_last, false);
+ int64_t last = Int64ヽfrom_int(int_last, false);
if (last < 0)
last = list.length + last + 1;
@@ -529,14 +529,14 @@ public List_t List$slice(List_t list, Int_t int_first, Int_t int_last)
};
}
-public List_t List$reversed(List_t list, int64_t padded_item_size)
+public List_t Listヽreversed(List_t list, int64_t padded_item_size)
{
// Just in case negating the stride gives a value that doesn't fit into a
- // 15-bit integer, fall back to List$by()'s more general method of copying
+ // 15-bit integer, fall back to Listヽby()'s more general method of copying
// the list. This should only happen if list.stride is MIN_STRIDE to
// begin with (very unlikely).
if (unlikely(-list.stride < LIST_MIN_STRIDE || -list.stride > LIST_MAX_STRIDE))
- return List$by(list, I(-1), padded_item_size);
+ return Listヽby(list, I(-1), padded_item_size);
List_t reversed = list;
reversed.stride = -list.stride;
@@ -544,7 +544,7 @@ public List_t List$reversed(List_t list, int64_t padded_item_size)
return reversed;
}
-public List_t List$concat(List_t x, List_t y, int64_t padded_item_size)
+public List_t Listヽconcat(List_t x, List_t y, int64_t padded_item_size)
{
void *data = x.atomic ? GC_MALLOC_ATOMIC((size_t)(padded_item_size*(x.length + y.length)))
: GC_MALLOC((size_t)(padded_item_size*(x.length + y.length)));
@@ -571,7 +571,7 @@ public List_t List$concat(List_t x, List_t y, int64_t padded_item_size)
};
}
-public bool List$has(List_t list, void *item, const TypeInfo_t *type)
+public bool Listヽhas(List_t list, void *item, const TypeInfo_t *type)
{
const TypeInfo_t *item_type = type->ListInfo.item;
for (int64_t i = 0; i < list.length; i++) {
@@ -581,12 +581,12 @@ public bool List$has(List_t list, void *item, const TypeInfo_t *type)
return false;
}
-public void List$clear(List_t *list)
+public void Listヽclear(List_t *list)
{
*list = (List_t){.data=0, .length=0};
}
-public int32_t List$compare(const void *vx, const void *vy, const TypeInfo_t *type)
+public int32_t Listヽcompare(const void *vx, const void *vy, const TypeInfo_t *type)
{
const List_t *x = (List_t*)vx, *y = (List_t*)vy;
// Early out for lists with the same data, e.g. two copies of the same list:
@@ -617,30 +617,30 @@ public int32_t List$compare(const void *vx, const void *vy, const TypeInfo_t *ty
return (x->length > y->length) - (x->length < y->length);
}
-public bool List$equal(const void *x, const void *y, const TypeInfo_t *type)
+public bool Listヽequal(const void *x, const void *y, const TypeInfo_t *type)
{
- return x == y || (((List_t*)x)->length == ((List_t*)y)->length && List$compare(x, y, type) == 0);
+ return x == y || (((List_t*)x)->length == ((List_t*)y)->length && Listヽcompare(x, y, type) == 0);
}
-public Text_t List$as_text(const void *obj, bool colorize, const TypeInfo_t *type)
+public Text_t Listヽas_text(const void *obj, bool colorize, const TypeInfo_t *type)
{
List_t *list = (List_t*)obj;
if (!list)
- return Text$concat(Text("["), generic_as_text(NULL, false, type->ListInfo.item), Text("]"));
+ return Textヽconcat(Text("["), generic_as_text(NULL, false, type->ListInfo.item), Text("]"));
const TypeInfo_t *item_type = type->ListInfo.item;
Text_t text = Text("[");
for (int64_t i = 0; i < list->length; i++) {
if (i > 0)
- text = Text$concat(text, Text(", "));
+ text = Textヽconcat(text, Text(", "));
Text_t item_text = generic_as_text(list->data + i*list->stride, colorize, item_type);
- text = Text$concat(text, item_text);
+ text = Textヽconcat(text, item_text);
}
- text = Text$concat(text, Text("]"));
+ text = Textヽconcat(text, Text("]"));
return text;
}
-public uint64_t List$hash(const void *obj, const TypeInfo_t *type)
+public uint64_t Listヽhash(const void *obj, const TypeInfo_t *type)
{
const List_t *list = (List_t*)obj;
const TypeInfo_t *item = type->ListInfo.item;
@@ -706,18 +706,18 @@ static void siftup(List_t *heap, int64_t pos, Closure_t comparison, int64_t padd
siftdown(heap, startpos, pos, comparison, padded_item_size);
}
-public void List$heap_push(List_t *heap, const void *item, Closure_t comparison, int64_t padded_item_size)
+public void Listヽheap_push(List_t *heap, const void *item, Closure_t comparison, int64_t padded_item_size)
{
- List$insert(heap, item, I(0), padded_item_size);
+ Listヽinsert(heap, item, I(0), padded_item_size);
if (heap->length > 1) {
if (heap->data_refcount != 0)
- List$compact(heap, padded_item_size);
+ Listヽcompact(heap, padded_item_size);
siftdown(heap, 0, heap->length-1, comparison, padded_item_size);
}
}
-public void List$heap_pop(List_t *heap, Closure_t comparison, int64_t padded_item_size)
+public void Listヽheap_pop(List_t *heap, Closure_t comparison, int64_t padded_item_size)
{
if (heap->length == 0)
fail("Attempt to pop from an empty list");
@@ -729,17 +729,17 @@ public void List$heap_pop(List_t *heap, Closure_t comparison, int64_t padded_ite
--heap->length;
} else {
if (heap->data_refcount != 0)
- List$compact(heap, padded_item_size);
+ Listヽcompact(heap, padded_item_size);
memcpy(heap->data, heap->data + heap->stride*(heap->length-1), (size_t)(padded_item_size));
--heap->length;
siftup(heap, 0, comparison, padded_item_size);
}
}
-public void List$heapify(List_t *heap, Closure_t comparison, int64_t padded_item_size)
+public void Listヽheapify(List_t *heap, Closure_t comparison, int64_t padded_item_size)
{
if (heap->data_refcount != 0)
- List$compact(heap, padded_item_size);
+ Listヽcompact(heap, padded_item_size);
// It's necessary to bump the refcount because the user's comparison
// function could do stuff that modifies the heap's data.
@@ -750,7 +750,7 @@ public void List$heapify(List_t *heap, Closure_t comparison, int64_t padded_item
LIST_DECREF(*heap);
}
-public Int_t List$binary_search(List_t list, void *target, Closure_t comparison)
+public Int_t Listヽbinary_search(List_t list, void *target, Closure_t comparison)
{
typedef int32_t (*cmp_fn_t)(void*, void*, void*);
int64_t lo = 0, hi = list.length-1;
@@ -768,17 +768,17 @@ public Int_t List$binary_search(List_t list, void *target, Closure_t comparison)
return I(lo+1); // Return the index where the target would be inserted
}
-public PUREFUNC bool List$is_none(const void *obj, const TypeInfo_t *info)
+public PUREFUNC bool Listヽis_none(const void *obj, const TypeInfo_t *info)
{
(void)info;
return ((List_t*)obj)->length < 0;
}
-public void List$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Listヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
List_t list = *(List_t*)obj;
int64_t len = list.length;
- Int64$serialize(&len, out, pointers, &Int64$info);
+ Int64ヽserialize(&len, out, pointers, &Int64ヽinfo);
serialize_fn_t item_serialize = type->ListInfo.item->metamethods.serialize;
if (item_serialize) {
for (int64_t i = 0; i < len; i++)
@@ -791,10 +791,10 @@ public void List$serialize(const void *obj, FILE *out, Table_t *pointers, const
}
}
-public void List$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type)
+public void Listヽdeserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type)
{
int64_t len = -1;
- Int64$deserialize(in, &len, pointers, &Int64$info);
+ Int64ヽdeserialize(in, &len, pointers, &Int64ヽinfo);
int64_t padded_size = type->ListInfo.item->size;
if (type->ListInfo.item->align > 0 && padded_size % type->ListInfo.item->align > 0)
padded_size += type->ListInfo.item->align - (padded_size % type->ListInfo.item->align);
diff --git a/src/stdlib/lists.h b/src/stdlib/lists.h
index a2853e48..95ff8966 100644
--- a/src/stdlib/lists.h
+++ b/src/stdlib/lists.h
@@ -25,13 +25,13 @@
if (unlikely(off < 0 || off >= list->length)) \
fail_source(__SOURCE_FILE__, start, end, "Invalid list index: ", index, " (list has length ", (int64_t)list->length, ")\n"); \
if (list->data_refcount > 0) \
- List$compact(list, sizeof(item_type)); \
+ Listヽcompact(list, sizeof(item_type)); \
(item_type*)(list->data + list->stride * off); })
#define List_lvalue_unchecked(item_type, arr_expr, index_expr) *({ \
List_t *list = arr_expr; int64_t index = index_expr; \
int64_t off = index + (index < 0) * (list->length + 1) - 1; \
if (list->data_refcount > 0) \
- List$compact(list, sizeof(item_type)); \
+ Listヽcompact(list, sizeof(item_type)); \
(item_type*)(list->data + list->stride * off); })
#define List_set(item_type, list, index, value, start, end) \
List_lvalue(item_type, arr_expr, index, start, end) = value
@@ -59,79 +59,79 @@
#define LIST_DECREF(list) (list).data_refcount -= ((list).data_refcount < LIST_MAX_DATA_REFCOUNT)
#define LIST_COPY(list) ({ LIST_INCREF(list); list; })
-#define List$insert_value(list, item_expr, index, padded_item_size) List$insert(list, (__typeof(item_expr)[1]){item_expr}, index, padded_item_size)
-void List$insert(List_t *list, const void *item, Int_t index, int64_t padded_item_size);
-void List$insert_all(List_t *list, List_t to_insert, Int_t index, int64_t padded_item_size);
-void List$remove_at(List_t *list, Int_t index, Int_t count, int64_t padded_item_size);
-void List$remove_item(List_t *list, void *item, Int_t max_removals, const TypeInfo_t *type);
-#define List$remove_item_value(list, item_expr, max, type) List$remove_item(list, (__typeof(item_expr)[1]){item_expr}, max, type)
+#define Listヽinsert_value(list, item_expr, index, padded_item_size) Listヽinsert(list, (__typeof(item_expr)[1]){item_expr}, index, padded_item_size)
+void Listヽinsert(List_t *list, const void *item, Int_t index, int64_t padded_item_size);
+void Listヽinsert_all(List_t *list, List_t to_insert, Int_t index, int64_t padded_item_size);
+void Listヽremove_at(List_t *list, Int_t index, Int_t count, int64_t padded_item_size);
+void Listヽremove_item(List_t *list, void *item, Int_t max_removals, const TypeInfo_t *type);
+#define Listヽremove_item_value(list, item_expr, max, type) Listヽremove_item(list, (__typeof(item_expr)[1]){item_expr}, max, type)
-#define List$pop(arr_expr, index_expr, item_type, nonnone_var, nonnone_expr, none_expr) ({ \
+#define Listヽpop(arr_expr, index_expr, item_type, nonnone_var, nonnone_expr, none_expr) ({ \
List_t *list = arr_expr; \
Int_t index = index_expr; \
- int64_t index64 = Int64$from_int(index, false); \
+ int64_t index64 = Int64ヽfrom_int(index, false); \
int64_t off = index64 + (index64 < 0) * (list->length + 1) - 1; \
(off >= 0 && off < list->length) ? ({ \
item_type nonnone_var = *(item_type*)(list->data + off*list->stride); \
- List$remove_at(list, index, I_small(1), sizeof(item_type)); \
+ Listヽremove_at(list, index, I_small(1), sizeof(item_type)); \
nonnone_expr; \
}) : none_expr; })
-OptionalInt_t List$find(List_t list, void *item, const TypeInfo_t *type);
-#define List$find_value(list, item_expr, type) ({ __typeof(item_expr) item = item_expr; List$find(list, &item, type); })
-OptionalInt_t List$first(List_t list, Closure_t predicate);
-void List$sort(List_t *list, Closure_t comparison, int64_t padded_item_size);
-List_t List$sorted(List_t list, Closure_t comparison, int64_t padded_item_size);
-void List$shuffle(List_t *list, OptionalClosure_t random_int64, int64_t padded_item_size);
-List_t List$shuffled(List_t list, OptionalClosure_t random_int64, int64_t padded_item_size);
-void *List$random(List_t list, OptionalClosure_t random_int64);
-#define List$random_value(list, random_int64, t) ({ List_t _arr = list; if (_arr.length == 0) fail("Cannot get a random value from an empty list!"); *(t*)List$random(_arr, random_int64); })
-List_t List$sample(List_t list, Int_t n, List_t weights, Closure_t random_num, int64_t padded_item_size);
-Table_t List$counts(List_t list, const TypeInfo_t *type);
-void List$clear(List_t *list);
-void List$compact(List_t *list, int64_t padded_item_size);
-PUREFUNC bool List$has(List_t list, void *item, const TypeInfo_t *type);
-#define List$has_value(list, item_expr, type) ({ __typeof(item_expr) item = item_expr; List$has(list, &item, type); })
-PUREFUNC List_t List$from(List_t list, Int_t first);
-PUREFUNC List_t List$to(List_t list, Int_t last);
-PUREFUNC List_t List$by(List_t list, Int_t stride, int64_t padded_item_size);
-PUREFUNC List_t List$slice(List_t list, Int_t int_first, Int_t int_last);
-PUREFUNC List_t List$reversed(List_t list, int64_t padded_item_size);
-List_t List$concat(List_t x, List_t y, int64_t padded_item_size);
-PUREFUNC uint64_t List$hash(const void *list, const TypeInfo_t *type);
-PUREFUNC int32_t List$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool List$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool List$is_none(const void *obj, const TypeInfo_t*);
-Text_t List$as_text(const void *list, bool colorize, const TypeInfo_t *type);
-void List$heapify(List_t *heap, Closure_t comparison, int64_t padded_item_size);
-void List$heap_push(List_t *heap, const void *item, Closure_t comparison, int64_t padded_item_size);
-#define List$heap_push_value(heap, _value, comparison, padded_item_size) ({ __typeof(_value) value = _value; List$heap_push(heap, &value, comparison, padded_item_size); })
-void List$heap_pop(List_t *heap, Closure_t comparison, int64_t padded_item_size);
-#define List$heap_pop_value(heap, comparison, type, nonnone_var, nonnone_expr, none_expr) \
+OptionalInt_t Listヽfind(List_t list, void *item, const TypeInfo_t *type);
+#define Listヽfind_value(list, item_expr, type) ({ __typeof(item_expr) item = item_expr; Listヽfind(list, &item, type); })
+OptionalInt_t Listヽfirst(List_t list, Closure_t predicate);
+void Listヽsort(List_t *list, Closure_t comparison, int64_t padded_item_size);
+List_t Listヽsorted(List_t list, Closure_t comparison, int64_t padded_item_size);
+void Listヽshuffle(List_t *list, OptionalClosure_t random_int64, int64_t padded_item_size);
+List_t Listヽshuffled(List_t list, OptionalClosure_t random_int64, int64_t padded_item_size);
+void *Listヽrandom(List_t list, OptionalClosure_t random_int64);
+#define Listヽrandom_value(list, random_int64, t) ({ List_t _arr = list; if (_arr.length == 0) fail("Cannot get a random value from an empty list!"); *(t*)Listヽrandom(_arr, random_int64); })
+List_t Listヽsample(List_t list, Int_t n, List_t weights, Closure_t random_num, int64_t padded_item_size);
+Table_t Listヽcounts(List_t list, const TypeInfo_t *type);
+void Listヽclear(List_t *list);
+void Listヽcompact(List_t *list, int64_t padded_item_size);
+PUREFUNC bool Listヽhas(List_t list, void *item, const TypeInfo_t *type);
+#define Listヽhas_value(list, item_expr, type) ({ __typeof(item_expr) item = item_expr; Listヽhas(list, &item, type); })
+PUREFUNC List_t Listヽfrom(List_t list, Int_t first);
+PUREFUNC List_t Listヽto(List_t list, Int_t last);
+PUREFUNC List_t Listヽby(List_t list, Int_t stride, int64_t padded_item_size);
+PUREFUNC List_t Listヽslice(List_t list, Int_t int_first, Int_t int_last);
+PUREFUNC List_t Listヽreversed(List_t list, int64_t padded_item_size);
+List_t Listヽconcat(List_t x, List_t y, int64_t padded_item_size);
+PUREFUNC uint64_t Listヽhash(const void *list, const TypeInfo_t *type);
+PUREFUNC int32_t Listヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Listヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Listヽis_none(const void *obj, const TypeInfo_t*);
+Text_t Listヽas_text(const void *list, bool colorize, const TypeInfo_t *type);
+void Listヽheapify(List_t *heap, Closure_t comparison, int64_t padded_item_size);
+void Listヽheap_push(List_t *heap, const void *item, Closure_t comparison, int64_t padded_item_size);
+#define Listヽheap_push_value(heap, _value, comparison, padded_item_size) ({ __typeof(_value) value = _value; Listヽheap_push(heap, &value, comparison, padded_item_size); })
+void Listヽheap_pop(List_t *heap, Closure_t comparison, int64_t padded_item_size);
+#define Listヽheap_pop_value(heap, comparison, type, nonnone_var, nonnone_expr, none_expr) \
({ List_t *_heap = heap; \
(_heap->length > 0) ? ({ \
type nonnone_var = *(type*)_heap->data; \
- List$heap_pop(_heap, comparison, sizeof(type)); \
+ Listヽheap_pop(_heap, comparison, sizeof(type)); \
nonnone_expr; \
}) : none_expr; })
-Int_t List$binary_search(List_t list, void *target, Closure_t comparison);
-#define List$binary_search_value(list, target, comparison) \
- ({ __typeof(target) _target = target; List$binary_search(list, &_target, comparison); })
-void List$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void List$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type);
+Int_t Listヽbinary_search(List_t list, void *target, Closure_t comparison);
+#define Listヽbinary_search_value(list, target, comparison) \
+ ({ __typeof(target) _target = target; Listヽbinary_search(list, &_target, comparison); })
+void Listヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Listヽdeserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type);
-#define List$metamethods { \
- .as_text=List$as_text, \
- .compare=List$compare, \
- .equal=List$equal, \
- .hash=List$hash, \
- .is_none=List$is_none, \
- .serialize=List$serialize, \
- .deserialize=List$deserialize, \
+#define Listヽmetamethods { \
+ .as_text=Listヽas_text, \
+ .compare=Listヽcompare, \
+ .equal=Listヽequal, \
+ .hash=Listヽhash, \
+ .is_none=Listヽis_none, \
+ .serialize=Listヽserialize, \
+ .deserialize=Listヽdeserialize, \
}
-#define List$info(item_info) &((TypeInfo_t){.size=sizeof(List_t), .align=__alignof__(List_t), \
+#define Listヽinfo(item_info) &((TypeInfo_t){.size=sizeof(List_t), .align=__alignof__(List_t), \
.tag=ListInfo, .ListInfo.item=item_info, \
- .metamethods=List$metamethods})
+ .metamethods=Listヽmetamethods})
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/memory.c b/src/stdlib/memory.c
index 46729f83..21893fd0 100644
--- a/src/stdlib/memory.c
+++ b/src/stdlib/memory.c
@@ -13,18 +13,18 @@
#include "types.h"
#include "util.h"
-public Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo_t *info) {
+public Text_t Memoryヽas_text(const void *p, bool colorize, const TypeInfo_t *info) {
(void)info;
if (!p) return Text("Memory");
- Text_t text = Text$from_str(String("Memory<", *(void**)p, ">"));
+ Text_t text = Textヽfrom_str(String("Memory<", *(void**)p, ">"));
return colorize ? Texts(Text("\x1b[0;34;1m"), text, Text("\x1b[m")) : text;
}
-public const TypeInfo_t Memory$info = {
+public const TypeInfo_t Memoryヽinfo = {
.size=0,
.align=0,
.metamethods={
- .as_text=Memory$as_text,
+ .as_text=Memoryヽas_text,
.serialize=cannot_serialize,
.deserialize=cannot_deserialize,
},
diff --git a/src/stdlib/memory.h b/src/stdlib/memory.h
index e03d5931..c8a777e6 100644
--- a/src/stdlib/memory.h
+++ b/src/stdlib/memory.h
@@ -7,7 +7,7 @@
#include "types.h"
-extern const TypeInfo_t Memory$info;
-Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo_t *type);
+extern const TypeInfo_t Memoryヽinfo;
+Text_t Memoryヽas_text(const void *p, bool colorize, const TypeInfo_t *type);
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/metamethods.c b/src/stdlib/metamethods.c
index e007a52c..7c12a724 100644
--- a/src/stdlib/metamethods.c
+++ b/src/stdlib/metamethods.c
@@ -94,7 +94,7 @@ public void _deserialize(FILE *input, void *outval, List_t *pointers, const Type
public void generic_deserialize(List_t bytes, void *outval, const TypeInfo_t *type)
{
if (bytes.stride != 1)
- List$compact(&bytes, 1);
+ Listヽcompact(&bytes, 1);
FILE *input = fmemopen(bytes.data, (size_t)bytes.length, "r");
List_t pointers = {};
@@ -105,7 +105,7 @@ public void generic_deserialize(List_t bytes, void *outval, const TypeInfo_t *ty
public int generic_print(const void *obj, bool colorize, const TypeInfo_t *type)
{
Text_t text = generic_as_text(obj, colorize, type);
- return Text$print(stdout, text) + fputc('\n', stdout);
+ return Textヽprint(stdout, text) + fputc('\n', stdout);
}
__attribute__((noreturn))
diff --git a/src/stdlib/nums.c b/src/stdlib/nums.c
index 3775c8f4..7627c887 100644
--- a/src/stdlib/nums.c
+++ b/src/stdlib/nums.c
@@ -14,17 +14,17 @@
#include "text.h"
#include "types.h"
-public PUREFUNC Text_t Num$as_text(const void *f, bool colorize, const TypeInfo_t *info) {
+public PUREFUNC Text_t Numヽas_text(const void *f, bool colorize, const TypeInfo_t *info) {
(void)info;
if (!f) return Text("Num");
char *str = GC_MALLOC_ATOMIC(24);
int len = fpconv_dtoa(*(double*)f, str);
static const Text_t color_prefix = Text("\x1b[35m"), color_suffix = Text("\x1b[m");
- Text_t text = Text$from_strn(str, (size_t)len);
+ Text_t text = Textヽfrom_strn(str, (size_t)len);
return colorize ? Texts(color_prefix, text, color_suffix) : text;
}
-public PUREFUNC int32_t Num$compare(const void *x, const void *y, const TypeInfo_t *info) {
+public PUREFUNC int32_t Numヽcompare(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
int64_t rx = *(int64_t*)x,
ry = *(int64_t*)y;
@@ -37,12 +37,12 @@ public PUREFUNC int32_t Num$compare(const void *x, const void *y, const TypeInfo
return (rx > ry) - (rx < ry);
}
-public PUREFUNC bool Num$equal(const void *x, const void *y, const TypeInfo_t *info) {
+public PUREFUNC bool Numヽequal(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
return *(double*)x == *(double*)y;
}
-public CONSTFUNC bool Num$near(double a, double b, double ratio, double absolute) {
+public CONSTFUNC bool Numヽnear(double a, double b, double ratio, double absolute) {
if (ratio < 0) ratio = 0;
else if (ratio > 1) ratio = 1;
@@ -57,13 +57,13 @@ public CONSTFUNC bool Num$near(double a, double b, double ratio, double absolute
return (diff < epsilon);
}
-public Text_t Num$percent(double f, double precision) {
+public Text_t Numヽpercent(double f, double precision) {
double d = 100. * f;
- d = Num$with_precision(d, precision);
- return Texts(Num$as_text(&d, false, &Num$info), Text("%"));
+ d = Numヽwith_precision(d, precision);
+ return Texts(Numヽas_text(&d, false, &Numヽinfo), Text("%"));
}
-public CONSTFUNC double Num$with_precision(double num, double precision) {
+public CONSTFUNC double Numヽwith_precision(double num, double precision) {
if (precision == 0.0) return num;
// Precision will be, e.g. 0.01 or 100.
if (precision < 1.) {
@@ -76,35 +76,35 @@ public CONSTFUNC double Num$with_precision(double num, double precision) {
}
}
-public CONSTFUNC double Num$mod(double num, double modulus) {
+public CONSTFUNC double Numヽmod(double num, double modulus) {
// Euclidean division, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
double r = remainder(num, modulus);
r -= (r < 0) * (2*(modulus < 0) - 1) * modulus;
return r;
}
-public CONSTFUNC double Num$mod1(double num, double modulus) {
- return 1.0 + Num$mod(num-1, modulus);
+public CONSTFUNC double Numヽmod1(double num, double modulus) {
+ return 1.0 + Numヽmod(num-1, modulus);
}
-public CONSTFUNC double Num$mix(double amount, double x, double y) {
+public CONSTFUNC double Numヽmix(double amount, double x, double y) {
return (1.0-amount)*x + amount*y;
}
-public CONSTFUNC bool Num$is_between(const double x, const double low, const double high) {
+public CONSTFUNC bool Numヽis_between(const double x, const double low, const double high) {
return low <= x && x <= high;
}
-public CONSTFUNC double Num$clamped(double x, double low, double high) {
+public CONSTFUNC double Numヽclamped(double x, double low, double high) {
return (x <= low) ? low : (x >= high ? high : x);
}
-public OptionalNum_t Num$parse(Text_t text, Text_t *remainder) {
- const char *str = Text$as_c_string(text);
+public OptionalNum_t Numヽparse(Text_t text, Text_t *remainder) {
+ const char *str = Textヽas_c_string(text);
char *end = NULL;
double d = strtod(str, &end);
if (end > str) {
if (remainder)
- *remainder = Text$from_str(end);
+ *remainder = Textヽfrom_str(end);
else if (*end != '\0')
return nan("none");
return d;
@@ -114,45 +114,45 @@ public OptionalNum_t Num$parse(Text_t text, Text_t *remainder) {
}
}
-static bool Num$is_none(const void *n, const TypeInfo_t *info)
+static bool Numヽis_none(const void *n, const TypeInfo_t *info)
{
(void)info;
return isnan(*(Num_t*)n);
}
-public CONSTFUNC bool Num$isinf(double n) { return (fpclassify(n) == FP_INFINITE); }
-public CONSTFUNC bool Num$finite(double n) { return (fpclassify(n) != FP_INFINITE); }
-public CONSTFUNC bool Num$isnan(double n) { return (fpclassify(n) == FP_NAN); }
+public CONSTFUNC bool Numヽisinf(double n) { return (fpclassify(n) == FP_INFINITE); }
+public CONSTFUNC bool Numヽfinite(double n) { return (fpclassify(n) != FP_INFINITE); }
+public CONSTFUNC bool Numヽisnan(double n) { return (fpclassify(n) == FP_NAN); }
-public const TypeInfo_t Num$info = {
+public const TypeInfo_t Numヽinfo = {
.size=sizeof(double),
.align=__alignof__(double),
.metamethods={
- .compare=Num$compare,
- .equal=Num$equal,
- .as_text=Num$as_text,
- .is_none=Num$is_none,
+ .compare=Numヽcompare,
+ .equal=Numヽequal,
+ .as_text=Numヽas_text,
+ .is_none=Numヽis_none,
},
};
-public PUREFUNC Text_t Num32$as_text(const void *f, bool colorize, const TypeInfo_t *info) {
+public PUREFUNC Text_t Num32ヽas_text(const void *f, bool colorize, const TypeInfo_t *info) {
(void)info;
if (!f) return Text("Num32");
double d = (double)(*(float*)f);
- return Num$as_text(&d, colorize, &Num$info);
+ return Numヽas_text(&d, colorize, &Numヽinfo);
}
-public PUREFUNC int32_t Num32$compare(const void *x, const void *y, const TypeInfo_t *info) {
+public PUREFUNC int32_t Num32ヽcompare(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
return (*(float*)x > *(float*)y) - (*(float*)x < *(float*)y);
}
-public PUREFUNC bool Num32$equal(const void *x, const void *y, const TypeInfo_t *info) {
+public PUREFUNC bool Num32ヽequal(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
return *(float*)x == *(float*)y;
}
-public CONSTFUNC bool Num32$near(float a, float b, float ratio, float absolute) {
+public CONSTFUNC bool Num32ヽnear(float a, float b, float ratio, float absolute) {
if (ratio < 0) ratio = 0;
else if (ratio > 1) ratio = 1;
@@ -167,13 +167,13 @@ public CONSTFUNC bool Num32$near(float a, float b, float ratio, float absolute)
return (diff < epsilon);
}
-public Text_t Num32$percent(float f, float precision) {
+public Text_t Num32ヽpercent(float f, float precision) {
double d = 100. * (double)f;
- d = Num$with_precision(d, (double)precision);
- return Texts(Num$as_text(&d, false, &Num$info), Text("%"));
+ d = Numヽwith_precision(d, (double)precision);
+ return Texts(Numヽas_text(&d, false, &Numヽinfo), Text("%"));
}
-public CONSTFUNC float Num32$with_precision(float num, float precision) {
+public CONSTFUNC float Num32ヽwith_precision(float num, float precision) {
if (precision == 0.0f) return num;
// Precision will be, e.g. 0.01 or 100.
if (precision < 1.f) {
@@ -186,35 +186,35 @@ public CONSTFUNC float Num32$with_precision(float num, float precision) {
}
}
-public CONSTFUNC float Num32$mod(float num, float modulus) {
+public CONSTFUNC float Num32ヽmod(float num, float modulus) {
// Euclidean division, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf
float r = remainderf(num, modulus);
r -= (r < 0) * (2*(modulus < 0) - 1) * modulus;
return r;
}
-public CONSTFUNC float Num32$mod1(float num, float modulus) {
- return 1.0f + Num32$mod(num-1, modulus);
+public CONSTFUNC float Num32ヽmod1(float num, float modulus) {
+ return 1.0f + Num32ヽmod(num-1, modulus);
}
-public CONSTFUNC float Num32$mix(float amount, float x, float y) {
+public CONSTFUNC float Num32ヽmix(float amount, float x, float y) {
return (1.0f-amount)*x + amount*y;
}
-public CONSTFUNC bool Num32$is_between(const float x, const float low, const float high) {
+public CONSTFUNC bool Num32ヽis_between(const float x, const float low, const float high) {
return low <= x && x <= high;
}
-public CONSTFUNC float Num32$clamped(float x, float low, float high) {
+public CONSTFUNC float Num32ヽclamped(float x, float low, float high) {
return (x <= low) ? low : (x >= high ? high : x);
}
-public OptionalNum32_t Num32$parse(Text_t text, Text_t *remainder) {
- const char *str = Text$as_c_string(text);
+public OptionalNum32_t Num32ヽparse(Text_t text, Text_t *remainder) {
+ const char *str = Textヽas_c_string(text);
char *end = NULL;
double d = strtod(str, &end);
if (end > str && end[0] == '\0') {
- if (remainder) *remainder = Text$from_str(end);
+ if (remainder) *remainder = Textヽfrom_str(end);
else if (*end != '\0')
return nan("none");
return d;
@@ -224,24 +224,24 @@ public OptionalNum32_t Num32$parse(Text_t text, Text_t *remainder) {
}
}
-static bool Num32$is_none(const void *n, const TypeInfo_t *info)
+static bool Num32ヽis_none(const void *n, const TypeInfo_t *info)
{
(void)info;
return isnan(*(Num32_t*)n);
}
-public CONSTFUNC bool Num32$isinf(float n) { return (fpclassify(n) == FP_INFINITE); }
-public CONSTFUNC bool Num32$finite(float n) { return (fpclassify(n) != FP_INFINITE); }
-public CONSTFUNC bool Num32$isnan(float n) { return (fpclassify(n) == FP_NAN); }
+public CONSTFUNC bool Num32ヽisinf(float n) { return (fpclassify(n) == FP_INFINITE); }
+public CONSTFUNC bool Num32ヽfinite(float n) { return (fpclassify(n) != FP_INFINITE); }
+public CONSTFUNC bool Num32ヽisnan(float n) { return (fpclassify(n) == FP_NAN); }
-public const TypeInfo_t Num32$info = {
+public const TypeInfo_t Num32ヽinfo = {
.size=sizeof(float),
.align=__alignof__(float),
.metamethods={
- .compare=Num32$compare,
- .equal=Num32$equal,
- .as_text=Num32$as_text,
- .is_none=Num32$is_none,
+ .compare=Num32ヽcompare,
+ .equal=Num32ヽequal,
+ .as_text=Num32ヽas_text,
+ .is_none=Num32ヽis_none,
},
};
diff --git a/src/stdlib/nums.h b/src/stdlib/nums.h
index fe76d1c3..1b757e4e 100644
--- a/src/stdlib/nums.h
+++ b/src/stdlib/nums.h
@@ -17,28 +17,28 @@
#define N32(n) ((float)(n))
#define N64(n) ((double)(n))
-Text_t Num$as_text(const void *f, bool colorize, const TypeInfo_t *type);
-PUREFUNC int32_t Num$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Num$equal(const void *x, const void *y, const TypeInfo_t *type);
-CONSTFUNC bool Num$near(double a, double b, double ratio, double absolute);
-Text_t Num$percent(double f, double precision);
-double CONSTFUNC Num$with_precision(double num, double precision);
-double Num$mod(double num, double modulus);
-double Num$mod1(double num, double modulus);
-CONSTFUNC bool Num$isinf(double n);
-CONSTFUNC bool Num$finite(double n);
-CONSTFUNC bool Num$isnan(double n);
-double Num$nan(Text_t tag);
-CONSTFUNC double Num$mix(double amount, double x, double y);
-OptionalNum_t Num$parse(Text_t text, Text_t *remainder);
-CONSTFUNC bool Num$is_between(const double x, const double low, const double high);
-CONSTFUNC double Num$clamped(double x, double low, double high);
-MACROLIKE CONSTFUNC double Num$from_num32(Num32_t n) { return (double)n; }
+Text_t Numヽas_text(const void *f, bool colorize, const TypeInfo_t *type);
+PUREFUNC int32_t Numヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Numヽequal(const void *x, const void *y, const TypeInfo_t *type);
+CONSTFUNC bool Numヽnear(double a, double b, double ratio, double absolute);
+Text_t Numヽpercent(double f, double precision);
+double CONSTFUNC Numヽwith_precision(double num, double precision);
+double Numヽmod(double num, double modulus);
+double Numヽmod1(double num, double modulus);
+CONSTFUNC bool Numヽisinf(double n);
+CONSTFUNC bool Numヽfinite(double n);
+CONSTFUNC bool Numヽisnan(double n);
+double Numヽnan(Text_t tag);
+CONSTFUNC double Numヽmix(double amount, double x, double y);
+OptionalNum_t Numヽparse(Text_t text, Text_t *remainder);
+CONSTFUNC bool Numヽis_between(const double x, const double low, const double high);
+CONSTFUNC double Numヽclamped(double x, double low, double high);
+MACROLIKE CONSTFUNC double Numヽfrom_num32(Num32_t n) { return (double)n; }
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
-MACROLIKE CONSTFUNC double Num$from_int(Int_t i, bool truncate) {
+MACROLIKE CONSTFUNC double Numヽfrom_int(Int_t i, bool truncate) {
if likely (i.small & 0x1) {
double ret = (double)(i.small >> 2);
if unlikely (!truncate && (int64_t)ret != (i.small >> 2))
@@ -58,41 +58,41 @@ MACROLIKE CONSTFUNC double Num$from_int(Int_t i, bool truncate) {
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
-MACROLIKE CONSTFUNC double Num$from_int64(Int64_t i, bool truncate) {
+MACROLIKE CONSTFUNC double Numヽfrom_int64(Int64_t i, bool truncate) {
double n = (double)i;
if unlikely (!truncate && (Int64_t)n != i)
fail("Could not convert integer to 64-bit floating point without losing precision: ", i);
return n;
}
-MACROLIKE CONSTFUNC double Num$from_int32(Int32_t i) { return (double)i; }
-MACROLIKE CONSTFUNC double Num$from_int16(Int16_t i) { return (double)i; }
-MACROLIKE CONSTFUNC double Num$from_int8(Int8_t i) { return (double)i; }
-MACROLIKE CONSTFUNC double Num$from_byte(Byte_t i) { return (double)i; }
+MACROLIKE CONSTFUNC double Numヽfrom_int32(Int32_t i) { return (double)i; }
+MACROLIKE CONSTFUNC double Numヽfrom_int16(Int16_t i) { return (double)i; }
+MACROLIKE CONSTFUNC double Numヽfrom_int8(Int8_t i) { return (double)i; }
+MACROLIKE CONSTFUNC double Numヽfrom_byte(Byte_t i) { return (double)i; }
-extern const TypeInfo_t Num$info;
+extern const TypeInfo_t Numヽinfo;
-Text_t Num32$as_text(const void *f, bool colorize, const TypeInfo_t *type);
-PUREFUNC int32_t Num32$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Num32$equal(const void *x, const void *y, const TypeInfo_t *type);
-CONSTFUNC bool Num32$near(float a, float b, float ratio, float absolute);
-Text_t Num32$percent(float f, float precision);
-float CONSTFUNC Num32$with_precision(float num, float precision);
-float Num32$mod(float num, float modulus);
-float Num32$mod1(float num, float modulus);
-CONSTFUNC bool Num32$isinf(float n);
-CONSTFUNC bool Num32$finite(float n);
-CONSTFUNC bool Num32$isnan(float n);
-CONSTFUNC float Num32$mix(float amount, float x, float y);
-OptionalNum32_t Num32$parse(Text_t text, Text_t *remainder);
-float Num32$nan(Text_t tag);
-CONSTFUNC bool Num32$is_between(const float x, const float low, const float high);
-CONSTFUNC float Num32$clamped(float x, float low, float high);
-MACROLIKE CONSTFUNC float Num32$from_num(Num_t n) { return (float)n; }
+Text_t Num32ヽas_text(const void *f, bool colorize, const TypeInfo_t *type);
+PUREFUNC int32_t Num32ヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Num32ヽequal(const void *x, const void *y, const TypeInfo_t *type);
+CONSTFUNC bool Num32ヽnear(float a, float b, float ratio, float absolute);
+Text_t Num32ヽpercent(float f, float precision);
+float CONSTFUNC Num32ヽwith_precision(float num, float precision);
+float Num32ヽmod(float num, float modulus);
+float Num32ヽmod1(float num, float modulus);
+CONSTFUNC bool Num32ヽisinf(float n);
+CONSTFUNC bool Num32ヽfinite(float n);
+CONSTFUNC bool Num32ヽisnan(float n);
+CONSTFUNC float Num32ヽmix(float amount, float x, float y);
+OptionalNum32_t Num32ヽparse(Text_t text, Text_t *remainder);
+float Num32ヽnan(Text_t tag);
+CONSTFUNC bool Num32ヽis_between(const float x, const float low, const float high);
+CONSTFUNC float Num32ヽclamped(float x, float low, float high);
+MACROLIKE CONSTFUNC float Num32ヽfrom_num(Num_t n) { return (float)n; }
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
-MACROLIKE CONSTFUNC float Num32$from_int(Int_t i, bool truncate) {
+MACROLIKE CONSTFUNC float Num32ヽfrom_int(Int_t i, bool truncate) {
if likely (i.small & 0x1) {
float ret = (float)(i.small >> 2);
if unlikely (!truncate && (int64_t)ret != (i.small >> 2))
@@ -112,22 +112,22 @@ MACROLIKE CONSTFUNC float Num32$from_int(Int_t i, bool truncate) {
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
-MACROLIKE CONSTFUNC float Num32$from_int64(Int64_t i, bool truncate) {
+MACROLIKE CONSTFUNC float Num32ヽfrom_int64(Int64_t i, bool truncate) {
float n = (float)i;
if unlikely (!truncate && (Int64_t)n != i)
fail("Could not convert integer to 32-bit floating point without losing precision: ", i);
return n;
}
-MACROLIKE CONSTFUNC float Num32$from_int32(Int32_t i, bool truncate) {
+MACROLIKE CONSTFUNC float Num32ヽfrom_int32(Int32_t i, bool truncate) {
float n = (float)i;
if unlikely (!truncate && (Int32_t)n != i)
fail("Could not convert integer to 32-bit floating point without losing precision: ", i);
return n;
}
-MACROLIKE CONSTFUNC float Num32$from_int16(Int16_t i) { return (float)i; }
-MACROLIKE CONSTFUNC float Num32$from_int8(Int8_t i) { return (float)i; }
-MACROLIKE CONSTFUNC float Num32$from_byte(Byte_t i) { return (float)i; }
+MACROLIKE CONSTFUNC float Num32ヽfrom_int16(Int16_t i) { return (float)i; }
+MACROLIKE CONSTFUNC float Num32ヽfrom_int8(Int8_t i) { return (float)i; }
+MACROLIKE CONSTFUNC float Num32ヽfrom_byte(Byte_t i) { return (float)i; }
-extern const TypeInfo_t Num32$info;
+extern const TypeInfo_t Num32ヽinfo;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/optionals.c b/src/stdlib/optionals.c
index ead9428a..9aaf5400 100644
--- a/src/stdlib/optionals.c
+++ b/src/stdlib/optionals.c
@@ -18,12 +18,12 @@ public PUREFUNC bool is_none(const void *obj, const TypeInfo_t *non_optional_typ
return *(bool*)dest;
}
-PUREFUNC public uint64_t Optional$hash(const void *obj, const TypeInfo_t *type)
+PUREFUNC public uint64_t Optionalヽhash(const void *obj, const TypeInfo_t *type)
{
return is_none(obj, type->OptionalInfo.type) ? 0 : generic_hash(obj, type->OptionalInfo.type);
}
-PUREFUNC public int32_t Optional$compare(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public int32_t Optionalヽcompare(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y) return 0;
bool x_is_null = is_none(x, type->OptionalInfo.type);
@@ -33,7 +33,7 @@ PUREFUNC public int32_t Optional$compare(const void *x, const void *y, const Typ
else return generic_compare(x, y, type->OptionalInfo.type);
}
-PUREFUNC public bool Optional$equal(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public bool Optionalヽequal(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y) return true;
@@ -44,17 +44,17 @@ PUREFUNC public bool Optional$equal(const void *x, const void *y, const TypeInfo
else return generic_equal(x, y, type->OptionalInfo.type);
}
-public Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t *type)
+public Text_t Optionalヽas_text(const void *obj, bool colorize, const TypeInfo_t *type)
{
if (!obj)
- return Text$concat(generic_as_text(obj, colorize, type->OptionalInfo.type), Text("?"));
+ return Textヽconcat(generic_as_text(obj, colorize, type->OptionalInfo.type), Text("?"));
if (is_none(obj, type->OptionalInfo.type))
return colorize ? Text("\x1b[31mnone\x1b[m") : Text("none");
return generic_as_text(obj, colorize, type->OptionalInfo.type);
}
-public void Optional$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Optionalヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
bool has_value = !is_none(obj, type->OptionalInfo.type);
assert(fputc((int)has_value, out) != EOF);
@@ -62,7 +62,7 @@ public void Optional$serialize(const void *obj, FILE *out, Table_t *pointers, co
_serialize(obj, out, pointers, type->OptionalInfo.type);
}
-public void Optional$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
+public void Optionalヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
{
bool has_value = (bool)fgetc(in);
const TypeInfo_t *nonnull = type->OptionalInfo.type;
@@ -76,9 +76,9 @@ public void Optional$deserialize(FILE *in, void *outval, List_t *pointers, const
*(List_t*)outval = (List_t){.length=-1};
else if (nonnull->tag == TableInfo)
*(Table_t*)outval = (Table_t){.entries={.length=-1}};
- else if (nonnull == &Num$info)
+ else if (nonnull == &Numヽinfo)
*(double*)outval = (double)NAN;
- else if (nonnull == &Num32$info)
+ else if (nonnull == &Num32ヽinfo)
*(float*)outval = (float)NAN;
else if (nonnull->tag == StructInfo || (nonnull->tag == OpaqueInfo && type->size > nonnull->size))
memset(outval + type->size, -1, (size_t)(type->size - nonnull->size));
diff --git a/src/stdlib/optionals.h b/src/stdlib/optionals.h
index 5be52e93..223cf47b 100644
--- a/src/stdlib/optionals.h
+++ b/src/stdlib/optionals.h
@@ -19,24 +19,24 @@
#define NONE_PATH ((Path_t){.type=PATH_NONE})
PUREFUNC bool is_none(const void *obj, const TypeInfo_t *non_optional_type);
-PUREFUNC uint64_t Optional$hash(const void *obj, const TypeInfo_t *type);
-PUREFUNC int32_t Optional$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Optional$equal(const void *x, const void *y, const TypeInfo_t *type);
-Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t *type);
-void Optional$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void Optional$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
-
-#define Optional$metamethods { \
- .hash=Optional$hash, \
- .compare=Optional$compare, \
- .equal=Optional$equal, \
- .as_text=Optional$as_text, \
- .serialize=Optional$serialize, \
- .deserialize=Optional$deserialize, \
+PUREFUNC uint64_t Optionalヽhash(const void *obj, const TypeInfo_t *type);
+PUREFUNC int32_t Optionalヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Optionalヽequal(const void *x, const void *y, const TypeInfo_t *type);
+Text_t Optionalヽas_text(const void *obj, bool colorize, const TypeInfo_t *type);
+void Optionalヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Optionalヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
+
+#define Optionalヽmetamethods { \
+ .hash=Optionalヽhash, \
+ .compare=Optionalヽcompare, \
+ .equal=Optionalヽequal, \
+ .as_text=Optionalヽas_text, \
+ .serialize=Optionalヽserialize, \
+ .deserialize=Optionalヽdeserialize, \
}
-#define Optional$info(_size, _align, t) &((TypeInfo_t){.size=_size, .align=_align, \
+#define Optionalヽinfo(_size, _align, t) &((TypeInfo_t){.size=_size, .align=_align, \
.tag=OptionalInfo, .OptionalInfo.type=t, \
- .metamethods=Optional$metamethods})
+ .metamethods=Optionalヽmetamethods})
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index 58702ec7..8aa57f17 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -33,20 +33,20 @@
#include "siphash.h"
#include "siphash-internals.h"
-static const Path_t HOME_PATH = {.type.$tag=PATH_HOME},
- ROOT_PATH = {.type.$tag=PATH_ABSOLUTE},
- CURDIR_PATH = {.type.$tag=PATH_RELATIVE};
+static const Path_t HOME_PATH = {.type.ヽtag=PATH_HOME},
+ ROOT_PATH = {.type.ヽtag=PATH_ABSOLUTE},
+ CURDIR_PATH = {.type.ヽtag=PATH_RELATIVE};
static void clean_components(List_t *components)
{
for (int64_t i = 0; i < components->length; ) {
Text_t *component = (Text_t*)(components->data + i*components->stride);
- if (component->length == 0 || Text$equal_values(*component, Text("."))) {
- List$remove_at(components, I(i+1), I(1), sizeof(Text_t));
- } else if (i > 0 && Text$equal_values(*component, Text(".."))) {
+ if (component->length == 0 || Textヽequal_values(*component, Text("."))) {
+ Listヽremove_at(components, I(i+1), I(1), sizeof(Text_t));
+ } else if (i > 0 && Textヽequal_values(*component, Text(".."))) {
Text_t *prev = (Text_t*)(components->data + (i-1)*components->stride);
- if (!Text$equal_values(*prev, Text(".."))) {
- List$remove_at(components, I(i), I(2), sizeof(Text_t));
+ if (!Textヽequal_values(*prev, Text(".."))) {
+ Listヽremove_at(components, I(i), I(2), sizeof(Text_t));
i -= 1;
} else {
i += 1;
@@ -57,7 +57,7 @@ static void clean_components(List_t *components)
}
}
-public Path_t Path$from_str(const char *str)
+public Path_t Pathヽfrom_str(const char *str)
{
if (!str || str[0] == '\0' || streq(str, "/")) return ROOT_PATH;
else if (streq(str, "~")) return HOME_PATH;
@@ -68,16 +68,16 @@ public Path_t Path$from_str(const char *str)
Path_t result = {.components={}};
if (str[0] == '/') {
- result.type.$tag = PATH_ABSOLUTE;
+ result.type.ヽtag = PATH_ABSOLUTE;
str += 1;
} else if (str[0] == '~' && str[1] == '/') {
- result.type.$tag = PATH_HOME;
+ result.type.ヽtag = PATH_HOME;
str += 2;
} else if (str[0] == '.' && str[1] == '/') {
- result.type.$tag = PATH_RELATIVE;
+ result.type.ヽtag = PATH_RELATIVE;
str += 2;
} else {
- result.type.$tag = PATH_RELATIVE;
+ result.type.ヽtag = PATH_RELATIVE;
}
while (str && *str) {
@@ -87,12 +87,12 @@ public Path_t Path$from_str(const char *str)
// ignore /./
} else if (component_len == 2 && strncmp(str, "..", 2) == 0
&& result.components.length > 1
- && !Text$equal_values(Text(".."), *(Text_t*)(result.components.data + result.components.stride*(result.components.length-1)))) {
+ && !Textヽequal_values(Text(".."), *(Text_t*)(result.components.data + result.components.stride*(result.components.length-1)))) {
// Pop off /foo/baz/.. -> /foo
- List$remove_at(&result.components, I(result.components.length), I(1), sizeof(Text_t));
+ Listヽremove_at(&result.components, I(result.components.length), I(1), sizeof(Text_t));
} else {
- Text_t component = Text$from_strn(str, component_len);
- List$insert_value(&result.components, component, I(0), sizeof(Text_t));
+ Text_t component = Textヽfrom_strn(str, component_len);
+ Listヽinsert_value(&result.components, component, I(0), sizeof(Text_t));
}
str += component_len;
}
@@ -101,90 +101,90 @@ public Path_t Path$from_str(const char *str)
return result;
}
-public Path_t Path$from_text(Text_t text)
+public Path_t Pathヽfrom_text(Text_t text)
{
- return Path$from_str(Text$as_c_string(text));
+ return Pathヽfrom_str(Textヽas_c_string(text));
}
-public Path_t Path$expand_home(Path_t path)
+public Path_t Pathヽexpand_home(Path_t path)
{
- if (path.type.$tag == PATH_HOME) {
- Path_t pwd = Path$from_str(getenv("HOME"));
- List_t components = List$concat(pwd.components, path.components, sizeof(Text_t));
+ if (path.type.ヽtag == PATH_HOME) {
+ Path_t pwd = Pathヽfrom_str(getenv("HOME"));
+ List_t components = Listヽconcat(pwd.components, path.components, sizeof(Text_t));
assert(components.length == path.components.length + pwd.components.length);
clean_components(&components);
- path = (Path_t){.type.$tag=PATH_ABSOLUTE, .components=components};
+ path = (Path_t){.type.ヽtag=PATH_ABSOLUTE, .components=components};
}
return path;
}
-public Path_t Path$_concat(int n, Path_t items[n])
+public Path_t Pathヽ_concat(int n, Path_t items[n])
{
assert(n > 0);
Path_t result = items[0];
LIST_INCREF(result.components);
for (int i = 1; i < n; i++) {
- if (items[i].type.$tag != PATH_RELATIVE)
+ if (items[i].type.ヽtag != PATH_RELATIVE)
fail("Cannot concatenate an absolute or home-based path onto another path: (", items[i], ")");
- List$insert_all(&result.components, items[i].components, I(0), sizeof(Text_t));
+ Listヽinsert_all(&result.components, items[i].components, I(0), sizeof(Text_t));
}
clean_components(&result.components);
return result;
}
-public Path_t Path$resolved(Path_t path, Path_t relative_to)
+public Path_t Pathヽresolved(Path_t path, Path_t relative_to)
{
- if (path.type.$tag == PATH_RELATIVE && !(relative_to.type.$tag == PATH_RELATIVE && relative_to.components.length == 0)) {
- Path_t result = {.type.$tag=relative_to.type.$tag};
+ if (path.type.ヽtag == PATH_RELATIVE && !(relative_to.type.ヽtag == PATH_RELATIVE && relative_to.components.length == 0)) {
+ Path_t result = {.type.ヽtag=relative_to.type.ヽtag};
result.components = relative_to.components;
LIST_INCREF(result.components);
- List$insert_all(&result.components, path.components, I(0), sizeof(Text_t));
+ Listヽinsert_all(&result.components, path.components, I(0), sizeof(Text_t));
clean_components(&result.components);
return result;
}
return path;
}
-public Path_t Path$relative_to(Path_t path, Path_t relative_to)
+public Path_t Pathヽrelative_to(Path_t path, Path_t relative_to)
{
- if (path.type.$tag != relative_to.type.$tag)
+ if (path.type.ヽtag != relative_to.type.ヽtag)
fail("Cannot create a path relative to a different path with a mismatching type: (", path, ") relative to (", relative_to, ")");
- Path_t result = {.type.$tag=PATH_RELATIVE};
+ Path_t result = {.type.ヽtag=PATH_RELATIVE};
int64_t shared = 0;
for (; shared < path.components.length && shared < relative_to.components.length; shared++) {
Text_t *p = (Text_t*)(path.components.data + shared*path.components.stride);
Text_t *r = (Text_t*)(relative_to.components.data + shared*relative_to.components.stride);
- if (!Text$equal_values(*p, *r))
+ if (!Textヽequal_values(*p, *r))
break;
}
for (int64_t i = shared; i < relative_to.components.length; i++)
- List$insert_value(&result.components, Text(".."), I(1), sizeof(Text_t));
+ Listヽinsert_value(&result.components, Text(".."), I(1), sizeof(Text_t));
for (int64_t i = shared; i < path.components.length; i++) {
Text_t *p = (Text_t*)(path.components.data + i*path.components.stride);
- List$insert(&result.components, p, I(0), sizeof(Text_t));
+ Listヽinsert(&result.components, p, I(0), sizeof(Text_t));
}
//clean_components(&result.components);
return result;
}
-public bool Path$exists(Path_t path)
+public bool Pathヽexists(Path_t path)
{
- path = Path$expand_home(path);
+ path = Pathヽexpand_home(path);
struct stat sb;
- return (stat(Path$as_c_string(path), &sb) == 0);
+ return (stat(Pathヽas_c_string(path), &sb) == 0);
}
static INLINE int path_stat(Path_t path, bool follow_symlinks, struct stat *sb)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
return follow_symlinks ? stat(path_str, sb) : lstat(path_str, sb);
}
-public bool Path$is_file(Path_t path, bool follow_symlinks)
+public bool Pathヽis_file(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -192,7 +192,7 @@ public bool Path$is_file(Path_t path, bool follow_symlinks)
return (sb.st_mode & S_IFMT) == S_IFREG;
}
-public bool Path$is_directory(Path_t path, bool follow_symlinks)
+public bool Pathヽis_directory(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -200,7 +200,7 @@ public bool Path$is_directory(Path_t path, bool follow_symlinks)
return (sb.st_mode & S_IFMT) == S_IFDIR;
}
-public bool Path$is_pipe(Path_t path, bool follow_symlinks)
+public bool Pathヽis_pipe(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -208,7 +208,7 @@ public bool Path$is_pipe(Path_t path, bool follow_symlinks)
return (sb.st_mode & S_IFMT) == S_IFIFO;
}
-public bool Path$is_socket(Path_t path, bool follow_symlinks)
+public bool Pathヽis_socket(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -216,7 +216,7 @@ public bool Path$is_socket(Path_t path, bool follow_symlinks)
return (sb.st_mode & S_IFMT) == S_IFSOCK;
}
-public bool Path$is_symlink(Path_t path)
+public bool Pathヽis_symlink(Path_t path)
{
struct stat sb;
int status = path_stat(path, false, &sb);
@@ -224,10 +224,10 @@ public bool Path$is_symlink(Path_t path)
return (sb.st_mode & S_IFMT) == S_IFLNK;
}
-public bool Path$can_read(Path_t path)
+public bool Pathヽcan_read(Path_t path)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
#ifdef _GNU_SOURCE
return (euidaccess(path_str, R_OK) == 0);
#else
@@ -235,10 +235,10 @@ public bool Path$can_read(Path_t path)
#endif
}
-public bool Path$can_write(Path_t path)
+public bool Pathヽcan_write(Path_t path)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
#ifdef _GNU_SOURCE
return (euidaccess(path_str, W_OK) == 0);
#else
@@ -246,10 +246,10 @@ public bool Path$can_write(Path_t path)
#endif
}
-public bool Path$can_execute(Path_t path)
+public bool Pathヽcan_execute(Path_t path)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
#ifdef _GNU_SOURCE
return (euidaccess(path_str, X_OK) == 0);
#else
@@ -257,7 +257,7 @@ public bool Path$can_execute(Path_t path)
#endif
}
-public OptionalInt64_t Path$modified(Path_t path, bool follow_symlinks)
+public OptionalInt64_t Pathヽmodified(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -265,7 +265,7 @@ public OptionalInt64_t Path$modified(Path_t path, bool follow_symlinks)
return (OptionalInt64_t){.value=(int64_t)sb.st_mtime};
}
-public OptionalInt64_t Path$accessed(Path_t path, bool follow_symlinks)
+public OptionalInt64_t Pathヽaccessed(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -273,7 +273,7 @@ public OptionalInt64_t Path$accessed(Path_t path, bool follow_symlinks)
return (OptionalInt64_t){.value=(int64_t)sb.st_atime};
}
-public OptionalInt64_t Path$changed(Path_t path, bool follow_symlinks)
+public OptionalInt64_t Pathヽchanged(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
@@ -283,46 +283,46 @@ public OptionalInt64_t Path$changed(Path_t path, bool follow_symlinks)
static void _write(Path_t path, List_t bytes, int mode, int permissions)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
int fd = open(path_str, mode, permissions);
if (fd == -1)
fail("Could not write to file: ", path_str, "\n", strerror(errno));
if (bytes.stride != 1)
- List$compact(&bytes, 1);
+ Listヽcompact(&bytes, 1);
ssize_t written = write(fd, bytes.data, (size_t)bytes.length);
if (written != (ssize_t)bytes.length)
fail("Could not write to file: ", path_str, "\n", strerror(errno));
close(fd);
}
-public void Path$write(Path_t path, Text_t text, int permissions)
+public void Pathヽwrite(Path_t path, Text_t text, int permissions)
{
- List_t bytes = Text$utf8_bytes(text);
+ List_t bytes = Textヽutf8_bytes(text);
_write(path, bytes, O_WRONLY | O_CREAT | O_TRUNC, permissions);
}
-public void Path$write_bytes(Path_t path, List_t bytes, int permissions)
+public void Pathヽwrite_bytes(Path_t path, List_t bytes, int permissions)
{
_write(path, bytes, O_WRONLY | O_CREAT | O_TRUNC, permissions);
}
-public void Path$append(Path_t path, Text_t text, int permissions)
+public void Pathヽappend(Path_t path, Text_t text, int permissions)
{
- List_t bytes = Text$utf8_bytes(text);
+ List_t bytes = Textヽutf8_bytes(text);
_write(path, bytes, O_WRONLY | O_APPEND | O_CREAT, permissions);
}
-public void Path$append_bytes(Path_t path, List_t bytes, int permissions)
+public void Pathヽappend_bytes(Path_t path, List_t bytes, int permissions)
{
_write(path, bytes, O_WRONLY | O_APPEND | O_CREAT, permissions);
}
-public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count)
+public OptionalList_t Pathヽread_bytes(Path_t path, OptionalInt_t count)
{
- path = Path$expand_home(path);
- int fd = open(Path$as_c_string(path), O_RDONLY);
+ path = Pathヽexpand_home(path);
+ int fd = open(Pathヽas_c_string(path), O_RDONLY);
if (fd == -1)
return NONE_LIST;
@@ -330,7 +330,7 @@ public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count)
if (fstat(fd, &sb) != 0)
return NONE_LIST;
- int64_t const target_count = count.small ? Int64$from_int(count, false) : INT64_MAX;
+ int64_t const target_count = count.small ? Int64ヽfrom_int(count, false) : INT64_MAX;
if (target_count < 0)
fail("Cannot read a negative number of bytes!");
@@ -376,47 +376,47 @@ public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count)
}
}
-public OptionalText_t Path$read(Path_t path)
+public OptionalText_t Pathヽread(Path_t path)
{
- List_t bytes = Path$read_bytes(path, NONE_INT);
+ List_t bytes = Pathヽread_bytes(path, NONE_INT);
if (bytes.length < 0) return NONE_TEXT;
- return Text$from_bytes(bytes);
+ return Textヽfrom_bytes(bytes);
}
-public OptionalText_t Path$owner(Path_t path, bool follow_symlinks)
+public OptionalText_t Pathヽowner(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
if (status != 0) return NONE_TEXT;
struct passwd *pw = getpwuid(sb.st_uid);
- return pw ? Text$from_str(pw->pw_name) : NONE_TEXT;
+ return pw ? Textヽfrom_str(pw->pw_name) : NONE_TEXT;
}
-public OptionalText_t Path$group(Path_t path, bool follow_symlinks)
+public OptionalText_t Pathヽgroup(Path_t path, bool follow_symlinks)
{
struct stat sb;
int status = path_stat(path, follow_symlinks, &sb);
if (status != 0) return NONE_TEXT;
struct group *gr = getgrgid(sb.st_uid);
- return gr ? Text$from_str(gr->gr_name) : NONE_TEXT;
+ return gr ? Textヽfrom_str(gr->gr_name) : NONE_TEXT;
}
-public void Path$set_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks)
+public void Pathヽset_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks)
{
uid_t owner_id = (uid_t)-1;
if (owner.length >= 0) {
- struct passwd *pwd = getpwnam(Text$as_c_string(owner));
+ struct passwd *pwd = getpwnam(Textヽas_c_string(owner));
if (pwd == NULL) fail("Not a valid user: ", owner);
owner_id = pwd->pw_uid;
}
gid_t group_id = (gid_t)-1;
if (group.length >= 0) {
- struct group *grp = getgrnam(Text$as_c_string(group));
+ struct group *grp = getgrnam(Textヽas_c_string(group));
if (grp == NULL) fail("Not a valid group: ", group);
group_id = grp->gr_gid;
}
- const char *path_str = Path$as_c_string(path);
+ const char *path_str = Pathヽas_c_string(path);
int result = follow_symlinks ? chown(path_str, owner_id, group_id) : lchown(path_str, owner_id, group_id);
if (result < 0)
fail("Could not set owner!");
@@ -442,10 +442,10 @@ static int _remove_files(const char *path, const struct stat *sbuf, int type, st
}
}
-public void Path$remove(Path_t path, bool ignore_missing)
+public void Pathヽremove(Path_t path, bool ignore_missing)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
struct stat sb;
if (lstat(path_str, &sb) != 0) {
if (!ignore_missing)
@@ -465,10 +465,10 @@ public void Path$remove(Path_t path, bool ignore_missing)
}
}
-public void Path$create_directory(Path_t path, int permissions)
+public void Pathヽcreate_directory(Path_t path, int permissions)
{
- path = Path$expand_home(path);
- const char *c_path = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *c_path = Pathヽas_c_string(path);
int status = mkdir(c_path, (mode_t)permissions);
if (status != 0 && errno != EEXIST)
fail("Could not create directory: ", c_path, " (", strerror(errno), ")");
@@ -476,10 +476,10 @@ public void Path$create_directory(Path_t path, int permissions)
static List_t _filtered_children(Path_t path, bool include_hidden, mode_t filter)
{
- path = Path$expand_home(path);
+ path = Pathヽexpand_home(path);
struct dirent *dir;
List_t children = {};
- const char *path_str = Path$as_c_string(path);
+ const char *path_str = Pathヽas_c_string(path);
size_t path_len = strlen(path_str);
DIR *d = opendir(path_str);
if (!d)
@@ -501,32 +501,32 @@ static List_t _filtered_children(Path_t path, bool include_hidden, mode_t filter
if (!((sb.st_mode & S_IFMT) & filter))
continue;
- Path_t child = Path$from_str(child_str);
- List$insert(&children, &child, I(0), sizeof(Path_t));
+ Path_t child = Pathヽfrom_str(child_str);
+ Listヽinsert(&children, &child, I(0), sizeof(Path_t));
}
closedir(d);
return children;
}
-public List_t Path$children(Path_t path, bool include_hidden)
+public List_t Pathヽchildren(Path_t path, bool include_hidden)
{
return _filtered_children(path, include_hidden, (mode_t)-1);
}
-public List_t Path$files(Path_t path, bool include_hidden)
+public List_t Pathヽfiles(Path_t path, bool include_hidden)
{
return _filtered_children(path, include_hidden, S_IFREG);
}
-public List_t Path$subdirectories(Path_t path, bool include_hidden)
+public List_t Pathヽsubdirectories(Path_t path, bool include_hidden)
{
return _filtered_children(path, include_hidden, S_IFDIR);
}
-public Path_t Path$unique_directory(Path_t path)
+public Path_t Pathヽunique_directory(Path_t path)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
size_t len = strlen(path_str);
if (len >= PATH_MAX) fail("Path is too long: ", path_str);
char buf[PATH_MAX] = {};
@@ -536,13 +536,13 @@ public Path_t Path$unique_directory(Path_t path)
buf[--len] = '\0';
char *created = mkdtemp(buf);
if (!created) fail("Failed to create temporary directory: ", path_str, " (", strerror(errno), ")");
- return Path$from_str(created);
+ return Pathヽfrom_str(created);
}
-public Path_t Path$write_unique_bytes(Path_t path, List_t bytes)
+public Path_t Pathヽwrite_unique_bytes(Path_t path, List_t bytes)
{
- path = Path$expand_home(path);
- const char *path_str = Path$as_c_string(path);
+ path = Pathヽexpand_home(path);
+ const char *path_str = Pathヽas_c_string(path);
size_t len = strlen(path_str);
if (len >= PATH_MAX) fail("Path is too long: ", path_str);
char buf[PATH_MAX] = {};
@@ -560,56 +560,56 @@ public Path_t Path$write_unique_bytes(Path_t path, List_t bytes)
fail("Could not write to unique file: ", buf, "\n", strerror(errno));
if (bytes.stride != 1)
- List$compact(&bytes, 1);
+ Listヽcompact(&bytes, 1);
ssize_t written = write(fd, bytes.data, (size_t)bytes.length);
if (written != (ssize_t)bytes.length)
fail("Could not write to file: ", buf, "\n", strerror(errno));
close(fd);
- return Path$from_str(buf);
+ return Pathヽfrom_str(buf);
}
-public Path_t Path$write_unique(Path_t path, Text_t text)
+public Path_t Pathヽwrite_unique(Path_t path, Text_t text)
{
- return Path$write_unique_bytes(path, Text$utf8_bytes(text));
+ return Pathヽwrite_unique_bytes(path, Textヽutf8_bytes(text));
}
-public Path_t Path$parent(Path_t path)
+public Path_t Pathヽparent(Path_t path)
{
- if (path.type.$tag == PATH_ABSOLUTE && path.components.length == 0) {
+ if (path.type.ヽtag == PATH_ABSOLUTE && path.components.length == 0) {
return path;
- } else if (path.components.length > 0 && !Text$equal_values(*(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)),
+ } else if (path.components.length > 0 && !Textヽequal_values(*(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)),
Text(".."))) {
- return (Path_t){.type.$tag=path.type.$tag, .components=List$slice(path.components, I(1), I(-2))};
+ return (Path_t){.type.ヽtag=path.type.ヽtag, .components=Listヽslice(path.components, I(1), I(-2))};
} else {
- Path_t result = {.type.$tag=path.type.$tag, .components=path.components};
+ Path_t result = {.type.ヽtag=path.type.ヽtag, .components=path.components};
LIST_INCREF(result.components);
- List$insert_value(&result.components, Text(".."), I(0), sizeof(Text_t));
+ Listヽinsert_value(&result.components, Text(".."), I(0), sizeof(Text_t));
return result;
}
}
-public PUREFUNC Text_t Path$base_name(Path_t path)
+public PUREFUNC Text_t Pathヽbase_name(Path_t path)
{
if (path.components.length >= 1)
return *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1));
- else if (path.type.$tag == PATH_HOME)
+ else if (path.type.ヽtag == PATH_HOME)
return Text("~");
- else if (path.type.$tag == PATH_RELATIVE)
+ else if (path.type.ヽtag == PATH_RELATIVE)
return Text(".");
else
return EMPTY_TEXT;
}
-public Text_t Path$extension(Path_t path, bool full)
+public Text_t Pathヽextension(Path_t path, bool full)
{
- const char *base = Text$as_c_string(Path$base_name(path));
+ const char *base = Textヽas_c_string(Pathヽbase_name(path));
const char *dot = full ? strchr(base + 1, '.') : strrchr(base + 1, '.');
const char *extension = dot ? dot + 1 : "";
- return Text$from_str(extension);
+ return Textヽfrom_str(extension);
}
-public bool Path$has_extension(Path_t path, Text_t extension)
+public bool Pathヽhas_extension(Path_t path, Text_t extension)
{
if (path.components.length < 2)
return extension.length == 0;
@@ -617,57 +617,57 @@ public bool Path$has_extension(Path_t path, Text_t extension)
Text_t last = *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1));
if (extension.length == 0)
- return !Text$has(Text$from(last, I(2)), Text(".")) || Text$equal_values(last, Text(".."));
+ return !Textヽhas(Textヽfrom(last, I(2)), Text(".")) || Textヽequal_values(last, Text(".."));
- if (!Text$starts_with(extension, Text("."), NULL))
+ if (!Textヽstarts_with(extension, Text("."), NULL))
extension = Texts(Text("."), extension);
- return Text$ends_with(Text$from(last, I(2)), extension, NULL);
+ return Textヽends_with(Textヽfrom(last, I(2)), extension, NULL);
}
-public Path_t Path$child(Path_t path, Text_t name)
+public Path_t Pathヽchild(Path_t path, Text_t name)
{
- if (Text$has(name, Text("/")) || Text$has(name, Text(";")))
+ if (Textヽhas(name, Text("/")) || Textヽhas(name, Text(";")))
fail("Path name has invalid characters: ", name);
Path_t result = {
- .type.$tag=path.type.$tag,
+ .type.ヽtag=path.type.ヽtag,
.components=path.components,
};
LIST_INCREF(result.components);
- List$insert(&result.components, &name, I(0), sizeof(Text_t));
+ Listヽinsert(&result.components, &name, I(0), sizeof(Text_t));
clean_components(&result.components);
return result;
}
-public Path_t Path$sibling(Path_t path, Text_t name)
+public Path_t Pathヽsibling(Path_t path, Text_t name)
{
- return Path$child(Path$parent(path), name);
+ return Pathヽchild(Pathヽparent(path), name);
}
-public Path_t Path$with_extension(Path_t path, Text_t extension, bool replace)
+public Path_t Pathヽwith_extension(Path_t path, Text_t extension, bool replace)
{
if (path.components.length == 0)
fail("A path with no components can't have an extension!");
- if (Text$has(extension, Text("/")) || Text$has(extension, Text(";")))
+ if (Textヽhas(extension, Text("/")) || Textヽhas(extension, Text(";")))
fail("Path extension has invalid characters: ", extension);
Path_t result = {
- .type.$tag=path.type.$tag,
+ .type.ヽtag=path.type.ヽtag,
.components=path.components,
};
LIST_INCREF(result.components);
Text_t last = *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1));
- List$remove_at(&result.components, I(-1), I(1), sizeof(Text_t));
+ Listヽremove_at(&result.components, I(-1), I(1), sizeof(Text_t));
if (replace) {
- const char *base = Text$as_c_string(last);
+ const char *base = Textヽas_c_string(last);
const char *dot = strchr(base + 1, '.');
if (dot)
- last = Text$from_strn(base, (size_t)(dot - base));
+ last = Textヽfrom_strn(base, (size_t)(dot - base));
}
- last = Text$concat(last, extension);
- List$insert(&result.components, &last, I(0), sizeof(Text_t));
+ last = Textヽconcat(last, extension);
+ Listヽinsert(&result.components, &last, I(0), sizeof(Text_t));
return result;
}
@@ -697,16 +697,16 @@ static Text_t _next_line(FILE **f)
if (u8_check((uint8_t*)line, (size_t)len) != NULL)
fail("Invalid UTF8!");
- Text_t line_text = Text$from_strn(line, (size_t)len);
+ Text_t line_text = Textヽfrom_strn(line, (size_t)len);
free(line);
return line_text;
}
-public OptionalClosure_t Path$by_line(Path_t path)
+public OptionalClosure_t Pathヽby_line(Path_t path)
{
- path = Path$expand_home(path);
+ path = Pathヽexpand_home(path);
- FILE *f = fopen(Path$as_c_string(path), "r");
+ FILE *f = fopen(Pathヽas_c_string(path), "r");
if (f == NULL)
return NONE_CLOSURE;
@@ -716,10 +716,10 @@ public OptionalClosure_t Path$by_line(Path_t path)
return (Closure_t){.fn=(void*)_next_line, .userdata=wrapper};
}
-public List_t Path$glob(Path_t path)
+public List_t Pathヽglob(Path_t path)
{
glob_t glob_result;
- int status = glob(Path$as_c_string(path), GLOB_BRACE | GLOB_TILDE, NULL, &glob_result);
+ int status = glob(Pathヽas_c_string(path), GLOB_BRACE | GLOB_TILDE, NULL, &glob_result);
if (status != 0 && status != GLOB_NOMATCH)
fail("Failed to perform globbing");
@@ -729,100 +729,100 @@ public List_t Path$glob(Path_t path)
if ((len >= 2 && glob_result.gl_pathv[i][len-1] == '.' && glob_result.gl_pathv[i][len-2] == '/')
|| (len >= 2 && glob_result.gl_pathv[i][len-1] == '.' && glob_result.gl_pathv[i][len-2] == '.' && glob_result.gl_pathv[i][len-3] == '/'))
continue;
- Path_t p = Path$from_str(glob_result.gl_pathv[i]);
- List$insert(&glob_files, &p, I(0), sizeof(Path_t));
+ Path_t p = Pathヽfrom_str(glob_result.gl_pathv[i]);
+ Listヽinsert(&glob_files, &p, I(0), sizeof(Path_t));
}
return glob_files;
}
-public Path_t Path$current_dir(void)
+public Path_t Pathヽcurrent_dir(void)
{
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == NULL)
fail("Could not get current working directory");
- return Path$from_str(cwd);
+ return Pathヽfrom_str(cwd);
}
-public PUREFUNC uint64_t Path$hash(const void *obj, const TypeInfo_t *type)
+public PUREFUNC uint64_t Pathヽhash(const void *obj, const TypeInfo_t *type)
{
(void)type;
Path_t *path = (Path_t*)obj;
siphash sh;
- siphashinit(&sh, (uint64_t)path->type.$tag);
+ siphashinit(&sh, (uint64_t)path->type.ヽtag);
for (int64_t i = 0; i < path->components.length; i++) {
- uint64_t item_hash = Text$hash(path->components.data + i*path->components.stride, &Text$info);
+ uint64_t item_hash = Textヽhash(path->components.data + i*path->components.stride, &Textヽinfo);
siphashadd64bits(&sh, item_hash);
}
return siphashfinish_last_part(&sh, (uint64_t)path->components.length);
}
-public PUREFUNC int32_t Path$compare(const void *va, const void *vb, const TypeInfo_t *type)
+public PUREFUNC int32_t Pathヽcompare(const void *va, const void *vb, const TypeInfo_t *type)
{
(void)type;
Path_t *a = (Path_t*)va, *b = (Path_t*)vb;
- int diff = ((int)a->type.$tag - (int)b->type.$tag);
+ int diff = ((int)a->type.ヽtag - (int)b->type.ヽtag);
if (diff != 0) return diff;
- return List$compare(&a->components, &b->components, List$info(&Text$info));
+ return Listヽcompare(&a->components, &b->components, Listヽinfo(&Textヽinfo));
}
-public PUREFUNC bool Path$equal(const void *va, const void *vb, const TypeInfo_t *type)
+public PUREFUNC bool Pathヽequal(const void *va, const void *vb, const TypeInfo_t *type)
{
(void)type;
Path_t *a = (Path_t*)va, *b = (Path_t*)vb;
- if (a->type.$tag != b->type.$tag) return false;
- return List$equal(&a->components, &b->components, List$info(&Text$info));
+ if (a->type.ヽtag != b->type.ヽtag) return false;
+ return Listヽequal(&a->components, &b->components, Listヽinfo(&Textヽinfo));
}
-public PUREFUNC bool Path$equal_values(Path_t a, Path_t b)
+public PUREFUNC bool Pathヽequal_values(Path_t a, Path_t b)
{
- if (a.type.$tag != b.type.$tag) return false;
- return List$equal(&a.components, &b.components, List$info(&Text$info));
+ if (a.type.ヽtag != b.type.ヽtag) return false;
+ return Listヽequal(&a.components, &b.components, Listヽinfo(&Textヽinfo));
}
-public int Path$print(FILE *f, Path_t path)
+public int Pathヽprint(FILE *f, Path_t path)
{
if (path.components.length == 0) {
- if (path.type.$tag == PATH_ABSOLUTE) return fputs("/", f);
- else if (path.type.$tag == PATH_RELATIVE) return fputs(".", f);
- else if (path.type.$tag == PATH_HOME) return fputs("~", f);
+ if (path.type.ヽtag == PATH_ABSOLUTE) return fputs("/", f);
+ else if (path.type.ヽtag == PATH_RELATIVE) return fputs(".", f);
+ else if (path.type.ヽtag == PATH_HOME) return fputs("~", f);
}
int n = 0;
- if (path.type.$tag == PATH_ABSOLUTE) {
+ if (path.type.ヽtag == PATH_ABSOLUTE) {
n += fputc('/', f);
- } else if (path.type.$tag == PATH_HOME) {
+ } else if (path.type.ヽtag == PATH_HOME) {
n += fputs("~/", f);
- } else if (path.type.$tag == PATH_RELATIVE) {
- if (!Text$equal_values(*(Text_t*)path.components.data, Text("..")))
+ } else if (path.type.ヽtag == PATH_RELATIVE) {
+ if (!Textヽequal_values(*(Text_t*)path.components.data, Text("..")))
n += fputs("./", f);
}
for (int64_t i = 0; i < path.components.length; i++) {
Text_t *comp = (Text_t*)(path.components.data + i*path.components.stride);
- n += Text$print(f, *comp);
+ n += Textヽprint(f, *comp);
if (i + 1 < path.components.length)
n += fputc('/', f);
}
return n;
}
-public const char *Path$as_c_string(Path_t path)
+public const char *Pathヽas_c_string(Path_t path)
{
return String(path);
}
-public Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type)
+public Text_t Pathヽas_text(const void *obj, bool color, const TypeInfo_t *type)
{
(void)type;
if (!obj) return Text("Path");
Path_t *path = (Path_t*)obj;
- Text_t text = Text$join(Text("/"), path->components);
- if (path->type.$tag == PATH_HOME)
- text = Text$concat(path->components.length > 0 ? Text("~/") : Text("~"), text);
- else if (path->type.$tag == PATH_ABSOLUTE)
- text = Text$concat(Text("/"), text);
- else if (path->type.$tag == PATH_RELATIVE && (path->components.length == 0 || !Text$equal_values(*(Text_t*)(path->components.data), Text(".."))))
- text = Text$concat(path->components.length > 0 ? Text("./") : Text("."), text);
+ Text_t text = Textヽjoin(Text("/"), path->components);
+ if (path->type.ヽtag == PATH_HOME)
+ text = Textヽconcat(path->components.length > 0 ? Text("~/") : Text("~"), text);
+ else if (path->type.ヽtag == PATH_ABSOLUTE)
+ text = Textヽconcat(Text("/"), text);
+ else if (path->type.ヽtag == PATH_RELATIVE && (path->components.length == 0 || !Textヽequal_values(*(Text_t*)(path->components.data), Text(".."))))
+ text = Textヽconcat(path->components.length > 0 ? Text("./") : Text("."), text);
if (color)
text = Texts(Text("\033[32;1m"), text, Text("\033[m"));
@@ -830,48 +830,48 @@ public Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type)
return text;
}
-public CONSTFUNC bool Path$is_none(const void *obj, const TypeInfo_t *type)
+public CONSTFUNC bool Pathヽis_none(const void *obj, const TypeInfo_t *type)
{
(void)type;
- return ((Path_t*)obj)->type.$tag == PATH_NONE;
+ return ((Path_t*)obj)->type.ヽtag == PATH_NONE;
}
-public void Path$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Pathヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
(void)type;
Path_t *path = (Path_t*)obj;
- fputc((int)path->type.$tag, out);
- List$serialize(&path->components, out, pointers, List$info(&Text$info));
+ fputc((int)path->type.ヽtag, out);
+ Listヽserialize(&path->components, out, pointers, Listヽinfo(&Textヽinfo));
}
-public void Path$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type)
+public void Pathヽdeserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type)
{
(void)type;
Path_t path = {};
- path.type.$tag = fgetc(in);
- List$deserialize(in, &path.components, pointers, List$info(&Text$info));
+ path.type.ヽtag = fgetc(in);
+ Listヽdeserialize(in, &path.components, pointers, Listヽinfo(&Textヽinfo));
*(Path_t*)obj = path;
}
-public const TypeInfo_t Path$info = {
+public const TypeInfo_t Pathヽinfo = {
.size=sizeof(Path_t),
.align=__alignof__(Path_t),
.tag=OpaqueInfo,
.metamethods={
- .as_text=Path$as_text,
- .hash=Path$hash,
- .compare=Path$compare,
- .equal=Path$equal,
- .is_none=Path$is_none,
- .serialize=Path$serialize,
- .deserialize=Path$deserialize,
+ .as_text=Pathヽas_text,
+ .hash=Pathヽhash,
+ .compare=Pathヽcompare,
+ .equal=Pathヽequal,
+ .is_none=Pathヽis_none,
+ .serialize=Pathヽserialize,
+ .deserialize=Pathヽdeserialize,
}
};
-public const TypeInfo_t PathType$info = {
+public const TypeInfo_t PathTypeヽinfo = {
.size=sizeof(PathType_t),
.align=__alignof__(PathType_t),
- .metamethods=PackedDataEnum$metamethods,
+ .metamethods=PackedDataEnumヽmetamethods,
.tag=EnumInfo,
.EnumInfo={
.name="PathType",
diff --git a/src/stdlib/paths.h b/src/stdlib/paths.h
index 3a9cdef7..4ae78cd5 100644
--- a/src/stdlib/paths.h
+++ b/src/stdlib/paths.h
@@ -9,67 +9,67 @@
#include "datatypes.h"
#include "optionals.h"
-Path_t Path$from_str(const char *str);
-Path_t Path$from_text(Text_t text);
-// int Path$print(FILE *f, Path_t path);
-const char *Path$as_c_string(Path_t path);
-#define Path(str) Path$from_str(str)
-Path_t Path$_concat(int n, Path_t items[n]);
-#define Path$concat(...) Path$_concat((int)sizeof((Path_t[]){__VA_ARGS__})/sizeof(Path_t), ((Path_t[]){__VA_ARGS__}))
-Path_t Path$resolved(Path_t path, Path_t relative_to);
-Path_t Path$relative_to(Path_t path, Path_t relative_to);
-Path_t Path$expand_home(Path_t path);
-bool Path$exists(Path_t path);
-bool Path$is_file(Path_t path, bool follow_symlinks);
-bool Path$is_directory(Path_t path, bool follow_symlinks);
-bool Path$is_pipe(Path_t path, bool follow_symlinks);
-bool Path$is_socket(Path_t path, bool follow_symlinks);
-bool Path$is_symlink(Path_t path);
-bool Path$can_read(Path_t path);
-bool Path$can_write(Path_t path);
-bool Path$can_execute(Path_t path);
-OptionalInt64_t Path$modified(Path_t path, bool follow_symlinks);
-OptionalInt64_t Path$accessed(Path_t path, bool follow_symlinks);
-OptionalInt64_t Path$changed(Path_t path, bool follow_symlinks);
-void Path$write(Path_t path, Text_t text, int permissions);
-void Path$write_bytes(Path_t path, List_t bytes, int permissions);
-void Path$append(Path_t path, Text_t text, int permissions);
-void Path$append_bytes(Path_t path, List_t bytes, int permissions);
-OptionalText_t Path$read(Path_t path);
-OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t limit);
-void Path$set_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks);
-OptionalText_t Path$owner(Path_t path, bool follow_symlinks);
-OptionalText_t Path$group(Path_t path, bool follow_symlinks);
-void Path$remove(Path_t path, bool ignore_missing);
-void Path$create_directory(Path_t path, int permissions);
-List_t Path$children(Path_t path, bool include_hidden);
-List_t Path$files(Path_t path, bool include_hidden);
-List_t Path$subdirectories(Path_t path, bool include_hidden);
-Path_t Path$unique_directory(Path_t path);
-Path_t Path$write_unique(Path_t path, Text_t text);
-Path_t Path$write_unique_bytes(Path_t path, List_t bytes);
-Path_t Path$parent(Path_t path);
-Text_t Path$base_name(Path_t path);
-Text_t Path$extension(Path_t path, bool full);
-bool Path$has_extension(Path_t path, Text_t extension);
-Path_t Path$child(Path_t path, Text_t name);
-Path_t Path$sibling(Path_t path, Text_t name);
-Path_t Path$with_extension(Path_t path, Text_t extension, bool replace);
-Path_t Path$current_dir(void);
-Closure_t Path$by_line(Path_t path);
-List_t Path$glob(Path_t path);
+Path_t Pathヽfrom_str(const char *str);
+Path_t Pathヽfrom_text(Text_t text);
+// int Pathヽprint(FILE *f, Path_t path);
+const char *Pathヽas_c_string(Path_t path);
+#define Path(str) Pathヽfrom_str(str)
+Path_t Pathヽ_concat(int n, Path_t items[n]);
+#define Pathヽconcat(...) Pathヽ_concat((int)sizeof((Path_t[]){__VA_ARGS__})/sizeof(Path_t), ((Path_t[]){__VA_ARGS__}))
+Path_t Pathヽresolved(Path_t path, Path_t relative_to);
+Path_t Pathヽrelative_to(Path_t path, Path_t relative_to);
+Path_t Pathヽexpand_home(Path_t path);
+bool Pathヽexists(Path_t path);
+bool Pathヽis_file(Path_t path, bool follow_symlinks);
+bool Pathヽis_directory(Path_t path, bool follow_symlinks);
+bool Pathヽis_pipe(Path_t path, bool follow_symlinks);
+bool Pathヽis_socket(Path_t path, bool follow_symlinks);
+bool Pathヽis_symlink(Path_t path);
+bool Pathヽcan_read(Path_t path);
+bool Pathヽcan_write(Path_t path);
+bool Pathヽcan_execute(Path_t path);
+OptionalInt64_t Pathヽmodified(Path_t path, bool follow_symlinks);
+OptionalInt64_t Pathヽaccessed(Path_t path, bool follow_symlinks);
+OptionalInt64_t Pathヽchanged(Path_t path, bool follow_symlinks);
+void Pathヽwrite(Path_t path, Text_t text, int permissions);
+void Pathヽwrite_bytes(Path_t path, List_t bytes, int permissions);
+void Pathヽappend(Path_t path, Text_t text, int permissions);
+void Pathヽappend_bytes(Path_t path, List_t bytes, int permissions);
+OptionalText_t Pathヽread(Path_t path);
+OptionalList_t Pathヽread_bytes(Path_t path, OptionalInt_t limit);
+void Pathヽset_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks);
+OptionalText_t Pathヽowner(Path_t path, bool follow_symlinks);
+OptionalText_t Pathヽgroup(Path_t path, bool follow_symlinks);
+void Pathヽremove(Path_t path, bool ignore_missing);
+void Pathヽcreate_directory(Path_t path, int permissions);
+List_t Pathヽchildren(Path_t path, bool include_hidden);
+List_t Pathヽfiles(Path_t path, bool include_hidden);
+List_t Pathヽsubdirectories(Path_t path, bool include_hidden);
+Path_t Pathヽunique_directory(Path_t path);
+Path_t Pathヽwrite_unique(Path_t path, Text_t text);
+Path_t Pathヽwrite_unique_bytes(Path_t path, List_t bytes);
+Path_t Pathヽparent(Path_t path);
+Text_t Pathヽbase_name(Path_t path);
+Text_t Pathヽextension(Path_t path, bool full);
+bool Pathヽhas_extension(Path_t path, Text_t extension);
+Path_t Pathヽchild(Path_t path, Text_t name);
+Path_t Pathヽsibling(Path_t path, Text_t name);
+Path_t Pathヽwith_extension(Path_t path, Text_t extension, bool replace);
+Path_t Pathヽcurrent_dir(void);
+Closure_t Pathヽby_line(Path_t path);
+List_t Pathヽglob(Path_t path);
-uint64_t Path$hash(const void *obj, const TypeInfo_t*);
-int32_t Path$compare(const void *a, const void *b, const TypeInfo_t *type);
-bool Path$equal(const void *a, const void *b, const TypeInfo_t *type);
-bool Path$equal_values(Path_t a, Path_t b);
-Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type);
-bool Path$is_none(const void *obj, const TypeInfo_t *type);
-void Path$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void Path$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type);
+uint64_t Pathヽhash(const void *obj, const TypeInfo_t*);
+int32_t Pathヽcompare(const void *a, const void *b, const TypeInfo_t *type);
+bool Pathヽequal(const void *a, const void *b, const TypeInfo_t *type);
+bool Pathヽequal_values(Path_t a, Path_t b);
+Text_t Pathヽas_text(const void *obj, bool color, const TypeInfo_t *type);
+bool Pathヽis_none(const void *obj, const TypeInfo_t *type);
+void Pathヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Pathヽdeserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type);
-extern const TypeInfo_t Path$info;
-extern const TypeInfo_t PathType$info;
+extern const TypeInfo_t Pathヽinfo;
+extern const TypeInfo_t PathTypeヽinfo;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/pointers.c b/src/stdlib/pointers.c
index 6874dd3c..08fce9e4 100644
--- a/src/stdlib/pointers.c
+++ b/src/stdlib/pointers.c
@@ -14,22 +14,22 @@
#include "types.h"
#include "util.h"
-public Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *type) {
+public Text_t Pointerヽas_text(const void *x, bool colorize, const TypeInfo_t *type) {
__typeof(type->PointerInfo) ptr_info = type->PointerInfo;
if (!x) {
Text_t typename = generic_as_text(NULL, false, ptr_info.pointed);
if (colorize)
- return Text$concat(Text("\x1b[34;1m"), Text$from_str(ptr_info.sigil), typename, Text("\x1b[m"));
+ return Textヽconcat(Text("\x1b[34;1m"), Textヽfrom_str(ptr_info.sigil), typename, Text("\x1b[m"));
else
- return Text$concat(Text$from_str(ptr_info.sigil), typename);
+ return Textヽconcat(Textヽfrom_str(ptr_info.sigil), typename);
}
const void *ptr = *(const void**)x;
if (!ptr) {
Text_t typename = generic_as_text(NULL, false, ptr_info.pointed);
if (colorize)
- return Text$concat(Text("\x1b[34;1m!"), typename, Text("\x1b[m"));
+ return Textヽconcat(Text("\x1b[34;1m!"), typename, Text("\x1b[m"));
else
- return Text$concat(Text("!"), typename);
+ return Textヽconcat(Text("!"), typename);
}
static const void *root = NULL;
@@ -41,17 +41,17 @@ public Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *ty
if (top_level) {
root = ptr;
} else if (ptr == root) {
- Text_t text = Texts(Text$from_str(ptr_info.sigil), Text("~1"));
+ Text_t text = Texts(Textヽfrom_str(ptr_info.sigil), Text("~1"));
return colorize ? Texts(Text("\x1b[34;1m"), text, Text("\x1b[m")) : text;
} else {
- TypeInfo_t rec_table = *Table$info(type, &Int64$info);
- int64_t *id = Table$get(pending, x, &rec_table);
+ TypeInfo_t rec_table = *Tableヽinfo(type, &Int64ヽinfo);
+ int64_t *id = Tableヽget(pending, x, &rec_table);
if (id) {
- Text_t text = Texts(Text$from_str(ptr_info.sigil), Int64$as_text(id, false, &Int64$info));
+ Text_t text = Texts(Textヽfrom_str(ptr_info.sigil), Int64ヽas_text(id, false, &Int64ヽinfo));
return colorize ? Texts(Text("\x1b[34;1m"), text, Text("\x1b[m")) : text;
}
int64_t next_id = pending.entries.length + 2;
- Table$set(&pending, x, &next_id, &rec_table);
+ Tableヽset(&pending, x, &next_id, &rec_table);
}
Text_t pointed = generic_as_text(ptr, colorize, ptr_info.pointed);
@@ -63,62 +63,62 @@ public Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *ty
Text_t text;
if (colorize)
- text = Text$concat(Text("\x1b[34;1m"), Text$from_str(ptr_info.sigil), Text("\x1b[m"), pointed);
+ text = Textヽconcat(Text("\x1b[34;1m"), Textヽfrom_str(ptr_info.sigil), Text("\x1b[m"), pointed);
else
- text = Text$concat(Text$from_str(ptr_info.sigil), pointed);
+ text = Textヽconcat(Textヽfrom_str(ptr_info.sigil), pointed);
return text;
}
-PUREFUNC public int32_t Pointer$compare(const void *x, const void *y, const TypeInfo_t *info) {
+PUREFUNC public int32_t Pointerヽcompare(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
const void *xp = *(const void**)x, *yp = *(const void**)y;
return (xp > yp) - (xp < yp);
}
-PUREFUNC public bool Pointer$equal(const void *x, const void *y, const TypeInfo_t *info) {
+PUREFUNC public bool Pointerヽequal(const void *x, const void *y, const TypeInfo_t *info) {
(void)info;
const void *xp = *(const void**)x, *yp = *(const void**)y;
return xp == yp;
}
-PUREFUNC public bool Pointer$is_none(const void *x, const TypeInfo_t *info)
+PUREFUNC public bool Pointerヽis_none(const void *x, const TypeInfo_t *info)
{
(void)info;
return *(void**)x == NULL;
}
-public void Pointer$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Pointerヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
void *ptr = *(void**)obj;
assert(ptr != NULL);
const TypeInfo_t ptr_to_int_table = {.size=sizeof(Table_t), .align=__alignof__(Table_t),
- .tag=TableInfo, .TableInfo.key=type, .TableInfo.value=&Int64$info};
+ .tag=TableInfo, .TableInfo.key=type, .TableInfo.value=&Int64ヽinfo};
- int64_t *id_ptr = Table$get(*pointers, &ptr, &ptr_to_int_table);
+ int64_t *id_ptr = Tableヽget(*pointers, &ptr, &ptr_to_int_table);
int64_t id;
if (id_ptr) {
id = *id_ptr;
} else {
id = pointers->entries.length + 1;
- Table$set(pointers, &ptr, &id, &ptr_to_int_table);
+ Tableヽset(pointers, &ptr, &id, &ptr_to_int_table);
}
- Int64$serialize(&id, out, pointers, &Int64$info);
+ Int64ヽserialize(&id, out, pointers, &Int64ヽinfo);
if (!id_ptr)
_serialize(ptr, out, pointers, type->PointerInfo.pointed);
}
-public void Pointer$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
+public void Pointerヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
{
int64_t id = 0;
- Int64$deserialize(in, &id, pointers, &Int64$info);
+ Int64ヽdeserialize(in, &id, pointers, &Int64ヽinfo);
assert(id != 0);
if (id > pointers->length) {
void *obj = GC_MALLOC((size_t)type->PointerInfo.pointed->size);
- List$insert(pointers, &obj, I(0), sizeof(void*));
+ Listヽinsert(pointers, &obj, I(0), sizeof(void*));
_deserialize(in, obj, pointers, type->PointerInfo.pointed);
*(void**)outval = obj;
} else {
diff --git a/src/stdlib/pointers.h b/src/stdlib/pointers.h
index b818452e..b0711d5c 100644
--- a/src/stdlib/pointers.h
+++ b/src/stdlib/pointers.h
@@ -9,28 +9,28 @@
#include "types.h"
#include "util.h"
-Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *type);
-PUREFUNC int32_t Pointer$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Pointer$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Pointer$is_none(const void *x, const TypeInfo_t*);
-void Pointer$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void Pointer$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
+Text_t Pointerヽas_text(const void *x, bool colorize, const TypeInfo_t *type);
+PUREFUNC int32_t Pointerヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Pointerヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Pointerヽis_none(const void *x, const TypeInfo_t*);
+void Pointerヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Pointerヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
#define Null(t) (t*)NULL
#define POINTER_TYPE(_sigil, _pointed) (&(TypeInfo_t){\
.size=sizeof(void*), .align=alignof(void*), .tag=PointerInfo, .PointerInfo.sigil=_sigil, .PointerInfo.pointed=_pointed})
-#define Pointer$metamethods { \
- .as_text=Pointer$as_text, \
- .compare=Pointer$compare, \
- .equal=Pointer$equal, \
- .is_none=Pointer$is_none, \
- .serialize=Pointer$serialize, \
- .deserialize=Pointer$deserialize, \
+#define Pointerヽmetamethods { \
+ .as_text=Pointerヽas_text, \
+ .compare=Pointerヽcompare, \
+ .equal=Pointerヽequal, \
+ .is_none=Pointerヽis_none, \
+ .serialize=Pointerヽserialize, \
+ .deserialize=Pointerヽdeserialize, \
}
-#define Pointer$info(sigil_expr, pointed_info) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \
+#define Pointerヽinfo(sigil_expr, pointed_info) &((TypeInfo_t){.size=sizeof(void*), .align=__alignof__(void*), \
.tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info}, \
- .metamethods=Pointer$metamethods})
+ .metamethods=Pointerヽmetamethods})
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/print.h b/src/stdlib/print.h
index ce20152b..2dbe8373 100644
--- a/src/stdlib/print.h
+++ b/src/stdlib/print.h
@@ -96,9 +96,9 @@ PRINT_FN _print_repeated_char(FILE *f, repeated_char_t repeated) {
return len;
}
-extern int Text$print(FILE *stream, Text_t text);
-extern int Path$print(FILE *stream, Path_t path);
-extern int Int$print(FILE *f, Int_t i);
+extern int Textヽprint(FILE *stream, Text_t text);
+extern int Pathヽprint(FILE *stream, Path_t path);
+extern int Intヽprint(FILE *f, Int_t i);
#ifndef _fprint1
#define _fprint1(f, x) _Generic((x), \
char*: _print_str, \
@@ -121,9 +121,9 @@ extern int Int$print(FILE *f, Int_t i);
quoted_t: _print_quoted, \
string_slice_t: _print_string_slice, \
repeated_char_t: _print_repeated_char, \
- Text_t: Text$print, \
- Path_t: Path$print, \
- Int_t: Int$print, \
+ Text_t: Textヽprint, \
+ Path_t: Pathヽprint, \
+ Int_t: Intヽprint, \
void*: _print_pointer)(f, x)
#endif
diff --git a/src/stdlib/stacktrace.c b/src/stdlib/stacktrace.c
index 3904ae70..5e92f10f 100644
--- a/src/stdlib/stacktrace.c
+++ b/src/stdlib/stacktrace.c
@@ -119,7 +119,7 @@ public void print_stacktrace(FILE *out, int offset)
const char *function = NULL, *filename = NULL;
long line_num = 0;
if (fparse(fp, &function, "\n", &filename, ":", &line_num) == NULL) {
- if (starts_with(function, "main$"))
+ if (starts_with(function, "mainヽ"))
main_func_onwards = true;
if (main_func_onwards)
_print_stack_frame(out, cwd, install_dir, function, filename, line_num);
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c
index 02ccd710..1372d945 100644
--- a/src/stdlib/stdlib.c
+++ b/src/stdlib/stdlib.c
@@ -84,51 +84,51 @@ static bool parse_single_arg(const TypeInfo_t *info, char *arg, void *dest)
while (info->tag == OptionalInfo)
info = info->OptionalInfo.type;
- if (info == &Int$info) {
- OptionalInt_t parsed = Int$from_str(arg);
+ if (info == &Intヽinfo) {
+ OptionalInt_t parsed = Intヽfrom_str(arg);
if (parsed.small != 0)
*(OptionalInt_t*)dest = parsed;
return parsed.small != 0;
- } else if (info == &Int64$info) {
- OptionalInt64_t parsed = Int64$parse(Text$from_str(arg), NULL);
+ } else if (info == &Int64ヽinfo) {
+ OptionalInt64_t parsed = Int64ヽparse(Textヽfrom_str(arg), NULL);
if (!parsed.is_none)
*(OptionalInt64_t*)dest = parsed;
return !parsed.is_none;
- } else if (info == &Int32$info) {
- OptionalInt32_t parsed = Int32$parse(Text$from_str(arg), NULL);
+ } else if (info == &Int32ヽinfo) {
+ OptionalInt32_t parsed = Int32ヽparse(Textヽfrom_str(arg), NULL);
if (!parsed.is_none)
*(OptionalInt32_t*)dest = parsed;
return !parsed.is_none;
- } else if (info == &Int16$info) {
- OptionalInt16_t parsed = Int16$parse(Text$from_str(arg), NULL);
+ } else if (info == &Int16ヽinfo) {
+ OptionalInt16_t parsed = Int16ヽparse(Textヽfrom_str(arg), NULL);
if (!parsed.is_none)
*(OptionalInt16_t*)dest = parsed;
return !parsed.is_none;
- } else if (info == &Int8$info) {
- OptionalInt8_t parsed = Int8$parse(Text$from_str(arg), NULL);
+ } else if (info == &Int8ヽinfo) {
+ OptionalInt8_t parsed = Int8ヽparse(Textヽfrom_str(arg), NULL);
if (!parsed.is_none)
*(OptionalInt8_t*)dest = parsed;
return !parsed.is_none;
- } else if (info == &Bool$info) {
- OptionalBool_t parsed = Bool$parse(Text$from_str(arg), NULL);
+ } else if (info == &Boolヽinfo) {
+ OptionalBool_t parsed = Boolヽparse(Textヽfrom_str(arg), NULL);
if (parsed != NONE_BOOL)
*(OptionalBool_t*)dest = parsed;
return parsed != NONE_BOOL;
- } else if (info == &Num$info) {
- OptionalNum_t parsed = Num$parse(Text$from_str(arg), NULL);
+ } else if (info == &Numヽinfo) {
+ OptionalNum_t parsed = Numヽparse(Textヽfrom_str(arg), NULL);
if (!isnan(parsed))
*(OptionalNum_t*)dest = parsed;
return !isnan(parsed);
- } else if (info == &Num32$info) {
- OptionalNum32_t parsed = Num32$parse(Text$from_str(arg), NULL);
+ } else if (info == &Num32ヽinfo) {
+ OptionalNum32_t parsed = Num32ヽparse(Textヽfrom_str(arg), NULL);
if (!isnan(parsed))
*(OptionalNum32_t*)dest = parsed;
return !isnan(parsed);
- } else if (info == &Path$info) {
- *(OptionalPath_t*)dest = Path$from_str(arg);
+ } else if (info == &Pathヽinfo) {
+ *(OptionalPath_t*)dest = Pathヽfrom_str(arg);
return true;
} else if (info->tag == TextInfo) {
- *(OptionalText_t*)dest = Text$from_str(arg);
+ *(OptionalText_t*)dest = Textヽfrom_str(arg);
return true;
} else if (info->tag == EnumInfo) {
for (int t = 0; t < info->EnumInfo.num_tags; t++) {
@@ -225,7 +225,7 @@ static Table_t parse_table(const TypeInfo_t *table, int n, char *args[])
*equals = '=';
}
- return Table$from_entries(entries, table);
+ return Tableヽfrom_entries(entries, table);
}
#ifdef __GNUC__
@@ -251,7 +251,7 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help,
while (non_opt_type->tag == OptionalInfo)
non_opt_type = non_opt_type->OptionalInfo.type;
- if (non_opt_type == &Bool$info
+ if (non_opt_type == &Boolヽinfo
&& strncmp(argv[i], "--no-", strlen("--no-")) == 0
&& strcmp(argv[i] + strlen("--no-"), spec[s].name) == 0) {
*(OptionalBool_t*)spec[s].dest = false;
@@ -286,7 +286,7 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help,
}
populated_args[s] = true;
*(OptionalTable_t*)spec[s].dest = parse_table(non_opt_type, num_args, &argv[i+1]);
- } else if (non_opt_type == &Bool$info) { // --flag
+ } else if (non_opt_type == &Boolヽinfo) { // --flag
populated_args[s] = true;
*(OptionalBool_t*)spec[s].dest = true;
} else {
@@ -351,7 +351,7 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help,
}
populated_args[s] = true;
*(OptionalTable_t*)spec[s].dest = parse_table(non_opt_type, num_args, &argv[i+1]);
- } else if (non_opt_type == &Bool$info) { // -f
+ } else if (non_opt_type == &Boolヽinfo) { // -f
populated_args[s] = true;
*(OptionalBool_t*)spec[s].dest = true;
} else {
@@ -403,7 +403,7 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help,
non_opt_type = non_opt_type->OptionalInfo.type;
// You can't specify boolean flags positionally
- if (non_opt_type == &Bool$info)
+ if (non_opt_type == &Boolヽinfo)
goto next_non_bool_flag;
if (non_opt_type->tag == ListInfo) {
@@ -456,7 +456,7 @@ public _Noreturn void fail_text(Text_t message)
public Text_t builtin_last_err()
{
- return Text$from_str(strerror(errno));
+ return Textヽfrom_str(strerror(errno));
}
static int _inspect_depth = 0;
@@ -548,7 +548,7 @@ public void test_value(const char *filename, int64_t start, int64_t end, const v
public void say(Text_t text, bool newline)
{
- Text$print(stdout, text);
+ Textヽprint(stdout, text);
if (newline)
fputc('\n', stdout);
fflush(stdout);
@@ -578,7 +578,7 @@ public OptionalText_t ask(Text_t prompt, bool bold, bool force_tty)
}
if (bold) fputs("\x1b[1m", out);
- Text$print(out, prompt);
+ Textヽprint(out, prompt);
if (bold) fputs("\x1b[m", out);
fflush(out);
@@ -604,7 +604,7 @@ public OptionalText_t ask(Text_t prompt, bool bold, bool force_tty)
gc_input = GC_MALLOC_ATOMIC((size_t)(length + 1));
memcpy(gc_input, line, (size_t)(length + 1));
- ret = Text$from_strn(gc_input, (size_t)(length));
+ ret = Textヽfrom_strn(gc_input, (size_t)(length));
cleanup:
if (out && out != stdout) fclose(out);
@@ -627,7 +627,7 @@ public bool pop_flag(char **argv, int *i, const char *flag, Text_t *result)
*i += 1;
return true;
} else if (strncmp(argv[*i] + 2, flag, strlen(flag)) == 0 && argv[*i][2 + strlen(flag)] == '=') {
- *result = Text$from_str(argv[*i] + 2 + strlen(flag) + 1);
+ *result = Textヽfrom_str(argv[*i] + 2 + strlen(flag) + 1);
argv[*i] = NULL;
*i += 1;
return true;
@@ -646,13 +646,13 @@ public void sleep_num(double seconds)
public OptionalText_t getenv_text(Text_t name)
{
- const char *val = getenv(Text$as_c_string(name));
- return val ? Text$from_str(val) : NONE_TEXT;
+ const char *val = getenv(Textヽas_c_string(name));
+ return val ? Textヽfrom_str(val) : NONE_TEXT;
}
public void setenv_text(Text_t name, Text_t value)
{
- setenv(Text$as_c_string(name), Text$as_c_string(value), 1);
+ setenv(Textヽas_c_string(name), Textヽas_c_string(value), 1);
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/structs.c b/src/stdlib/structs.c
index d4a22d93..3b42f2ac 100644
--- a/src/stdlib/structs.c
+++ b/src/stdlib/structs.c
@@ -18,7 +18,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
#endif
-PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type)
+PUREFUNC public uint64_t Structヽhash(const void *obj, const TypeInfo_t *type)
{
if (type->StructInfo.num_fields == 0)
return 0;
@@ -31,7 +31,7 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type)
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
NamedType_t field = type->StructInfo.fields[i];
- if (field.type == &Bool$info) {
+ if (field.type == &Boolヽinfo) {
bool b = ((*(char*)(obj + byte_offset)) >> bit_offset) & 0x1;
field_hashes[i] = (uint32_t)b;
bit_offset += 1;
@@ -56,7 +56,7 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type)
#pragma GCC diagnostic pop
#endif
-PUREFUNC public uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type)
+PUREFUNC public uint64_t PackedDataヽhash(const void *obj, const TypeInfo_t *type)
{
if (type->StructInfo.num_fields == 0)
return 0;
@@ -64,7 +64,7 @@ PUREFUNC public uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type
return siphash24(obj, (size_t)type->size);
}
-PUREFUNC public int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public int32_t Structヽcompare(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y)
return 0;
@@ -73,7 +73,7 @@ PUREFUNC public int32_t Struct$compare(const void *x, const void *y, const TypeI
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
NamedType_t field = type->StructInfo.fields[i];
- if (field.type == &Bool$info) {
+ if (field.type == &Boolヽinfo) {
bool bx = ((*(char*)(x + byte_offset)) >> bit_offset) & 0x1;
bool by = ((*(char*)(y + byte_offset)) >> bit_offset) & 0x1;
if (bx != by)
@@ -99,7 +99,7 @@ PUREFUNC public int32_t Struct$compare(const void *x, const void *y, const TypeI
return 0;
}
-PUREFUNC public bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public bool Structヽequal(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y)
return true;
@@ -108,7 +108,7 @@ PUREFUNC public bool Struct$equal(const void *x, const void *y, const TypeInfo_t
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
NamedType_t field = type->StructInfo.fields[i];
- if (field.type == &Bool$info) {
+ if (field.type == &Boolヽinfo) {
bool bx = ((*(char*)(x + byte_offset)) >> bit_offset) & 0x1;
bool by = ((*(char*)(y + byte_offset)) >> bit_offset) & 0x1;
if (bx != by)
@@ -133,35 +133,35 @@ PUREFUNC public bool Struct$equal(const void *x, const void *y, const TypeInfo_t
return true;
}
-PUREFUNC public bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *type)
+PUREFUNC public bool PackedDataヽequal(const void *x, const void *y, const TypeInfo_t *type)
{
if (x == y) return true;
return (memcmp(x, y, (size_t)type->size) == 0);
}
-PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type)
+PUREFUNC public Text_t Structヽas_text(const void *obj, bool colorize, const TypeInfo_t *type)
{
- if (!obj) return Text$from_str(type->StructInfo.name);
+ if (!obj) return Textヽfrom_str(type->StructInfo.name);
- Text_t name = Text$from_str(type->StructInfo.name);
+ Text_t name = Textヽfrom_str(type->StructInfo.name);
if (type->StructInfo.is_secret || type->StructInfo.is_opaque) {
- return colorize ? Texts(Text("\x1b[0;1m"), name, Text("\x1b[m(...)")) : Texts(name, Text("(...)"));
+ return colorize ? Texts(Text("\x1b[0;1m"), name, Text("\x1b[m(...)")) : Texts(name, "(...)");
}
- Text_t text = colorize ? Texts(Text("\x1b[0;1m"), name, Text("\x1b[m(")) : Texts(name, Text("("));
+ Text_t text = colorize ? Texts(Text("\x1b[0;1m"), name, Text("\x1b[m(")) : Texts(name, "(");
ptrdiff_t byte_offset = 0;
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
NamedType_t field = type->StructInfo.fields[i];
if (i > 0)
- text = Text$concat(text, Text(", "));
+ text = Textヽconcat(text, Text(", "));
if (type->StructInfo.num_fields > 1)
- text = Text$concat(text, Text$from_str(field.name), Text("="));
+ text = Textヽconcat(text, Textヽfrom_str(field.name), Text("="));
- if (field.type == &Bool$info) {
+ if (field.type == &Boolヽinfo) {
bool b = ((*(char*)(obj + byte_offset)) >> bit_offset) & 0x1;
- text = Text$concat(text, Text$from_str(colorize ? (b ? "\x1b[35myes\x1b[m" : "\x1b[35mno\x1b[m") : (b ? "yes" : "no")));
+ text = Textヽconcat(text, Textヽfrom_str(colorize ? (b ? "\x1b[35myes\x1b[m" : "\x1b[35mno\x1b[m") : (b ? "yes" : "no")));
bit_offset += 1;
if (bit_offset >= 8) {
byte_offset += 1;
@@ -174,25 +174,25 @@ PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const Type
}
if (field.type->align && byte_offset % field.type->align > 0)
byte_offset += field.type->align - (byte_offset % field.type->align);
- text = Text$concat(text, generic_as_text(obj + byte_offset, colorize, field.type));
+ text = Textヽconcat(text, generic_as_text(obj + byte_offset, colorize, field.type));
byte_offset += field.type->size;
}
}
- return Text$concat(text, Text(")"));
+ return Textヽconcat(text, Text(")"));
}
-PUREFUNC public bool Struct$is_none(const void *obj, const TypeInfo_t *type)
+PUREFUNC public bool Structヽis_none(const void *obj, const TypeInfo_t *type)
{
return *(bool*)(obj + type->size);
}
-public void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Structヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
ptrdiff_t byte_offset = 0;
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
NamedType_t field = type->StructInfo.fields[i];
- if (field.type == &Bool$info) {
+ if (field.type == &Boolヽinfo) {
bool b = ((*(char*)(obj + byte_offset)) >> bit_offset) & 0x1;
fputc((int)b, out);
bit_offset += 1;
@@ -213,13 +213,13 @@ public void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, cons
}
}
-public void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
+public void Structヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
{
ptrdiff_t byte_offset = 0;
ptrdiff_t bit_offset = 0;
for (int i = 0; i < type->StructInfo.num_fields; i++) {
NamedType_t field = type->StructInfo.fields[i];
- if (field.type == &Bool$info) {
+ if (field.type == &Boolヽinfo) {
bool b = (bool)fgetc(in);
*(char*)(outval + byte_offset) |= (b << bit_offset);
bit_offset += 1;
diff --git a/src/stdlib/structs.h b/src/stdlib/structs.h
index c9c6c40a..c04df1fc 100644
--- a/src/stdlib/structs.h
+++ b/src/stdlib/structs.h
@@ -7,34 +7,34 @@
#include "types.h"
#include "util.h"
-PUREFUNC uint64_t Struct$hash(const void *obj, const TypeInfo_t *type);
-PUREFUNC uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type);
-PUREFUNC int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type);
-PUREFUNC bool Struct$is_none(const void *obj, const TypeInfo_t *type);
-void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
+PUREFUNC uint64_t Structヽhash(const void *obj, const TypeInfo_t *type);
+PUREFUNC uint64_t PackedDataヽhash(const void *obj, const TypeInfo_t *type);
+PUREFUNC int32_t Structヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Structヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool PackedDataヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC Text_t Structヽas_text(const void *obj, bool colorize, const TypeInfo_t *type);
+PUREFUNC bool Structヽis_none(const void *obj, const TypeInfo_t *type);
+void Structヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Structヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
-#define Struct$metamethods { \
- .hash=Struct$hash, \
- .compare=Struct$compare, \
- .equal=Struct$equal, \
- .as_text=Struct$as_text, \
- .is_none=Struct$is_none, \
- .serialize=Struct$serialize, \
- .deserialize=Struct$deserialize, \
+#define Structヽmetamethods { \
+ .hash=Structヽhash, \
+ .compare=Structヽcompare, \
+ .equal=Structヽequal, \
+ .as_text=Structヽas_text, \
+ .is_none=Structヽis_none, \
+ .serialize=Structヽserialize, \
+ .deserialize=Structヽdeserialize, \
}
-#define PackedData$metamethods { \
- .hash=PackedData$hash, \
- .compare=Struct$compare, \
- .equal=PackedData$equal, \
- .as_text=Struct$as_text, \
- .is_none=Struct$is_none, \
- .serialize=Struct$serialize, \
- .deserialize=Struct$deserialize, \
+#define PackedDataヽmetamethods { \
+ .hash=PackedDataヽhash, \
+ .compare=Structヽcompare, \
+ .equal=PackedDataヽequal, \
+ .as_text=Structヽas_text, \
+ .is_none=Structヽis_none, \
+ .serialize=Structヽserialize, \
+ .deserialize=Structヽdeserialize, \
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c
index 9301914c..284b6e83 100644
--- a/src/stdlib/tables.c
+++ b/src/stdlib/tables.c
@@ -50,17 +50,17 @@ static TypeInfo_t MemoryPointer = {
.tag=PointerInfo,
.PointerInfo={
.sigil="@",
- .pointed=&Memory$info,
+ .pointed=&Memoryヽinfo,
},
- .metamethods=Pointer$metamethods,
+ .metamethods=Pointerヽmetamethods,
};
const TypeInfo_t CStrToVoidStarTable = {
.size=sizeof(Table_t),
.align=__alignof__(Table_t),
.tag=TableInfo,
- .TableInfo={.key=&CString$info, .value=&MemoryPointer},
- .metamethods=Table$metamethods,
+ .TableInfo={.key=&CStringヽinfo, .value=&MemoryPointer},
+ .metamethods=Tableヽmetamethods,
};
PUREFUNC static INLINE size_t entry_size(const TypeInfo_t *info)
@@ -98,7 +98,7 @@ static INLINE void hshow(const Table_t *t)
static void maybe_copy_on_write(Table_t *t, const TypeInfo_t *type)
{
if (t->entries.data_refcount != 0)
- List$compact(&t->entries, (int64_t)entry_size(type));
+ Listヽcompact(&t->entries, (int64_t)entry_size(type));
if (t->bucket_info && t->bucket_info->data_refcount != 0) {
size_t size = sizeof(bucket_info_t) + sizeof(bucket_t[t->bucket_info->count]);
@@ -108,7 +108,7 @@ static void maybe_copy_on_write(Table_t *t, const TypeInfo_t *type)
}
// Return address of value or NULL
-PUREFUNC public void *Table$get_raw(Table_t t, const void *key, const TypeInfo_t *type)
+PUREFUNC public void *Tableヽget_raw(Table_t t, const void *key, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
if (!key || !t.bucket_info) return NULL;
@@ -130,17 +130,17 @@ PUREFUNC public void *Table$get_raw(Table_t t, const void *key, const TypeInfo_t
return NULL;
}
-PUREFUNC public void *Table$get(Table_t t, const void *key, const TypeInfo_t *type)
+PUREFUNC public void *Tableヽget(Table_t t, const void *key, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
for (const Table_t *iter = &t; iter; iter = iter->fallback) {
- void *ret = Table$get_raw(*iter, key, type);
+ void *ret = Tableヽget_raw(*iter, key, type);
if (ret) return ret;
}
return NULL;
}
-static void Table$set_bucket(Table_t *t, const void *entry, int32_t index, const TypeInfo_t *type)
+static void Tableヽset_bucket(Table_t *t, const void *entry, int32_t index, const TypeInfo_t *type)
{
assert(t->bucket_info);
hshow(t);
@@ -202,9 +202,9 @@ static void hashmap_resize_buckets(Table_t *t, uint32_t new_capacity, const Type
t->bucket_info->count = new_capacity;
t->bucket_info->last_free = new_capacity-1;
// Rehash:
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
hdebug("Rehashing ", i, "\n");
- Table$set_bucket(t, GET_ENTRY(*t, i), i, type);
+ Tableヽset_bucket(t, GET_ENTRY(*t, i), i, type);
}
hshow(t);
@@ -216,7 +216,7 @@ static void hashmap_resize_buckets(Table_t *t, uint32_t new_capacity, const Type
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
#endif
-public void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
+public void *Tableヽreserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
if (!t || !key) return NULL;
@@ -230,7 +230,7 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const
hashmap_resize_buckets(t, 8, type);
} else {
// Check if we are clobbering a value:
- void *value_home = Table$get_raw(*t, key, type);
+ void *value_home = Tableヽget_raw(*t, key, type);
if (value_home) { // Update existing slot
// Ensure that `value_home` is still inside t->entries, even if COW occurs
ptrdiff_t offset = value_home - t->entries.data;
@@ -256,7 +256,7 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const
if (!value && value_size > 0) {
for (Table_t *iter = t->fallback; iter; iter = iter->fallback) {
- value = Table$get_raw(*iter, key, type);
+ value = Tableヽget_raw(*iter, key, type);
if (value) break;
}
}
@@ -270,27 +270,27 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const
memcpy(buf + value_offset(type), value, (size_t)value_size);
else if (value_size > 0)
memset(buf + value_offset(type), 0, (size_t)value_size);
- List$insert(&t->entries, buf, I(0), (int64_t)entry_size(type));
+ Listヽinsert(&t->entries, buf, I(0), (int64_t)entry_size(type));
int64_t entry_index = t->entries.length-1;
void *entry = GET_ENTRY(*t, entry_index);
- Table$set_bucket(t, entry, entry_index, type);
+ Tableヽset_bucket(t, entry, entry_index, type);
return entry + value_offset(type);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
-public void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
+public void Tableヽset(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
- (void)Table$reserve(t, key, value, type);
+ (void)Tableヽreserve(t, key, value, type);
}
-public void Table$remove(Table_t *t, const void *key, const TypeInfo_t *type)
+public void Tableヽremove(Table_t *t, const void *key, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
- if (!t || Table$length(*t) == 0) return;
+ if (!t || Tableヽlength(*t) == 0) return;
// TODO: this work doesn't need to be done if the key is already missing
maybe_copy_on_write(t, type);
@@ -358,7 +358,7 @@ public void Table$remove(Table_t *t, const void *key, const TypeInfo_t *type)
// Last entry is being removed, so clear it out to be safe:
memset(GET_ENTRY(*t, last_entry), 0, entry_size(type));
- List$remove_at(&t->entries, I(t->entries.length), I(1), (int64_t)entry_size(type));
+ Listヽremove_at(&t->entries, I(t->entries.length), I(1), (int64_t)entry_size(type));
int64_t bucket_to_clear;
if (prev) { // Middle (or end) of a chain
@@ -381,26 +381,26 @@ public void Table$remove(Table_t *t, const void *key, const TypeInfo_t *type)
hshow(t);
}
-CONSTFUNC public void *Table$entry(Table_t t, int64_t n)
+CONSTFUNC public void *Tableヽentry(Table_t t, int64_t n)
{
- if (n < 1 || n > Table$length(t))
+ if (n < 1 || n > Tableヽlength(t))
return NULL;
return GET_ENTRY(t, n-1);
}
-public void Table$clear(Table_t *t)
+public void Tableヽclear(Table_t *t)
{
memset(t, 0, sizeof(Table_t));
}
-public Table_t Table$sorted(Table_t t, const TypeInfo_t *type)
+public Table_t Tableヽsorted(Table_t t, const TypeInfo_t *type)
{
Closure_t cmp = (Closure_t){.fn=generic_compare, .userdata=(void*)type->TableInfo.key};
- List_t entries = List$sorted(t.entries, cmp, (int64_t)entry_size(type));
- return Table$from_entries(entries, type);
+ List_t entries = Listヽsorted(t.entries, cmp, (int64_t)entry_size(type));
+ return Tableヽfrom_entries(entries, type);
}
-PUREFUNC public bool Table$equal(const void *vx, const void *vy, const TypeInfo_t *type)
+PUREFUNC public bool Tableヽequal(const void *vx, const void *vy, const TypeInfo_t *type)
{
if (vx == vy) return true;
Table_t *x = (Table_t*)vx, *y = (Table_t*)vy;
@@ -419,7 +419,7 @@ PUREFUNC public bool Table$equal(const void *vx, const void *vy, const TypeInfo_
size_t offset = value_offset(type);
for (int64_t i = 0; i < x->entries.length; i++) {
void *x_key = x->entries.data + i*x->entries.stride;
- void *y_value = Table$get_raw(*y, x_key, type);
+ void *y_value = Tableヽget_raw(*y, x_key, type);
if (!y_value) return false;
void *x_value = x_key + offset;
if (!generic_equal(y_value, x_value, value_type))
@@ -428,7 +428,7 @@ PUREFUNC public bool Table$equal(const void *vx, const void *vy, const TypeInfo_
return true;
}
-PUREFUNC public int32_t Table$compare(const void *vx, const void *vy, const TypeInfo_t *type)
+PUREFUNC public int32_t Tableヽcompare(const void *vx, const void *vy, const TypeInfo_t *type)
{
if (vx == vy) return 0;
@@ -458,7 +458,7 @@ PUREFUNC public int32_t Table$compare(const void *vx, const void *vy, const Type
max_x_key = key;
void *x_value = key + value_offset(type);
- void *y_value = Table$get_raw(*y, key, type);
+ void *y_value = Tableヽget_raw(*y, key, type);
if (!y_value || (table.value->size > 0 && !generic_equal(x_value, y_value, table.value))) {
if (mismatched_key == NULL || generic_compare(key, mismatched_key, table.key) < 0)
@@ -475,7 +475,7 @@ PUREFUNC public int32_t Table$compare(const void *vx, const void *vy, const Type
max_y_key = key;
void *y_value = key + value_offset(type);
- void *x_value = Table$get_raw(*x, key, type);
+ void *x_value = Tableヽget_raw(*x, key, type);
if (!x_value || !generic_equal(x_value, y_value, table.value)) {
if (mismatched_key == NULL || generic_compare(key, mismatched_key, table.key) < 0)
mismatched_key = key;
@@ -483,8 +483,8 @@ PUREFUNC public int32_t Table$compare(const void *vx, const void *vy, const Type
}
if (mismatched_key) {
- void *x_value = Table$get_raw(*x, mismatched_key, type);
- void *y_value = Table$get_raw(*y, mismatched_key, type);
+ void *x_value = Tableヽget_raw(*x, mismatched_key, type);
+ void *y_value = Tableヽget_raw(*y, mismatched_key, type);
if (x_value && y_value) {
return generic_compare(x_value, y_value, table.value);
} else if (y_value) {
@@ -515,7 +515,7 @@ PUREFUNC public int32_t Table$compare(const void *vx, const void *vy, const Type
for (int64_t i = 0; i < x->entries.length; i++) {
void *key = x->entries.data + x->entries.stride * i;
void *x_value = key + value_offset(type);
- void *y_value = Table$get_raw(*y, key, type);
+ void *y_value = Tableヽget_raw(*y, key, type);
int32_t diff = generic_compare(x_value, y_value, table.value);
if (diff != 0) return diff;
}
@@ -530,7 +530,7 @@ PUREFUNC public int32_t Table$compare(const void *vx, const void *vy, const Type
return 0;
}
-PUREFUNC public uint64_t Table$hash(const void *obj, const TypeInfo_t *type)
+PUREFUNC public uint64_t Tableヽhash(const void *obj, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
Table_t *t = (Table_t*)obj;
@@ -560,7 +560,7 @@ PUREFUNC public uint64_t Table$hash(const void *obj, const TypeInfo_t *type)
t->entries.length,
keys_hash,
values_hash,
- t->fallback ? Table$hash(t->fallback, type) : 0,
+ t->fallback ? Tableヽhash(t->fallback, type) : 0,
};
t->hash = siphash24((void*)&components, sizeof(components));
if unlikely (t->hash == 0)
@@ -568,47 +568,47 @@ PUREFUNC public uint64_t Table$hash(const void *obj, const TypeInfo_t *type)
return t->hash;
}
-public Text_t Table$as_text(const void *obj, bool colorize, const TypeInfo_t *type)
+public Text_t Tableヽas_text(const void *obj, bool colorize, const TypeInfo_t *type)
{
Table_t *t = (Table_t*)obj;
assert(type->tag == TableInfo);
__typeof(type->TableInfo) table = type->TableInfo;
if (!t) {
- if (table.value != &Void$info)
- return Text$concat(
+ if (table.value != &Voidヽinfo)
+ return Textヽconcat(
Text("{"),
generic_as_text(NULL, false, table.key),
Text("="),
generic_as_text(NULL, false, table.value),
Text("}"));
else
- return Text$concat(
+ return Textヽconcat(
Text("|"),
generic_as_text(NULL, false, table.key),
Text("|"));
}
int64_t val_off = (int64_t)value_offset(type);
- Text_t text = table.value == &Void$info ? Text("|") : Text("{");
- for (int64_t i = 0, length = Table$length(*t); i < length; i++) {
+ Text_t text = table.value == &Voidヽinfo ? Text("|") : Text("{");
+ for (int64_t i = 0, length = Tableヽlength(*t); i < length; i++) {
if (i > 0)
- text = Text$concat(text, Text(", "));
+ text = Textヽconcat(text, Text(", "));
void *entry = GET_ENTRY(*t, i);
- text = Text$concat(text, generic_as_text(entry, colorize, table.key));
- if (table.value != &Void$info)
- text = Text$concat(text, Text("="), generic_as_text(entry + val_off, colorize, table.value));
+ text = Textヽconcat(text, generic_as_text(entry, colorize, table.key));
+ if (table.value != &Voidヽinfo)
+ text = Textヽconcat(text, Text("="), generic_as_text(entry + val_off, colorize, table.value));
}
if (t->fallback) {
- text = Text$concat(text, Text("; fallback="), Table$as_text(t->fallback, colorize, type));
+ text = Textヽconcat(text, Text("; fallback="), Tableヽas_text(t->fallback, colorize, type));
}
- text = Text$concat(text, table.value == &Void$info ? Text("|") : Text("}"));
+ text = Textヽconcat(text, table.value == &Voidヽinfo ? Text("|") : Text("}"));
return text;
}
-public Table_t Table$from_entries(List_t entries, const TypeInfo_t *type)
+public Table_t Tableヽfrom_entries(List_t entries, const TypeInfo_t *type)
{
assert(type->tag == TableInfo);
if (entries.length == 0)
@@ -625,92 +625,92 @@ public Table_t Table$from_entries(List_t entries, const TypeInfo_t *type)
size_t offset = value_offset(type);
for (int64_t i = 0; i < entries.length; i++) {
void *key = entries.data + i*entries.stride;
- Table$set(&t, key, key + offset, type);
+ Tableヽset(&t, key, key + offset, type);
}
return t;
}
// Overlap is "set intersection" in formal terms
-public Table_t Table$overlap(Table_t a, Table_t b, const TypeInfo_t *type)
+public Table_t Tableヽoverlap(Table_t a, Table_t b, const TypeInfo_t *type)
{
// Return a table such that t[k]==a[k] for all k such that a.has(k), b.has(k), and a[k]==b[k]
Table_t result = {};
const size_t offset = value_offset(type);
for (Table_t *t = &a; t; t = t->fallback) {
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
void *key = GET_ENTRY(*t, i);
void *a_value = key + offset;
- void *b_value = Table$get(b, key, type);
+ void *b_value = Tableヽget(b, key, type);
if (b_value && generic_equal(a_value, b_value, type->TableInfo.value))
- Table$set(&result, key, a_value, type);
+ Tableヽset(&result, key, a_value, type);
}
}
return result;
}
// With is "set union" in formal terms
-public Table_t Table$with(Table_t a, Table_t b, const TypeInfo_t *type)
+public Table_t Tableヽwith(Table_t a, Table_t b, const TypeInfo_t *type)
{
// return a table such that t[k]==b[k] for all k such that b.has(k), and t[k]==a[k] for all k such that a.has(k) and not b.has(k)
Table_t result = {};
const size_t offset = value_offset(type);
for (Table_t *t = &a; t; t = t->fallback) {
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
void *key = GET_ENTRY(*t, i);
- Table$set(&result, key, key + offset, type);
+ Tableヽset(&result, key, key + offset, type);
}
}
for (Table_t *t = &b; t; t = t->fallback) {
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
void *key = GET_ENTRY(*t, i);
- Table$set(&result, key, key + offset, type);
+ Tableヽset(&result, key, key + offset, type);
}
}
return result;
}
// Xor is "disjunctive union" or "symmetric difference" in formal terms
-public Table_t Table$xor(Table_t a, Table_t b, const TypeInfo_t *type)
+public Table_t Tableヽxor(Table_t a, Table_t b, const TypeInfo_t *type)
{
// return a table with elements in `a` or `b`, but not both
Table_t result = {};
const size_t offset = value_offset(type);
for (Table_t *t = &a; t; t = t->fallback) {
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
void *key = GET_ENTRY(*t, i);
- if (Table$get(b, key, type) == NULL)
- Table$set(&result, key, key + offset, type);
+ if (Tableヽget(b, key, type) == NULL)
+ Tableヽset(&result, key, key + offset, type);
}
}
for (Table_t *t = &b; t; t = t->fallback) {
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
void *key = GET_ENTRY(*t, i);
- if (Table$get(a, key, type) == NULL)
- Table$set(&result, key, key + offset, type);
+ if (Tableヽget(a, key, type) == NULL)
+ Tableヽset(&result, key, key + offset, type);
}
}
return result;
}
// Without is "set difference" in formal terms
-public Table_t Table$without(Table_t a, Table_t b, const TypeInfo_t *type)
+public Table_t Tableヽwithout(Table_t a, Table_t b, const TypeInfo_t *type)
{
// Return a table such that t[k]==a[k] for all k such that not b.has(k) or b[k] != a[k]
Table_t result = {};
const size_t offset = value_offset(type);
for (Table_t *t = &a; t; t = t->fallback) {
- for (int64_t i = 0; i < Table$length(*t); i++) {
+ for (int64_t i = 0; i < Tableヽlength(*t); i++) {
void *key = GET_ENTRY(*t, i);
void *a_value = key + offset;
- void *b_value = Table$get(b, key, type);
+ void *b_value = Tableヽget(b, key, type);
if (!b_value || !generic_equal(a_value, b_value, type->TableInfo.value))
- Table$set(&result, key, a_value, type);
+ Tableヽset(&result, key, a_value, type);
}
}
return result;
}
-public Table_t Table$with_fallback(Table_t t, OptionalTable_t fallback)
+public Table_t Tableヽwith_fallback(Table_t t, OptionalTable_t fallback)
{
if (fallback.entries.length <= 0) {
t.fallback = NULL;
@@ -723,66 +723,66 @@ public Table_t Table$with_fallback(Table_t t, OptionalTable_t fallback)
}
}
-PUREFUNC public bool Table$is_subset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type)
+PUREFUNC public bool Tableヽis_subset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type)
{
if (a.entries.length > b.entries.length || (strict && a.entries.length == b.entries.length))
return false;
- for (int64_t i = 0; i < Table$length(a); i++) {
- void *found = Table$get_raw(b, GET_ENTRY(a, i), type);
+ for (int64_t i = 0; i < Tableヽlength(a); i++) {
+ void *found = Tableヽget_raw(b, GET_ENTRY(a, i), type);
if (!found) return false;
}
return true;
}
-PUREFUNC public bool Table$is_superset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type)
+PUREFUNC public bool Tableヽis_superset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type)
{
- return Table$is_subset_of(b, a, strict, type);
+ return Tableヽis_subset_of(b, a, strict, type);
}
-PUREFUNC public void *Table$str_get(Table_t t, const char *key)
+PUREFUNC public void *Tableヽstr_get(Table_t t, const char *key)
{
- void **ret = Table$get(t, &key, &CStrToVoidStarTable);
+ void **ret = Tableヽget(t, &key, &CStrToVoidStarTable);
return ret ? *ret : NULL;
}
-PUREFUNC public void *Table$str_get_raw(Table_t t, const char *key)
+PUREFUNC public void *Tableヽstr_get_raw(Table_t t, const char *key)
{
- void **ret = Table$get_raw(t, &key, &CStrToVoidStarTable);
+ void **ret = Tableヽget_raw(t, &key, &CStrToVoidStarTable);
return ret ? *ret : NULL;
}
-public void *Table$str_reserve(Table_t *t, const char *key, const void *value)
+public void *Tableヽstr_reserve(Table_t *t, const char *key, const void *value)
{
- return Table$reserve(t, &key, &value, &CStrToVoidStarTable);
+ return Tableヽreserve(t, &key, &value, &CStrToVoidStarTable);
}
-public void Table$str_set(Table_t *t, const char *key, const void *value)
+public void Tableヽstr_set(Table_t *t, const char *key, const void *value)
{
- Table$set(t, &key, &value, &CStrToVoidStarTable);
+ Tableヽset(t, &key, &value, &CStrToVoidStarTable);
}
-public void Table$str_remove(Table_t *t, const char *key)
+public void Tableヽstr_remove(Table_t *t, const char *key)
{
- return Table$remove(t, &key, &CStrToVoidStarTable);
+ return Tableヽremove(t, &key, &CStrToVoidStarTable);
}
-CONSTFUNC public void *Table$str_entry(Table_t t, int64_t n)
+CONSTFUNC public void *Tableヽstr_entry(Table_t t, int64_t n)
{
- return Table$entry(t, n);
+ return Tableヽentry(t, n);
}
-PUREFUNC public bool Table$is_none(const void *obj, const TypeInfo_t *info)
+PUREFUNC public bool Tableヽis_none(const void *obj, const TypeInfo_t *info)
{
(void)info;
return ((Table_t*)obj)->entries.length < 0;
}
-public void Table$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
+public void Tableヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type)
{
Table_t *t = (Table_t*)obj;
int64_t len = t->entries.length;
- Int64$serialize(&len, out, pointers, &Int64$info);
+ Int64ヽserialize(&len, out, pointers, &Int64ヽinfo);
size_t offset = value_offset(type);
for (int64_t i = 0; i < len; i++) {
@@ -793,17 +793,17 @@ public void Table$serialize(const void *obj, FILE *out, Table_t *pointers, const
assert(fputc(t->fallback != NULL ? 1 : 0, out) != EOF);
if (t->fallback)
- Table$serialize(t->fallback, out, pointers, type);
+ Tableヽserialize(t->fallback, out, pointers, type);
}
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector"
#endif
-public void Table$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
+public void Tableヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type)
{
int64_t len;
- Int64$deserialize(in, &len, pointers, &Int$info);
+ Int64ヽdeserialize(in, &len, pointers, &Intヽinfo);
Table_t t = {};
for (int64_t i = 0; i < len; i++) {
@@ -812,12 +812,12 @@ public void Table$deserialize(FILE *in, void *outval, List_t *pointers, const Ty
char value[type->TableInfo.value->size];
if (type->TableInfo.value->size > 0)
_deserialize(in, value, pointers, type->TableInfo.value);
- Table$set(&t, key, value, type);
+ Tableヽset(&t, key, value, type);
}
if (fgetc(in) != 0) {
t.fallback = GC_MALLOC(sizeof(Table_t));
- Table$deserialize(in, t.fallback, pointers, type);
+ Tableヽdeserialize(in, t.fallback, pointers, type);
}
*(Table_t*)outval = t;
diff --git a/src/stdlib/tables.h b/src/stdlib/tables.h
index f80c16c3..eac8c7d8 100644
--- a/src/stdlib/tables.h
+++ b/src/stdlib/tables.h
@@ -13,94 +13,94 @@
#define Table(key_t, val_t, key_info, value_info, fb, N, ...) ({ \
struct { key_t k; val_t v; } ents[N] = {__VA_ARGS__}; \
- Table_t table = Table$from_entries((List_t){ \
+ Table_t table = Tableヽfrom_entries((List_t){ \
.data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \
.length=sizeof(ents)/sizeof(ents[0]), \
.stride=(void*)&ents[1] - (void*)&ents[0], \
- }, Table$info(key_info, value_info)); \
+ }, Tableヽinfo(key_info, value_info)); \
table.fallback = fb; \
table; })
#define Set(item_t, item_info, N, ...) ({ \
item_t ents[N] = {__VA_ARGS__}; \
- Table_t set = Table$from_entries((List_t){ \
+ Table_t set = Tableヽfrom_entries((List_t){ \
.data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \
.length=sizeof(ents)/sizeof(ents[0]), \
.stride=(void*)&ents[1] - (void*)&ents[0], \
- }, Set$info(item_info)); \
+ }, Setヽinfo(item_info)); \
set; })
-Table_t Table$from_entries(List_t entries, const TypeInfo_t *type);
-void *Table$get(Table_t t, const void *key, const TypeInfo_t *type);
-#define Table$get_optional(table_expr, key_t, val_t, key_expr, nonnull_var, nonnull_expr, null_expr, info_expr) ({ \
+Table_t Tableヽfrom_entries(List_t entries, const TypeInfo_t *type);
+void *Tableヽget(Table_t t, const void *key, const TypeInfo_t *type);
+#define Tableヽget_optional(table_expr, key_t, val_t, key_expr, nonnull_var, nonnull_expr, null_expr, info_expr) ({ \
const Table_t t = table_expr; const key_t k = key_expr; \
- val_t *nonnull_var = Table$get(t, &k, info_expr); \
+ val_t *nonnull_var = Tableヽget(t, &k, info_expr); \
nonnull_var ? nonnull_expr : null_expr; })
-#define Table$get_or_setdefault(table_expr, key_t, val_t, key_expr, default_expr, info_expr) ({ \
+#define Tableヽget_or_setdefault(table_expr, key_t, val_t, key_expr, default_expr, info_expr) ({ \
Table_t *t = table_expr; const key_t k = key_expr; \
- if (t->entries.data_refcount > 0) List$compact(&t->entries, sizeof(struct {key_t k; val_t v;})); \
- val_t *v = Table$get(*t, &k, info_expr); \
- v ? v : (val_t*)Table$reserve(t, &k, (val_t[1]){default_expr}, info_expr); })
-#define Table$get_or_default(table_expr, key_t, val_t, key_expr, default_expr, info_expr) ({ \
+ if (t->entries.data_refcount > 0) Listヽcompact(&t->entries, sizeof(struct {key_t k; val_t v;})); \
+ val_t *v = Tableヽget(*t, &k, info_expr); \
+ v ? v : (val_t*)Tableヽreserve(t, &k, (val_t[1]){default_expr}, info_expr); })
+#define Tableヽget_or_default(table_expr, key_t, val_t, key_expr, default_expr, info_expr) ({ \
const Table_t t = table_expr; const key_t k = key_expr; \
- val_t *v = Table$get(t, &k, info_expr); \
+ val_t *v = Tableヽget(t, &k, info_expr); \
v ? *v : default_expr; })
-#define Table$has_value(table_expr, key_expr, info_expr) ({ \
+#define Tableヽhas_value(table_expr, key_expr, info_expr) ({ \
const Table_t t = table_expr; __typeof(key_expr) k = key_expr; \
- (Table$get(t, &k, info_expr) != NULL); })
-PUREFUNC void *Table$get_raw(Table_t t, const void *key, const TypeInfo_t *type);
-CONSTFUNC void *Table$entry(Table_t t, int64_t n);
-void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type);
-void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo_t *type);
-#define Table$set_value(t, key_expr, value_expr, type) ({ __typeof(key_expr) k = key_expr; __typeof(value_expr) v = value_expr; \
- Table$set(t, &k, &v, type); })
-void Table$remove(Table_t *t, const void *key, const TypeInfo_t *type);
-#define Table$remove_value(t, key_expr, type) ({ __typeof(key_expr) k = key_expr; Table$remove(t, &k, type); })
+ (Tableヽget(t, &k, info_expr) != NULL); })
+PUREFUNC void *Tableヽget_raw(Table_t t, const void *key, const TypeInfo_t *type);
+CONSTFUNC void *Tableヽentry(Table_t t, int64_t n);
+void *Tableヽreserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type);
+void Tableヽset(Table_t *t, const void *key, const void *value, const TypeInfo_t *type);
+#define Tableヽset_value(t, key_expr, value_expr, type) ({ __typeof(key_expr) k = key_expr; __typeof(value_expr) v = value_expr; \
+ Tableヽset(t, &k, &v, type); })
+void Tableヽremove(Table_t *t, const void *key, const TypeInfo_t *type);
+#define Tableヽremove_value(t, key_expr, type) ({ __typeof(key_expr) k = key_expr; Tableヽremove(t, &k, type); })
-Table_t Table$overlap(Table_t a, Table_t b, const TypeInfo_t *type);
-Table_t Table$with(Table_t a, Table_t b, const TypeInfo_t *type);
-Table_t Table$without(Table_t a, Table_t b, const TypeInfo_t *type);
-Table_t Table$xor(Table_t a, Table_t b, const TypeInfo_t *type);
-Table_t Table$with_fallback(Table_t t, OptionalTable_t fallback);
-PUREFUNC bool Table$is_subset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type);
-PUREFUNC bool Table$is_superset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type);
+Table_t Tableヽoverlap(Table_t a, Table_t b, const TypeInfo_t *type);
+Table_t Tableヽwith(Table_t a, Table_t b, const TypeInfo_t *type);
+Table_t Tableヽwithout(Table_t a, Table_t b, const TypeInfo_t *type);
+Table_t Tableヽxor(Table_t a, Table_t b, const TypeInfo_t *type);
+Table_t Tableヽwith_fallback(Table_t t, OptionalTable_t fallback);
+PUREFUNC bool Tableヽis_subset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type);
+PUREFUNC bool Tableヽis_superset_of(Table_t a, Table_t b, bool strict, const TypeInfo_t *type);
-void Table$clear(Table_t *t);
-Table_t Table$sorted(Table_t t, const TypeInfo_t *type);
-void Table$mark_copy_on_write(Table_t *t);
+void Tableヽclear(Table_t *t);
+Table_t Tableヽsorted(Table_t t, const TypeInfo_t *type);
+void Tableヽmark_copy_on_write(Table_t *t);
#define TABLE_INCREF(t) ({ LIST_INCREF((t).entries); if ((t).bucket_info) (t).bucket_info->data_refcount += ((t).bucket_info->data_refcount < TABLE_MAX_DATA_REFCOUNT); })
#define TABLE_COPY(t) ({ TABLE_INCREF(t); t; })
-PUREFUNC int32_t Table$compare(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC bool Table$equal(const void *x, const void *y, const TypeInfo_t *type);
-PUREFUNC uint64_t Table$hash(const void *t, const TypeInfo_t *type);
-Text_t Table$as_text(const void *t, bool colorize, const TypeInfo_t *type);
-PUREFUNC bool Table$is_none(const void *obj, const TypeInfo_t*);
+PUREFUNC int32_t Tableヽcompare(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool Tableヽequal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC uint64_t Tableヽhash(const void *t, const TypeInfo_t *type);
+Text_t Tableヽas_text(const void *t, bool colorize, const TypeInfo_t *type);
+PUREFUNC bool Tableヽis_none(const void *obj, const TypeInfo_t*);
-CONSTFUNC void *Table$str_entry(Table_t t, int64_t n);
-PUREFUNC void *Table$str_get(Table_t t, const char *key);
-PUREFUNC void *Table$str_get_raw(Table_t t, const char *key);
-void Table$str_set(Table_t *t, const char *key, const void *value);
-void *Table$str_reserve(Table_t *t, const char *key, const void *value);
-void Table$str_remove(Table_t *t, const char *key);
-void Table$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
-void Table$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
+CONSTFUNC void *Tableヽstr_entry(Table_t t, int64_t n);
+PUREFUNC void *Tableヽstr_get(Table_t t, const char *key);
+PUREFUNC void *Tableヽstr_get_raw(Table_t t, const char *key);
+void Tableヽstr_set(Table_t *t, const char *key, const void *value);
+void *Tableヽstr_reserve(Table_t *t, const char *key, const void *value);
+void Tableヽstr_remove(Table_t *t, const char *key);
+void Tableヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
+void Tableヽdeserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
-#define Table$length(t) ((t).entries.length)
+#define Tableヽlength(t) ((t).entries.length)
extern const TypeInfo_t CStrToVoidStarTable;
-#define Table$metamethods { \
- .as_text=Table$as_text, \
- .compare=Table$compare, \
- .equal=Table$equal, \
- .hash=Table$hash, \
- .is_none=Table$is_none, \
- .serialize=Table$serialize, \
- .deserialize=Table$deserialize, \
+#define Tableヽmetamethods { \
+ .as_text=Tableヽas_text, \
+ .compare=Tableヽcompare, \
+ .equal=Tableヽequal, \
+ .hash=Tableヽhash, \
+ .is_none=Tableヽis_none, \
+ .serialize=Tableヽserialize, \
+ .deserialize=Tableヽdeserialize, \
}
-#define Table$info(key_expr, value_expr) &((TypeInfo_t){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
- .tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr, .metamethods=Table$metamethods})
-#define Set$info(item_info) &((TypeInfo_t){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
- .tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&Void$info, .metamethods=Table$metamethods})
+#define Tableヽinfo(key_expr, value_expr) &((TypeInfo_t){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
+ .tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr, .metamethods=Tableヽmetamethods})
+#define Setヽinfo(item_info) &((TypeInfo_t){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
+ .tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&Voidヽinfo, .metamethods=Tableヽmetamethods})
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index 8ef0874e..ec444bfe 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -195,8 +195,8 @@ public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_le
if (last_grapheme != 0 && graphemes_equal(&ptr, &synthetic_graphemes[-last_grapheme-1].utf32_cluster, NULL))
return last_grapheme;
- TypeInfo_t GraphemeIDLookupTableInfo = *Table$info(&GraphemeClusterInfo, &Int32$info);
- int32_t *found = Table$get(grapheme_ids_by_codepoints, &ptr, &GraphemeIDLookupTableInfo);
+ TypeInfo_t GraphemeIDLookupTableInfo = *Tableヽinfo(&GraphemeClusterInfo, &Int32ヽinfo);
+ int32_t *found = Tableヽget(grapheme_ids_by_codepoints, &ptr, &GraphemeIDLookupTableInfo);
if (found) return *found;
// New synthetic grapheme:
@@ -266,7 +266,7 @@ public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_le
// Cleanup from unicode API:
if (u8 != u8_buf) free(u8);
- Table$set(&grapheme_ids_by_codepoints, &codepoint_copy, &grapheme_id, &GraphemeIDLookupTableInfo);
+ Tableヽset(&grapheme_ids_by_codepoints, &codepoint_copy, &grapheme_id, &GraphemeIDLookupTableInfo);
last_grapheme = grapheme_id;
return grapheme_id;
@@ -275,7 +275,7 @@ public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_le
#pragma GCC diagnostic pop
#endif
-public int Text$print(FILE *stream, Text_t t)
+public int Textヽprint(FILE *stream, Text_t t)
{
if (t.length == 0) return 0;
@@ -321,8 +321,8 @@ public int Text$print(FILE *stream, Text_t t)
return written;
}
case TEXT_CONCAT: {
- int written = Text$print(stream, *t.left);
- written += Text$print(stream, *t.right);
+ int written = Textヽprint(stream, *t.left);
+ written += Textヽprint(stream, *t.right);
return written;
}
default: return 0;
@@ -478,8 +478,8 @@ static Text_t concat2(Text_t a, Text_t b)
if (a.length == 0) return b;
if (b.length == 0) return a;
- int32_t last_a = Text$get_grapheme(a, a.length-1);
- int32_t first_b = Text$get_grapheme(b, 0);
+ int32_t last_a = Textヽget_grapheme(a, a.length-1);
+ int32_t first_b = Textヽget_grapheme(b, 0);
// Magic number, we know that no codepoints below here trigger instability:
static const int32_t LOWEST_CODEPOINT_TO_CHECK = 0x300; // COMBINING GRAVE ACCENT
@@ -525,7 +525,7 @@ static Text_t concat2(Text_t a, Text_t b)
return concat2_assuming_safe(a, b);
}
- Text_t glue = Text$from_codepoints((List_t){.data=norm_buf, .length=(int64_t)norm_length, .stride=sizeof(int32_t)});
+ Text_t glue = Textヽfrom_codepoints((List_t){.data=norm_buf, .length=(int64_t)norm_length, .stride=sizeof(int32_t)});
if (normalized != norm_buf)
free(normalized);
@@ -533,16 +533,16 @@ static Text_t concat2(Text_t a, Text_t b)
if (a.length == 1 && b.length == 1)
return glue;
else if (a.length == 1)
- return concat2_assuming_safe(glue, Text$slice(b, I(2), I(b.length)));
+ return concat2_assuming_safe(glue, Textヽslice(b, I(2), I(b.length)));
else if (b.length == 1)
- return concat2_assuming_safe(Text$slice(a, I(1), I(a.length-1)), glue);
+ return concat2_assuming_safe(Textヽslice(a, I(1), I(a.length-1)), glue);
else
return concat2_assuming_safe(
- concat2_assuming_safe(Text$slice(a, I(1), I(a.length-1)), glue),
- Text$slice(b, I(2), I(b.length)));
+ concat2_assuming_safe(Textヽslice(a, I(1), I(a.length-1)), glue),
+ Textヽslice(b, I(2), I(b.length)));
}
-public Text_t Text$_concat(int n, Text_t items[n])
+public Text_t Textヽ_concat(int n, Text_t items[n])
{
if (n == 0) return EMPTY_TEXT;
@@ -554,35 +554,35 @@ public Text_t Text$_concat(int n, Text_t items[n])
return ret;
}
-public Text_t Text$repeat(Text_t text, Int_t count)
+public Text_t Textヽrepeat(Text_t text, Int_t count)
{
- if (text.length == 0 || Int$is_negative(count))
+ if (text.length == 0 || Intヽis_negative(count))
return EMPTY_TEXT;
- Int_t result_len = Int$times(count, I(text.length));
- if (Int$compare_value(result_len, I(1l<<40)) > 0)
+ Int_t result_len = Intヽtimes(count, I(text.length));
+ if (Intヽcompare_value(result_len, I(1l<<40)) > 0)
fail("Text repeating would produce too big of an result!");
- int64_t count64 = Int64$from_int(count, false);
+ int64_t count64 = Int64ヽfrom_int(count, false);
Text_t ret = text;
for (int64_t c = 1; c < count64; c++)
ret = concat2(ret, text);
return ret;
}
-public Int_t Text$width(Text_t text, Text_t language)
+public Int_t Textヽwidth(Text_t text, Text_t language)
{
- int width = u8_strwidth((const uint8_t*)Text$as_c_string(text), Text$as_c_string(language));
- return Int$from_int32(width);
+ int width = u8_strwidth((const uint8_t*)Textヽas_c_string(text), Textヽas_c_string(language));
+ return Intヽfrom_int32(width);
}
-static Text_t Text$repeat_to_width(Text_t to_repeat, int64_t target_width, Text_t language)
+static Text_t Textヽrepeat_to_width(Text_t to_repeat, int64_t target_width, Text_t language)
{
if (target_width <= 0)
return EMPTY_TEXT;
- const char *lang_str = Text$as_c_string(language);
- int64_t width = (int64_t)u8_strwidth((const uint8_t*)Text$as_c_string(to_repeat), lang_str);
+ const char *lang_str = Textヽas_c_string(language);
+ int64_t width = (int64_t)u8_strwidth((const uint8_t*)Textヽas_c_string(to_repeat), lang_str);
Text_t repeated = EMPTY_TEXT;
int64_t repeated_width = 0;
while (repeated_width + width <= target_width) {
@@ -592,10 +592,10 @@ static Text_t Text$repeat_to_width(Text_t to_repeat, int64_t target_width, Text_
if (repeated_width < target_width) {
for (int64_t i = 0; repeated_width < target_width && i < to_repeat.length; i++) {
- Text_t c = Text$slice(to_repeat, I_small(i+1), I_small(i+1));
- int64_t w = (int64_t)u8_strwidth((const uint8_t*)Text$as_c_string(c), lang_str);
+ Text_t c = Textヽslice(to_repeat, I_small(i+1), I_small(i+1));
+ int64_t w = (int64_t)u8_strwidth((const uint8_t*)Textヽas_c_string(c), lang_str);
if (repeated_width + w > target_width) {
- repeated = concat2(repeated, Text$repeat(Text(" "), I(target_width - repeated_width)));
+ repeated = concat2(repeated, Textヽrepeat(Text(" "), I(target_width - repeated_width)));
repeated_width = target_width;
break;
}
@@ -607,37 +607,37 @@ static Text_t Text$repeat_to_width(Text_t to_repeat, int64_t target_width, Text_
return repeated;
}
-public Text_t Text$left_pad(Text_t text, Int_t width, Text_t padding, Text_t language)
+public Text_t Textヽleft_pad(Text_t text, Int_t width, Text_t padding, Text_t language)
{
if (padding.length == 0)
fail("Cannot pad with an empty text!");
- int64_t needed = Int64$from_int(width, false) - Int64$from_int(Text$width(text, language), false);
- return concat2(Text$repeat_to_width(padding, needed, language), text);
+ int64_t needed = Int64ヽfrom_int(width, false) - Int64ヽfrom_int(Textヽwidth(text, language), false);
+ return concat2(Textヽrepeat_to_width(padding, needed, language), text);
}
-public Text_t Text$right_pad(Text_t text, Int_t width, Text_t padding, Text_t language)
+public Text_t Textヽright_pad(Text_t text, Int_t width, Text_t padding, Text_t language)
{
if (padding.length == 0)
fail("Cannot pad with an empty text!");
- int64_t needed = Int64$from_int(width, false) - Int64$from_int(Text$width(text, language), false);
- return concat2(text, Text$repeat_to_width(padding, needed, language));
+ int64_t needed = Int64ヽfrom_int(width, false) - Int64ヽfrom_int(Textヽwidth(text, language), false);
+ return concat2(text, Textヽrepeat_to_width(padding, needed, language));
}
-public Text_t Text$middle_pad(Text_t text, Int_t width, Text_t padding, Text_t language)
+public Text_t Textヽmiddle_pad(Text_t text, Int_t width, Text_t padding, Text_t language)
{
if (padding.length == 0)
fail("Cannot pad with an empty text!");
- int64_t needed = Int64$from_int(width, false) - Int64$from_int(Text$width(text, language), false);
- return Texts(Text$repeat_to_width(padding, needed/2, language), text, Text$repeat_to_width(padding, (needed+1)/2, language));
+ int64_t needed = Int64ヽfrom_int(width, false) - Int64ヽfrom_int(Textヽwidth(text, language), false);
+ return Texts(Textヽrepeat_to_width(padding, needed/2, language), text, Textヽrepeat_to_width(padding, (needed+1)/2, language));
}
-public Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int)
+public Text_t Textヽslice(Text_t text, Int_t first_int, Int_t last_int)
{
- int64_t first = Int64$from_int(first_int, false);
- int64_t last = Int64$from_int(last_int, false);
+ int64_t first = Int64ヽfrom_int(first_int, false);
+ int64_t last = Int64ヽfrom_int(last_int, false);
if (first == 0) fail("Invalid index: 0");
if (last == 0) return EMPTY_TEXT;
@@ -660,8 +660,8 @@ public Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int)
last -= text.left->length;
text = *text.right;
} else {
- return concat2_assuming_safe(Text$slice(*text.left, I(first), I(text.length)),
- Text$slice(*text.right, I(1), I(last-text.left->length)));
+ return concat2_assuming_safe(Textヽslice(*text.left, I(first), I(text.length)),
+ Textヽslice(*text.right, I(1), I(last-text.left->length)));
}
}
@@ -694,17 +694,17 @@ public Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int)
return EMPTY_TEXT;
}
-public Text_t Text$from(Text_t text, Int_t first)
+public Text_t Textヽfrom(Text_t text, Int_t first)
{
- return Text$slice(text, first, I_small(-1));
+ return Textヽslice(text, first, I_small(-1));
}
-public Text_t Text$to(Text_t text, Int_t last)
+public Text_t Textヽto(Text_t text, Int_t last)
{
- return Text$slice(text, I_small(1), last);
+ return Textヽslice(text, I_small(1), last);
}
-public Text_t Text$reversed(Text_t text)
+public Text_t Textヽreversed(Text_t text)
{
switch (text.tag) {
case TEXT_ASCII: {
@@ -739,19 +739,19 @@ public Text_t Text$reversed(Text_t text)
return ret;
}
case TEXT_CONCAT: {
- return concat2_assuming_safe(Text$reversed(*text.right), Text$reversed(*text.left));
+ return concat2_assuming_safe(Textヽreversed(*text.right), Textヽreversed(*text.left));
}
default: errx(1, "Invalid tag");
}
return EMPTY_TEXT;
}
-public PUREFUNC Text_t Text$cluster(Text_t text, Int_t index)
+public PUREFUNC Text_t Textヽcluster(Text_t text, Int_t index)
{
- return Text$slice(text, index, index);
+ return Textヽslice(text, index, index);
}
-static Text_t Text$from_components(List_t graphemes, Table_t unique_clusters)
+static Text_t Textヽfrom_components(List_t graphemes, Table_t unique_clusters)
{
struct {
int32_t map[unique_clusters.entries.length];
@@ -771,7 +771,7 @@ static Text_t Text$from_components(List_t graphemes, Table_t unique_clusters)
}
for (int64_t i = 0; i < graphemes.length; i++) {
int32_t g = *(int32_t*)(graphemes.data + i*graphemes.stride);
- uint8_t *byte = Table$get(unique_clusters, &g, Table$info(&Int32$info, &Byte$info));
+ uint8_t *byte = Tableヽget(unique_clusters, &g, Tableヽinfo(&Int32ヽinfo, &Byteヽinfo));
assert(byte);
blob->bytes[i] = *byte;
}
@@ -787,7 +787,7 @@ static Text_t Text$from_components(List_t graphemes, Table_t unique_clusters)
}
}
-public OptionalText_t Text$from_strn(const char *str, size_t len)
+public OptionalText_t Textヽfrom_strn(const char *str, size_t len)
{
int64_t ascii_span = 0;
for (size_t i = 0; i < len && isascii(str[i]); i++)
@@ -820,23 +820,23 @@ public OptionalText_t Text$from_strn(const char *str, size_t len)
uint32_t *u32s_normalized = u32_normalize(UNINORM_NFC, u32s, u32_len, buf2, &u32_normlen);
int32_t g = get_synthetic_grapheme(u32s_normalized, (int64_t)u32_normlen);
- List$insert(&graphemes, &g, I(0), sizeof(int32_t));
- Table$get_or_setdefault(&unique_clusters, int32_t, uint8_t, g, (uint8_t)unique_clusters.entries.length, Table$info(&Int32$info, &Byte$info));
+ Listヽinsert(&graphemes, &g, I(0), sizeof(int32_t));
+ Tableヽget_or_setdefault(&unique_clusters, int32_t, uint8_t, g, (uint8_t)unique_clusters.entries.length, Tableヽinfo(&Int32ヽinfo, &Byteヽinfo));
if (u32s != buf) free(u32s);
if (u32s_normalized != buf2) free(u32s_normalized);
if (unique_clusters.entries.length >= 256) {
- return concat2_assuming_safe(Text$from_components(graphemes, unique_clusters), Text$from_strn(next, (size_t)(end-next)));
+ return concat2_assuming_safe(Textヽfrom_components(graphemes, unique_clusters), Textヽfrom_strn(next, (size_t)(end-next)));
}
}
- return Text$from_components(graphemes, unique_clusters);
+ return Textヽfrom_components(graphemes, unique_clusters);
}
-public OptionalText_t Text$from_str(const char *str)
+public OptionalText_t Textヽfrom_str(const char *str)
{
- return str ? Text$from_strn(str, strlen(str)) : Text("");
+ return str ? Textヽfrom_strn(str, strlen(str)) : Text("");
}
static void u8_buf_append(Text_t text, char **buf, int64_t *capacity, int64_t *i)
@@ -924,7 +924,7 @@ static void u8_buf_append(Text_t text, char **buf, int64_t *capacity, int64_t *i
}
}
-public char *Text$as_c_string(Text_t text)
+public char *Textヽas_c_string(Text_t text)
{
int64_t capacity = text.length + 1;
char *buf = GC_MALLOC_ATOMIC((size_t)capacity);
@@ -939,7 +939,7 @@ public char *Text$as_c_string(Text_t text)
return buf;
}
-PUREFUNC public uint64_t Text$hash(const void *obj, const TypeInfo_t *info)
+PUREFUNC public uint64_t Textヽhash(const void *obj, const TypeInfo_t *info)
{
(void)info;
Text_t text = *(Text_t*)obj;
@@ -983,12 +983,12 @@ PUREFUNC public uint64_t Text$hash(const void *obj, const TypeInfo_t *info)
case TEXT_CONCAT: {
TextIter_t state = NEW_TEXT_ITER_STATE(text);
for (int64_t i = 0; i + 1 < text.length; i += 2) {
- tmp.chunks[0] = Text$get_grapheme_fast(&state, i);
- tmp.chunks[1] = Text$get_grapheme_fast(&state, i+1);
+ tmp.chunks[0] = Textヽget_grapheme_fast(&state, i);
+ tmp.chunks[1] = Textヽget_grapheme_fast(&state, i+1);
siphashadd64bits(&sh, tmp.whole);
}
- int32_t last = (text.length & 0x1) ? Text$get_grapheme_fast(&state, text.length-1) : 0;
+ int32_t last = (text.length & 0x1) ? Textヽget_grapheme_fast(&state, text.length-1) : 0;
return siphashfinish_last_part(&sh, (uint64_t)last);
}
default: errx(1, "Invalid text");
@@ -996,7 +996,7 @@ PUREFUNC public uint64_t Text$hash(const void *obj, const TypeInfo_t *info)
return 0;
}
-public int32_t Text$get_grapheme_fast(TextIter_t *state, int64_t index)
+public int32_t Textヽget_grapheme_fast(TextIter_t *state, int64_t index)
{
if (index < 0) return 0;
if (index >= state->stack[0].text.length) return 0;
@@ -1047,13 +1047,13 @@ public int32_t Text$get_grapheme_fast(TextIter_t *state, int64_t index)
return 0;
}
-public uint32_t Text$get_main_grapheme_fast(TextIter_t *state, int64_t index)
+public uint32_t Textヽget_main_grapheme_fast(TextIter_t *state, int64_t index)
{
- int32_t g = Text$get_grapheme_fast(state, index);
+ int32_t g = Textヽget_grapheme_fast(state, index);
return (g) >= 0 ? (ucs4_t)(g) : synthetic_graphemes[-(g)-1].main_codepoint;
}
-PUREFUNC public int32_t Text$compare(const void *va, const void *vb, const TypeInfo_t *info)
+PUREFUNC public int32_t Textヽcompare(const void *va, const void *vb, const TypeInfo_t *info)
{
(void)info;
if (va == vb) return 0;
@@ -1064,8 +1064,8 @@ PUREFUNC public int32_t Text$compare(const void *va, const void *vb, const TypeI
int64_t len = MAX(a.length, b.length);
TextIter_t a_state = NEW_TEXT_ITER_STATE(a), b_state = NEW_TEXT_ITER_STATE(b);
for (int64_t i = 0; i < len; i++) {
- int32_t ai = Text$get_grapheme_fast(&a_state, i);
- int32_t bi = Text$get_grapheme_fast(&b_state, i);
+ int32_t ai = Textヽget_grapheme_fast(&a_state, i);
+ int32_t bi = Textヽget_grapheme_fast(&b_state, i);
if (ai == bi) continue;
int32_t cmp;
if (ai > 0 && bi > 0) {
@@ -1095,20 +1095,20 @@ PUREFUNC public int32_t Text$compare(const void *va, const void *vb, const TypeI
bool _matches(TextIter_t *text_state, TextIter_t *target_state, int64_t pos)
{
for (int64_t i = 0; i < target_state->stack[0].text.length; i++) {
- int32_t text_i = Text$get_grapheme_fast(text_state, pos + i);
- int32_t prefix_i = Text$get_grapheme_fast(target_state, i);
+ int32_t text_i = Textヽget_grapheme_fast(text_state, pos + i);
+ int32_t prefix_i = Textヽget_grapheme_fast(target_state, i);
if (text_i != prefix_i) return false;
}
return true;
}
-PUREFUNC public bool Text$starts_with(Text_t text, Text_t prefix, Text_t *remainder)
+PUREFUNC public bool Textヽstarts_with(Text_t text, Text_t prefix, Text_t *remainder)
{
if (text.length < prefix.length)
return false;
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), prefix_state = NEW_TEXT_ITER_STATE(prefix);
if (_matches(&text_state, &prefix_state, 0)) {
- if (remainder) *remainder = Text$from(text, Int$from_int64(prefix.length + 1));
+ if (remainder) *remainder = Textヽfrom(text, Intヽfrom_int64(prefix.length + 1));
return true;
} else {
if (remainder) *remainder = text;
@@ -1116,13 +1116,13 @@ PUREFUNC public bool Text$starts_with(Text_t text, Text_t prefix, Text_t *remain
}
}
-PUREFUNC public bool Text$ends_with(Text_t text, Text_t suffix, Text_t *remainder)
+PUREFUNC public bool Textヽends_with(Text_t text, Text_t suffix, Text_t *remainder)
{
if (text.length < suffix.length)
return false;
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), suffix_state = NEW_TEXT_ITER_STATE(suffix);
if (_matches(&text_state, &suffix_state, text.length - suffix.length)) {
- if (remainder) *remainder = Text$to(text, Int$from_int64(text.length - suffix.length));
+ if (remainder) *remainder = Textヽto(text, Intヽfrom_int64(text.length - suffix.length));
return true;
} else {
if (remainder) *remainder = text;
@@ -1130,45 +1130,45 @@ PUREFUNC public bool Text$ends_with(Text_t text, Text_t suffix, Text_t *remainde
}
}
-public Text_t Text$without_prefix(Text_t text, Text_t prefix)
+public Text_t Textヽwithout_prefix(Text_t text, Text_t prefix)
{
- return Text$starts_with(text, prefix, false) ? Text$slice(text, I(prefix.length + 1), I(text.length)) : text;
+ return Textヽstarts_with(text, prefix, false) ? Textヽslice(text, I(prefix.length + 1), I(text.length)) : text;
}
-public Text_t Text$without_suffix(Text_t text, Text_t suffix)
+public Text_t Textヽwithout_suffix(Text_t text, Text_t suffix)
{
- return Text$ends_with(text, suffix, false) ? Text$slice(text, I(1), I(text.length - suffix.length)) : text;
+ return Textヽends_with(text, suffix, false) ? Textヽslice(text, I(1), I(text.length - suffix.length)) : text;
}
static bool _has_grapheme(TextIter_t *text, int32_t g)
{
for (int64_t t = 0; t < text->stack[0].text.length; t++) {
- if (g == Text$get_grapheme_fast(text, t)) {
+ if (g == Textヽget_grapheme_fast(text, t)) {
return true;
}
}
return false;
}
-public Text_t Text$trim(Text_t text, Text_t to_trim, bool left, bool right)
+public Text_t Textヽtrim(Text_t text, Text_t to_trim, bool left, bool right)
{
int64_t first = 0;
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), trim_state = NEW_TEXT_ITER_STATE(to_trim);
if (left) {
- while (first < text.length && _has_grapheme(&trim_state, Text$get_grapheme_fast(&text_state, first))) {
+ while (first < text.length && _has_grapheme(&trim_state, Textヽget_grapheme_fast(&text_state, first))) {
first += 1;
}
}
int64_t last = text.length-1;
if (right) {
- while (last >= first && _has_grapheme(&trim_state, Text$get_grapheme_fast(&text_state, last))) {
+ while (last >= first && _has_grapheme(&trim_state, Textヽget_grapheme_fast(&text_state, last))) {
last -= 1;
}
}
- return (first != 0 || last != text.length-1) ? Text$slice(text, I(first+1), I(last+1)) : text;
+ return (first != 0 || last != text.length-1) ? Textヽslice(text, I(first+1), I(last+1)) : text;
}
-public Text_t Text$translate(Text_t text, Table_t translations)
+public Text_t Textヽtranslate(Text_t text, Table_t translations)
{
TextIter_t text_state = NEW_TEXT_ITER_STATE(text);
Text_t result = EMPTY_TEXT;
@@ -1180,7 +1180,7 @@ public Text_t Text$translate(Text_t text, Table_t translations)
TextIter_t target_state = NEW_TEXT_ITER_STATE(entry->target);
if (_matches(&text_state, &target_state, i)) {
if (i > span_start)
- result = concat2(result, Text$slice(text, I(span_start+1), I(i)));
+ result = concat2(result, Textヽslice(text, I(span_start+1), I(i)));
result = concat2(result, entry->replacement);
i += entry->target.length;
@@ -1192,11 +1192,11 @@ public Text_t Text$translate(Text_t text, Table_t translations)
found_match: continue;
}
if (span_start < text.length)
- result = concat2(result, Text$slice(text, I(span_start+1), I(text.length)));
+ result = concat2(result, Textヽslice(text, I(span_start+1), I(text.length)));
return result;
}
-public Text_t Text$replace(Text_t text, Text_t target, Text_t replacement)
+public Text_t Textヽreplace(Text_t text, Text_t target, Text_t replacement)
{
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), target_state = NEW_TEXT_ITER_STATE(target);
Text_t result = EMPTY_TEXT;
@@ -1204,7 +1204,7 @@ public Text_t Text$replace(Text_t text, Text_t target, Text_t replacement)
for (int64_t i = 0; i < text.length; ) {
if (_matches(&text_state, &target_state, i)) {
if (i > span_start)
- result = concat2(result, Text$slice(text, I(span_start+1), I(i)));
+ result = concat2(result, Textヽslice(text, I(span_start+1), I(i)));
result = concat2(result, replacement);
i += target.length;
@@ -1214,11 +1214,11 @@ public Text_t Text$replace(Text_t text, Text_t target, Text_t replacement)
}
}
if (span_start < text.length)
- result = concat2(result, Text$slice(text, I(span_start+1), I(text.length)));
+ result = concat2(result, Textヽslice(text, I(span_start+1), I(text.length)));
return result;
}
-public PUREFUNC bool Text$has(Text_t text, Text_t target)
+public PUREFUNC bool Textヽhas(Text_t text, Text_t target)
{
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), target_state = NEW_TEXT_ITER_STATE(target);
for (int64_t i = 0; i < text.length; i++) {
@@ -1228,10 +1228,10 @@ public PUREFUNC bool Text$has(Text_t text, Text_t target)
return false;
}
-public List_t Text$split(Text_t text, Text_t delimiters)
+public List_t Textヽsplit(Text_t text, Text_t delimiters)
{
if (delimiters.length == 0)
- return Text$clusters(text);
+ return Textヽclusters(text);
TextIter_t text_state = NEW_TEXT_ITER_STATE(text), delim_state = NEW_TEXT_ITER_STATE(delimiters);
List_t splits = {};
@@ -1240,18 +1240,18 @@ public List_t Text$split(Text_t text, Text_t delimiters)
while (i + span_len < text.length && !_matches(&text_state, &delim_state, i + span_len)) {
span_len += 1;
}
- Text_t slice = Text$slice(text, I(i+1), I(i+span_len));
- List$insert(&splits, &slice, I(0), sizeof(slice));
+ Text_t slice = Textヽslice(text, I(i+1), I(i+span_len));
+ Listヽinsert(&splits, &slice, I(0), sizeof(slice));
i += span_len + delimiters.length;
if (i == text.length) {
Text_t empty = Text("");
- List$insert(&splits, &empty, I(0), sizeof(empty));
+ Listヽinsert(&splits, &empty, I(0), sizeof(empty));
}
}
return splits;
}
-public List_t Text$split_any(Text_t text, Text_t delimiters)
+public List_t Textヽsplit_any(Text_t text, Text_t delimiters)
{
if (delimiters.length == 0)
return List(text);
@@ -1260,19 +1260,19 @@ public List_t Text$split_any(Text_t text, Text_t delimiters)
List_t splits = {};
for (int64_t i = 0; i < text.length; ) {
int64_t span_len = 0;
- while (i + span_len < text.length && !_has_grapheme(&delim_state, Text$get_grapheme_fast(&text_state, i + span_len))) {
+ while (i + span_len < text.length && !_has_grapheme(&delim_state, Textヽget_grapheme_fast(&text_state, i + span_len))) {
span_len += 1;
}
bool trailing_delim = i + span_len < text.length;
- Text_t slice = Text$slice(text, I(i+1), I(i+span_len));
- List$insert(&splits, &slice, I(0), sizeof(slice));
+ Text_t slice = Textヽslice(text, I(i+1), I(i+span_len));
+ Listヽinsert(&splits, &slice, I(0), sizeof(slice));
i += span_len + 1;
- while (i < text.length && _has_grapheme(&delim_state, Text$get_grapheme_fast(&text_state, i))) {
+ while (i < text.length && _has_grapheme(&delim_state, Textヽget_grapheme_fast(&text_state, i))) {
i += 1;
}
if (i >= text.length && trailing_delim) {
Text_t empty = Text("");
- List$insert(&splits, &empty, I(0), sizeof(empty));
+ Listヽinsert(&splits, &empty, I(0), sizeof(empty));
}
}
return splits;
@@ -1306,12 +1306,12 @@ static OptionalText_t next_split(split_iter_state_t *state)
while (i + span_len < text.length && !_matches(&state->state, &delim_state, i + span_len)) {
span_len += 1;
}
- Text_t slice = Text$slice(text, I(i+1), I(i+span_len));
+ Text_t slice = Textヽslice(text, I(i+1), I(i+span_len));
state->i = i + span_len + state->delimiter.length;
return slice;
}
-public Closure_t Text$by_split(Text_t text, Text_t delimiter)
+public Closure_t Textヽby_split(Text_t text, Text_t delimiter)
{
return (Closure_t){
.fn=(void*)next_split,
@@ -1331,7 +1331,7 @@ static OptionalText_t next_split_any(split_iter_state_t *state)
}
if (state->delimiter.length == 0) { // special case
- Text_t ret = Text$cluster(text, I(state->i+1));
+ Text_t ret = Textヽcluster(text, I(state->i+1));
state->i += 1;
return ret;
}
@@ -1339,19 +1339,19 @@ static OptionalText_t next_split_any(split_iter_state_t *state)
TextIter_t delim_state = NEW_TEXT_ITER_STATE(state->delimiter);
int64_t i = state->i;
int64_t span_len = 0;
- while (i + span_len < text.length && !_has_grapheme(&delim_state, Text$get_grapheme_fast(&state->state, i + span_len))) {
+ while (i + span_len < text.length && !_has_grapheme(&delim_state, Textヽget_grapheme_fast(&state->state, i + span_len))) {
span_len += 1;
}
- Text_t slice = Text$slice(text, I(i+1), I(i+span_len));
+ Text_t slice = Textヽslice(text, I(i+1), I(i+span_len));
i += span_len + 1;
- while (i < text.length && _has_grapheme(&delim_state, Text$get_grapheme_fast(&state->state, i))) {
+ while (i < text.length && _has_grapheme(&delim_state, Textヽget_grapheme_fast(&state->state, i))) {
i += 1;
}
state->i = i;
return slice;
}
-public Closure_t Text$by_split_any(Text_t text, Text_t delimiters)
+public Closure_t Textヽby_split_any(Text_t text, Text_t delimiters)
{
return (Closure_t){
.fn=(void*)next_split_any,
@@ -1359,7 +1359,7 @@ public Closure_t Text$by_split_any(Text_t text, Text_t delimiters)
};
}
-PUREFUNC public bool Text$equal_values(Text_t a, Text_t b)
+PUREFUNC public bool Textヽequal_values(Text_t a, Text_t b)
{
if (a.length != b.length)
return false;
@@ -1367,30 +1367,30 @@ PUREFUNC public bool Text$equal_values(Text_t a, Text_t b)
TextIter_t a_state = NEW_TEXT_ITER_STATE(a), b_state = NEW_TEXT_ITER_STATE(b);
// TODO: make this smarter and more efficient
for (int64_t i = 0; i < len; i++) {
- int32_t ai = Text$get_grapheme_fast(&a_state, i);
- int32_t bi = Text$get_grapheme_fast(&b_state, i);
+ int32_t ai = Textヽget_grapheme_fast(&a_state, i);
+ int32_t bi = Textヽget_grapheme_fast(&b_state, i);
if (ai != bi) return false;
}
return true;
}
-PUREFUNC public bool Text$equal(const void *a, const void *b, const TypeInfo_t *info)
+PUREFUNC public bool Textヽequal(const void *a, const void *b, const TypeInfo_t *info)
{
(void)info;
if (a == b) return true;
- return Text$equal_values(*(Text_t*)a, *(Text_t*)b);
+ return Textヽequal_values(*(Text_t*)a, *(Text_t*)b);
}
-PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b, Text_t language)
+PUREFUNC public bool Textヽequal_ignoring_case(Text_t a, Text_t b, Text_t language)
{
if (a.length != b.length)
return false;
int64_t len = a.length;
TextIter_t a_state = NEW_TEXT_ITER_STATE(a), b_state = NEW_TEXT_ITER_STATE(b);
- const char *uc_language = Text$as_c_string(language);
+ const char *uc_language = Textヽas_c_string(language);
for (int64_t i = 0; i < len; i++) {
- int32_t ai = Text$get_grapheme_fast(&a_state, i);
- int32_t bi = Text$get_grapheme_fast(&b_state, i);
+ int32_t ai = Textヽget_grapheme_fast(&a_state, i);
+ int32_t bi = Textヽget_grapheme_fast(&b_state, i);
if (ai != bi) {
const ucs4_t *a_codepoints = ai >= 0 ? (ucs4_t*)&ai : GRAPHEME_CODEPOINTS(ai);
int64_t a_len = ai >= 0 ? 1 : NUM_GRAPHEME_CODEPOINTS(ai);
@@ -1407,54 +1407,54 @@ PUREFUNC public bool Text$equal_ignoring_case(Text_t a, Text_t b, Text_t languag
return true;
}
-public Text_t Text$upper(Text_t text, Text_t language)
+public Text_t Textヽupper(Text_t text, Text_t language)
{
if (text.length == 0) return text;
- List_t codepoints = Text$utf32_codepoints(text);
- const char *uc_language = Text$as_c_string(language);
+ List_t codepoints = Textヽutf32_codepoints(text);
+ const char *uc_language = Textヽas_c_string(language);
size_t out_len = 0;
ucs4_t *upper = u32_toupper(codepoints.data, (size_t)codepoints.length, uc_language, UNINORM_NFC, NULL, &out_len);
- Text_t ret = Text$from_codepoints((List_t){.data=upper, .length=(int64_t)out_len, .stride=sizeof(int32_t)});
+ Text_t ret = Textヽfrom_codepoints((List_t){.data=upper, .length=(int64_t)out_len, .stride=sizeof(int32_t)});
return ret;
}
-public Text_t Text$lower(Text_t text, Text_t language)
+public Text_t Textヽlower(Text_t text, Text_t language)
{
if (text.length == 0) return text;
- List_t codepoints = Text$utf32_codepoints(text);
- const char *uc_language = Text$as_c_string(language);
+ List_t codepoints = Textヽutf32_codepoints(text);
+ const char *uc_language = Textヽas_c_string(language);
size_t out_len = 0;
ucs4_t *lower = u32_tolower(codepoints.data, (size_t)codepoints.length, uc_language, UNINORM_NFC, NULL, &out_len);
- Text_t ret = Text$from_codepoints((List_t){.data=lower, .length=(int64_t)out_len, .stride=sizeof(int32_t)});
+ Text_t ret = Textヽfrom_codepoints((List_t){.data=lower, .length=(int64_t)out_len, .stride=sizeof(int32_t)});
return ret;
}
-public Text_t Text$title(Text_t text, Text_t language)
+public Text_t Textヽtitle(Text_t text, Text_t language)
{
if (text.length == 0) return text;
- List_t codepoints = Text$utf32_codepoints(text);
- const char *uc_language = Text$as_c_string(language);
+ List_t codepoints = Textヽutf32_codepoints(text);
+ const char *uc_language = Textヽas_c_string(language);
size_t out_len = 0;
ucs4_t *title = u32_totitle(codepoints.data, (size_t)codepoints.length, uc_language, UNINORM_NFC, NULL, &out_len);
- Text_t ret = Text$from_codepoints((List_t){.data=title, .length=(int64_t)out_len, .stride=sizeof(int32_t)});
+ Text_t ret = Textヽfrom_codepoints((List_t){.data=title, .length=(int64_t)out_len, .stride=sizeof(int32_t)});
return ret;
}
-public Text_t Text$quoted(Text_t text, bool colorize, Text_t quotation_mark)
+public Text_t Textヽquoted(Text_t text, bool colorize, Text_t quotation_mark)
{
if (quotation_mark.length != 1)
fail("Invalid quote text: ", quotation_mark, " (must have length == 1)");
Text_t ret = colorize ? Text("\x1b[35m") : EMPTY_TEXT;
- if (!Text$equal_values(quotation_mark, Text("\"")) && !Text$equal_values(quotation_mark, Text("'")) && !Text$equal_values(quotation_mark, Text("`")))
+ if (!Textヽequal_values(quotation_mark, Text("\"")) && !Textヽequal_values(quotation_mark, Text("'")) && !Textヽequal_values(quotation_mark, Text("`")))
ret = concat2_assuming_safe(ret, Text("$"));
ret = concat2_assuming_safe(ret, quotation_mark);
- int32_t quote_char = Text$get_grapheme(quotation_mark, 0);
+ int32_t quote_char = Textヽget_grapheme(quotation_mark, 0);
#define flush_unquoted() ({ \
if (unquoted_span > 0) { \
- ret = concat2_assuming_safe(ret, Text$slice(text, I(i-unquoted_span+1), I(i))); \
+ ret = concat2_assuming_safe(ret, Textヽslice(text, I(i-unquoted_span+1), I(i))); \
unquoted_span = 0; \
} })
#define add_escaped(str) ({ \
@@ -1466,7 +1466,7 @@ public Text_t Text$quoted(Text_t text, bool colorize, Text_t quotation_mark)
int64_t unquoted_span = 0;
int64_t i = 0;
for (i = 0; i < text.length; i++) {
- int32_t g = Text$get_grapheme_fast(&state, i);
+ int32_t g = Textヽget_grapheme_fast(&state, i);
switch (g) {
case '\a': add_escaped("a"); break;
case '\b': add_escaped("b"); break;
@@ -1494,7 +1494,7 @@ public Text_t Text$quoted(Text_t text, bool colorize, Text_t quotation_mark)
(g & 15) > 9 ? 'a' + (g & 15) - 10 : '0' + (g & 15),
'\0',
};
- ret = concat2_assuming_safe(ret, Text$from_strn(tmp, 2));
+ ret = concat2_assuming_safe(ret, Textヽfrom_strn(tmp, 2));
if (colorize)
ret = concat2_assuming_safe(ret, Text("\x1b[0;35m"));
break;
@@ -1524,10 +1524,10 @@ public Text_t Text$quoted(Text_t text, bool colorize, Text_t quotation_mark)
return ret;
}
-public Text_t Text$as_text(const void *vtext, bool colorize, const TypeInfo_t *info)
+public Text_t Textヽas_text(const void *vtext, bool colorize, const TypeInfo_t *info)
{
(void)info;
- if (!vtext) return info && info->TextInfo.lang ? Text$from_str(info->TextInfo.lang) : Text("Text");
+ if (!vtext) return info && info->TextInfo.lang ? Textヽfrom_str(info->TextInfo.lang) : Text("Text");
Text_t text = *(Text_t*)vtext;
// Figure out the best quotation mark to use:
@@ -1535,7 +1535,7 @@ public Text_t Text$as_text(const void *vtext, bool colorize, const TypeInfo_t *i
has_single_quote = false, needs_escapes = false;
TextIter_t state = NEW_TEXT_ITER_STATE(text);
for (int64_t i = 0; i < text.length; i++) {
- int32_t g = Text$get_grapheme_fast(&state, i);
+ int32_t g = Textヽget_grapheme_fast(&state, i);
if (g == '"') {
has_double_quote = true;
} else if (g == '`') {
@@ -1560,58 +1560,58 @@ public Text_t Text$as_text(const void *vtext, bool colorize, const TypeInfo_t *i
else
quote = Text("\"");
- Text_t as_text = Text$quoted(text, colorize, quote);
- if (info && info->TextInfo.lang && info != &Text$info)
- as_text = Text$concat(
+ Text_t as_text = Textヽquoted(text, colorize, quote);
+ if (info && info->TextInfo.lang && info != &Textヽinfo)
+ as_text = Textヽconcat(
colorize ? Text("\x1b[1m$") : Text("$"),
- Text$from_str(info->TextInfo.lang),
- colorize ? Text("\x1b[0m") : Text(""),
+ Textヽfrom_str(info->TextInfo.lang),
+ colorize ? Text("\x1b[0m") : EMPTY_TEXT,
as_text);
return as_text;
}
-public Text_t Text$join(Text_t glue, List_t pieces)
+public Text_t Textヽjoin(Text_t glue, List_t pieces)
{
if (pieces.length == 0) return EMPTY_TEXT;
Text_t result = *(Text_t*)pieces.data;
for (int64_t i = 1; i < pieces.length; i++) {
- result = Text$concat(result, glue, *(Text_t*)(pieces.data + i*pieces.stride));
+ result = Textヽconcat(result, glue, *(Text_t*)(pieces.data + i*pieces.stride));
}
return result;
}
-public List_t Text$clusters(Text_t text)
+public List_t Textヽclusters(Text_t text)
{
List_t clusters = {};
for (int64_t i = 1; i <= text.length; i++) {
- Text_t cluster = Text$slice(text, I(i), I(i));
- List$insert(&clusters, &cluster, I_small(0), sizeof(Text_t));
+ Text_t cluster = Textヽslice(text, I(i), I(i));
+ Listヽinsert(&clusters, &cluster, I_small(0), sizeof(Text_t));
}
return clusters;
}
-public List_t Text$utf32_codepoints(Text_t text)
+public List_t Textヽutf32_codepoints(Text_t text)
{
List_t codepoints = {.atomic=1};
TextIter_t state = NEW_TEXT_ITER_STATE(text);
for (int64_t i = 0; i < text.length; i++) {
- int32_t grapheme = Text$get_grapheme_fast(&state, i);
+ int32_t grapheme = Textヽget_grapheme_fast(&state, i);
if (grapheme < 0) {
for (int64_t c = 0; c < NUM_GRAPHEME_CODEPOINTS(grapheme); c++) {
ucs4_t subg = GRAPHEME_CODEPOINTS(grapheme)[c];
- List$insert(&codepoints, &subg, I_small(0), sizeof(ucs4_t));
+ Listヽinsert(&codepoints, &subg, I_small(0), sizeof(ucs4_t));
}
} else {
- List$insert(&codepoints, &grapheme, I_small(0), sizeof(ucs4_t));
+ Listヽinsert(&codepoints, &grapheme, I_small(0), sizeof(ucs4_t));
}
}
return codepoints;
}
-public List_t Text$utf8_bytes(Text_t text)
+public List_t Textヽutf8_bytes(Text_t text)
{
- const char *str = Text$as_c_string(text);
+ const char *str = Textヽas_c_string(text);
return (List_t){.length=(int64_t)strlen(str), .stride=1, .atomic=1, .data=(void*)str};
}
@@ -1625,31 +1625,31 @@ static INLINE const char *codepoint_name(ucs4_t c)
return String(block->name, "-", hex(c, .no_prefix=true, .uppercase=true));
}
-public List_t Text$codepoint_names(Text_t text)
+public List_t Textヽcodepoint_names(Text_t text)
{
List_t names = {};
TextIter_t state = NEW_TEXT_ITER_STATE(text);
for (int64_t i = 0; i < text.length; i++) {
- int32_t grapheme = Text$get_grapheme_fast(&state, i);
+ int32_t grapheme = Textヽget_grapheme_fast(&state, i);
if (grapheme < 0) {
for (int64_t c = 0; c < NUM_GRAPHEME_CODEPOINTS(grapheme); c++) {
const char *name = codepoint_name(GRAPHEME_CODEPOINTS(grapheme)[c]);
- Text_t name_text = Text$from_str(name);
- List$insert(&names, &name_text, I_small(0), sizeof(Text_t));
+ Text_t name_text = Textヽfrom_str(name);
+ Listヽinsert(&names, &name_text, I_small(0), sizeof(Text_t));
}
} else {
const char *name = codepoint_name((ucs4_t)grapheme);
- Text_t name_text = Text$from_str(name);
- List$insert(&names, &name_text, I_small(0), sizeof(Text_t));
+ Text_t name_text = Textヽfrom_str(name);
+ Listヽinsert(&names, &name_text, I_small(0), sizeof(Text_t));
}
}
return names;
}
-public Text_t Text$from_codepoints(List_t codepoints)
+public Text_t Textヽfrom_codepoints(List_t codepoints)
{
if (codepoints.stride != sizeof(uint32_t))
- List$compact(&codepoints, sizeof(uint32_t));
+ Listヽcompact(&codepoints, sizeof(uint32_t));
List_t graphemes = {};
Table_t unique_clusters = {};
@@ -1663,10 +1663,10 @@ public Text_t Text$from_codepoints(List_t codepoints)
uint32_t *u32s_normalized = u32_normalize(UNINORM_NFC, pos, (size_t)(next-pos), buf, &u32_normlen);
int32_t g = get_synthetic_grapheme(u32s_normalized, (int64_t)u32_normlen);
- List$insert(&graphemes, &g, I(0), sizeof(int32_t));
- Table$get_or_setdefault(
+ Listヽinsert(&graphemes, &g, I(0), sizeof(int32_t));
+ Tableヽget_or_setdefault(
&unique_clusters, int32_t, uint8_t, g, (uint8_t)unique_clusters.entries.length,
- Table$info(&Int32$info, &Byte$info));
+ Tableヽinfo(&Int32ヽinfo, &Byteヽinfo));
if (u32s_normalized != buf) free(u32s_normalized);
@@ -1676,52 +1676,52 @@ public Text_t Text$from_codepoints(List_t codepoints)
.data=(void*)next,
.stride=sizeof(int32_t),
};
- return concat2_assuming_safe(Text$from_components(graphemes, unique_clusters), Text$from_codepoints(remaining_codepoints));
+ return concat2_assuming_safe(Textヽfrom_components(graphemes, unique_clusters), Textヽfrom_codepoints(remaining_codepoints));
}
}
- return Text$from_components(graphemes, unique_clusters);
+ return Textヽfrom_components(graphemes, unique_clusters);
}
-public OptionalText_t Text$from_codepoint_names(List_t codepoint_names)
+public OptionalText_t Textヽfrom_codepoint_names(List_t codepoint_names)
{
List_t codepoints = {};
for (int64_t i = 0; i < codepoint_names.length; i++) {
Text_t *name = ((Text_t*)(codepoint_names.data + i*codepoint_names.stride));
- const char *name_str = Text$as_c_string(*name);
+ const char *name_str = Textヽas_c_string(*name);
ucs4_t codepoint = unicode_name_character(name_str);
if (codepoint == UNINAME_INVALID)
return NONE_TEXT;
- List$insert(&codepoints, &codepoint, I_small(0), sizeof(ucs4_t));
+ Listヽinsert(&codepoints, &codepoint, I_small(0), sizeof(ucs4_t));
}
- return Text$from_codepoints(codepoints);
+ return Textヽfrom_codepoints(codepoints);
}
-public OptionalText_t Text$from_bytes(List_t bytes)
+public OptionalText_t Textヽfrom_bytes(List_t bytes)
{
if (bytes.stride != sizeof(int8_t))
- List$compact(&bytes, sizeof(int8_t));
+ Listヽcompact(&bytes, sizeof(int8_t));
- return Text$from_strn(bytes.data, (size_t)bytes.length);
+ return Textヽfrom_strn(bytes.data, (size_t)bytes.length);
}
-public List_t Text$lines(Text_t text)
+public List_t Textヽlines(Text_t text)
{
List_t lines = {};
TextIter_t state = NEW_TEXT_ITER_STATE(text);
for (int64_t i = 0, line_start = 0; i < text.length; i++) {
- int32_t grapheme = Text$get_grapheme_fast(&state, i);
- if (grapheme == '\r' && Text$get_grapheme_fast(&state, i + 1) == '\n') { // CRLF
- Text_t line = Text$slice(text, I(line_start+1), I(i));
- List$insert(&lines, &line, I_small(0), sizeof(Text_t));
+ int32_t grapheme = Textヽget_grapheme_fast(&state, i);
+ if (grapheme == '\r' && Textヽget_grapheme_fast(&state, i + 1) == '\n') { // CRLF
+ Text_t line = Textヽslice(text, I(line_start+1), I(i));
+ Listヽinsert(&lines, &line, I_small(0), sizeof(Text_t));
i += 1; // skip one extra for CR
line_start = i + 1;
} else if (grapheme == '\n') { // newline
- Text_t line = Text$slice(text, I(line_start+1), I(i));
- List$insert(&lines, &line, I_small(0), sizeof(Text_t));
+ Text_t line = Textヽslice(text, I(line_start+1), I(i));
+ Listヽinsert(&lines, &line, I_small(0), sizeof(Text_t));
line_start = i + 1;
} else if (i == text.length-1 && line_start != i) { // last line
- Text_t line = Text$slice(text, I(line_start+1), I(i+1));
- List$insert(&lines, &line, I_small(0), sizeof(Text_t));
+ Text_t line = Textヽslice(text, I(line_start+1), I(i+1));
+ Listヽinsert(&lines, &line, I_small(0), sizeof(Text_t));
}
}
return lines;
@@ -1736,17 +1736,17 @@ static OptionalText_t next_line(line_iter_state_t *state)
{
Text_t text = state->state.stack[0].text;
for (int64_t i = state->i; i < text.length; i++) {
- int32_t grapheme = Text$get_grapheme_fast(&state->state, i);
- if (grapheme == '\r' && Text$get_grapheme_fast(&state->state, i + 1) == '\n') { // CRLF
- Text_t line = Text$slice(text, I(state->i+1), I(i));
+ int32_t grapheme = Textヽget_grapheme_fast(&state->state, i);
+ if (grapheme == '\r' && Textヽget_grapheme_fast(&state->state, i + 1) == '\n') { // CRLF
+ Text_t line = Textヽslice(text, I(state->i+1), I(i));
state->i = i + 2; // skip one extra for CR
return line;
} else if (grapheme == '\n') { // newline
- Text_t line = Text$slice(text, I(state->i+1), I(i));
+ Text_t line = Textヽslice(text, I(state->i+1), I(i));
state->i = i + 1;
return line;
} else if (i == text.length-1 && state->i != i) { // last line
- Text_t line = Text$slice(text, I(state->i+1), I(i+1));
+ Text_t line = Textヽslice(text, I(state->i+1), I(i+1));
state->i = i + 1;
return line;
}
@@ -1754,7 +1754,7 @@ static OptionalText_t next_line(line_iter_state_t *state)
return NONE_TEXT;
}
-public Closure_t Text$by_line(Text_t text)
+public Closure_t Textヽby_line(Text_t text)
{
return (Closure_t){
.fn=(void*)next_line,
@@ -1762,73 +1762,73 @@ public Closure_t Text$by_line(Text_t text)
};
}
-PUREFUNC public bool Text$is_none(const void *t, const TypeInfo_t *info)
+PUREFUNC public bool Textヽis_none(const void *t, const TypeInfo_t *info)
{
(void)info;
return ((Text_t*)t)->length < 0;
}
-public Int_t Text$memory_size(Text_t text)
+public Int_t Textヽmemory_size(Text_t text)
{
switch (text.tag) {
case TEXT_ASCII:
- return Int$from_int64((int64_t)sizeof(Text_t) + (int64_t)sizeof(char[text.length]));
+ return Intヽfrom_int64((int64_t)sizeof(Text_t) + (int64_t)sizeof(char[text.length]));
case TEXT_GRAPHEMES:
- return Int$from_int64((int64_t)sizeof(Text_t) + (int64_t)sizeof(int32_t[text.length]));
+ return Intヽfrom_int64((int64_t)sizeof(Text_t) + (int64_t)sizeof(int32_t[text.length]));
case TEXT_BLOB:
- return Int$from_int64((int64_t)sizeof(Text_t) + (int64_t)((void*)text.blob.bytes - (void*)text.blob.map) + (int64_t)sizeof(uint8_t[text.length]));
+ return Intヽfrom_int64((int64_t)sizeof(Text_t) + (int64_t)((void*)text.blob.bytes - (void*)text.blob.map) + (int64_t)sizeof(uint8_t[text.length]));
case TEXT_CONCAT:
- return Int$plus(
- Int$from_int64((int64_t)sizeof(Text_t)),
- Int$plus(Text$memory_size(*text.left), Text$memory_size(*text.right)));
+ return Intヽplus(
+ Intヽfrom_int64((int64_t)sizeof(Text_t)),
+ Intヽplus(Textヽmemory_size(*text.left), Textヽmemory_size(*text.right)));
default: errx(1, "Invalid text tag: ", text.tag);
}
}
-public Text_t Text$layout(Text_t text)
+public Text_t Textヽlayout(Text_t text)
{
switch (text.tag) {
case TEXT_ASCII:
- return Texts(Text("ASCII("), Int64$as_text((int64_t[1]){text.length}, false, NULL), Text(")"));
+ return Texts(Text("ASCII("), Int64ヽas_text((int64_t[1]){text.length}, false, NULL), Text(")"));
case TEXT_GRAPHEMES:
- return Texts(Text("Graphemes("), Int64$as_text((int64_t[1]){text.length}, false, NULL), Text(")"));
+ return Texts(Text("Graphemes("), Int64ヽas_text((int64_t[1]){text.length}, false, NULL), Text(")"));
case TEXT_BLOB:
- return Texts(Text("Blob("), Int64$as_text((int64_t[1]){text.length}, false, NULL), Text(")"));
+ return Texts(Text("Blob("), Int64ヽas_text((int64_t[1]){text.length}, false, NULL), Text(")"));
case TEXT_CONCAT:
- return Texts(Text("Concat("), Text$layout(*text.left), Text(", "), Text$layout(*text.right), Text(")"));
+ return Texts(Text("Concat("), Textヽlayout(*text.left), Text(", "), Textヽlayout(*text.right), Text(")"));
default: errx(1, "Invalid text tag: ", text.tag);
}
}
-public void Text$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
+public void Textヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info)
{
(void)info;
- const char *str = Text$as_c_string(*(Text_t*)obj);
+ const char *str = Textヽas_c_string(*(Text_t*)obj);
int64_t len = (int64_t)strlen(str);
- Int64$serialize(&len, out, pointers, &Int64$info);
+ Int64ヽserialize(&len, out, pointers, &Int64ヽinfo);
fwrite(str, sizeof(char), (size_t)len, out);
}
-public void Text$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info)
+public void Textヽdeserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info)
{
(void)info;
int64_t len = 0;
- Int64$deserialize(in, &len, pointers, &Int64$info);
+ Int64ヽdeserialize(in, &len, pointers, &Int64ヽinfo);
if (len < 0)
fail("Cannot deserialize text with a negative length!");
char *buf = GC_MALLOC_ATOMIC((size_t)len+1);
if (fread(buf, sizeof(char), (size_t)len, in) != (size_t)len)
fail("Not enough data in stream to deserialize");
buf[len+1] = '\0';
- *(Text_t*)out = Text$from_strn(buf, (size_t)len);
+ *(Text_t*)out = Textヽfrom_strn(buf, (size_t)len);
}
-public const TypeInfo_t Text$info = {
+public const TypeInfo_t Textヽinfo = {
.size=sizeof(Text_t),
.align=__alignof__(Text_t),
.tag=TextInfo,
.TextInfo={.lang="Text"},
- .metamethods=Text$metamethods,
+ .metamethods=Textヽmetamethods,
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index 637a3db7..87e7dcb5 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -35,82 +35,82 @@ static inline Text_t Text_from_text(Text_t t) {
return t;
}
-#define convert_to_text(x) _Generic(x, Text_t: Text_from_text, char*: Text$from_str, const char*: Text$from_str)(x)
+#define convert_to_text(x) _Generic(x, Text_t: Text_from_text, char*: Textヽfrom_str, const char*: Textヽfrom_str)(x)
-Text_t Text$_concat(int n, Text_t items[n]);
-#define Text$concat(...) Text$_concat(sizeof((Text_t[]){__VA_ARGS__})/sizeof(Text_t), (Text_t[]){__VA_ARGS__})
-#define Texts(...) Text$concat(MAP_LIST(convert_to_text, __VA_ARGS__))
-// int Text$print(FILE *stream, Text_t t);
-Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int);
-Text_t Text$from(Text_t text, Int_t first);
-Text_t Text$to(Text_t text, Int_t last);
-Text_t Text$reversed(Text_t text);
-Text_t Text$cluster(Text_t text, Int_t index_int);
-OptionalText_t Text$from_str(const char *str);
-OptionalText_t Text$from_strn(const char *str, size_t len);
-PUREFUNC uint64_t Text$hash(const void *text, const TypeInfo_t*);
-PUREFUNC int32_t Text$compare(const void *va, const void *vb, const TypeInfo_t*);
-PUREFUNC bool Text$equal(const void *a, const void *b, const TypeInfo_t*);
-PUREFUNC bool Text$equal_values(Text_t a, Text_t b);
-PUREFUNC bool Text$equal_ignoring_case(Text_t a, Text_t b, Text_t language);
-PUREFUNC bool Text$is_none(const void *t, const TypeInfo_t*);
-Text_t Text$upper(Text_t text, Text_t language);
-Text_t Text$lower(Text_t text, Text_t language);
-Text_t Text$title(Text_t text, Text_t language);
-Text_t Text$as_text(const void *text, bool colorize, const TypeInfo_t *info);
-Text_t Text$quoted(Text_t str, bool colorize, Text_t quotation_mark);
-PUREFUNC bool Text$starts_with(Text_t text, Text_t prefix, Text_t *remainder);
-PUREFUNC bool Text$ends_with(Text_t text, Text_t suffix, Text_t *remainder);
-Text_t Text$without_prefix(Text_t text, Text_t prefix);
-Text_t Text$without_suffix(Text_t text, Text_t suffix);
-Text_t Text$replace(Text_t text, Text_t target, Text_t replacement);
-Text_t Text$translate(Text_t text, Table_t translations);
-PUREFUNC bool Text$has(Text_t text, Text_t target);
-List_t Text$split(Text_t text, Text_t delimiter);
-List_t Text$split_any(Text_t text, Text_t delimiters);
-Closure_t Text$by_split(Text_t text, Text_t delimiter);
-Closure_t Text$by_split_any(Text_t text, Text_t delimiters);
-Text_t Text$trim(Text_t text, Text_t to_trim, bool left, bool right);
-char *Text$as_c_string(Text_t text);
-List_t Text$clusters(Text_t text);
-List_t Text$utf32_codepoints(Text_t text);
-List_t Text$utf8_bytes(Text_t text);
-List_t Text$codepoint_names(Text_t text);
-Text_t Text$from_codepoints(List_t codepoints);
-OptionalText_t Text$from_codepoint_names(List_t codepoint_names);
-OptionalText_t Text$from_bytes(List_t bytes);
-List_t Text$lines(Text_t text);
-Closure_t Text$by_line(Text_t text);
-Text_t Text$join(Text_t glue, List_t pieces);
-Text_t Text$repeat(Text_t text, Int_t count);
-Int_t Text$width(Text_t text, Text_t language);
-Text_t Text$left_pad(Text_t text, Int_t width, Text_t padding, Text_t language);
-Text_t Text$right_pad(Text_t text, Int_t width, Text_t padding, Text_t language);
-Text_t Text$middle_pad(Text_t text, Int_t width, Text_t padding, Text_t language);
-int32_t Text$get_grapheme_fast(TextIter_t *state, int64_t index);
-uint32_t Text$get_main_grapheme_fast(TextIter_t *state, int64_t index);
-Int_t Text$memory_size(Text_t text);
-Text_t Text$layout(Text_t text);
-void Text$serialize(const void *obj, FILE *out, Table_t *, const TypeInfo_t *);
-void Text$deserialize(FILE *in, void *out, List_t *, const TypeInfo_t *);
+Text_t Textヽ_concat(int n, Text_t items[n]);
+#define Textヽconcat(...) Textヽ_concat(sizeof((Text_t[]){__VA_ARGS__})/sizeof(Text_t), (Text_t[]){__VA_ARGS__})
+#define Texts(...) Textヽconcat(MAP_LIST(convert_to_text, __VA_ARGS__))
+// int Textヽprint(FILE *stream, Text_t t);
+Text_t Textヽslice(Text_t text, Int_t first_int, Int_t last_int);
+Text_t Textヽfrom(Text_t text, Int_t first);
+Text_t Textヽto(Text_t text, Int_t last);
+Text_t Textヽreversed(Text_t text);
+Text_t Textヽcluster(Text_t text, Int_t index_int);
+OptionalText_t Textヽfrom_str(const char *str);
+OptionalText_t Textヽfrom_strn(const char *str, size_t len);
+PUREFUNC uint64_t Textヽhash(const void *text, const TypeInfo_t*);
+PUREFUNC int32_t Textヽcompare(const void *va, const void *vb, const TypeInfo_t*);
+PUREFUNC bool Textヽequal(const void *a, const void *b, const TypeInfo_t*);
+PUREFUNC bool Textヽequal_values(Text_t a, Text_t b);
+PUREFUNC bool Textヽequal_ignoring_case(Text_t a, Text_t b, Text_t language);
+PUREFUNC bool Textヽis_none(const void *t, const TypeInfo_t*);
+Text_t Textヽupper(Text_t text, Text_t language);
+Text_t Textヽlower(Text_t text, Text_t language);
+Text_t Textヽtitle(Text_t text, Text_t language);
+Text_t Textヽas_text(const void *text, bool colorize, const TypeInfo_t *info);
+Text_t Textヽquoted(Text_t str, bool colorize, Text_t quotation_mark);
+PUREFUNC bool Textヽstarts_with(Text_t text, Text_t prefix, Text_t *remainder);
+PUREFUNC bool Textヽends_with(Text_t text, Text_t suffix, Text_t *remainder);
+Text_t Textヽwithout_prefix(Text_t text, Text_t prefix);
+Text_t Textヽwithout_suffix(Text_t text, Text_t suffix);
+Text_t Textヽreplace(Text_t text, Text_t target, Text_t replacement);
+Text_t Textヽtranslate(Text_t text, Table_t translations);
+PUREFUNC bool Textヽhas(Text_t text, Text_t target);
+List_t Textヽsplit(Text_t text, Text_t delimiter);
+List_t Textヽsplit_any(Text_t text, Text_t delimiters);
+Closure_t Textヽby_split(Text_t text, Text_t delimiter);
+Closure_t Textヽby_split_any(Text_t text, Text_t delimiters);
+Text_t Textヽtrim(Text_t text, Text_t to_trim, bool left, bool right);
+char *Textヽas_c_string(Text_t text);
+List_t Textヽclusters(Text_t text);
+List_t Textヽutf32_codepoints(Text_t text);
+List_t Textヽutf8_bytes(Text_t text);
+List_t Textヽcodepoint_names(Text_t text);
+Text_t Textヽfrom_codepoints(List_t codepoints);
+OptionalText_t Textヽfrom_codepoint_names(List_t codepoint_names);
+OptionalText_t Textヽfrom_bytes(List_t bytes);
+List_t Textヽlines(Text_t text);
+Closure_t Textヽby_line(Text_t text);
+Text_t Textヽjoin(Text_t glue, List_t pieces);
+Text_t Textヽrepeat(Text_t text, Int_t count);
+Int_t Textヽwidth(Text_t text, Text_t language);
+Text_t Textヽleft_pad(Text_t text, Int_t width, Text_t padding, Text_t language);
+Text_t Textヽright_pad(Text_t text, Int_t width, Text_t padding, Text_t language);
+Text_t Textヽmiddle_pad(Text_t text, Int_t width, Text_t padding, Text_t language);
+int32_t Textヽget_grapheme_fast(TextIter_t *state, int64_t index);
+uint32_t Textヽget_main_grapheme_fast(TextIter_t *state, int64_t index);
+Int_t Textヽmemory_size(Text_t text);
+Text_t Textヽlayout(Text_t text);
+void Textヽserialize(const void *obj, FILE *out, Table_t *, const TypeInfo_t *);
+void Textヽdeserialize(FILE *in, void *out, List_t *, const TypeInfo_t *);
-MACROLIKE int32_t Text$get_grapheme(Text_t text, int64_t index)
+MACROLIKE int32_t Textヽget_grapheme(Text_t text, int64_t index)
{
TextIter_t state = NEW_TEXT_ITER_STATE(text);
- return Text$get_grapheme_fast(&state, index);
+ return Textヽget_grapheme_fast(&state, index);
}
-extern const TypeInfo_t Text$info;
+extern const TypeInfo_t Textヽinfo;
extern Text_t EMPTY_TEXT;
-#define Text$metamethods { \
- .as_text=Text$as_text, \
- .hash=Text$hash, \
- .compare=Text$compare, \
- .equal=Text$equal, \
- .is_none=Text$is_none, \
- .serialize=Text$serialize, \
- .deserialize=Text$deserialize, \
+#define Textヽmetamethods { \
+ .as_text=Textヽas_text, \
+ .hash=Textヽhash, \
+ .compare=Textヽcompare, \
+ .equal=Textヽequal, \
+ .is_none=Textヽis_none, \
+ .serialize=Textヽserialize, \
+ .deserialize=Textヽdeserialize, \
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/types.c b/src/stdlib/types.c
index 0f51d6ea..f12bcaa1 100644
--- a/src/stdlib/types.c
+++ b/src/stdlib/types.c
@@ -12,20 +12,20 @@
#include "text.h"
#include "types.h"
-public Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type)
+public Text_t Typeヽas_text(const void *typeinfo, bool colorize, const TypeInfo_t *type)
{
if (!typeinfo) return Text("Type");
if (colorize)
- return Text$concat(
+ return Textヽconcat(
Text("\x1b[36;1m"),
- Text$from_str(type->TypeInfoInfo.type_str),
+ Textヽfrom_str(type->TypeInfoInfo.type_str),
Text("\x1b[m"));
else
- return Text$from_str(type->TypeInfoInfo.type_str);
+ return Textヽfrom_str(type->TypeInfoInfo.type_str);
}
-public const TypeInfo_t Void$info = {.size=0, .align=0, .tag=StructInfo};
-public const TypeInfo_t Abort$info = {.size=0, .align=0, .tag=StructInfo};
+public const TypeInfo_t Voidヽinfo = {.size=0, .align=0, .tag=StructInfo};
+public const TypeInfo_t Abortヽinfo = {.size=0, .align=0, .tag=StructInfo};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/src/stdlib/types.h b/src/stdlib/types.h
index 60f1fcfd..c890f07e 100644
--- a/src/stdlib/types.h
+++ b/src/stdlib/types.h
@@ -78,15 +78,15 @@ struct TypeInfo_s {
};
};
-extern const TypeInfo_t Void$info;
-extern const TypeInfo_t Abort$info;
+extern const TypeInfo_t Voidヽinfo;
+extern const TypeInfo_t Abortヽinfo;
#define Void_t void
-Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type);
+Text_t Typeヽas_text(const void *typeinfo, bool colorize, const TypeInfo_t *type);
-#define Type$info(typestr) &((TypeInfo_t){.size=sizeof(TypeInfo_t), .align=__alignof__(TypeInfo_t), \
+#define Typeヽinfo(typestr) &((TypeInfo_t){.size=sizeof(TypeInfo_t), .align=__alignof__(TypeInfo_t), \
.tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr, \
- .metamethods={.serialize=cannot_serialize, .deserialize=cannot_deserialize, .as_text=Type$as_text}})
+ .metamethods={.serialize=cannot_serialize, .deserialize=cannot_deserialize, .as_text=Typeヽas_text}})
#define DEFINE_OPTIONAL_TYPE(t, unpadded_size, name) \
typedef struct { \
diff --git a/src/stdlib/util.h b/src/stdlib/util.h
index 3b00e6e9..499f89cc 100644
--- a/src/stdlib/util.h
+++ b/src/stdlib/util.h
@@ -19,7 +19,7 @@
#define IF_DECLARE(decl, expr, block) if (({ decl; expr ? ({ block; 1; }) : 0; })) {}
-#define WHEN(type, subj, var, body) { type var = subj; switch (var.$tag) body }
+#define WHEN(type, subj, var, body) { type var = subj; switch (var.々tag) body }
#ifndef public
#define public __attribute__ ((visibility ("default")))