31 for (i = 0; i < c->extra; i++)
54 # define FUNCNAME "sub"
56 # define FUNCNAME "function"
94 for (i = 0; i < t->
len; i++) {
118 for (i = 0; i < t->
len; i++) {
143 for (i = 0; i < t->
len; i++) {
147 if (count == index) {
176 for (i = 0; i < t->
len; i++) {
216 vt->parent =
self ? ((
struct PNVtable *)
self)->type : 0;
241 ((
struct PNVtable *)vt)->callset = cl;
259 PN pvars = ((
struct PNVtable *)parent)->ivars;
273 ((
struct PNVtable *)
self)->ctor = cl;
284 if (vt && vt->name == name)
297 #ifdef POTION_JIT_TARGET
313 if (vt->ivfunc != NULL)
314 return vt->ivfunc(
PN_UNIQ(ivar));
320 return found ==
PN_FALSE ? -1 : found;
330 return ((
struct PNObject *)
self)->ivars[i];
337 ((
struct PNObject *)
self)->ivars[i] = value;
356 unsigned k =
kh_put(
PN, vt->methods, key, &ret);
374 kh_val(
PN, vt->methods, k) = method;
383 if (asmb->
len <= 4096) {
384 if (vt->mcache == NULL)
387 }
else if (vt->mcache != NULL) {
399 if (vt->mcache != NULL)
400 return vt->mcache(
PN_UNIQ(key));
402 unsigned k =
kh_get(
PN, vt->methods, key);
535 return sizeof(
struct PNObject) + (((struct PNVtable *)
PN_VTABLE(obj->vt))->ivlen *
sizeof(
PN));
571 return (
PN)
self->meta;
586 return (
void *)str !=
PN_NIL ? str :
621 char meta_str[strlen(
"<metaclass: >") +
PN_STR_LEN(name) + 1];
624 sprintf(meta_str,
"<metaclass: %s>",
PN_STR_PTR(name));
642 potion_str(P,
"“I love _why, but learning Ruby from him is like trying to learn to pole vault "
643 "by having Salvador Dali punch you in the face.” - Steven Frank"));
645 potion_str(P,
"“The sad thing about ‘minimalism’ is that it has a name.” "
648 potion_str(P,
"“Recently no move on Potion. I git pull everyday.” "
651 potion_str(P,
"“Setting up my new anarchist bulletin board so that during registration, if you accept "
652 "the terms and conditions, you are banned forever.” - Dr. Casey Hall"));
656 potion_str(P,
"“pigeon%” - Guy Decoux (1955 - 2008)"));
658 potion_str(P,
"“I smell as how a leprechaun looks.” - Alana Post"));
686 # define LOBBY_NAME "P2"
687 # define BOOLEAN_NAME "Bool"
688 # define NUMBER_NAME "Num"
689 # define INTEGER_NAME "Int"
690 # define DOUBLE_NAME "Dbl"
691 # define STRING_NAME "Str"
693 # define LOBBY_NAME "Lobby"
694 # define BOOLEAN_NAME "Boolean"
695 # define NUMBER_NAME "Number"
696 # define INTEGER_NAME "Integer"
697 # define DOUBLE_NAME "Double"
698 # define STRING_NAME "String"
735 #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)