|
problem
This page is a placeholder for future content under mu; see toy for a guide to future topic location and purpose. /*
struct { // bits inside t_32 «
u32 t_len : 16; // if isvec(), the count of array members
u32 t_alt : 7; // use depends on kind (tree: node_height)
u32 t_const : 1; // const means box cannot be modified
u32 t_esc : 1; // escaped (depends on kind)
// weakly referenced objects
u32 t_weak: 1; // weak means box uses weak gc peg ptrs
u32 t_vec : 1; // vec means variable length array
u32 t_kind : 5; // yt::Tkind enum value
} b;
*/
/* 3 2 1 «
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| length | alt |c|e|w|v| kind |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | . . . |
const bit --------------------o | | | | . . . |
esc bit ----------------------o | | | . . . |
weak bit ------------------------o | | . . . |
vec bit --------------------------o | . . . |
| . . . |
kind bits ----------------------------o-o-o-o-o
**/
struct yt { // four bytes preceding a box in gc memory «
u32 t_32; // all 32 bits as single int «
// more api shown below
};
struct yt { // four bytes preceding a box in gc memory
u32 t_32; // all 32 bits as single int
enum Trig { // Trig val for b.t_alt if b.t_kind == k_rig «
r_snark = 0,
r_use, r_setter,
r_module, r_context,
r_stream, r_method,
r_set, r_exit,
r_frame, r_err,
r_face
};
enum Talt { // Trig values shifted over to alt position «
a_use = r_use<<9, a_setter = r_setter<<9,
a_module = r_module<<9, a_context = r_context<<9,
a_stream = r_stream<<9, a_method = r_method<<9,
a_set = r_set<<9, a_exit = r_exit<<9,
a_frame = r_frame<<9, a_err = r_err<<9,
a_face = r_face<<9
};
enum Tkind { // yt::Tkind type of box (k_none=zero unused) «
k_none = 0, k_p1, // 00, 01: <none>, 1-tuple
k_p2, k_p3, // 02, 03: pair, triple
k_p4, k_hash, // 04, 05: 4-tuple, hash
k_r128, k_i128, // 06, 07: r128, i128
k_vec, k_obj, // 10, 11: n-tuple, object
k_class, k_int, // 12, 13: class, bigint
k_tree, k_cord, // 14, 15: tree, cord
k_sym, k_far, // 16, 17: symbol, foreign
// k_cord and k_sym must be adjacent for k_text to work
k_map, k_row, // 18, 19: hashmap, row
k_rig, k_toc, // 1a, 1b: misc/rig, toc
k_iter, k_table, // 1c, 1d: iter, matrix
k_fore, k_back // 1e, 1f: forward, backward
}; // enum Tkind
enum et32 { // to select parts of t_32 «
e_5 = (1 << 5) - 1, // the low 5 bits: 0x1f
e_6 = (1 << 6) - 1, // the low 6 bits: 0x3f
e_7 = (1 << 7) - 1, // the low 7 bits: 0x7f
e_k = e_5, // the low five bits: t_kind = 0x1f
e_kk = ~(e_k),
e_v = (1 << 5), // the sixth bit: t_vec = 0x20
e_vv = ~(e_v),
e_w = (1 << 6), // the seventh bit: t_weak = 0x40
e_ww = ~(e_w),
e_e = (1 << 7), // the eighth bit: t_esc = 0x80
e_ee = ~(e_e),
e_c = (1 << 8), // the ninth bit: t_const = 0x100
e_cc = ~(e_c),
e_aa = ~(e_7 << 9) // zeroes where the alt field goes
};
enum Tvec { «
v_r128 = (e_v | k_r128), v_i128 = (e_v | k_i128),
v_i16 = (e_v | k_i16), v_u16 = (e_v | k_u16),
v_i32 = (e_v | k_i32), v_u32 = (e_v | k_u32),
v_i64 = (e_v | k_i64), v_u64 = (e_v | k_u64),
v_r32 = (e_v | k_r32), v_r64 = (e_v | k_r64),
v_vec = (e_v | k_vec), v_obj = (e_v | k_obj),
v_tree = (e_v | k_tree), v_cord = (e_v | k_cord),
v_sym = (e_v | k_sym),
};
// tname() supports printing a nobox peg immed w/ tag inside
const char* tname() const; // description WITHOUT len field
const char* tname(yb& outBuf) const; // ditto: no len field
// static const str for kind or alt type
const char* tkindname() const;
const char* trigname() const; // static str: rig/alt field
yt() { t_32 = k_none; }
explicit yt(u32 i) { t_32 = i; }
explicit yt(n32 n, u32 i) { t_32 = (n << 16) | i; }
explicit yt(Tkind k) { t_32 = k; }
explicit yt(n32 n, Tkind k) { t_32 = (n << 16) | k; }
explicit yt(n32 n, Tvec v) { t_32 = (n << 16) | v; }
unsigned alt() const { return (t_32 >> 9) & e_7; } «
bool isalt(unsigned a) const { «
return ((t_32 >> 9) & e_7) == a;
}
void talt(unsigned a) { // set 7-bit alt field «
t_32 = (t_32 & e_aa) | ((a & e_7) << 9);
}
unsigned len() const { return (t_32 >> 16) & 0x0FFFF; } «
u32 bytes() const; // bytes of space in following box
void tkind(unsigned k) { t_32 = (t_32 & e_kk)|(k & e_5); } «
unsigned kind() const { return t_32 & e_5; } «
bool iskind(unsigned k) const { return (t_32 & e_5) == k; } «
unsigned ckind() const { return t_32 & (e_c | e_5); } «
unsigned vkind() const { return t_32 & (e_v | e_5); } «
unsigned cvkind() const { return t_32 & (e_c|e_v|e_5); } «
bool isTvec(Tvec vt) const { // is this vector kind? «
return (t_32 & e_6) == (u32) vt;
}
bool isvec() const { return (t_32 & e_v) != 0; } «
void tvec(bool b) { // set the vector bit «
if (b) t_32 |= e_v; else t_32 &= e_vv;
}
bool isconst() const { return (t_32 & e_c) != 0; } «
void tconst(bool b) { // set const bit «
if (b) t_32 |= e_c; else t_32 &= e_cc;
}
bool isescaped() const { return (t_32 & e_e) != 0; } «
void tescape(bool b) { // set escape bit «
if (b) t_32 |= e_e; else t_32 &= e_ee;
}
bool isweak() const { return (t_32 & e_w) != 0; } «
void tweak(bool b) { // set weak bit «
if (b) t_32 |= e_w; else t_32 &= e_ww;
}
enum Ttext { // mask matching BOTH cord and symbol «
// k_cord and k_sym differ only in lowest bit position;
// k_text: either k_cord or k_sym (whichever sets low bit)
k_text = (k_cord | k_sym), // must have lowest bit set «
};
|
menu
mu, toy, peg, imm, tag « Þ, box, symbol, token, number, bigint, class, method, reader, writer, eval, env, vm, gc, world, pcode, compiler, asm, lathe, lisp, smalltalk, design, weight, jar, card, harp, debug, profile (thorn, todo, names, fd, iovec, assert, log, run, hex, crc, buf, in, out, quote, escape, compare, file, deck, cow, arc, blob, tree, slice, rand, time, stat, hash, heap, node, primes, page, book, pile, stack, atomic, lock, mutex, thread, map, meter, list, iter, ctype) const char* yt::trigname() const { // t(ag) rig name «
// static const str for kind alt field
switch (this->alt()) {
case r_snark: return "snark";
case r_use: return "use";
case r_setter: return "setter";
case r_module: return "module";
case r_context: return "context";
case r_stream: return "stream";
case r_method: return "method";
case r_set: return "set";
case r_exit: return "exit";
case r_frame: return "frame";
case r_err: return "err";
case r_face: return "face";
}
static char tmp_alt[48+1];
tmp_alt[48] = 0;
::sprintf(tmp_alt, "Talt0x%x", (int) this->alt());
return tmp_alt;
}
const char* yt::tkindname() const { // t(ag) kind name «
// static const str for kind or alt type
switch (this->kind()) {
case k_none: return "none";
case k_p1: return "1-tuple";
case k_p2: return "pair";
case k_p3: return "triple";
case k_p4: return "quad";
case k_hash: return "hash";
case k_r128: return "r128";
case k_i128: return "i128";
case k_i16: return "i16";
case k_u16: return "u16";
case k_i32: return "i32";
case k_u32: return "u32";
case k_i64: return "i64";
case k_u64: return "u64";
case k_r32: return "r32";
case k_r64: return "r64";
case k_vec: return "vector";
case k_obj: return "object";
case k_class: return "class";
case k_int: return "bigint";
case k_tree: return "tree";
case k_cord: return "string";
case k_sym: return "symbol";
case k_far: return "far";
case k_map: return "map";
case k_row: return "row";
case k_rig: return this->trigname();
case k_toc: return "toc";
case k_iter: return "iter";
case k_table: return "table";
case k_fore: return "fore";
case k_back: return "back";
}
static char tmp_kind[48+1];
tmp_kind[48] = 0;
::sprintf(tmp_kind, "Tkind0x%x", (int) this->kind());
return tmp_kind;
}
const char* yt::tname(yb& outBuf) const { // t(ag) name «
// description WITHOUT length field
// tname() supports printing nobox peg imm with tag inside
ybo bo(&outBuf);
if (isconst())
bo << "const-";
if (isescaped())
bo << "esc-";
if (isweak())
bo << "weak-";
if (isvec())
bo << "vec-";
bo << this->tkindname();
bo.o1c(0); // end nul byte
bo.oflush(); // bring outBuf.v_n up to date
return (const char*) outBuf.v_p;
}
|