Potion *potion_create(void *sp) { Potion *P = potion_gc_boot(sp); //zeros P P->vt = PN_TSTATE; P->uniq = (PNUniq)potion_rand_int(); PN_FLEX_NEW(P->vts, PN_TFLEX, PNFlex, TYPE_BATCH_SIZE); PN_FLEX_SIZE(P->vts) = PN_TYPE_ID(PN_TUSER) + 1; P->prec = PN_PREC; P->fileno = -1; //P->flags = (Potion_Flags)EXEC_VM; potion_init(P); return P; }
///\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); });
PN potion_delegated(Potion *P, PN closure, PN self) { PNType t = PN_FLEX_SIZE(P->vts) + PN_TNIL; PN_FLEX_NEEDS(1, P->vts, PN_TFLEX, PNFlex, TYPE_BATCH_SIZE); return potion_type_new(P, t, self); }
void *potion_mark_major(Potion *P, const struct PNObject *ptr) { struct PNMemory *M = P->mem; PN_SIZE i; PN_SIZE sz = 16; switch (((struct PNFwd *)ptr)->fwd) { case POTION_COPIED: case POTION_FWD: GC_MAJOR_UPDATE(((struct PNFwd *)ptr)->ptr); goto done; } if (ptr->vt > PN_TUSER) { GC_MAJOR_UPDATE(PN_VTABLE(ptr->vt)); int ivars = ((struct PNVtable *)PN_VTABLE(ptr->vt))->ivlen; for (i = 0; i < ivars; i++) GC_MAJOR_UPDATE(((struct PNObject *)ptr)->ivars[i]); goto done; } switch (ptr->vt) { case PN_TWEAK: GC_MAJOR_UPDATE(((struct PNWeakRef *)ptr)->data); break; case PN_TCLOSURE: GC_MAJOR_UPDATE(((struct PNClosure *)ptr)->sig); for (i = 0; i < ((struct PNClosure *)ptr)->extra; i++) GC_MAJOR_UPDATE(((struct PNClosure *)ptr)->data[i]); break; case PN_TTUPLE: { struct PNTuple * volatile t = (struct PNTuple *)potion_fwd((PN)ptr); for (i = 0; i < t->len; i++) GC_MAJOR_UPDATE(t->set[i]); } break; case PN_TSTATE: GC_MAJOR_UPDATE(((Potion *)ptr)->strings); GC_MAJOR_UPDATE(((Potion *)ptr)->lobby); GC_MAJOR_UPDATE(((Potion *)ptr)->vts); GC_MAJOR_UPDATE(((Potion *)ptr)->source); GC_MAJOR_UPDATE(((Potion *)ptr)->input); GC_MAJOR_UPDATE(((Potion *)ptr)->pbuf); GC_MAJOR_UPDATE(((Potion *)ptr)->unclosed); GC_MAJOR_UPDATE(((Potion *)ptr)->call); GC_MAJOR_UPDATE(((Potion *)ptr)->callset); break; case PN_TFILE: GC_MAJOR_UPDATE(((struct PNFile *)ptr)->path); break; case PN_TVTABLE: GC_MAJOR_UPDATE(((struct PNVtable *)ptr)->parent); GC_MAJOR_UPDATE(((struct PNVtable *)ptr)->ivars); GC_MAJOR_UPDATE(((struct PNVtable *)ptr)->methods); GC_MAJOR_UPDATE(((struct PNVtable *)ptr)->ctor); GC_MAJOR_UPDATE(((struct PNVtable *)ptr)->call); GC_MAJOR_UPDATE(((struct PNVtable *)ptr)->callset); break; case PN_TSOURCE: GC_MAJOR_UPDATE(((struct PNSource *)ptr)->a[0]); GC_MAJOR_UPDATE(((struct PNSource *)ptr)->a[1]); GC_MAJOR_UPDATE(((struct PNSource *)ptr)->a[2]); break; case PN_TPROTO: GC_MAJOR_UPDATE(((struct PNProto *)ptr)->source); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->sig); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->stack); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->paths); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->locals); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->upvals); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->values); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->protos); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->tree); GC_MAJOR_UPDATE(((struct PNProto *)ptr)->asmb); break; case PN_TTABLE: GC_MAJOR_UPDATE_TABLE(PN, (struct PNTable *)potion_fwd((PN)ptr), 1); break; case PN_TFLEX: for (i = 0; i < PN_FLEX_SIZE(ptr); i++) GC_MAJOR_UPDATE(PN_FLEX_AT(ptr, i)); break; case PN_TCONT: GC_KEEP(ptr); pngc_mark_array(P, (_PN *)((struct PNCont *)ptr)->stack + 3, ((struct PNCont *)ptr)->len - 3, 2); break; } done: sz = potion_type_size(P, ptr); return (void *)((char *)ptr + sz); }