///\return string of the sig tuple. "arg1=o,arg2=o" PN potion_sig_string(Potion *P, PN cl, PN sig) { PN out = potion_byte_str(P, ""); if (PN_IS_TUPLE(sig)) { int nextdef = 0; struct PNTuple * volatile t = ((struct PNTuple *)potion_fwd(sig)); if (t->len != 0) { PN_SIZE i, comma=0; for (i = 0; i < t->len; i++) { PN v = (PN)t->set[i]; if (PN_IS_NUM(v)) { // currently types are still encoded as NUM, TODO: support VTABLE also int c = PN_INT(v); comma=0; if (c == '.') // is end pn_printf(P, out, "."); else if (c == '|') // is optional pn_printf(P, out, "|"); else if (c == ':') { nextdef = 1; pn_printf(P, out, ":"); // is default } else { if (comma++) pn_printf(P, out, ","); if (nextdef) { nextdef = 0; pn_printf(P, out, "="); potion_bytes_obj_string(P, out, v); } else pn_printf(P, out, "=%c", c); } } else { if (comma++) pn_printf(P, out, ","); if (nextdef) { nextdef = 0; pn_printf(P, out, "="); } potion_bytes_obj_string(P, out, v); }}}} return PN_STR_B(out); }
PN potion_source_string(Potion *P, PN cl, PN self) { int i, n; struct PNSource *t = (struct PNSource *)self; PN out = potion_byte_str(P, potion_ast_names[t->part]); n = potion_ast_sizes[t->part]; for (i = 0; i < n; i++) { pn_printf(P, out, " "); if (i == 0 && n > 1) pn_printf(P, out, "("); potion_bytes_obj_string(P, out, t->a[i]); if (i == n - 1 && n > 1) pn_printf(P, out, ")"); } return out; }
///\memberof PNProto /// string method of PNProto. ascii dump of a function definition PN potion_proto_string(Potion *P, PN cl, PN self) { vPN(Proto) t = (struct PNProto *)self; int x = 0; PN_SIZE num = 1; PN_SIZE numcols; PN out = potion_byte_str(P, "; function definition"); #ifdef JIT_DEBUG pn_printf(P, out, ": %p; %u bytes\n", t, PN_FLEX_SIZE(t->asmb)); #else pn_printf(P, out, ": %u bytes\n", PN_FLEX_SIZE(t->asmb)); #endif if (t->name) pn_printf(P, out, "; %s(", PN_STR_PTR(t->name)); else pn_printf(P, out, "; ("); potion_bytes_obj_string(P, out, potion_sig_string(P, cl, t->sig)); pn_printf(P, out, ") %ld registers\n", PN_INT(t->stack)); PN_TUPLE_EACH(t->paths, i, v, { pn_printf(P, out, ".path /"); v = PN_TUPLE_AT(t->values, PN_INT(v)); potion_bytes_obj_string(P, out, v); pn_printf(P, out, " ; %u\n", i); });
PN potion_proto_string(Potion *P, PN cl, PN self) { vPN(Proto) t = (struct PNProto *)self; int x = 0; PN_SIZE num = 1; PN_SIZE numcols; PN out = potion_byte_str(P, "; function definition"); pn_printf(P, out, ": %p ; %u bytes\n", t, PN_FLEX_SIZE(t->asmb)); pn_printf(P, out, "; ("); PN_TUPLE_EACH(t->sig, i, v, { if (PN_IS_NUM(v)) { if (v == '.') pn_printf(P, out, ". "); else if (v == '|') pn_printf(P, out, "| "); else pn_printf(P, out, "=%c, ", (int)PN_INT(v)); } else potion_bytes_obj_string(P, out, v); });