clean up ascii/utf8 functions
This commit is contained in:
parent
e3da1da8f6
commit
1fd88c1749
@ -227,11 +227,11 @@ HArr_p r = m_harrUp(10); // 10-item array without any set shape. Use the arr_shW
|
||||
// you can use withFill to add a fill element to a created array (or manually create a fillarr, see src/core/fillarr.h)
|
||||
|
||||
B r = m_str32(U"⟨1⋄2⋄3⟩"); // a constant string with unicode chars
|
||||
B r = m_str8(5, "hello"); // an ASCII string with specified length
|
||||
B r = m_str8l("hello"); // an ASCII string, read until null byte
|
||||
B r = m_ascii("hello", 5); // an ASCII string with specified length
|
||||
B r = m_ascii0("hello"); // ↑ but read as null-terminated
|
||||
#include "utils/utf.h"
|
||||
B r = fromUTF8l("⟨1⋄2⋄3⟩") // parse UTF-8 from a char*
|
||||
B r = fromUTF8("⟨1⋄2⋄3⟩", 17) // ↑ but with a specified length
|
||||
B r = utf8Decode("⟨1⋄2⋄3⟩", 17) // decode UTF-8 from a char*
|
||||
B r = utf8Decode0("⟨1⋄2⋄3⟩") // ↑ but read as null-terminated
|
||||
u64 sz = utf8lenB(x); TALLOC(char, buf, sz+1); toUTF8(x, buf); buf[sz]=0; /*use buf as a C-string*/ TFREE(buf);
|
||||
|
||||
// src/utils/mut.h provides a way to build an array by copying parts of other arrays
|
||||
|
||||
@ -7,14 +7,14 @@
|
||||
B itype_c1(B t, B x) {
|
||||
B r;
|
||||
if(isVal(x)) {
|
||||
r = m_str8l(type_repr(v(x)->type));
|
||||
r = m_ascii0(type_repr(v(x)->type));
|
||||
} else {
|
||||
if (isF64(x)) r = m_str8l("tagged f64");
|
||||
else if (isC32(x)) r = m_str8l("tagged c32");
|
||||
else if (isTag(x)) r = m_str8l("tagged tag");
|
||||
else if (isVar(x)) r = m_str8l("tagged var");
|
||||
else if (isExt(x)) r = m_str8l("tagged extvar");
|
||||
else r = m_str8l("tagged unknown");
|
||||
if (isF64(x)) r = m_ascii0("tagged f64");
|
||||
else if (isC32(x)) r = m_ascii0("tagged c32");
|
||||
else if (isTag(x)) r = m_ascii0("tagged tag");
|
||||
else if (isVar(x)) r = m_ascii0("tagged var");
|
||||
else if (isExt(x)) r = m_ascii0("tagged extvar");
|
||||
else r = m_ascii0("tagged unknown");
|
||||
}
|
||||
dec(x);
|
||||
return r;
|
||||
@ -25,7 +25,7 @@ B elType_c1(B t, B x) {
|
||||
return r;
|
||||
}
|
||||
B refc_c1(B t, B x) {
|
||||
B r = isVal(x)? m_i32(v(x)->refc) : m_str8l("(not heap-allocated)");
|
||||
B r = isVal(x)? m_i32(v(x)->refc) : m_ascii0("(not heap-allocated)");
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
@ -300,10 +300,10 @@ B unshare_c1(B t, B x) {
|
||||
static B internalNS;
|
||||
B getInternalNS() {
|
||||
if (internalNS.u == 0) {
|
||||
#define F(X) v_##X = m_str8l(#X);
|
||||
#define F(X) v_##X = m_ascii0(#X);
|
||||
FOR_VARIATION(F)
|
||||
#undef F
|
||||
listVariations_def = m_str8l("if");
|
||||
listVariations_def = m_ascii0("if");
|
||||
gc_addFn(variation_gcRoot);
|
||||
#define F(X) inc(bi_##X),
|
||||
Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info","listvariations","variation","clearrefs","unshare","deepsqueeze","heapdump","eequal","temp");
|
||||
|
||||
@ -38,6 +38,6 @@ B nativeInvSwap_c1(B t, B x) {
|
||||
}
|
||||
|
||||
void inverse_init() {
|
||||
fn_invRegDesc = registerNFn(m_str8l("(fn_invReg)"), fn_invReg_c1, fn_invReg_c2);
|
||||
fn_invSwapDesc = registerNFn(m_str8l("(fn_invSwap)"), fn_invSwap_c1, fn_invSwap_c2);
|
||||
fn_invRegDesc = registerNFn(m_ascii0("(fn_invReg)"), fn_invReg_c1, fn_invReg_c2);
|
||||
fn_invSwapDesc = registerNFn(m_ascii0("(fn_invSwap)"), fn_invSwap_c1, fn_invSwap_c2);
|
||||
}
|
||||
@ -72,13 +72,13 @@ B glyph_c1(B t, B x) {
|
||||
return r;
|
||||
}
|
||||
u8 ty = v(x)->type;
|
||||
if (ty==t_funBI) { B r = fromUTF8l(pfn_repr(c(Fun,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_md1BI) { B r = fromUTF8l(pm1_repr(c(Md1,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_md2BI) { B r = fromUTF8l(pm2_repr(c(Md2,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_funBI) { B r = utf8Decode0(pfn_repr(c(Fun,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_md1BI) { B r = utf8Decode0(pm1_repr(c(Md1,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_md2BI) { B r = utf8Decode0(pm2_repr(c(Md2,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_nfn) { B r = nfn_name(x); decG(x); return r; }
|
||||
if (ty==t_funBl) { decG(x); return m_str8l("(function block)"); }
|
||||
if (ty==t_md1Bl) { decG(x); return m_str8l("(1-modifier block)"); }
|
||||
if (ty==t_md2Bl) { decG(x); return m_str8l("(2-modifier block)"); }
|
||||
if (ty==t_funBl) { decG(x); return m_ascii0("(function block)"); }
|
||||
if (ty==t_md1Bl) { decG(x); return m_ascii0("(1-modifier block)"); }
|
||||
if (ty==t_md2Bl) { decG(x); return m_ascii0("(2-modifier block)"); }
|
||||
if (ty==t_ns) return nsFmt(x);
|
||||
return m_str32(U"(•Glyph: given object with unexpected type)");
|
||||
}
|
||||
@ -86,7 +86,7 @@ B glyph_c1(B t, B x) {
|
||||
B repr_c1(B t, B x) {
|
||||
if (isF64(x)) {
|
||||
NUM_FMT_BUF(buf, x.f);
|
||||
return fromUTF8(buf, strlen(buf));
|
||||
return utf8Decode(buf, strlen(buf));
|
||||
} else {
|
||||
#if FORMATTER
|
||||
return bqn_repr(x);
|
||||
@ -498,9 +498,9 @@ static NOINLINE void rand_init() {
|
||||
rand_ns = m_nnsDesc("seed1", "seed2", "range", "deal", "subset");
|
||||
NSDesc* d = rand_ns->nsDesc;
|
||||
d->expGIDs[0] = d->expGIDs[1] = -1;
|
||||
rand_rangeName = m_str8l("range"); gc_add(rand_rangeName); rand_rangeDesc = registerNFn(m_str8l("(rand).Range"), rand_range_c1, rand_range_c2);
|
||||
rand_dealName = m_str8l("deal"); gc_add(rand_dealName); rand_dealDesc = registerNFn(m_str8l("(rand).Deal"), rand_deal_c1, rand_deal_c2);
|
||||
rand_subsetName = m_str8l("subset"); gc_add(rand_subsetName); rand_subsetDesc = registerNFn(m_str8l("(rand).Subset"), c1_bad, rand_subset_c2);
|
||||
rand_rangeName = m_ascii0("range"); gc_add(rand_rangeName); rand_rangeDesc = registerNFn(m_ascii0("(rand).Range"), rand_range_c1, rand_range_c2);
|
||||
rand_dealName = m_ascii0("deal"); gc_add(rand_dealName); rand_dealDesc = registerNFn(m_ascii0("(rand).Deal"), rand_deal_c1, rand_deal_c2);
|
||||
rand_subsetName = m_ascii0("subset"); gc_add(rand_subsetName); rand_subsetDesc = registerNFn(m_ascii0("(rand).Subset"), c1_bad, rand_subset_c2);
|
||||
}
|
||||
B makeRand_c1(B t, B x) {
|
||||
if (!isNum(x)) thrM("•MakeRand: 𝕩 must be a number");
|
||||
@ -529,7 +529,7 @@ B reBQN_c1(B t, B x) {
|
||||
B prim = ns_getC(x, "primitives");
|
||||
i32 replVal = q_N(repl) || eqStr(repl,U"none")? 0 : eqStr(repl,U"strict")? 1 : eqStr(repl,U"loose")? 2 : 3;
|
||||
if (replVal==3) thrM("•ReBQN: Invalid repl value");
|
||||
Block* initBlock = bqn_comp(m_str8l("\"(REPL initializer)\""), inc(cdPath), m_f64(0));
|
||||
Block* initBlock = bqn_comp(m_ascii0("\"(REPL initializer)\""), inc(cdPath), m_f64(0));
|
||||
B scVal;
|
||||
if (replVal==0) {
|
||||
scVal = bi_N;
|
||||
@ -772,7 +772,7 @@ B getLine_c1(B t, B x) {
|
||||
if (ln) free(ln);
|
||||
return m_c32(0);
|
||||
}
|
||||
B r = fromUTF8(ln, strlen(ln)-1);
|
||||
B r = utf8Decode(ln, strlen(ln)-1);
|
||||
free(ln);
|
||||
return r;
|
||||
}
|
||||
@ -794,7 +794,7 @@ B fromUtf8_c1(B t, B x) {
|
||||
chrs[i] = v&0xff;
|
||||
}
|
||||
}
|
||||
B r = fromUTF8(chrs, ia);
|
||||
B r = utf8Decode(chrs, ia);
|
||||
decG(x);
|
||||
TFREE(chrs);
|
||||
return r;
|
||||
@ -928,8 +928,8 @@ B sh_c2(B t, B w, B x) {
|
||||
dec(w); dec(x);
|
||||
B s_outRaw = toC8Any(s_out);
|
||||
B s_errRaw = toC8Any(s_err);
|
||||
B s_outObj = fromUTF8((char*)c8any_ptr(s_outRaw), a(s_outRaw)->ia); dec(s_outRaw);
|
||||
B s_errObj = fromUTF8((char*)c8any_ptr(s_errRaw), a(s_errRaw)->ia); dec(s_errRaw);
|
||||
B s_outObj = utf8Decode((char*)c8any_ptr(s_outRaw), a(s_outRaw)->ia); dec(s_outRaw);
|
||||
B s_errObj = utf8Decode((char*)c8any_ptr(s_errRaw), a(s_errRaw)->ia); dec(s_errRaw);
|
||||
return m_hVec3(m_i32(WEXITSTATUS(status)), s_outObj, s_errObj);
|
||||
}
|
||||
#else
|
||||
@ -1176,7 +1176,7 @@ B sys_c1(B t, B x) {
|
||||
else if (eqStr(c, U"rand")) cr = getRandNS();
|
||||
else if (eqStr(c, U"rebqn")) cr = incG(bi_reBQN);
|
||||
else if (eqStr(c, U"primitives")) cr = getPrimitives();
|
||||
else if (eqStr(c, U"fromutf8")) cr = incG(bi_fromUtf8);
|
||||
else if (eqStr(c, U"utf8Decode")) cr = incG(bi_fromUtf8);
|
||||
else if (eqStr(c, U"path")) cr = inc(REQ_PATH);
|
||||
else if (eqStr(c, U"name")) cr = inc(REQ_NAME);
|
||||
else if (eqStr(c, U"fchars")) cr = m_nfn(fCharsDesc, inc(REQ_PATH));
|
||||
@ -1208,21 +1208,21 @@ void sysfn_init() {
|
||||
#if CATCH_ERRORS
|
||||
lastErrMsg = bi_N;
|
||||
#endif
|
||||
cdPath = m_str8(1, "."); gc_add(cdPath); gc_addFn(sys_gcFn);
|
||||
fCharsDesc = registerNFn(m_str8l("(file).Chars"), fchars_c1, fchars_c2);
|
||||
fileAtDesc = registerNFn(m_str8l("(file).At"), fileAt_c1, fileAt_c2);
|
||||
fLinesDesc = registerNFn(m_str8l("(file).Lines"), flines_c1, flines_c2);
|
||||
fBytesDesc = registerNFn(m_str8l("(file).Bytes"), fbytes_c1, fbytes_c2);
|
||||
fListDesc = registerNFn(m_str8l("(file).List"), list_c1, c2_bad);
|
||||
fTypeDesc = registerNFn(m_str8l("(file).Type"), ftype_c1, c2_bad);
|
||||
createdirDesc = registerNFn(m_str8l("(file).CreateDir"), createdir_c1, c2_bad);
|
||||
renameDesc = registerNFn(m_str8l("(file).Rename"), c1_bad, rename_c2);
|
||||
removeDesc = registerNFn(m_str8l("(file).Remove"), remove_c1, c2_bad);
|
||||
fMapBytesDesc = registerNFn(m_str8l("(file).MapBytes"), mapBytes_c1, c2_bad);
|
||||
fExistsDesc = registerNFn(m_str8l("(file).Exists"), fexists_c1, c2_bad);
|
||||
importDesc = registerNFn(m_str32(U"•Import"), import_c1, import_c2);
|
||||
reBQNDesc = registerNFn(m_str8l("(REPL)"), repl_c1, repl_c2);
|
||||
ffiloadDesc = registerNFn(m_str32(U"•FFI"), c1_bad, ffiload_c2);
|
||||
cdPath = m_ascii(".", 1); gc_add(cdPath); gc_addFn(sys_gcFn);
|
||||
fCharsDesc = registerNFn(m_ascii0("(file).Chars"), fchars_c1, fchars_c2);
|
||||
fileAtDesc = registerNFn(m_ascii0("(file).At"), fileAt_c1, fileAt_c2);
|
||||
fLinesDesc = registerNFn(m_ascii0("(file).Lines"), flines_c1, flines_c2);
|
||||
fBytesDesc = registerNFn(m_ascii0("(file).Bytes"), fbytes_c1, fbytes_c2);
|
||||
fListDesc = registerNFn(m_ascii0("(file).List"), list_c1, c2_bad);
|
||||
fTypeDesc = registerNFn(m_ascii0("(file).Type"), ftype_c1, c2_bad);
|
||||
createdirDesc= registerNFn(m_ascii0("(file).CreateDir"), createdir_c1, c2_bad);
|
||||
renameDesc = registerNFn(m_ascii0("(file).Rename"), c1_bad, rename_c2);
|
||||
removeDesc = registerNFn(m_ascii0("(file).Remove"), remove_c1, c2_bad);
|
||||
fMapBytesDesc= registerNFn(m_ascii0("(file).MapBytes"), mapBytes_c1, c2_bad);
|
||||
fExistsDesc = registerNFn(m_ascii0("(file).Exists"), fexists_c1, c2_bad);
|
||||
reBQNDesc = registerNFn(m_ascii0("(REPL)"), repl_c1, repl_c2);
|
||||
importDesc = registerNFn(m_str32(U"•Import"), import_c1, import_c2);
|
||||
ffiloadDesc = registerNFn(m_str32(U"•FFI"), c1_bad, ffiload_c2);
|
||||
}
|
||||
void sysfnPost_init() {
|
||||
file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines","type","exists","name","mapbytes","createdir","rename","remove");
|
||||
|
||||
@ -17,11 +17,12 @@
|
||||
#undef c32
|
||||
|
||||
|
||||
B m_str8(usz sz, char* s);
|
||||
B m_str8l(char* s);
|
||||
B m_str32(u32* s);
|
||||
B fromUTF8l(const char* x);
|
||||
B fromUTF8a(I8Arr* x);
|
||||
B m_ascii0(char* s);
|
||||
B m_ascii(char* s, i64 sz);
|
||||
B utf8Decode0(const char* x);
|
||||
B utf8Decode(const char* x, i64 sz);
|
||||
B utf8DecodeA(I8Arr* x);
|
||||
|
||||
C8Arr* cpyC8Arr (B x); // consumes
|
||||
C16Arr* cpyC16Arr(B x); // consumes
|
||||
|
||||
@ -125,6 +125,6 @@ void derv_init() {
|
||||
TIi(t_md1D,identity) = md1D_identity;
|
||||
}
|
||||
void dervPost_init() {
|
||||
ucwWrapDesc = registerNFn(m_str8l("(temporary function for ⌾)"), ucwWrap_c1, c2_bad);
|
||||
ucwWrapDesc = registerNFn(m_ascii0("(temporary function for ⌾)"), ucwWrap_c1, c2_bad);
|
||||
TIi(t_fork,fn_uc1) = fork_uc1; // in post probably to make sure it's not used while not fully initialized or something? idk
|
||||
}
|
||||
@ -235,7 +235,7 @@ NOINLINE B do_fmt(B s, char* p, va_list a) {
|
||||
char* lp = p;
|
||||
while (*p != 0) { c = *p++;
|
||||
if (c!='%') continue;
|
||||
if (lp!=p-1) AJOIN(fromUTF8(lp, p-1-lp));
|
||||
if (lp!=p-1) AJOIN(utf8Decode(lp, p-1-lp));
|
||||
switch(c = *p++) { default: printf("Unknown format character '%c'", c); err(""); UD;
|
||||
case 'R': {
|
||||
B b = va_arg(a, B);
|
||||
@ -322,7 +322,7 @@ NOINLINE B do_fmt(B s, char* p, va_list a) {
|
||||
}
|
||||
lp = p;
|
||||
}
|
||||
if (lp!=p) AJOIN(fromUTF8(lp, p-lp));
|
||||
if (lp!=p) AJOIN(utf8Decode(lp, p-lp));
|
||||
return s;
|
||||
}
|
||||
NOINLINE B append_fmt(B s, char* p, ...) {
|
||||
|
||||
@ -154,8 +154,8 @@ void print_fmt(char* p, ...);
|
||||
#define AJOIN(X) s = vec_join(s,X) // consumes X
|
||||
#define AOBJ(X) s = vec_addN(s,X) // consumes X
|
||||
#define ACHR(X) AOBJ(m_c32(X))
|
||||
#define A8(X) AJOIN(m_str8l(X))
|
||||
#define AU(X) AJOIN(fromUTF8l(X))
|
||||
#define A8(X) AJOIN(m_ascii0(X))
|
||||
#define AU(X) AJOIN(utf8Decode0(X))
|
||||
#define AFMT(...) s = append_fmt(s, __VA_ARGS__)
|
||||
|
||||
// function stuff
|
||||
|
||||
@ -38,10 +38,10 @@ B m_c8(u8 x) { return m_c32(x); } B m_c16(u16 x) { return m_c32(x); }
|
||||
#define TP(W,X) W##f64##X
|
||||
#include "tyarrTemplate.c"
|
||||
|
||||
NOINLINE B m_caf64(usz sz, f64* a) { f64* rp; B r = m_f64arrv(&rp, sz); for (usz i = 0; i < sz; i++) rp[i] = a[i]; return r; }
|
||||
NOINLINE B m_cai32(usz sz, i32* a) { i32* rp; B r = m_i32arrv(&rp, sz); for (usz i = 0; i < sz; i++) rp[i] = a[i]; return r; }
|
||||
NOINLINE B m_str8(usz sz, char* s) { u8* rp; B r = m_c8arrv (&rp, sz); for (u64 i = 0; i < sz; i++) rp[i] = s[i]; return r; }
|
||||
NOINLINE B m_str8l(char* s) { return m_str8(strlen(s), s); }
|
||||
NOINLINE B m_caf64(usz sz, f64* a) { f64* rp; B r = m_f64arrv(&rp, sz); for (usz i = 0; i < sz; i++) rp[i] = a[i]; return r; }
|
||||
NOINLINE B m_cai32(usz sz, i32* a) { i32* rp; B r = m_i32arrv(&rp, sz); for (usz i = 0; i < sz; i++) rp[i] = a[i]; return r; }
|
||||
NOINLINE B m_ascii(char* s, i64 sz) { u8* rp; B r = m_c8arrv (&rp, sz); for (u64 i = 0; i < sz; i++) rp[i] = s[i]; return r; }
|
||||
NOINLINE B m_ascii0(char* s) { return m_ascii(s, strlen(s)); }
|
||||
NOINLINE B m_str32(u32* s) {
|
||||
usz sz = 0; while(s[sz]) sz++;
|
||||
u32* rp; B r = m_c32arrv(&rp, sz);
|
||||
|
||||
@ -50,7 +50,7 @@ BQNV bqn_eval(BQNV src) {
|
||||
return makeX(bqn_exec(inc(getB(src)), bi_N, bi_N));
|
||||
}
|
||||
BQNV bqn_evalCStr(const char* str) {
|
||||
return makeX(bqn_exec(fromUTF8l(str), bi_N, bi_N));
|
||||
return makeX(bqn_exec(utf8Decode0(str), bi_N, bi_N));
|
||||
}
|
||||
|
||||
|
||||
@ -126,7 +126,7 @@ BQNV bqn_makeC8Vec (size_t len, const u8* data) { u8* rp; B r = m_c8arrv (&rp
|
||||
BQNV bqn_makeC16Vec(size_t len, const u16* data) { u16* rp; B r = m_c16arrv(&rp,len); memcpy(rp,data,len*2); return makeX(r); }
|
||||
BQNV bqn_makeC32Vec(size_t len, const u32* data) { u32* rp; B r = m_c32arrv(&rp,len); memcpy(rp,data,len*4); return makeX(r); }
|
||||
BQNV bqn_makeObjVec(size_t len, const BQNV* data) { HArr_p r = m_harrUv(len); copyBData(r.a,data,len ); return makeX(r.b); }
|
||||
BQNV bqn_makeUTF8Str(size_t len, const char* str) { return makeX(fromUTF8(str, len)); }
|
||||
BQNV bqn_makeUTF8Str(size_t len, const char* str) { return makeX(utf8Decode(str, len)); }
|
||||
|
||||
typedef struct BoundFn {
|
||||
struct NFn;
|
||||
@ -742,8 +742,8 @@ void ffiType_print(FILE* f, B x) {
|
||||
}
|
||||
|
||||
void ffi_init() {
|
||||
boundFnDesc = registerNFn(m_str8l("(foreign function)"), boundFn_c1, boundFn_c2);
|
||||
foreignFnDesc = registerNFn(m_str8l("(foreign function)"), directFn_c1, directFn_c2);
|
||||
boundFnDesc = registerNFn(m_ascii0("(foreign function)"), boundFn_c1, boundFn_c2);
|
||||
foreignFnDesc = registerNFn(m_ascii0("(foreign function)"), directFn_c1, directFn_c2);
|
||||
TIi(t_ffiType,freeO) = ffiType_freeO;
|
||||
TIi(t_ffiType,freeF) = ffiType_freeF;
|
||||
TIi(t_ffiType,visit) = ffiType_visit;
|
||||
|
||||
@ -493,22 +493,22 @@ void freeOpt(OptRes o) {
|
||||
static void write_asm(u8* p, u64 sz) {
|
||||
i32* rp; B r = m_i32arrv(&rp, sz);
|
||||
for (u64 i = 0; i < sz; i++) rp[i] = p[i];
|
||||
path_wBytes(m_str8l("asm_bin"), r); dec(r);
|
||||
path_wBytes(m_ascii0("asm_bin"), r); dec(r);
|
||||
char off[20]; snprintf(off, 20, "%p", p);
|
||||
B o = m_str8l(off);
|
||||
path_wChars(m_str8l("asm_off"), o); dec(o);
|
||||
B o = m_ascii0(off);
|
||||
path_wChars(m_ascii0("asm_off"), o); dec(o);
|
||||
B s = emptyCVec();
|
||||
#define F(X) AFMT("s/%p$/%p # i_" #X "/;", i_##X, i_##X);
|
||||
F(POPS)F(INC)F(FN1C)F(FN1O)F(FN2C)F(FN2O)F(FN1Oi)F(FN2Oi)F(LST_0)F(LST_p)F(ARMM)F(ARMO)F(DFND_0)F(DFND_1)F(DFND_2)F(MD1C)F(MD2C)F(MD2R)F(TR2D)F(TR3D)F(TR3O)F(NOVAR)F(EXTO)F(EXTU)F(SETN)F(SETU)F(SETM)F(SETC)F(SETH1)F(SETH2)F(PRED1)F(PRED2)F(SETNi)F(SETUi)F(SETMi)F(SETCi)F(SETNv)F(SETUv)F(SETMv)F(SETCv)F(FLDO)F(VFYM)F(ALIM)F(CHKV)F(FAIL)F(RETD)
|
||||
#undef F
|
||||
path_wChars(m_str8l("asm_sed"), s); dec(s);
|
||||
path_wChars(m_ascii0("asm_sed"), s); dec(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void onJIT(Body* body, u8* binEx, u64 sz) {
|
||||
#if USE_PERF
|
||||
if (!perf_map) {
|
||||
B s = m_str8l("/tmp/perf-"); AFMT("%l.map", getpid());
|
||||
B s = m_ascii0("/tmp/perf-"); AFMT("%l.map", getpid());
|
||||
perf_map = file_open(s, "open", "wa");
|
||||
print(s); printf(": map\n");
|
||||
dec(s);
|
||||
|
||||
@ -117,11 +117,11 @@ Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src
|
||||
#include "gen/src"
|
||||
#if RT_SRC
|
||||
Block* load_compImport(char* name, B bc, B objs, B blocks, B bodies, B inds, B src) { // consumes all
|
||||
return compile(bc, objs, blocks, bodies, inds, bi_N, src, m_str8l(name), NULL);
|
||||
return compile(bc, objs, blocks, bodies, inds, bi_N, src, m_ascii0(name), NULL);
|
||||
}
|
||||
#else
|
||||
Block* load_compImport(char* name, B bc, B objs, B blocks, B bodies) { // consumes all
|
||||
return compile(bc, objs, blocks, bodies, bi_N, bi_N, bi_N, m_str8l(name), NULL);
|
||||
return compile(bc, objs, blocks, bodies, bi_N, bi_N, bi_N, m_ascii0(name), NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
32
src/main.c
32
src/main.c
@ -13,7 +13,7 @@ static bool init = false;
|
||||
static void repl_init() {
|
||||
if (init) return;
|
||||
cbqn_init();
|
||||
replPath = m_str8l("."); gc_add(replPath);
|
||||
replPath = m_ascii0("."); gc_add(replPath);
|
||||
Body* body = m_nnsDesc();
|
||||
B ns = m_nns(body);
|
||||
gsc = ptr_inc(c(NS, ns)->sc); gc_add(tag(gsc,OBJ_TAG));
|
||||
@ -68,14 +68,14 @@ void cbqn_runLine0(char* ln, i64 read) {
|
||||
char* cmdS = ln+1;
|
||||
char* cmdE;
|
||||
if (isCmd(cmdS, &cmdE, "ex ")) {
|
||||
B path = fromUTF8l(cmdE);
|
||||
B path = utf8Decode0(cmdE);
|
||||
code = path_chars(path);
|
||||
output = 0;
|
||||
} else if (isCmd(cmdS, &cmdE, "r ")) {
|
||||
code = fromUTF8l(cmdE);
|
||||
code = utf8Decode0(cmdE);
|
||||
output = 0;
|
||||
} else if (isCmd(cmdS, &cmdE, "t ") || isCmd(cmdS, &cmdE, "time ")) {
|
||||
code = fromUTF8l(cmdE);
|
||||
code = utf8Decode0(cmdE);
|
||||
time = -1;
|
||||
output = 0;
|
||||
} else if (isCmd(cmdS, &cmdE, "profile ") || isCmd(cmdS, &cmdE, "profile@")) {
|
||||
@ -83,14 +83,14 @@ void cbqn_runLine0(char* ln, i64 read) {
|
||||
profile = '@'==*(cpos-1)? readInt(&cpos) : 5000;
|
||||
if (profile==0) { printf("Cannot profile with 0hz sampling frequency\n"); return; }
|
||||
if (profile>999999) { printf("Cannot profile with >999999hz frequency\n"); return; }
|
||||
code = fromUTF8l(cpos);
|
||||
code = utf8Decode0(cpos);
|
||||
output = 0;
|
||||
} else if (isCmd(cmdS, &cmdE, "t:") || isCmd(cmdS, &cmdE, "time:")) {
|
||||
char* repE = cmdE;
|
||||
i64 am = readInt(&repE);
|
||||
if (repE==cmdE) { printf("time command not given repetition count\n"); return; }
|
||||
if (am==0) { printf("repetition count was zero\n"); return; }
|
||||
code = fromUTF8l(repE);
|
||||
code = utf8Decode0(repE);
|
||||
time = am;
|
||||
output = 0;
|
||||
} else if (isCmd(cmdS, &cmdE, "mem ")) {
|
||||
@ -177,14 +177,14 @@ void cbqn_runLine0(char* ln, i64 read) {
|
||||
#endif
|
||||
return;
|
||||
} else if (isCmd(cmdS, &cmdE, "internalPrint ")) {
|
||||
code = fromUTF8l(cmdE);
|
||||
code = utf8Decode0(cmdE);
|
||||
output = 2;
|
||||
} else {
|
||||
printf("Unknown REPL command\n");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
code = fromUTF8l(ln);
|
||||
code = utf8Decode0(ln);
|
||||
output = 1;
|
||||
}
|
||||
Block* block = bqn_compSc(code, inc(replPath), emptySVec(), gsc, true);
|
||||
@ -260,7 +260,7 @@ void cbqn_runLine(char* ln, i64 len) {
|
||||
|
||||
#if WASM
|
||||
void cbqn_evalSrc(char* src, i64 len) {
|
||||
B code = fromUTF8(src, len);
|
||||
B code = utf8Decode(src, len);
|
||||
B res = bqn_exec(code, bi_N, bi_N);
|
||||
|
||||
B resFmt = bqn_fmt(res);
|
||||
@ -312,18 +312,18 @@ int main(int argc, char* argv[]) {
|
||||
#define REQARG(X) if(*carg) { fprintf(stderr, "%s: -%s must end the option\n", argv[0], #X); exit(1); } if (i==argc) { fprintf(stderr, "%s: -%s requires an argument\n", argv[0], #X); exit(1); }
|
||||
case 'f': repl_init(); REQARG(f); goto execFile;
|
||||
case 'e': { repl_init(); REQARG(e);
|
||||
dec(gsc_exec_inline(fromUTF8l(argv[i++]), m_str8l("(-e)"), emptySVec()));
|
||||
dec(gsc_exec_inline(utf8Decode0(argv[i++]), m_ascii0("(-e)"), emptySVec()));
|
||||
break;
|
||||
}
|
||||
case 'L': { repl_init(); break; } // just initialize. mostly for perf testing
|
||||
case 'p': { repl_init(); REQARG(p);
|
||||
B r = bqn_fmt(gsc_exec_inline(fromUTF8l(argv[i++]), m_str8l("(-p)"), emptySVec()));
|
||||
B r = bqn_fmt(gsc_exec_inline(utf8Decode0(argv[i++]), m_ascii0("(-p)"), emptySVec()));
|
||||
printRaw(r); dec(r);
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
case 'o': { repl_init(); REQARG(o);
|
||||
B r = gsc_exec_inline(fromUTF8l(argv[i++]), m_str8l("(-o)"), emptySVec());
|
||||
B r = gsc_exec_inline(utf8Decode0(argv[i++]), m_ascii0("(-o)"), emptySVec());
|
||||
printRaw(r); dec(r);
|
||||
printf("\n");
|
||||
break;
|
||||
@ -342,7 +342,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
#ifdef PERF_TEST
|
||||
case 'R': { repl_init(); REQARG(R);
|
||||
B path = fromUTF8l(argv[i++]);
|
||||
B path = utf8Decode0(argv[i++]);
|
||||
B lines = path_lines(path);
|
||||
usz ia = a(lines)->ia;
|
||||
SGet(lines)
|
||||
@ -362,19 +362,19 @@ int main(int argc, char* argv[]) {
|
||||
if (i!=argc || execStdin) {
|
||||
repl_init();
|
||||
B src;
|
||||
if (!execStdin) src = fromUTF8l(argv[i++]);
|
||||
if (!execStdin) src = utf8Decode0(argv[i++]);
|
||||
B args;
|
||||
if (i==argc) {
|
||||
args = emptySVec();
|
||||
} else {
|
||||
M_HARR(ap, argc-i)
|
||||
for (usz j = 0; j < argc-i; j++) HARR_ADD(ap, j, fromUTF8l(argv[i+j]));
|
||||
for (usz j = 0; j < argc-i; j++) HARR_ADD(ap, j, utf8Decode0(argv[i+j]));
|
||||
args = HARR_FV(ap);
|
||||
}
|
||||
|
||||
B execRes;
|
||||
if (execStdin) {
|
||||
execRes = gsc_exec_inline(fromUTF8a(stream_bytes(stdin)), m_str8l("(-)"), args);
|
||||
execRes = gsc_exec_inline(utf8DecodeA(stream_bytes(stdin)), m_ascii0("(-)"), args);
|
||||
} else {
|
||||
execRes = bqn_execFile(src, args);
|
||||
}
|
||||
|
||||
4
src/ns.c
4
src/ns.c
@ -68,7 +68,7 @@ B ns_getNU(B ns, B name, bool thrEmpty) { VTY(ns, t_ns);
|
||||
return bi_N;
|
||||
}
|
||||
B ns_getC(B ns, char* name) {
|
||||
B field = m_str8l(name);
|
||||
B field = m_ascii0(name);
|
||||
B r = ns_getNU(ns, field, false);
|
||||
decG(field);
|
||||
return r;
|
||||
@ -101,7 +101,7 @@ Body* m_nnsDescF(i32 n, char** names) {
|
||||
incBy(emptyi32obj, 3);
|
||||
|
||||
M_HARR(nl, n)
|
||||
for (usz i = 0; i < n; i++) HARR_ADD(nl, i, m_str8l(names[i]));
|
||||
for (usz i = 0; i < n; i++) HARR_ADD(nl, i, m_ascii0(names[i]));
|
||||
|
||||
Comp* comp = mm_alloc(sizeof(Comp), t_comp);
|
||||
comp->bc = emptyi32obj;
|
||||
|
||||
@ -58,7 +58,7 @@ I8Arr* path_bytes(B path) { // consumes
|
||||
return src;
|
||||
}
|
||||
B path_chars(B path) { // consumes
|
||||
return fromUTF8a(path_bytes(path));
|
||||
return utf8DecodeA(path_bytes(path));
|
||||
}
|
||||
B path_lines(B path) { // consumes; TODO rewrite this, it's horrible
|
||||
I8Arr* tf = path_bytes(path);
|
||||
@ -77,7 +77,7 @@ B path_lines(B path) { // consumes; TODO rewrite this, it's horrible
|
||||
for (usz i = 0; i < lineCount; i++) {
|
||||
usz spos = pos;
|
||||
while(pos<ia && p[pos]!='\n' && p[pos]!='\r') pos++;
|
||||
HARR_ADD(r, i, fromUTF8((char*)p+spos, pos-spos));
|
||||
HARR_ADD(r, i, utf8Decode((char*)p+spos, pos-spos));
|
||||
if (pos<ia && p[pos]=='\r' && pos+1<ia && p[pos+1]=='\n') pos+= 2;
|
||||
else pos++;
|
||||
}
|
||||
@ -155,7 +155,7 @@ B path_abs(B path) {
|
||||
p[plen] = 0;
|
||||
char* res = realpath(p, NULL);
|
||||
if (res==NULL) thrF("Failed to convert %R to absolute path", path);
|
||||
B r = fromUTF8l(res);
|
||||
B r = utf8Decode0(res);
|
||||
free(res);
|
||||
dec(path);
|
||||
TFREE(p);
|
||||
@ -216,7 +216,7 @@ B path_list(B path) {
|
||||
B res = emptySVec();
|
||||
while ((c = readdir(d)) != NULL) {
|
||||
char* name = c->d_name;
|
||||
if (name[0]=='.'? !(name[1]==0 || (name[1]=='.'&&name[2]==0)) : true) res = vec_addN(res, m_str8l(name));
|
||||
if (name[0]=='.'? !(name[1]==0 || (name[1]=='.'&&name[2]==0)) : true) res = vec_addN(res, m_ascii0(name));
|
||||
}
|
||||
closedir(d);
|
||||
dec(path);
|
||||
|
||||
@ -19,7 +19,7 @@ static u32 utf8_p(u8* p) {
|
||||
}
|
||||
}
|
||||
|
||||
B fromUTF8(const char* s, i64 len) {
|
||||
B utf8Decode(const char* s, i64 len) {
|
||||
u64 sz = 0;
|
||||
i64 j = 0;
|
||||
while (true) {
|
||||
@ -45,12 +45,12 @@ B fromUTF8(const char* s, i64 len) {
|
||||
}
|
||||
}
|
||||
|
||||
B fromUTF8l(const char* s) {
|
||||
return fromUTF8(s, strlen(s));
|
||||
B utf8Decode0(const char* s) {
|
||||
return utf8Decode(s, strlen(s));
|
||||
}
|
||||
|
||||
B fromUTF8a(I8Arr* a) { // consumes a
|
||||
B r = fromUTF8((char*)a->a, a->ia);
|
||||
B utf8DecodeA(I8Arr* a) { // consumes a
|
||||
B r = utf8Decode((char*)a->a, a->ia);
|
||||
ptr_dec(a);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
B fromUTF8(const char* s, i64 len);
|
||||
B fromUTF8l(const char* s);
|
||||
|
||||
void printUTF8(u32 c);
|
||||
void fprintUTF8(FILE* f, u32 c);
|
||||
|
||||
|
||||
4
src/vm.c
4
src/vm.c
@ -1152,7 +1152,7 @@ void comp_init() {
|
||||
TIi(t_funBl,fn_iw) = funBl_iw; TIi(t_md1Bl,m1_iw) = md1Bl_iw; TIi(t_md2Bl,m2_iw) = md2Bl_iw;
|
||||
TIi(t_funBl,fn_ix) = funBl_ix; TIi(t_md1Bl,m1_ix) = md1Bl_ix; TIi(t_md2Bl,m2_ix) = md2Bl_ix;
|
||||
|
||||
oomMessage = m_str8l("Out of memory"); gc_add(oomMessage);
|
||||
oomMessage = m_ascii0("Out of memory"); gc_add(oomMessage);
|
||||
|
||||
#ifndef GS_REALLOC
|
||||
allocStack((void**)&gStack, (void**)&gStackStart, (void**)&gStackEnd, sizeof(B), GS_SIZE);
|
||||
@ -1610,7 +1610,7 @@ NOINLINE void freeThrown() {
|
||||
}
|
||||
|
||||
NOINLINE NORETURN void thrM(char* s) {
|
||||
thr(fromUTF8(s, strlen(s)));
|
||||
thr(utf8Decode(s, strlen(s)));
|
||||
}
|
||||
NOINLINE NORETURN void thrOOM() {
|
||||
if (oomMessage.u==0) err("out-of-memory encountered before out-of-memory error message object was initialized");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user