aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-05 15:31:54 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-05 15:31:54 -0400
commit04c8fb0362dc4f922c1e96ca01fb87a3e8e74214 (patch)
treea5a65a625a9b697ac6875874b9b4c04abd3d0a65
parent391c1b6bde0d5fd6f306f9613109e18ec487afe7 (diff)
Replace $Type with Type$info for builtin TypeInfos
-rw-r--r--builtins/array.c2
-rw-r--r--builtins/bool.c2
-rw-r--r--builtins/bool.h2
-rw-r--r--builtins/c_string.c2
-rw-r--r--builtins/c_string.h2
-rw-r--r--builtins/integers.c8
-rw-r--r--builtins/integers.h6
-rw-r--r--builtins/memory.c2
-rw-r--r--builtins/memory.h2
-rw-r--r--builtins/nums.c4
-rw-r--r--builtins/nums.h4
-rw-r--r--builtins/pointer.c2
-rw-r--r--builtins/range.c12
-rw-r--r--builtins/table.c12
-rw-r--r--builtins/table.h4
-rw-r--r--builtins/text.c10
-rw-r--r--builtins/text.h4
-rw-r--r--builtins/types.c6
-rw-r--r--builtins/types.h26
-rw-r--r--compile.c42
-rw-r--r--docs/namespacing.md2
-rw-r--r--environment.c26
-rw-r--r--repl.c24
23 files changed, 105 insertions, 101 deletions
diff --git a/builtins/array.c b/builtins/array.c
index 32aeab23..174bcbdd 100644
--- a/builtins/array.c
+++ b/builtins/array.c
@@ -282,7 +282,7 @@ public Table_t Array$counts(Array_t arr, const TypeInfo *type)
{
Table_t counts = {};
const TypeInfo count_type = {.size=sizeof(Table_t), .align=__alignof__(Table_t),
- .tag=TableInfo, .TableInfo.key=type->ArrayInfo.item, .TableInfo.value=&$Int};
+ .tag=TableInfo, .TableInfo.key=type->ArrayInfo.item, .TableInfo.value=&Int$info};
for (int64_t i = 0; i < arr.length; i++) {
void *key = arr.data + i*arr.stride;
int64_t *count = Table$get(counts, key, &count_type);
diff --git a/builtins/bool.c b/builtins/bool.c
index b3ba0bd7..677cfd97 100644
--- a/builtins/bool.c
+++ b/builtins/bool.c
@@ -48,7 +48,7 @@ public Bool_t Bool$random(double p)
return (drand48() < p);
}
-public const TypeInfo $Bool = {
+public const TypeInfo Bool$info = {
.size=sizeof(bool),
.align=__alignof__(bool),
.tag=CustomInfo,
diff --git a/builtins/bool.h b/builtins/bool.h
index 578cad6c..cf2237fd 100644
--- a/builtins/bool.h
+++ b/builtins/bool.h
@@ -16,6 +16,6 @@ Text_t Bool$as_text(const bool *b, bool colorize, const TypeInfo *type);
bool Bool$from_text(Text_t text, bool *success);
Bool_t Bool$random(double p);
-extern const TypeInfo $Bool;
+extern const TypeInfo Bool$info;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/c_string.c b/builtins/c_string.c
index 47ea4858..b0c70f0a 100644
--- a/builtins/c_string.c
+++ b/builtins/c_string.c
@@ -46,7 +46,7 @@ public uint32_t CString$hash(const char **c_str)
return hash;
}
-public const TypeInfo $CString = {
+public const TypeInfo CString$info = {
.size=sizeof(char*),
.align=__alignof__(char*),
.tag=CustomInfo,
diff --git a/builtins/c_string.h b/builtins/c_string.h
index d909083d..76c74c23 100644
--- a/builtins/c_string.h
+++ b/builtins/c_string.h
@@ -13,6 +13,6 @@ int CString$compare(const char **x, const char **y);
bool CString$equal(const char **x, const char **y);
uint64_t CString$hash(const char **str);
-extern const TypeInfo $CString;
+extern const TypeInfo CString$info;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/integers.c b/builtins/integers.c
index 0f0400f1..aad4bf33 100644
--- a/builtins/integers.c
+++ b/builtins/integers.c
@@ -318,7 +318,7 @@ public Int_t Int$sqrt(Int_t i)
public Int_t Int$random(Int_t min, Int_t max) {
int32_t cmp = Int$compare_value(min, max);
if (cmp > 0) {
- Text_t min_text = Int$as_text(&min, false, &$Int), max_text = Int$as_text(&max, false, &$Int);
+ Text_t min_text = Int$as_text(&min, false, &Int$info), max_text = Int$as_text(&max, false, &Int$info);
fail("Random minimum value (%k) is larger than the maximum value (%k)",
&min_text, &max_text);
}
@@ -387,11 +387,11 @@ public Int_t Int$prev_prime(Int_t x)
mpz_t p;
mpz_init_set_int(p, x);
if (mpz_prevprime(p, p) == 0)
- fail("There is no prime number before %k", (Text_t[1]){Int$as_text(&x, false, &$Int)});
+ fail("There is no prime number before %k", (Text_t[1]){Int$as_text(&x, false, &Int$info)});
return Int$from_mpz(p);
}
-public const TypeInfo $Int = {
+public const TypeInfo Int$info = {
.size=sizeof(Int_t),
.align=__alignof__(Int_t),
.tag=CustomInfo,
@@ -476,7 +476,7 @@ public const TypeInfo $Int = {
} \
public const c_type KindOfInt##$min = min_val; \
public const c_type KindOfInt##$max = max_val; \
- public const TypeInfo $ ## KindOfInt = { \
+ public const TypeInfo KindOfInt##$info = { \
.size=sizeof(c_type), \
.align=__alignof__(c_type), \
.tag=CustomInfo, \
diff --git a/builtins/integers.h b/builtins/integers.h
index d70f609a..e5765de3 100644
--- a/builtins/integers.h
+++ b/builtins/integers.h
@@ -38,7 +38,7 @@
return x < min ? min : (x > max ? max : x); \
} \
extern const c_type type_name ## $min, type_name##$max; \
- extern const TypeInfo $ ## type_name; \
+ extern const TypeInfo type_name ## $info; \
static inline c_type type_name ## $divided_by(c_type D, c_type d) { \
c_type q = D/d, r = D%d; \
if (r < 0) { \
@@ -126,11 +126,11 @@ bool Int$is_prime(Int_t x, Int_t reps);
Int_t Int$next_prime(Int_t x);
Int_t Int$prev_prime(Int_t x);
-extern const TypeInfo $Int;
+extern const TypeInfo Int$info;
static inline Int_t Int$clamped(Int_t x, Int_t low, Int_t high)
{
- return (Int$compare(&x, &low, &$Int) <= 0) ? low : (Int$compare(&x, &high, &$Int) >= 0 ? high : x);
+ return (Int$compare(&x, &low, &Int$info) <= 0) ? low : (Int$compare(&x, &high, &Int$info) >= 0 ? high : x);
}
// Fast-path inline versions for the common case where integer arithmetic is
diff --git a/builtins/memory.c b/builtins/memory.c
index 06fb7bb2..47ff081b 100644
--- a/builtins/memory.c
+++ b/builtins/memory.c
@@ -19,7 +19,7 @@ public Text_t Memory__as_text(const void *p, bool colorize, const TypeInfo *type
return Text$format(colorize ? "\x1b[0;34;1mMemory<%p>\x1b[m" : "Memory<%p>", p);
}
-public const TypeInfo $Memory = {
+public const TypeInfo Memory$info = {
.size=0,
.align=0,
.tag=CustomInfo,
diff --git a/builtins/memory.h b/builtins/memory.h
index e3cb2983..9bde4617 100644
--- a/builtins/memory.h
+++ b/builtins/memory.h
@@ -8,7 +8,7 @@
#include "types.h"
-extern const TypeInfo $Memory;
+extern const TypeInfo Memory$info;
Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo *type);
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/nums.c b/builtins/nums.c
index ab386c78..35ec9b18 100644
--- a/builtins/nums.c
+++ b/builtins/nums.c
@@ -82,7 +82,7 @@ public bool Num$isinf(double n) { return !!isinf(n); }
public bool Num$finite(double n) { return !!finite(n); }
public bool Num$isnan(double n) { return !!isnan(n); }
-public const TypeInfo $Num = {
+public const TypeInfo Num$info = {
.size=sizeof(double),
.align=__alignof__(double),
.tag=CustomInfo,
@@ -161,7 +161,7 @@ public bool Num32$isinf(float n) { return isinf(n); }
public bool Num32$finite(float n) { return finite(n); }
public bool Num32$isnan(float n) { return isnan(n); }
-public const TypeInfo $Num32 = {
+public const TypeInfo Num32$info = {
.size=sizeof(float),
.align=__alignof__(float),
.tag=CustomInfo,
diff --git a/builtins/nums.h b/builtins/nums.h
index a3f862d7..059ac7bd 100644
--- a/builtins/nums.h
+++ b/builtins/nums.h
@@ -31,7 +31,7 @@ double Num$from_text(Text_t text, bool *success);
static inline double Num$clamped(double x, double low, double high) {
return (x <= low) ? low : (x >= high ? high : x);
}
-extern const TypeInfo $Num;
+extern const TypeInfo Num$info;
Text_t Num32$as_text(const float *f, bool colorize, const TypeInfo *type);
int32_t Num32$compare(const float *x, const float *y, const TypeInfo *type);
@@ -50,6 +50,6 @@ float Num32$nan(Text_t tag);
static inline float Num32$clamped(float x, float low, float high) {
return (x <= low) ? low : (x >= high ? high : x);
}
-extern const TypeInfo $Num32;
+extern const TypeInfo Num32$info;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/pointer.c b/builtins/pointer.c
index 5090edd9..bd18a1e4 100644
--- a/builtins/pointer.c
+++ b/builtins/pointer.c
@@ -54,7 +54,7 @@ public Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo *type
colorize ? Text("\x1b[34;1m") : Text(""),
Text$from_str(ptr_info.sigil),
Text(".."),
- Int32$as_text(&depth, false, &$Int32),
+ Int32$as_text(&depth, false, &Int32$info),
colorize ? Text("\x1b[m") : Text(""));
if (ptr_info.is_optional)
text = Text$concat(text, colorize ? Text("\x1b[34;1m?\x1b[m") : Text("?"));
diff --git a/builtins/range.c b/builtins/range.c
index 068d8cea..1c8106eb 100644
--- a/builtins/range.c
+++ b/builtins/range.c
@@ -19,18 +19,18 @@ static int32_t Range$compare(const Range_t *x, const Range_t *y, const TypeInfo
{
(void)type;
if (x == y) return 0;
- int32_t diff = Int$compare(&x->first, &y->first, &$Int);
+ int32_t diff = Int$compare(&x->first, &y->first, &Int$info);
if (diff != 0) return diff;
- diff = Int$compare(&x->last, &y->last, &$Int);
+ diff = Int$compare(&x->last, &y->last, &Int$info);
if (diff != 0) return diff;
- return Int$compare(&x->step, &y->step, &$Int);
+ return Int$compare(&x->step, &y->step, &Int$info);
}
static bool Range$equal(const Range_t *x, const Range_t *y, const TypeInfo *type)
{
(void)type;
if (x == y) return true;
- return Int$equal(&x->first, &y->first, &$Int) && Int$equal(&x->last, &y->last, &$Int) && Int$equal(&x->step, &y->step, &$Int);
+ return Int$equal(&x->first, &y->first, &Int$info) && Int$equal(&x->last, &y->last, &Int$info) && Int$equal(&x->step, &y->step, &Int$info);
}
static Text_t Range$as_text(const Range_t *r, bool use_color, const TypeInfo *type)
@@ -40,8 +40,8 @@ static Text_t Range$as_text(const Range_t *r, bool use_color, const TypeInfo *ty
return Text$format(use_color ? "\x1b[0;1mRange\x1b[m(first=%r, last=%r, step=%r)"
: "Range(first=%r, last=%r, step=%r)",
- Int$as_text(&r->first, use_color, &$Int), Int$as_text(&r->last, use_color, &$Int),
- Int$as_text(&r->step, use_color, &$Int));
+ Int$as_text(&r->first, use_color, &Int$info), Int$as_text(&r->last, use_color, &Int$info),
+ Int$as_text(&r->step, use_color, &Int$info));
}
public Range_t Range$reversed(Range_t r)
diff --git a/builtins/table.c b/builtins/table.c
index b0b95af7..3a672e0f 100644
--- a/builtins/table.c
+++ b/builtins/table.c
@@ -48,7 +48,7 @@ static const TypeInfo MemoryPointer = {
.tag=PointerInfo,
.PointerInfo={
.sigil="@",
- .pointed=&$Memory,
+ .pointed=&Memory$info,
},
};
@@ -56,7 +56,7 @@ const TypeInfo CStrToVoidStarTable = {
.size=sizeof(Table_t),
.align=__alignof__(Table_t),
.tag=TableInfo,
- .TableInfo={.key=&$CString, .value=&MemoryPointer},
+ .TableInfo={.key=&CString$info, .value=&MemoryPointer},
};
static inline size_t entry_size(const TypeInfo *info)
@@ -446,8 +446,8 @@ public uint32_t Table$hash(const Table_t *t, const TypeInfo *type)
// Where fallback and default hash to zero if absent
auto table = type->TableInfo;
uint32_t components[] = {
- Array$hash(&t->entries, $ArrayInfo(table.key)),
- Array$hash(&t->entries + value_offset(type), $ArrayInfo(table.value)),
+ Array$hash(&t->entries, Array$info(table.key)),
+ Array$hash(&t->entries + value_offset(type), Array$info(table.value)),
t->fallback ? Table$hash(t->fallback, type) : 0,
};
uint32_t hash;
@@ -461,7 +461,7 @@ public Text_t Table$as_text(const Table_t *t, bool colorize, const TypeInfo *typ
auto table = type->TableInfo;
if (!t) {
- if (table.value != &$Void)
+ if (table.value != &Void$info)
return Text$concat(
Text("{"),
generic_as_text(NULL, false, table.key),
@@ -482,7 +482,7 @@ public Text_t Table$as_text(const Table_t *t, bool colorize, const TypeInfo *typ
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)
+ if (table.value != &Void$info)
text = Text$concat(text, Text(":"), generic_as_text(entry + val_off, colorize, table.value));
}
diff --git a/builtins/table.h b/builtins/table.h
index d7afb56f..cd267912 100644
--- a/builtins/table.h
+++ b/builtins/table.h
@@ -17,7 +17,7 @@
.data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \
.length=sizeof(ents)/sizeof(ents[0]), \
.stride=(void*)&ents[1] - (void*)&ents[0], \
- }, $TableInfo(key_info, value_info)); \
+ }, Table$info(key_info, value_info)); \
table.fallback = fb; \
table; })
#define Set(item_t, item_info, N, ...) ({ \
@@ -26,7 +26,7 @@
.data=memcpy(GC_MALLOC(sizeof(ents)), ents, sizeof(ents)), \
.length=sizeof(ents)/sizeof(ents[0]), \
.stride=(void*)&ents[1] - (void*)&ents[0], \
- }, $SetInfo(item_info)); \
+ }, Set$info(item_info)); \
set; })
Table_t Table$from_entries(Array_t entries, const TypeInfo *type);
diff --git a/builtins/text.c b/builtins/text.c
index 4bca6516..39222ed4 100644
--- a/builtins/text.c
+++ b/builtins/text.c
@@ -126,7 +126,7 @@ static const TypeInfo GraphemeClusterInfo = {
static const TypeInfo GraphemeIDLookupTableInfo = {
.size=sizeof(Table_t), .align=__alignof__(Table_t),
- .tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&$Int32},
+ .tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&Int32$info},
};
int32_t get_synthetic_grapheme(const uint32_t *codepoints, int64_t utf32_len)
@@ -1762,8 +1762,8 @@ public Text_t Text$as_text(const void *text, bool colorize, const TypeInfo *info
{
(void)info;
if (!text) return info && info->TextInfo.lang ? Text$from_str(info->TextInfo.lang) : Text("Text");
- Text_t as_text = _quoted(*(Text_t*)text, colorize, info == &Pattern ? '/' : '"');
- if (info && info->TextInfo.lang && info != &$Text && info != &Pattern)
+ Text_t as_text = _quoted(*(Text_t*)text, colorize, info == &Pattern$info ? '/' : '"');
+ if (info && info->TextInfo.lang && info != &Text$info && info != &Pattern$info)
as_text = Text$concat(
colorize ? Text("\x1b[1m$") : Text("$"),
Text$from_str(info->TextInfo.lang),
@@ -2165,7 +2165,7 @@ public Array_t Text$lines(Text_t text)
return lines;
}
-public const TypeInfo $Text = {
+public const TypeInfo Text$info = {
.size=sizeof(Text_t),
.align=__alignof__(Text_t),
.tag=TextInfo,
@@ -2202,7 +2202,7 @@ public Pattern_t Pattern$escape_text(Text_t text)
#undef add_escaped
}
-public const TypeInfo Pattern = {
+public const TypeInfo Pattern$info = {
.size=sizeof(Text_t),
.align=__alignof__(Text_t),
.tag=TextInfo,
diff --git a/builtins/text.h b/builtins/text.h
index a8ca85fc..eff01dbe 100644
--- a/builtins/text.h
+++ b/builtins/text.h
@@ -54,11 +54,11 @@ Text_t Text$join(Text_t glue, Array_t pieces);
Text_t Text$map(Text_t text, Pattern_t pattern, closure_t fn);
Text_t Text$repeat(Text_t text, Int_t count);
-extern const TypeInfo $Text;
+extern const TypeInfo Text$info;
#define Pattern(text) ((Pattern_t)Text(text))
#define Patterns(...) ((Pattern_t)Texts(__VA_ARGS__))
Pattern_t Pattern$escape_text(Text_t text);
-extern const TypeInfo Pattern;
+extern const TypeInfo Pattern$info;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/types.c b/builtins/types.c
index c34882f0..6d9e2408 100644
--- a/builtins/types.c
+++ b/builtins/types.c
@@ -25,15 +25,15 @@ public Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo *
return Text$from_str(type->TypeInfoInfo.type_str);
}
-public const TypeInfo $TypeInfo = {
+public const TypeInfo TypeInfo$info = {
.size=sizeof(TypeInfo),
.align=__alignof__(TypeInfo),
.tag=CustomInfo,
.TypeInfoInfo.type_str="TypeInfo",
};
-public const TypeInfo $Void = {.size=0, .align=0, .tag=EmptyStruct};
-public const TypeInfo $Abort = {.size=0, .align=0, .tag=EmptyStruct};
+public const TypeInfo Void$info = {.size=0, .align=0, .tag=EmptyStruct};
+public const TypeInfo Abort$info = {.size=0, .align=0, .tag=EmptyStruct};
public Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo *type)
{
diff --git a/builtins/types.h b/builtins/types.h
index 24640f89..70cf89c3 100644
--- a/builtins/types.h
+++ b/builtins/types.h
@@ -53,26 +53,26 @@ typedef struct TypeInfo {
};
} TypeInfo;
-#define $PointerInfo(sigil_expr, pointed_info, opt) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \
- .tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info, .is_optional=opt}})
-#define $ArrayInfo(item_info) &((TypeInfo){.size=sizeof(Array_t), .align=__alignof__(Array_t), \
+#define Pointer$info(sigil_expr, pointed_info, opt) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \
+ .tag=PointerInfo, .PointerInfo={.sigil=sigil_expr, .pointed=pointed_info, .is_optional=opt}})
+#define Array$info(item_info) &((TypeInfo){.size=sizeof(Array_t), .align=__alignof__(Array_t), \
.tag=ArrayInfo, .ArrayInfo.item=item_info})
-#define $SetInfo(item_info) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
- .tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&$Void})
-#define $ChannelInfo(item_info) &((TypeInfo){.size=sizeof(channel_t), .align=__alignof__(channel_t), \
+#define Set$info(item_info) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
+ .tag=TableInfo, .TableInfo.key=item_info, .TableInfo.value=&Void$info})
+#define Channel$info(item_info) &((TypeInfo){.size=sizeof(channel_t), .align=__alignof__(channel_t), \
.tag=ChannelInfo, .ChannelInfo.item=item_info})
-#define $TableInfo(key_expr, value_expr) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
+#define Table$info(key_expr, value_expr) &((TypeInfo){.size=sizeof(Table_t), .align=__alignof__(Table_t), \
.tag=TableInfo, .TableInfo.key=key_expr, .TableInfo.value=value_expr})
-#define $FunctionInfo(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \
+#define Function$info(typestr) &((TypeInfo){.size=sizeof(void*), .align=__alignof__(void*), \
.tag=FunctionInfo, .FunctionInfo.type_str=typestr})
-#define $ClosureInfo(typestr) &((TypeInfo){.size=sizeof(void*[2]), .align=__alignof__(void*), \
+#define Closure$info(typestr) &((TypeInfo){.size=sizeof(void*[2]), .align=__alignof__(void*), \
.tag=FunctionInfo, .FunctionInfo.type_str=typestr})
-#define $TypeInfoInfo(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \
+#define TypeInfo$info(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \
.tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr})
-extern const TypeInfo $TypeInfo;
-extern const TypeInfo $Void;
-extern const TypeInfo $Abort;
+extern const TypeInfo TypeInfo$info;
+extern const TypeInfo Void$info;
+extern const TypeInfo Abort$info;
#define Void_t void
Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo *type);
diff --git a/compile.c b/compile.c
index 7ecd614a..125db5a5 100644
--- a/compile.c
+++ b/compile.c
@@ -741,7 +741,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
is_private ? CORD_EMPTY : "public ", ret_type_code, " ", name, arg_signature, "{\n"
"static Table_t cache = {};\n",
compile_type(args_t), " args = {", all_args, "};\n"
- "const TypeInfo *table_type = $TableInfo(", compile_type_info(env, args_t), ", ", compile_type_info(env, ret_t), ");\n",
+ "const TypeInfo *table_type = Table$info(", compile_type_info(env, args_t), ", ", compile_type_info(env, ret_t), ");\n",
compile_declaration(Type(PointerType, .pointed=ret_t, .is_optional=true), "cached"), " = Table$get_raw(cache, &args, table_type);\n"
"if (cached) return *cached;\n",
compile_declaration(ret_t, "ret"), " = ", name, "$uncached(", all_args, ");\n",
@@ -1252,16 +1252,16 @@ CORD compile_statement(env_t *env, ast_t *ast)
CORD expr_as_text(env_t *env, CORD expr, type_t *t, CORD color)
{
switch (t->tag) {
- case MemoryType: return CORD_asprintf("Memory$as_text(stack(%r), %r, &$Memory)", expr, color);
- case BoolType: return CORD_asprintf("Bool$as_text((Bool_t[1]){%r}, %r, &$Bool)", expr, color);
- case CStringType: return CORD_asprintf("CString$as_text(stack(%r), %r, &$CString)", expr, color);
+ case MemoryType: return CORD_asprintf("Memory$as_text(stack(%r), %r, &Memory$info)", expr, color);
+ case BoolType: return CORD_asprintf("Bool$as_text((Bool_t[1]){%r}, %r, &Bool$info)", expr, color);
+ case CStringType: return CORD_asprintf("CString$as_text(stack(%r), %r, &CString$info)", expr, color);
case BigIntType: case IntType: {
CORD name = type_to_cord(t);
- return CORD_asprintf("%r$as_text(stack(%r), %r, &$%r)", name, expr, color, name);
+ return CORD_asprintf("%r$as_text(stack(%r), %r, &%r$info)", name, expr, color, name);
}
case NumType: {
CORD name = type_to_cord(t);
- return CORD_asprintf("%r$as_text(stack(%r), %r, &$%r)", name, expr, color, name);
+ return CORD_asprintf("%r$as_text(stack(%r), %r, &%r$info)", name, expr, color, name);
}
case TextType: {
return CORD_asprintf("Text$as_text(stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
@@ -2398,7 +2398,7 @@ CORD compile(env_t *env, ast_t *ast)
} else if (streq(call->name, "unique")) {
CORD self = compile_to_pointer_depth(env, call->self, 0, false);
(void)compile_arguments(env, ast, NULL, call->args);
- return CORD_all("Table$from_entries(", self, ", $SetInfo(", compile_type_info(env, item_t), "))");
+ return CORD_all("Table$from_entries(", self, ", Set$info(", compile_type_info(env, item_t), "))");
} else if (streq(call->name, "counts")) {
CORD self = compile_to_pointer_depth(env, call->self, 0, false);
(void)compile_arguments(env, ast, NULL, call->args);
@@ -2985,10 +2985,14 @@ CORD compile_type_info(env_t *env, type_t *t)
{
switch (t->tag) {
case BoolType: case IntType: case BigIntType: case NumType: case CStringType:
- return CORD_asprintf("&$%r", type_to_cord(t));
+ return CORD_all("&", type_to_cord(t), "$info");
case TextType: {
auto text = Match(t, TextType);
- return text->lang ? CORD_all("(&", namespace_prefix(text->env->libname, text->env->namespace->parent), text->lang, ")") : "&$Text";
+ if (!text->lang)
+ return "&Text$info";
+ else if (streq(text->lang, "Pattern"))
+ return "&Pattern$info";
+ return CORD_all("(&", namespace_prefix(text->env->libname, text->env->namespace->parent), text->lang, ")");
}
case StructType: {
auto s = Match(t, StructType);
@@ -3000,39 +3004,39 @@ CORD compile_type_info(env_t *env, type_t *t)
}
case ArrayType: {
type_t *item_t = Match(t, ArrayType)->item_type;
- return CORD_all("$ArrayInfo(", compile_type_info(env, item_t), ")");
+ return CORD_all("Array$info(", compile_type_info(env, item_t), ")");
}
case SetType: {
type_t *item_type = Match(t, SetType)->item_type;
- return CORD_all("$SetInfo(", compile_type_info(env, item_type), ")");
+ return CORD_all("Set$info(", compile_type_info(env, item_type), ")");
}
case ChannelType: {
type_t *item_t = Match(t, ChannelType)->item_type;
- return CORD_asprintf("$ChannelInfo(%r)", compile_type_info(env, item_t));
+ return CORD_asprintf("Channel$info(%r)", compile_type_info(env, item_t));
}
case TableType: {
type_t *key_type = Match(t, TableType)->key_type;
type_t *value_type = Match(t, TableType)->value_type;
- return CORD_all("$TableInfo(", compile_type_info(env, key_type), ", ", compile_type_info(env, value_type), ")");
+ return CORD_all("Table$info(", compile_type_info(env, key_type), ", ", compile_type_info(env, value_type), ")");
}
case PointerType: {
auto ptr = Match(t, PointerType);
CORD sigil = ptr->is_stack ? "&" : "@";
if (ptr->is_readonly) sigil = CORD_cat(sigil, "%");
- return CORD_asprintf("$PointerInfo(%r, %r, %s)",
+ return CORD_asprintf("Pointer$info(%r, %r, %s)",
CORD_quoted(sigil),
compile_type_info(env, ptr->pointed),
ptr->is_optional ? "yes" : "no");
}
case FunctionType: {
- return CORD_asprintf("$FunctionInfo(%r)", CORD_quoted(type_to_cord(t)));
+ return CORD_asprintf("Function$info(%r)", CORD_quoted(type_to_cord(t)));
}
case ClosureType: {
- return CORD_asprintf("$ClosureInfo(%r)", CORD_quoted(type_to_cord(t)));
+ return CORD_asprintf("Closure$info(%r)", CORD_quoted(type_to_cord(t)));
}
- case TypeInfoType: return "&$TypeInfo";
- case MemoryType: return "&$Memory";
- case VoidType: return "&$Void";
+ case TypeInfoType: return "&TypeInfo$info";
+ case MemoryType: return "&Memory$info";
+ case VoidType: return "&Void$info";
default:
compiler_err(NULL, 0, 0, "I couldn't convert to a type info: %T", t);
}
diff --git a/docs/namespacing.md b/docs/namespacing.md
index 381956d8..bc7dbe7c 100644
--- a/docs/namespacing.md
+++ b/docs/namespacing.md
@@ -49,7 +49,7 @@ static CORD foo$Baz$as_text(foo$Baz_t *obj, bool use_color)
if (!obj)
return "Baz";
return CORD_all(use_color ? "\x1b[0;1mBaz\x1b[m(" : "Baz(", "x=",
- Int$as_text(stack(obj->$x), use_color, &$Int), ")");
+ Int$as_text(stack(obj->$x), use_color, &Int$info), ")");
}
public Int_t foo$Baz$frob(struct foo$Baz_s $b)
diff --git a/environment.c b/environment.c
index 260bb586..320d2573 100644
--- a/environment.c
+++ b/environment.c
@@ -77,13 +77,13 @@ env_t *new_compilation_unit(CORD *libname)
CORD struct_val;
Array_t namespace;
} global_types[] = {
- {"Void", Type(VoidType), "Void_t", "$Void", {}},
- {"Memory", Type(MemoryType), "Memory_t", "$Memory", {}},
- {"Bool", Type(BoolType), "Bool_t", "$Bool", TypedArray(ns_entry_t,
+ {"Void", Type(VoidType), "Void_t", "Void$info", {}},
+ {"Memory", Type(MemoryType), "Memory_t", "Memory$info", {}},
+ {"Bool", Type(BoolType), "Bool_t", "Bool$info", TypedArray(ns_entry_t,
{"from_text", "Bool$from_text", "func(text:Text, success=!&Bool)->Bool"},
{"random", "Bool$random", "func(p=0.5)->Bool"},
)},
- {"Int", Type(BigIntType), "Int_t", "$Int", TypedArray(ns_entry_t,
+ {"Int", Type(BigIntType), "Int_t", "Int$info", TypedArray(ns_entry_t,
{"abs", "Int$abs", "func(x:Int)->Int"},
{"bit_and", "Int$bit_and", "func(x:Int,y:Int)->Int"},
{"bit_or", "Int$bit_or", "func(x:Int,y:Int)->Int"},
@@ -111,7 +111,7 @@ env_t *new_compilation_unit(CORD *libname)
{"times", "Int$times", "func(x:Int,y:Int)->Int"},
{"to", "Int$to", "func(from:Int,to:Int)->Range"},
)},
- {"Int64", Type(IntType, .bits=TYPE_IBITS64), "Int64_t", "$Int64", TypedArray(ns_entry_t,
+ {"Int64", Type(IntType, .bits=TYPE_IBITS64), "Int64_t", "Int64$info", TypedArray(ns_entry_t,
{"abs", "labs", "func(i:Int64)->Int64"},
{"bits", "Int64$bits", "func(x:Int64)->[Bool]"},
{"clamped", "Int64$clamped", "func(x:Int64,low:Int64,high:Int64)->Int64"},
@@ -127,7 +127,7 @@ env_t *new_compilation_unit(CORD *libname)
{"random", "Int64$random", "func(min=-0x8000000000000000_i64, max=0x7FFFFFFFFFFFFFFF_i64)->Int64"},
{"to", "Int64$to", "func(from:Int64,to:Int64)->Range"},
)},
- {"Int32", Type(IntType, .bits=TYPE_IBITS32), "Int32_t", "$Int32", TypedArray(ns_entry_t,
+ {"Int32", Type(IntType, .bits=TYPE_IBITS32), "Int32_t", "Int32$info", TypedArray(ns_entry_t,
{"abs", "abs", "func(i:Int32)->Int32"},
{"bits", "Int32$bits", "func(x:Int32)->[Bool]"},
{"clamped", "Int32$clamped", "func(x:Int32,low:Int32,high:Int32)->Int32"},
@@ -143,7 +143,7 @@ env_t *new_compilation_unit(CORD *libname)
{"random", "Int32$random", "func(min=-0x80000000_i32, max=0x7FFFFFFF_i32)->Int32"},
{"to", "Int32$to", "func(from:Int32,to:Int32)->Range"},
)},
- {"Int16", Type(IntType, .bits=TYPE_IBITS16), "Int16_t", "$Int16", TypedArray(ns_entry_t,
+ {"Int16", Type(IntType, .bits=TYPE_IBITS16), "Int16_t", "Int16$info", TypedArray(ns_entry_t,
{"abs", "abs", "func(i:Int16)->Int16"},
{"bits", "Int16$bits", "func(x:Int16)->[Bool]"},
{"clamped", "Int16$clamped", "func(x:Int16,low:Int16,high:Int16)->Int16"},
@@ -159,7 +159,7 @@ env_t *new_compilation_unit(CORD *libname)
{"random", "Int16$random", "func(min=-0x8000_i16, max=0x7FFF_i16)->Int16"},
{"to", "Int16$to", "func(from:Int16,to:Int16)->Range"},
)},
- {"Int8", Type(IntType, .bits=TYPE_IBITS8), "Int8_t", "$Int8", TypedArray(ns_entry_t,
+ {"Int8", Type(IntType, .bits=TYPE_IBITS8), "Int8_t", "Int8$info", TypedArray(ns_entry_t,
{"abs", "abs", "func(i:Int8)->Int8"},
{"bits", "Int8$bits", "func(x:Int8)->[Bool]"},
{"clamped", "Int8$clamped", "func(x:Int8,low:Int8,high:Int8)->Int8"},
@@ -178,7 +178,7 @@ env_t *new_compilation_unit(CORD *libname)
#define C(name) {#name, "M_"#name, "Num"}
#define F(name) {#name, #name, "func(n:Num)->Num"}
#define F2(name) {#name, #name, "func(x:Num, y:Num)->Num"}
- {"Num", Type(NumType, .bits=TYPE_NBITS64), "Num_t", "$Num", TypedArray(ns_entry_t,
+ {"Num", Type(NumType, .bits=TYPE_NBITS64), "Num_t", "Num$info", TypedArray(ns_entry_t,
{"near", "Num$near", "func(x:Num, y:Num, ratio=1e-9, min_epsilon=1e-9)->Bool"},
{"clamped", "Num$clamped", "func(x:Num,low:Num,high:Num)->Num"},
{"format", "Num$format", "func(n:Num, precision=0)->Text"},
@@ -207,7 +207,7 @@ env_t *new_compilation_unit(CORD *libname)
#define C(name) {#name, "(Num32_t)(M_"#name")", "Num32"}
#define F(name) {#name, #name"f", "func(n:Num32)->Num32"}
#define F2(name) {#name, #name"f", "func(x:Num32, y:Num32)->Num32"}
- {"Num32", Type(NumType, .bits=TYPE_NBITS32), "Num32_t", "$Num32", TypedArray(ns_entry_t,
+ {"Num32", Type(NumType, .bits=TYPE_NBITS32), "Num32_t", "Num32$info", TypedArray(ns_entry_t,
{"near", "Num32$near", "func(x:Num32, y:Num32, ratio=1e-9f32, min_epsilon=1e-9f32)->Bool"},
{"clamped", "Num32$clamped", "func(x:Num32,low:Num32,high:Num32)->Num32"},
{"format", "Num32$format", "func(n:Num32, precision=0)->Text"},
@@ -230,7 +230,7 @@ env_t *new_compilation_unit(CORD *libname)
F(tan), F(tanh), F(tgamma), F(trunc), F(y0), F(y1),
F2(atan2), F2(copysign), F2(fdim), F2(hypot), F2(nextafter), F2(pow), F2(remainder),
)},
- {"CString", Type(CStringType), "char*", "$CString", TypedArray(ns_entry_t,
+ {"CString", Type(CStringType), "char*", "CString$info", TypedArray(ns_entry_t,
{"as_text", "CORD_from_char_star", "func(str:CString)->Text"},
)},
#undef F2
@@ -240,10 +240,10 @@ env_t *new_compilation_unit(CORD *libname)
{"reversed", "Range$reversed", "func(range:Range)->Range"},
{"by", "Range$by", "func(range:Range, step:Int)->Range"},
)},
- {"Pattern", Type(TextType, .lang="Pattern", .env=namespace_env(env, "Pattern")), "Text_t", "Pattern", TypedArray(ns_entry_t,
+ {"Pattern", Type(TextType, .lang="Pattern", .env=namespace_env(env, "Pattern")), "Pattern_t", "Pattern$info", TypedArray(ns_entry_t,
{"escape_text", "Pattern$escape_text", "func(text:Text)->Pattern"},
)},
- {"Text", TEXT_TYPE, "Text_t", "$Text", TypedArray(ns_entry_t,
+ {"Text", TEXT_TYPE, "Text_t", "Text$info", TypedArray(ns_entry_t,
{"find", "Text$find", "func(text:Text, pattern:Pattern, start=1, length=!&Int64)->Int"},
{"find_all", "Text$find_all", "func(text:Text, pattern:Pattern)->[Text]"},
{"as_c_string", "CORD_to_char_star", "func(text:Text)->CString"},
diff --git a/repl.c b/repl.c
index d5b207b3..e5eeb354 100644
--- a/repl.c
+++ b/repl.c
@@ -98,27 +98,27 @@ static void repl_err(ast_t *node, const char *fmt, ...)
const TypeInfo *type_to_type_info(type_t *t)
{
switch (t->tag) {
- case AbortType: return &$Abort;
+ case AbortType: return &Abort$info;
case ReturnType: errx(1, "Shouldn't be getting a typeinfo for ReturnType");
- case VoidType: return &$Void;
- case MemoryType: return &$Memory;
- case BoolType: return &$Bool;
- case BigIntType: return &$Int;
+ case VoidType: return &Void$info;
+ case MemoryType: return &Memory$info;
+ case BoolType: return &Bool$info;
+ case BigIntType: return &Int$info;
case IntType:
switch (Match(t, IntType)->bits) {
- case TYPE_IBITS64: return &$Int64;
- case TYPE_IBITS32: return &$Int32;
- case TYPE_IBITS16: return &$Int16;
- case TYPE_IBITS8: return &$Int8;
+ case TYPE_IBITS64: return &Int64$info;
+ case TYPE_IBITS32: return &Int32$info;
+ case TYPE_IBITS16: return &Int16$info;
+ case TYPE_IBITS8: return &Int8$info;
default: errx(1, "Invalid bits");
}
case NumType:
switch (Match(t, NumType)->bits) {
- case TYPE_NBITS64: return &$Num;
- case TYPE_NBITS32: return &$Num32;
+ case TYPE_NBITS64: return &Num$info;
+ case TYPE_NBITS32: return &Num32$info;
default: errx(1, "Invalid bits");
}
- case TextType: return &$Text;
+ case TextType: return &Text$info;
case ArrayType: {
const TypeInfo *item_info = type_to_type_info(Match(t, ArrayType)->item_type);
const TypeInfo array_info = {.size=sizeof(Array_t), .align=__alignof__(Array_t),