updated formatter

This commit is contained in:
dzaima 2021-05-19 15:08:55 +03:00
parent 23af3f56e9
commit dd865697ef
3 changed files with 16 additions and 7 deletions

View File

@ -263,6 +263,8 @@ B m_str32(u32* s); // meant to be used as m_str32(U"{𝕨‿𝕩}"), so doesn't
B bqn_exec(B str, B path, B args); // consumes both
B bqn_execFile(B path, B args); // consumes
B bqn_fmt(B x); // consumes
B bqn_repr(B x); // consumes
NOINLINE NORETURN void thr(B b);
NOINLINE NORETURN void thrM(char* s);

View File

@ -23,10 +23,13 @@ B load_comp;
B load_compArg;
#ifdef FORMATTER
B load_fmt;
B load_fmt, load_repr;
B bqn_fmt(B x) { // consumes
return c1(load_fmt, x);
}
B bqn_repr(B x) { // consumes
return c1(load_repr, x);
}
#endif
void load_gcFn() {
@ -170,8 +173,11 @@ static inline void load_init() {
#include "formatter"
);
B fmtM = m_funBlock(fmt_b, 0); ptr_dec(fmt_b);
load_fmt = TI(fmtM).m1_d(fmtM, m_caB(4, (B[]){inc(bi_type), inc(bi_decp), inc(bi_fmtF), inc(bi_fmtN)}));
gc_add(load_fmt);
B fmtR = c1(fmtM, m_caB(4, (B[]){inc(bi_type), inc(bi_decp), inc(bi_fmtF), inc(bi_repr)}));
BS2B fget = TI(fmtR).get;
load_fmt = fget(fmtR, 0); gc_add(load_fmt);
load_repr = fget(fmtR, 1); gc_add(load_repr);
dec(fmtR);
#endif
gc_enable();
#endif // NO_COMP

View File

@ -34,10 +34,11 @@ B glyph_c1(B t, B x) {
B repr_c1(B t, B x) {
#define BL 100
char buf[BL];
if (isF64(x)) snprintf(buf, BL, "%g", x.f);
else snprintf(buf, BL, "(fmtN: not given a number?)");
return m_str8(strlen(buf), buf);
if (isF64(x)) {
char buf[BL];
snprintf(buf, BL, "%g", x.f);
return m_str8(strlen(buf), buf);
} else return bqn_repr(x);
}
B fill_c1(B t, B x) {