31 for (i = 0; i < c->extra; i++)
89 for (i = 0; i < t->
len; i++) {
113 for (i = 0; i < t->
len; i++) {
138 for (i = 0; i < t->
len; i++) {
142 if (count == index) {
171 for (i = 0; i < t->
len; i++) {
211 vt->parent =
self ? ((
struct PNVtable *)
self)->type : 0;
236 ((
struct PNVtable *)vt)->callset = cl;
254 PN pvars = ((
struct PNVtable *)parent)->ivars;
268 ((
struct PNVtable *)
self)->ctor = cl;
279 if (vt && vt->name == name)
292 #ifdef POTION_JIT_TARGET
308 if (vt->ivfunc != NULL)
309 return vt->ivfunc(
PN_UNIQ(ivar));
315 return found ==
PN_FALSE ? -1 : found;
325 return ((
struct PNObject *)
self)->ivars[i];
332 ((
struct PNObject *)
self)->ivars[i] = value;
351 unsigned k =
kh_put(
PN, vt->methods, key, &ret);
369 kh_val(
PN, vt->methods, k) = method;
378 if (asmb->
len <= 4096) {
379 if (vt->mcache == NULL)
382 }
else if (vt->mcache != NULL) {
394 if (vt->mcache != NULL)
395 return vt->mcache(
PN_UNIQ(key));
397 unsigned k =
kh_get(
PN, vt->methods, key);
529 return sizeof(
struct PNObject) + (((struct PNVtable *)
PN_VTABLE(obj->vt))->ivlen *
sizeof(
PN));
565 return (
PN)
self->meta;
580 return (
void *)str !=
PN_NIL ? str :
615 char meta_str[strlen(
"<metaclass: >") +
PN_STR_LEN(name) + 1];
618 sprintf(meta_str,
"<metaclass: %s>",
PN_STR_PTR(name));
636 potion_str(P,
"“I love _why, but learning Ruby from him is like trying to learn to pole vault "
637 "by having Salvador Dali punch you in the face.” - Steven Frank"));
639 potion_str(P,
"“The sad thing about ‘minimalism’ is that it has a name.” "
642 potion_str(P,
"“Recently no move on Potion. I git pull everyday.” "
645 potion_str(P,
"“Setting up my new anarchist bulletin board so that during registration, if you accept "
646 "the terms and conditions, you are banned forever.” - Dr. Casey Hall"));
650 potion_str(P,
"“pigeon%” - Guy Decoux (1955 - 2008)"));
652 potion_str(P,
"“I smell as how a leprechaun looks.” - Alana Post"));
712 #ifndef DISABLE_CALLCC
PN potion_vm(Potion *, PN, PN, PN, PN_SIZE, PN *volatile)
the bytecode run-loop
PN potion_closure_new(Potion *P, PN_F meth, PN sig, PN_SIZE extra)
#define PN_IS_METACLASS(v)
PN potion_def_method(Potion *P, PN closure, PN self, PN key, PN method)
define a method for a class
void potion_destroy(Potion *P)
PN potion_rand(Potion *P, PN cl, PN self)
PN potion_no_call(Potion *P, PN cl, PN self)
PN potion_proto_method(Potion *P, PN cl, PN self, PN args)
only used in def_method
#define PN_FLEX_NEEDS(X, N, V, T, S)
PN potion_str(Potion *, const char *)
PN potion_class(Potion *P, PN cl, PN self, PN ivars)
create a user-class (ie type)
PN potion_ref_string(Potion *P, PN cl, PN self, PN len)
PN potion_exit(Potion *P, PN cl, PN self)
klib hash table library based on double hashing http://en.wikipedia.org/wiki/Double_hashing ...
a tuple is an array of PNs.
PN potion_lobby_can(Potion *P, PN cl, PN self, PN method)
#define PN_ALLOC_N(V, T, C)
PN potion_bind(Potion *P, PN rcv, PN msg)
find method for given receiver and message (method lookup)
a closure is an anonymous function, without closed values,
the central vtable, see io http://www.piumarta.com/pepsi/objmodel.pdf
PN potion_obj_set(Potion *P, PN cl, PN self, PN ivar, PN value)
implements OP_SETPATH
PN_SIZE void potion_bytes_obj_string(Potion *, PN, PN)
PN potion_lobby_say(Potion *P, PN cl, PN self)
int potion_sig_minargs(Potion *P, PN sig)
number of mandatory args, without any optional arguments
PN potion_lobby_string(Potion *P, PN cl, PN self)
PN potion_table_put(Potion *P, PN cl, PN self, PN key, PN value)
PN PN potion_byte_str(Potion *, const char *)
PN potion_sig_string(Potion *P, PN cl, PN sig)
void potion_lobby_init(Potion *P)
#define potion_method(RCV, MSG, FN, SIG)
PN potion_closure_arity(Potion *P, PN cl, PN self)
PN potion_ref(Potion *P, PN data)
PN potion_byte_str2(Potion *, const char *, size_t len)
static PN potion_fwd(PN)
the potion type is the 't' in the vtable tuple (m,t)
static long potion_obj_find_ivar(Potion *P, PN self, PN ivar)
void potion_type_call_is(PN vt, PN cl)
sets the default call method of the PNVtable
#define kh_put(name, h, k, r)
PN potion_obj_bitl(Potion *P, PN a, PN b)
void potion_add_metaclass(Potion *P, vPN(Vtable) vt)
a weak ref is used for upvals, it acts as a memory slot, non-volatile but mutable.
PNType potion_class_type(Potion *P, PN class)
PN potion_sig_at(Potion *P, PN sig, int index)
PN potion_class_find(Potion *P, PN name)
find class by name. At first only system metaclasses (types), no user classes yet.
static void potion_init_class_reference(Potion *P, PN name, PN vt)
int potion_munmap(void *mem, size_t len)
standard objects act like C structs the fields are defined by the type and it's a fixed size...
PN name
classes/types need to be found by name.
PN potion_closure_string(Potion *P, PN cl, PN self, PN maxlen)
PN potion_about(Potion *P, PN cl, PN self)
PN potion_get_metaclass(Potion *P, PN cl, vPN(Vtable) self)
PN potion_getter_method(Potion *P, PN cl, PN self)
only used in def_method
PN potion_closure_code(Potion *P, PN cl, PN self)
PN potion_table_empty(Potion *P)
void potion_type_callset_is(PN vt, PN cl)
set default writer
void(* mcache)(Potion *, struct PNVtable *volatile, PNAsm *volatile *)
PN potion_type_error(Potion *P, PN obj)
the table class, based on khash
PN potion_tuple_new(Potion *, PN)
PN potion_obj_get(Potion *P, PN cl, PN self, PN ivar)
implements OP_GETPATH
PN potion_obj_get_callset(Potion *P, PN obj)
get default writer
void potion_define_global(Potion *P, PN name, PN val)
PN potion_obj_sub(Potion *P, PN a, PN b)
PN potion_obj_add(Potion *P, PN a, PN b)
#define PN_MEMCPY_N(X, Y, T, N)
PN potion_tuple_bsearch(Potion *P, PN cl, PN self, PN x)
PN potion_ivars(Potion *P, PN cl, PN self, PN ivars)
void potion_object_init(Potion *P)
PN potion_lobby_kind(Potion *P, PN cl, PN self)
#define PN_CHECK_TYPE(obj, type)
PN callset
generic call and setter
PNAsm * potion_asm_new(Potion *P)
PN potion_obj_mult(Potion *P, PN a, PN b)
PN potion_object_string(Potion *P, PN cl, vPN(Object) self)
PN potion_obj_get_call(Potion *P, PN obj)
get the default accessor (usually "at")
PNType parent
parent type, default: for P->lobby: PN_VTABLE(PN_TOBJECT)
PN potion_tuple_push(Potion *, PN, PN)
PNFlex *volatile vts
built in types
PN potion_obj_bitr(Potion *P, PN a, PN b)
PN(* PN_IVAR_FUNC)(PNUniq hash)
PN potion_object_send(Potion *P, PN cl, PN self, PN method)
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS PN potion_callcc(Potion *P, PN cl, PN self)
#define PN_ALLOC_FUNC(size)
void(* ivars)(Potion *, PN, PNAsm *volatile *)
PN potion_type_new(Potion *P, PNType t, PN self)
create a non-user type, derived from self
PN_SIZE potion_type_size(Potion *P, const struct PNObject *ptr)
PN potion_closure_minargs(Potion *P, PN cl, PN self)
#define kh_val(name, h, x)
PN potion_object_size(Potion *P, PN cl, PN self)
the global interpreter state P. currently singleton (not threads yet)
PN_SIZE pn_printf(Potion *, PN, const char *,...) __attribute__((format(printf
PN potion_obj_rem(Potion *P, PN a, PN b)
static PN potion_lobby_self(Potion *P, PN cl, PN self)
PN potion_srand(Potion *P, PN cl, PN self, PN seed)
PN potion_message(Potion *P, PN rcv, PN msg)
#define PN_QUICK_FWD(t, obj)
PN_QUICK_FWD - doing a single fwd check after a possible realloc.
the central table type, based on core/khash.h
PN potion_object_forward(Potion *P, PN cl, PN self, PN method)
_PN(* PN_F)(Potion *, PN, PN,...)
PN potion_obj_bitn(Potion *P, PN a)
PN potion_lookup(Potion *P, PN closure, PN self, PN key)
used in bind and def_method
#define potion_send(RCV, MSG, ARGS...)
method caches (more great stuff from ian piumarta)
PN potion_object_subclass(Potion *P, PN cl, PN self, vPN(Vtable) vtable)
PN potion_type_error_want(Potion *P, const char *param, PN obj, const char *type)
PN potion_type_new2(Potion *P, PNType t, PN self, PN name)
create a named type
int potion_sig_arity(Potion *P, PN sig)
number of args of sig tuple, implements the potion_closure_arity method.
int ivlen
PN_TUPLE_LEN(ivars)
#define PN_CALLOC_N(V, T, C)
void potion_type_constructor_is(PN vt, PN cl)
set default constructor
#define PN_TUPLE_EACH(T, I, V, B)
PN potion_sig_name_at(Potion *P, PN sig, int index)
void potion_fatal(char *message)
PN ivars
PNTuple of all our or the parents inherited vars.
PN potion_object_new(Potion *P, PN cl, PN self)
PN potion_lobby_print(Potion *P, PN cl, PN self)
PN potion_lobby_isa(Potion *P, PN cl, PN self, vPN(Vtable) vtable)
#define kh_get(name, h, k)
PN potion_obj_div(Potion *P, PN a, PN b)