p2  0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
objmodel.c File Reference

objects, classes, types, methods, weakrefs and mop. More...

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "p2.h"
#include "internal.h"
#include "khash.h"
#include "table.h"
#include "asm.h"
+ Include dependency graph for objmodel.c:

Go to the source code of this file.

Macros

#define FUNCNAME   "function"
 
#define LOBBY_NAME   "Lobby"
 
#define BOOLEAN_NAME   "Boolean"
 
#define NUMBER_NAME   "Number"
 
#define INTEGER_NAME   "Integer"
 
#define DOUBLE_NAME   "Double"
 
#define STRING_NAME   "String"
 

Functions

PN potion_closure_new (Potion *P, PN_F meth, PN sig, PN_SIZE extra)
 
int potion_sig_arity (Potion *P, PN sig)
 number of args of sig tuple, implements the potion_closure_arity method. More...
 
int potion_sig_minargs (Potion *P, PN sig)
 number of mandatory args, without any optional arguments More...
 
PN potion_sig_at (Potion *P, PN sig, int index)
 
PN potion_sig_name_at (Potion *P, PN sig, int index)
 
PN potion_no_call (Potion *P, PN cl, PN self)
 
void potion_add_metaclass (Potion *P, vPN(Vtable) vt)
 
PN potion_type_new (Potion *P, PNType t, PN self)
 create a non-user type, derived from self More...
 
PN potion_type_new2 (Potion *P, PNType t, PN self, PN name)
 create a named type More...
 
void potion_type_call_is (PN vt, PN cl)
 sets the default call method of the PNVtable More...
 
PN potion_obj_get_call (Potion *P, PN obj)
 get the default accessor (usually "at") More...
 
void potion_type_callset_is (PN vt, PN cl)
 set default writer More...
 
PN potion_obj_get_callset (Potion *P, PN obj)
 get default writer More...
 
void potion_type_constructor_is (PN vt, PN cl)
 set default constructor More...
 
PN potion_class (Potion *P, PN cl, PN self, PN ivars)
 create a user-class (ie type) More...
 
PN potion_class_find (Potion *P, PN name)
 find class by name. At first only system metaclasses (types), no user classes yet. More...
 
PNType potion_class_type (Potion *P, PN class)
 
PN potion_ivars (Potion *P, PN cl, PN self, PN ivars)
 
static long potion_obj_find_ivar (Potion *P, PN self, PN ivar)
 
PN potion_obj_get (Potion *P, PN cl, PN self, PN ivar)
 implements OP_GETPATH More...
 
PN potion_obj_set (Potion *P, PN cl, PN self, PN ivar, PN value)
 implements OP_SETPATH More...
 
PN potion_proto_method (Potion *P, PN cl, PN self, PN args)
 only used in def_method More...
 
PN potion_getter_method (Potion *P, PN cl, PN self)
 only used in def_method More...
 
PN potion_def_method (Potion *P, PN closure, PN self, PN key, PN method)
 define a method for a class More...
 
PN potion_lookup (Potion *P, PN closure, PN self, PN key)
 used in bind and def_method More...
 
PN potion_bind (Potion *P, PN rcv, PN msg)
 find method for given receiver and message (method lookup) More...
 
PN potion_message (Potion *P, PN rcv, PN msg)
 
PN potion_obj_add (Potion *P, PN a, PN b)
 
PN potion_obj_sub (Potion *P, PN a, PN b)
 
PN potion_obj_mult (Potion *P, PN a, PN b)
 
PN potion_obj_div (Potion *P, PN a, PN b)
 
PN potion_obj_rem (Potion *P, PN a, PN b)
 
PN potion_obj_bitn (Potion *P, PN a)
 
PN potion_obj_bitl (Potion *P, PN a, PN b)
 
PN potion_obj_bitr (Potion *P, PN a, PN b)
 
static void potion_init_class_reference (Potion *P, PN name, PN vt)
 
void potion_define_global (Potion *P, PN name, PN val)
 
void potion_object_init (Potion *P)
 
void potion_lobby_init (Potion *P)
 

Detailed Description

objects, classes, types, methods, weakrefs and mop.

much of this is based on the work of ian piumarta http://www.piumarta.com/pepsi/objmodel.pdf

p2-mop.png

Definition in file objmodel.c.

Macro Definition Documentation

#define FUNCNAME   "function"
#define LOBBY_NAME   "Lobby"

Definition at line 693 of file objmodel.c.

#define BOOLEAN_NAME   "Boolean"

Definition at line 694 of file objmodel.c.

#define NUMBER_NAME   "Number"

Definition at line 695 of file objmodel.c.

#define INTEGER_NAME   "Integer"

Definition at line 696 of file objmodel.c.

#define DOUBLE_NAME   "Double"

Definition at line 697 of file objmodel.c.

#define STRING_NAME   "String"

Definition at line 698 of file objmodel.c.

Function Documentation

PN potion_closure_new ( Potion P,
PN_F  meth,
PN  sig,
PN_SIZE  extra 
)

Definition at line 17 of file objmodel.c.

int potion_sig_arity ( Potion P,
PN  sig 
)

number of args of sig tuple, implements the potion_closure_arity method.

sigs are encoded as tuples of len 2-3, (name type|modifier [default-value]) names String, modifiers Num. types also Num, but want to switch to special SIG VTable. default-value can be a value of any type and is prefixed with ':'

Returns
number of args as integer

Definition at line 87 of file objmodel.c.

int potion_sig_minargs ( Potion P,
PN  sig 
)

number of mandatory args, without any optional arguments

Returns
number of args as integer

Definition at line 112 of file objmodel.c.

PN potion_sig_at ( Potion P,
PN  sig,
int  index 
)
Returns
sig tuple at index, zero-based

Definition at line 136 of file objmodel.c.

PN potion_sig_name_at ( Potion P,
PN  sig,
int  index 
)
Returns
sig name at index, zero-based

Definition at line 170 of file objmodel.c.

PN potion_no_call ( Potion P,
PN  cl,
PN  self 
)

Definition at line 194 of file objmodel.c.

void potion_add_metaclass ( Potion P,
vPN(Vtable)  vt 
)

Definition at line 198 of file objmodel.c.

PN potion_type_new ( Potion P,
PNType  t,
PN  self 
)

create a non-user type, derived from self

Definition at line 212 of file objmodel.c.

PN potion_type_new2 ( Potion P,
PNType  t,
PN  self,
PN  name 
)

create a named type

Definition at line 224 of file objmodel.c.

void potion_type_call_is ( PN  vt,
PN  cl 
)

sets the default call method of the PNVtable

Definition at line 230 of file objmodel.c.

PN potion_obj_get_call ( Potion P,
PN  obj 
)

get the default accessor (usually "at")

Definition at line 234 of file objmodel.c.

void potion_type_callset_is ( PN  vt,
PN  cl 
)

set default writer

Definition at line 240 of file objmodel.c.

PN potion_obj_get_callset ( Potion P,
PN  obj 
)

get default writer

Definition at line 244 of file objmodel.c.

void potion_type_constructor_is ( PN  vt,
PN  cl 
)

set default constructor

Definition at line 250 of file objmodel.c.

PN potion_class ( Potion P,
PN  cl,
PN  self,
PN  ivars 
)

create a user-class (ie type)

Parameters
clPNClosure or nil, set the ctor, uses the parent ctor if nil
selfPNVtable the parent class, lobby or another type
ivarsPNTuple of object members

Definition at line 257 of file objmodel.c.

PN potion_class_find ( Potion P,
PN  name 
)

find class by name. At first only system metaclasses (types), no user classes yet.

Definition at line 280 of file objmodel.c.

PNType potion_class_type ( Potion P,
PN  class 
)
Returns
type for the vtable (struct PNVtable only defined in table.h, not exported)

Definition at line 290 of file objmodel.c.

PN potion_ivars ( Potion P,
PN  cl,
PN  self,
PN  ivars 
)

Definition at line 295 of file objmodel.c.

static long potion_obj_find_ivar ( Potion P,
PN  self,
PN  ivar 
)
inlinestatic

Definition at line 310 of file objmodel.c.

PN potion_obj_get ( Potion P,
PN  cl,
PN  self,
PN  ivar 
)

implements OP_GETPATH

Definition at line 327 of file objmodel.c.

PN potion_obj_set ( Potion P,
PN  cl,
PN  self,
PN  ivar,
PN  value 
)

implements OP_SETPATH

Definition at line 334 of file objmodel.c.

PN potion_proto_method ( Potion P,
PN  cl,
PN  self,
PN  args 
)

only used in def_method

Definition at line 343 of file objmodel.c.

PN potion_getter_method ( Potion P,
PN  cl,
PN  self 
)

only used in def_method

Definition at line 347 of file objmodel.c.

PN potion_def_method ( Potion P,
PN  closure,
PN  self,
PN  key,
PN  method 
)

define a method for a class

Definition at line 351 of file objmodel.c.

PN potion_lookup ( Potion P,
PN  closure,
PN  self,
PN  key 
)

used in bind and def_method

Definition at line 396 of file objmodel.c.

PN potion_bind ( Potion P,
PN  rcv,
PN  msg 
)

find method for given receiver and message (method lookup)

Definition at line 408 of file objmodel.c.

PN potion_message ( Potion P,
PN  rcv,
PN  msg 
)

Definition at line 429 of file objmodel.c.

PN potion_obj_add ( Potion P,
PN  a,
PN  b 
)

Definition at line 436 of file objmodel.c.

PN potion_obj_sub ( Potion P,
PN  a,
PN  b 
)

Definition at line 440 of file objmodel.c.

PN potion_obj_mult ( Potion P,
PN  a,
PN  b 
)

Definition at line 444 of file objmodel.c.

PN potion_obj_div ( Potion P,
PN  a,
PN  b 
)

Definition at line 448 of file objmodel.c.

PN potion_obj_rem ( Potion P,
PN  a,
PN  b 
)

Definition at line 452 of file objmodel.c.

PN potion_obj_bitn ( Potion P,
PN  a 
)

Definition at line 456 of file objmodel.c.

PN potion_obj_bitl ( Potion P,
PN  a,
PN  b 
)

Definition at line 460 of file objmodel.c.

PN potion_obj_bitr ( Potion P,
PN  a,
PN  b 
)

Definition at line 464 of file objmodel.c.

static void potion_init_class_reference ( Potion P,
PN  name,
PN  vt 
)
static

Definition at line 620 of file objmodel.c.

void potion_define_global ( Potion P,
PN  name,
PN  val 
)

Definition at line 628 of file objmodel.c.

void potion_object_init ( Potion P)

Definition at line 669 of file objmodel.c.

void potion_lobby_init ( Potion P)

Definition at line 704 of file objmodel.c.