aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-27 13:39:12 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-27 13:39:12 -0500
commitce0e1c25e237849ecd8bea28b5c0ac6112374654 (patch)
treeb9168c1df899edf707714122d1717b0d9026d2e8
parent55d44fe9f235b7916e3184c9a6da8922fd60b056 (diff)
Stop using namespace types
-rw-r--r--builtins/bool.c14
-rw-r--r--builtins/bool.h6
-rw-r--r--builtins/integers.c31
-rw-r--r--builtins/integers.h18
-rw-r--r--builtins/nums.c80
-rw-r--r--builtins/nums.h98
-rw-r--r--builtins/string.c32
-rw-r--r--builtins/string.h27
-rw-r--r--builtins/table.c2
-rw-r--r--builtins/types.c12
-rw-r--r--builtins/types.h6
-rw-r--r--compile.c16
12 files changed, 121 insertions, 221 deletions
diff --git a/builtins/bool.c b/builtins/bool.c
index 31e28d82..774ccff9 100644
--- a/builtins/bool.c
+++ b/builtins/bool.c
@@ -13,8 +13,6 @@
#include "bool.h"
#include "types.h"
-extern const void *SSS_HASH_VECTOR;
-
public CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type)
{
(void)type;
@@ -25,13 +23,11 @@ public CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type)
return *b ? "yes" : "no";
}
-public Bool_namespace_t Bool = {
- .type={
- .size=sizeof(bool),
- .align=__alignof__(bool),
- .tag=CustomInfo,
- .CustomInfo={.as_str=(void*)Bool__as_str},
- },
+public TypeInfo Bool = {
+ .size=sizeof(bool),
+ .align=__alignof__(bool),
+ .tag=CustomInfo,
+ .CustomInfo={.as_str=(void*)Bool__as_str},
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/bool.h b/builtins/bool.h
index bbe67dba..2d1a6f88 100644
--- a/builtins/bool.h
+++ b/builtins/bool.h
@@ -11,10 +11,6 @@
CORD Bool__as_str(const bool *b, bool colorize, const TypeInfo *type);
-typedef struct {
- TypeInfo type;
-} Bool_namespace_t;
-
-extern Bool_namespace_t Bool;
+extern TypeInfo Bool;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/integers.c b/builtins/integers.c
index 2b8e715c..b221a8ba 100644
--- a/builtins/integers.c
+++ b/builtins/integers.c
@@ -13,7 +13,7 @@
#define xstr(a) str(a)
#define str(a) #a
-#define DEFINE_INT_TYPE(c_type, KindOfInt, fmt, abs_fn, min_val, max_val)\
+#define DEFINE_INT_TYPE(c_type, KindOfInt, fmt, min_val, max_val)\
public CORD KindOfInt ## __as_str(const c_type *i, bool colorize, const TypeInfo *type) { \
(void)type; \
if (!i) return #KindOfInt; \
@@ -46,26 +46,19 @@
uint32_t r = arc4random_uniform((uint32_t)range); \
return min + (c_type)r; \
} \
- public KindOfInt##_namespace_t KindOfInt = { \
- .type={ \
- .size=sizeof(c_type), \
- .align=__alignof__(c_type), \
- .tag=CustomInfo, \
- .CustomInfo={.compare=(void*)KindOfInt##__compare, .as_str=(void*)KindOfInt##__as_str}, \
- }, \
- .min=min_val, \
- .max=max_val, \
- .abs=(void*)abs_fn, \
- .format=KindOfInt##__format, \
- .hex=KindOfInt##__hex, \
- .octal=KindOfInt##__octal, \
- .random=KindOfInt##__random, \
+ public const c_type KindOfInt##__min = min_val; \
+ public const c_type KindOfInt##__max = max_val; \
+ public TypeInfo KindOfInt = { \
+ .size=sizeof(c_type), \
+ .align=__alignof__(c_type), \
+ .tag=CustomInfo, \
+ .CustomInfo={.compare=(void*)KindOfInt##__compare, .as_str=(void*)KindOfInt##__as_str}, \
};
-DEFINE_INT_TYPE(int64_t, Int64, "ld", labs, INT64_MIN, INT64_MAX);
-DEFINE_INT_TYPE(int32_t, Int32, "d_i32", abs, INT32_MIN, INT32_MAX);
-DEFINE_INT_TYPE(int16_t, Int16, "d_i16", abs, INT16_MIN, INT16_MAX);
-DEFINE_INT_TYPE(int8_t, Int8, "d_i8", abs, INT8_MIN, INT8_MAX);
+DEFINE_INT_TYPE(int64_t, Int64, "ld", INT64_MIN, INT64_MAX);
+DEFINE_INT_TYPE(int32_t, Int32, "d_i32", INT32_MIN, INT32_MAX);
+DEFINE_INT_TYPE(int16_t, Int16, "d_i16", INT16_MIN, INT16_MAX);
+DEFINE_INT_TYPE(int8_t, Int8, "d_i8", INT8_MIN, INT8_MAX);
#undef DEFINE_INT_TYPE
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/integers.h b/builtins/integers.h
index d4679a81..bbb92f91 100644
--- a/builtins/integers.h
+++ b/builtins/integers.h
@@ -22,16 +22,8 @@
CORD type_name ## __hex(c_type i, int64_t digits, bool uppercase, bool prefix); \
CORD type_name ## __octal(c_type i, int64_t digits, bool prefix); \
c_type type_name ## __random(int64_t min, int64_t max); \
- typedef struct { \
- TypeInfo type; \
- c_type min, max; \
- c_type (*abs)(c_type i); \
- CORD (*format)(c_type i, int64_t digits); \
- CORD (*hex)(c_type i, int64_t digits, bool uppercase, bool prefix); \
- CORD (*octal)(c_type i, int64_t digits, bool prefix); \
- c_type (*random)(int64_t min, int64_t max); \
- } type_name##_namespace_t; \
- extern type_name##_namespace_t type_name;
+ extern const c_type type_name ## __min, type_name##__max; \
+ extern TypeInfo type_name;
DEFINE_INT_TYPE(int64_t, Int64);
DEFINE_INT_TYPE(int32_t, Int32);
@@ -39,6 +31,12 @@ DEFINE_INT_TYPE(int16_t, Int16);
DEFINE_INT_TYPE(int8_t, Int8);
#undef DEFINE_INT_TYPE
+#define Int__abs(...) I64(labs(__VA_ARGS__))
+#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__))
+
#define Int__as_str Int64__as_str
#define Int__compare Int64__compare
#define Int__format Int64__format
diff --git a/builtins/nums.c b/builtins/nums.c
index 557e98c0..3f924ac3 100644
--- a/builtins/nums.c
+++ b/builtins/nums.c
@@ -46,41 +46,26 @@ public double Num64__mod(double num, double modulus) {
return (result < 0) != (modulus < 0) ? result + modulus : result;
}
+public double Num64__nan(CORD tag) {
+ return nan(CORD_to_const_char_star(tag));
+}
+
public bool Num64__isinf(double n) { return isinf(n); }
public bool Num64__finite(double n) { return finite(n); }
public bool Num64__isnan(double n) { return isnan(n); }
-public Num64_namespace_t Num64 = {
- .type=(TypeInfo){
- .size=sizeof(double),
- .align=__alignof__(double),
- .tag=CustomInfo,
- .CustomInfo={
- .compare=(void*)Num64__compare,
- .equal=(void*)Num64__equal,
- .as_str=(void*)Num64__as_str,
- },
+public TypeInfo Num64 = {
+ .size=sizeof(double),
+ .align=__alignof__(double),
+ .tag=CustomInfo,
+ .CustomInfo={
+ .compare=(void*)Num64__compare,
+ .equal=(void*)Num64__equal,
+ .as_str=(void*)Num64__as_str,
},
- .NaN=NAN, ._2_sqrt_pi=M_2_SQRTPI, .e=M_E, .half_pi=M_PI_2, .inf=1./0., .inverse_half_pi=M_2_PI,
- .inverse_pi=M_1_PI, .ln10=M_LN10, .ln2=M_LN2, .log2e=M_LOG2E, .pi=M_PI, .quarter_pi=M_PI_4,
- .sqrt2=M_SQRT2, .sqrt_half=M_SQRT1_2, .tau=2.*M_PI,
- .random=drand48,
- .finite=Num64__finite,
- .isinf=Num64__isinf,
- .isnan=Num64__isnan,
- .atan2=atan2, .copysign=copysign, .dist=fdim, .hypot=hypot, .maxmag=fmaxmag, .minmag=fminmag,
- .mod=Num64__mod, .nextafter=nextafter, .pow=pow, .remainder=remainder,
- .abs=fabs, .acos=acos, .acosh=acosh, .asin=asin, .asinh=asinh, .atan=atan, .atanh=atanh,
- .cbrt=cbrt, .ceil=ceil, .cos=cos, .cosh=cosh, .erf=erf, .erfc=erfc, .exp=exp,
- .exp10=exp10, .exp2=exp2, .expm1=expm1, .floor=floor, .j0=j0, .j1=j1, .log=log,
- .log10=log10, .log1p=log1p, .log2=log2, .logb=logb, .nextdown=nextdown, .nextup=nextup,
- .rint=rint, .round=round, .roundeven=roundeven, .significand=significand, .sin=sin,
- .sinh=sinh, .sqrt=sqrt, .tan=tan, .tanh=tanh, .tgamma=tgamma, .trunc=trunc, .y0=y0, .y1=y1,
- .format=Num64__format,
- .scientific=Num64__scientific,
};
-public CORD Num32__as_str(float *f, bool colorize, const TypeInfo *type) {
+public CORD Num32__as_str(const float *f, bool colorize, const TypeInfo *type) {
(void)type;
if (!f) return "Num32";
CORD c;
@@ -116,38 +101,23 @@ public float Num32__random(void) {
return (float)drand48();
}
+public float Num32__nan(CORD tag) {
+ return nanf(CORD_to_const_char_star(tag));
+}
+
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 Num32_namespace_t Num32 = {
- .type=(TypeInfo){
- .size=sizeof(float),
- .align=__alignof__(float),
- .tag=CustomInfo,
- .CustomInfo={
- .compare=(void*)Num32__compare,
- .equal=(void*)Num32__equal,
- .as_str=(void*)Num32__as_str,
- },
+public TypeInfo Num32 = {
+ .size=sizeof(float),
+ .align=__alignof__(float),
+ .tag=CustomInfo,
+ .CustomInfo={
+ .compare=(void*)Num32__compare,
+ .equal=(void*)Num32__equal,
+ .as_str=(void*)Num32__as_str,
},
- .NaN=NAN, ._2_sqrt_pi=M_2_SQRTPI, .e=M_E, .half_pi=M_PI_2, .inf=1./0., .inverse_half_pi=M_2_PI,
- .inverse_pi=M_1_PI, .ln10=M_LN10, .ln2=M_LN2, .log2e=M_LOG2E, .pi=M_PI, .quarter_pi=M_PI_4,
- .sqrt2=M_SQRT2, .sqrt_half=M_SQRT1_2, .tau=2.*M_PI,
- .random=Num32__random,
- .finite=Num32__finite,
- .isinf=Num32__isinf,
- .isnan=Num32__isnan,
- .atan2=atan2f, .copysign=copysignf, .dist=fdimf, .hypot=hypotf, .maxmag=fmaxmagf, .minmag=fminmagf,
- .mod=Num32__mod, .nextafter=nextafterf, .pow=powf, .remainder=remainderf,
- .abs=fabsf, .acos=acosf, .acosh=acoshf, .asin=asinf, .asinh=asinhf, .atan=atanf, .atanh=atanhf,
- .cbrt=cbrtf, .ceil=ceilf, .cos=cosf, .cosh=coshf, .erf=erff, .erfc=erfcf, .exp=expf,
- .exp10=exp10f, .exp2=exp2f, .expm1=expm1f, .floor=floorf, .j0=j0f, .j1=j1f, .log=logf,
- .log10=log10f, .log1p=log1pf, .log2=log2f, .logb=logbf, .nextdown=nextdownf, .nextup=nextupf,
- .rint=rintf, .round=roundf, .roundeven=roundevenf, .significand=significandf, .sin=sinf,
- .sinh=sinhf, .sqrt=sqrtf, .tan=tanf, .tanh=tanhf, .tgamma=tgammaf, .trunc=truncf, .y0=y0f, .y1=y1f,
- .format=Num32__format,
- .scientific=Num32__scientific,
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/nums.h b/builtins/nums.h
index 83299ccf..7529a5df 100644
--- a/builtins/nums.h
+++ b/builtins/nums.h
@@ -1,5 +1,6 @@
#pragma once
#include <gc/cord.h>
+#include <math.h>
#include <stdbool.h>
#include <stdint.h>
@@ -18,68 +19,57 @@ double Num64__mod(double num, double modulus);
bool Num64__isinf(double n);
bool Num64__finite(double n);
bool Num64__isnan(double n);
+double Num64__nan(CORD tag);
+// Constants:
+#define C(name) const double Num64__##name = M_##name;
+C(2_SQRTPI) C(E) C(PI_2) C(2_PI) C(1_PI) C(LN10) C(LN2) C(LOG2E) C(PI) C(PI_4) C(SQRT2) C(SQRT1_2)
+const double Num64__INF = INFINITY, Num64__TAU = 2.*M_PI;
+#undef C
+double Num64__random(void);
+bool Num64__finite(double n);
+bool Num64__isinf(double n);
+bool Num64__isnan(double n);
+#define F(name) double (*Num64__##name)(double n) = name;
+double (*Num64__abs)(double) = fabs;
+F(acos) F(acosh) F(asin) F(asinh) F(atan) F(atanh) F(cbrt) F(ceil) F(cos) F(cosh) F(erf) F(erfc)
+F(exp) F(exp2) F(expm1) F(floor) F(j0) F(j1) F(log) F(log10) F(log1p) F(log2) F(logb)
+F(rint) F(round) F(significand) F(sin) F(sinh) F(sqrt)
+F(tan) F(tanh) F(tgamma) F(trunc) F(y0) F(y1)
+#undef F
+#define F(name) double (*Num64__##name)(double x, double y) = name;
+F(atan2) F(copysign) F(fdim) F(hypot) F(nextafter) F(pow) F(remainder)
+#undef F
+extern TypeInfo Num64;
-typedef bool (*double_pred_t)(double);
-typedef double (*double_unary_fn_t)(double);
-typedef double (*double_binary_fn_t)(double, double);
-
-typedef struct {
- TypeInfo type;
- // Constants:
- double NaN, _2_sqrt_pi, e, half_pi, inf, inverse_half_pi, inverse_pi, ln10, ln2,
- log2e, pi, quarter_pi, sqrt2, sqrt_half, tau;
- // Nullary functions:
- double (*random)(void);
- // Predicates:
- double_pred_t finite, isinf, isnan;
- // Unary functions:
- double_unary_fn_t abs, acos, acosh, asin, asinh, atan, atanh, cbrt, ceil, cos, cosh, erf, erfc,
- exp, exp10, exp2, expm1, floor, j0, j1, log, log10, log1p, log2, logb,
- nextdown, nextup, rint, round, roundeven, significand, sin, sinh, sqrt,
- tan, tanh, tgamma, trunc, y0, y1;
- // Binary functions:
- double_binary_fn_t atan2, copysign, dist, hypot, maxmag, minmag, mod, nextafter, pow, remainder;
- // Odds and ends:
- CORD (*format)(double f, int64_t precision);
- CORD (*scientific)(double f, int64_t precision);
-} Num64_namespace_t;
-extern Num64_namespace_t Num64;
-
-CORD Num32__as_str(float *f, bool colorize, const TypeInfo *type);
+CORD Num32__as_str(const float *f, bool colorize, const TypeInfo *type);
int32_t Num32__compare(const float *x, const float *y, const TypeInfo *type);
bool Num32__equal(const float *x, const float *y, const TypeInfo *type);
CORD Num32__format(float f, int64_t precision);
CORD Num32__scientific(float f, int64_t precision);
float Num32__mod(float num, float modulus);
-float Num32__random(void);
bool Num32__isinf(float n);
bool Num32__finite(float n);
bool Num32__isnan(float n);
-
-typedef bool (*float_pred_t)(float);
-typedef float (*float_unary_fn_t)(float);
-typedef float (*float_binary_fn_t)(float, float);
-
-typedef struct {
- TypeInfo type;
- // Alphabetized:
- float NaN, _2_sqrt_pi, e, half_pi, inf, inverse_half_pi, inverse_pi, ln10, ln2,
- log2e, pi, quarter_pi, sqrt2, sqrt_half, tau;
- // Nullary functions:
- float (*random)(void);
- // Predicates:
- float_pred_t finite, isinf, isnan;
- // Unary functions:
- float_unary_fn_t abs, acos, acosh, asin, asinh, atan, atanh, cbrt, ceil, cos, cosh, erf, erfc,
- exp, exp10, exp2, expm1, floor, j0, j1, log, log10, log1p, log2, logb,
- nextdown, nextup, rint, round, roundeven, significand, sin, sinh, sqrt,
- tan, tanh, tgamma, trunc, y0, y1;
- // Binary functions:
- float_binary_fn_t atan2, copysign, dist, hypot, maxmag, minmag, mod, nextafter, pow, remainder;
- // Odds and ends:
- CORD (*format)(float f, int64_t precision);
- CORD (*scientific)(float f, int64_t precision);
-} Num32_namespace_t;
-extern Num32_namespace_t Num32;
+// Constants:
+#define C(name) const float Num32__##name = M_##name;
+C(2_SQRTPI) C(E) C(PI_2) C(2_PI) C(1_PI) C(LN10) C(LN2) C(LOG2E) C(PI) C(PI_4) C(SQRT2) C(SQRT1_2)
+const float Num32__INF = INFINITY, Num32__TAU = 2.*M_PI;
+#undef C
+float Num32__random(void);
+bool Num32__finite(float n);
+bool Num32__isinf(float n);
+bool Num32__isnan(float n);
+float Num32__nan(CORD tag);
+#define F(name) float (*Num32__##name)(float n) = name##f;
+float (*Num32__abs)(float) = fabsf;
+F(acos) F(acosh) F(asin) F(asinh) F(atan) F(atanh) F(cbrt) F(ceil) F(cos) F(cosh) F(erf) F(erfc)
+F(exp) F(exp2) F(expm1) F(floor) F(j0) F(j1) F(log) F(log10) F(log1p) F(log2) F(logb)
+F(rint) F(round) F(significand) F(sin) F(sinh) F(sqrt)
+F(tan) F(tanh) F(tgamma) F(trunc) F(y0) F(y1)
+#undef F
+#define F(name) float (*Num32__##name)(float x, float y) = name##f;
+F(atan2) F(copysign) F(fdim) F(hypot) F(nextafter) F(pow) F(remainder)
+#undef F
+extern TypeInfo Num32;
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/string.c b/builtins/string.c
index cd6e2548..91ef5ff7 100644
--- a/builtins/string.c
+++ b/builtins/string.c
@@ -254,30 +254,16 @@ public CORD Str__join(CORD glue, Str_Array_t pieces)
return ret;
}
-public Str_namespace_t Str = {
- .type={
- .size=sizeof(CORD),
- .align=__alignof__(CORD),
- .tag=CustomInfo,
- .CustomInfo={
- .as_str=(void*)Str__as_str,
- .compare=(void*)Str__compare,
- .equal=(void*)Str__equal,
- .hash=(void*)Str__hash,
- },
+public TypeInfo Str = {
+ .size=sizeof(CORD),
+ .align=__alignof__(CORD),
+ .tag=CustomInfo,
+ .CustomInfo={
+ .as_str=(void*)Str__as_str,
+ .compare=(void*)Str__compare,
+ .equal=(void*)Str__equal,
+ .hash=(void*)Str__hash,
},
- .uppercased=Str__uppercased,
- .lowercased=Str__lowercased,
- .titlecased=Str__titlecased,
- .has=Str__has,
- .without=Str__without,
- .trimmed=Str__trimmed,
- .slice=Str__slice,
- .find=Str__find,
- .replace=Str__replace,
- .quoted=Str__quoted,
- .split=Str__split,
- .join=Str__join,
};
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/string.h b/builtins/string.h
index f9dc83cc..278a2f9c 100644
--- a/builtins/string.h
+++ b/builtins/string.h
@@ -22,31 +22,6 @@ typedef struct {
int32_t index;
} find_result_t;
-typedef struct {
- TypeInfo type;
- CORD (*uppercased)(CORD s);
- CORD (*lowercased)(CORD s);
- CORD (*titlecased)(CORD s);
- bool (*has)(CORD s, CORD prefix, where_e where);
- bool (*ends_with)(CORD s, CORD suffix);
- CORD (*without)(CORD s, CORD target, where_e where);
- CORD (*without_suffix)(CORD s, CORD suffix);
- CORD (*trimmed)(CORD s, CORD trim_chars, where_e where);
- CORD (*slice)(CORD s, int64_t first, int64_t stride, int64_t length);
- char *(*c_string)(CORD str);
- CORD (*from_c_string)(char *str);
- find_result_t (*find)(CORD str, CORD pat);
- CORD (*replace)(CORD text, CORD pat, CORD replacement, int64_t limit);
- CORD (*quoted)(CORD text, bool colorize);
- Str_Array_t (*split)(CORD str, CORD split_chars);
- CORD (*join)(CORD glue, Str_Array_t pieces);
- bool (*equal)(CORD *x, CORD *y);
- int32_t (*compare)(CORD *x, CORD *y);
- int (*hash)(CORD *s, TypeInfo *type);
- CORD (*cord)(CORD *s, bool colorize, TypeInfo *type);
-} Str_namespace_t;
-extern Str_namespace_t Str;
-
CORD Str__as_str(const void *str, bool colorize, const TypeInfo *info);
CORD Str__quoted(CORD str, bool colorize);
int Str__compare(CORD *x, CORD *y);
@@ -64,4 +39,6 @@ CORD Str__replace(CORD text, CORD pat, CORD replacement, int64_t limit);
Str_Array_t Str__split(CORD str, CORD split);
CORD Str__join(CORD glue, Str_Array_t pieces);
+extern TypeInfo Str;
+
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/table.c b/builtins/table.c
index bff09af9..677def7b 100644
--- a/builtins/table.c
+++ b/builtins/table.c
@@ -55,7 +55,7 @@ TypeInfo StrToVoidStarTable = {
.size=sizeof(table_t),
.align=__alignof__(table_t),
.tag=TableInfo,
- .TableInfo={.key=&Str.type, .value=&MemoryPointer},
+ .TableInfo={.key=&Str, .value=&MemoryPointer},
};
static inline size_t entry_size(const TypeInfo *info)
diff --git a/builtins/types.c b/builtins/types.c
index c7e29cf8..6fe3f682 100644
--- a/builtins/types.c
+++ b/builtins/types.c
@@ -23,13 +23,11 @@ public CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *ty
return c;
}
-public TypeInfo_namespace_t TypeInfo_namespace = {
- .type={
- .size=sizeof(TypeInfo),
- .align=__alignof__(TypeInfo),
- .tag=CustomInfo,
- .TypeInfoInfo.type_str="TypeInfo",
- },
+public TypeInfo TypeInfo_info = {
+ .size=sizeof(TypeInfo),
+ .align=__alignof__(TypeInfo),
+ .tag=CustomInfo,
+ .TypeInfoInfo.type_str="TypeInfo",
};
public struct {
diff --git a/builtins/types.h b/builtins/types.h
index 253cba84..32080975 100644
--- a/builtins/types.h
+++ b/builtins/types.h
@@ -55,11 +55,7 @@ typedef struct TypeInfo {
#define $TypeInfoInfo(typestr) &((TypeInfo){.size=sizeof(TypeInfo), .align=__alignof__(TypeInfo), \
.tag=TypeInfoInfo, .TypeInfoInfo.type_str=typestr})
-typedef struct {
- TypeInfo type;
-} TypeInfo_namespace_t;
-
-extern TypeInfo_namespace_t TypeInfo_namespace;
+extern TypeInfo TypeInfo_info;
CORD Type__as_str(const void *typeinfo, bool colorize, const TypeInfo *type);
CORD Func__as_str(const void *fn, bool colorize, const TypeInfo *type);
diff --git a/compile.c b/compile.c
index fc5fa539..c6d42a2a 100644
--- a/compile.c
+++ b/compile.c
@@ -74,7 +74,7 @@ CORD expr_as_string(env_t *env, CORD expr, type_t *t, CORD color)
case BoolType: return CORD_asprintf("Bool__as_str($stack(%r), %r, NULL)", expr, color);
case IntType: return CORD_asprintf("Int%ld__as_str($stack(%r), %r, NULL)", Match(t, IntType)->bits, expr, color);
case NumType: return CORD_asprintf("Num%ld__as_str($stack(%r), %r, NULL)", Match(t, NumType)->bits, expr, color);
- case StringType: return CORD_asprintf("Str__as_str($stack(%r), %r, &Str.type)", expr, color);
+ case StringType: return CORD_asprintf("Str__as_str($stack(%r), %r, &Str)", expr, color);
case ArrayType: return CORD_asprintf("Array__as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
case TableType: return CORD_asprintf("Table_as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
case FunctionType: return CORD_asprintf("Func__as_str($stack(%r), %r, %r)", expr, color, compile_type_info(env, t));
@@ -1014,12 +1014,12 @@ CORD compile(env_t *env, ast_t *ast)
CORD compile_type_info(env_t *env, type_t *t)
{
switch (t->tag) {
- case BoolType: return "&Bool.type";
- case IntType: return CORD_asprintf("&Int%ld.type", Match(t, IntType)->bits);
- case NumType: return CORD_asprintf("&Num%ld.type", Match(t, NumType)->bits);
- case StringType: return CORD_all("&", Match(t, StringType)->dsl ? Match(t, StringType)->dsl : "Str", ".type");
- case StructType: return CORD_all("&", Match(t, StructType)->name, ".type");
- case EnumType: return CORD_all("&", Match(t, EnumType)->name, ".type");
+ case BoolType: return "&Bool";
+ case IntType: return CORD_asprintf("&Int%ld", Match(t, IntType)->bits);
+ case NumType: return CORD_asprintf("&Num%ld", Match(t, NumType)->bits);
+ case StringType: return CORD_all("&", Match(t, StringType)->dsl ? Match(t, StringType)->dsl : "Str");
+ case StructType: return CORD_all("&", Match(t, StructType)->name);
+ case EnumType: return CORD_all("&", Match(t, EnumType)->name);
case ArrayType: {
type_t *item_t = Match(t, ArrayType)->item_type;
return CORD_asprintf("$ArrayInfo(%r)", compile_type_info(env, item_t));
@@ -1041,7 +1041,7 @@ CORD compile_type_info(env_t *env, type_t *t)
case ClosureType: {
errx(1, "No typeinfo for closures yet");
}
- case TypeInfoType: return "&TypeInfo_namespace.type";
+ case TypeInfoType: return "&TypeInfo_info";
default:
compiler_err(NULL, 0, 0, "I couldn't convert to a type info: %T", t);
}