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

The potion API. More...

#include <limits.h>
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#include "config.h"
+ Include dependency graph for potion.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PNObject
 standard objects act like C structs the fields are defined by the type and it's a fixed size, not volatile. More...
 
struct  PNFwd
 forwarding pointer (in case of reallocation) More...
 
struct  PNData
 struct to wrap arbitrary data that we may want to allocate from Potion. More...
 
struct  PNString
 strings are immutable UTF-8, the ID is incremental and they may be garbage collected. More...
 
struct  PNBytes
 byte strings are raw character data, volatile, may be appended/changed. More...
 
struct  PNDouble
 doubles are floating point numbers stored as binary data. More...
 
struct  PNFile
 a file is wrapper around a file descriptor, non-volatile but mutable. More...
 
struct  PNClosure
 a closure is an anonymous function, without closed values, More...
 
struct  PNSource
 
struct  PNProto
 a prototype is compiled source code, a closure block (lambda) non-volatile. More...
 
class  PNTuple
 a tuple is an array of PNs. More...
 
struct  PNWeakRef
 a weak ref is used for upvals, it acts as a memory slot, non-volatile but mutable. More...
 
struct  PNError
 an error, including a description, file location, a brief excerpt. More...
 
struct  PNLick
 a lick is a unit of generic tree data. More...
 
struct  PNCont
 a continuation saves the stack and all stack pointers. More...
 
struct  PNAsm
 
struct  PNTarget
 definition of the jit targets: x86, ppc, arm More...
 
struct  Potion_State
 the global interpreter state P. currently singleton (not threads yet) More...
 
struct  PNMemory
 the garbage collector More...
 

Macros

#define POTION_SIG   "p\07\10n"
 
#define POTION_VMID   0x79
 
#define POTION_X86   0
 
#define POTION_PPC   1
 
#define POTION_ARM   2
 
#define DLLEXPORT
 
#define _XSTR(s)   _STR(s)
 
#define _STR(s)   #s
 
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS   __attribute__((no_address_safety_analysis))
 
#define __WORDSIZE   64
 
#define PN_TNIL   0x250000
 
#define PN_TNUMBER   (1+PN_TNIL)
 
#define PN_TBOOLEAN   (2+PN_TNIL)
 
#define PN_TDOUBLE   (3+PN_TNIL)
 
#define PN_TINTEGER   (4+PN_TNIL)
 
#define PN_TSTRING   (5+PN_TNIL)
 
#define PN_TWEAK   (6+PN_TNIL)
 
#define PN_TCLOSURE   (7+PN_TNIL)
 
#define PN_TTUPLE   (8+PN_TNIL)
 
#define PN_TSTATE   (9+PN_TNIL)
 
#define PN_TFILE   (10+PN_TNIL)
 
#define PN_TOBJECT   (11+PN_TNIL)
 
#define PN_TVTABLE   (12+PN_TNIL)
 
#define PN_TSOURCE   (13+PN_TNIL)
 
#define PN_TBYTES   (14+PN_TNIL)
 
#define PN_TPROTO   (15+PN_TNIL)
 
#define PN_TLOBBY   (16+PN_TNIL)
 
#define PN_TTABLE   (17+PN_TNIL)
 
#define PN_TLICK   (18+PN_TNIL)
 
#define PN_TFLEX   (19+PN_TNIL)
 
#define PN_TSTRINGS   (20+PN_TNIL)
 
#define PN_TERROR   (21+PN_TNIL)
 
#define PN_TCONT   (22+PN_TNIL)
 
#define PN_TUSER   (23+PN_TNIL)
 
#define PN_TYPE(x)   potion_type((PN)(x))
 
#define PN_VTYPE(x)   (((struct PNObject *)(x))->vt)
 
#define PN_TYPE_ID(t)   ((t)-PN_TNIL)
 
#define PN_VTABLE(t)   (PN_FLEX_AT(P->vts, PN_TYPE_ID(t)))
 
#define PN_TYPECHECK(t)   (PN_TYPE_ID(t) >= 0 && PN_TYPE_ID(t) < PN_FLEX_SIZE(P->vts))
 
#define PN_NIL   ((PN)0)
 
#define PN_ZERO   ((PN)1)
 
#define PN_FALSE   ((PN)2)
 
#define PN_TRUE   ((PN)6)
 
#define PN_PRIMITIVE   7
 
#define PN_REF_MASK   ~7
 
#define PN_NONE   ((PN_SIZE)-1)
 
#define POTION_FWD   0xFFFFFFFE
 
#define POTION_COPIED   0xFFFFFFFF
 
#define NIL_NAME   "nil"
 
#define NILKIND_NAME   "NilKind"
 
#define PN_FINTEGER   1
 
#define PN_FBOOLEAN   2
 
#define PN_TEST(v)   ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)
 
#define PN_TEST1(v)   ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)
 
#define PN_BOOL(v)   (PN_TEST(v) ? PN_TRUE : PN_FALSE)
 
#define PN_IS_PTR(v)   (!PN_IS_INT(v) && ((PN)(v) & PN_REF_MASK))
 
#define PN_IS_NIL(v)   ((PN)(v) == PN_NIL)
 
#define PN_IS_BOOL(v)   ((PN)(v) & PN_FBOOLEAN)
 
#define PN_IS_INT(v)   ((PN)(v) & PN_FINTEGER)
 
#define PN_IS_DBL(v)   (PN_IS_PTR(v) && ({PNType _t = potion_qptr_type((PN)v); _t == PN_TNUMBER || _t == PN_TDOUBLE;}))
 
#define PN_IS_NUM(v)   (PN_IS_INT(v) || PN_IS_DBL(v))
 
#define PN_IS_TUPLE(v)   (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTUPLE))
 
#define PN_IS_STR(v)   (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TSTRING))
 
#define PN_IS_TABLE(v)   (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTABLE))
 
#define PN_IS_CLOSURE(v)   (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TCLOSURE))
 
#define PN_IS_PROTO(v)   (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TPROTO))
 
#define PN_IS_REF(v)   (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TWEAK))
 
#define PN_IS_METACLASS(v)   (((struct PNVtable *)v)->meta == PN_NIL)
 
#define PN_IS_FFIPTR(p)
 
#define PN_CHECK_STR(obj)   if (!PN_IS_STR(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "String")
 
#define PN_CHECK_STRB(obj)   if (!PN_IS_STR(obj) || (PN_TYPE(obj) != PN_TBYTES)) return potion_type_error_want(P, ""#obj, (PN)obj, "String or Bytes")
 
#define PN_CHECK_NUM(obj)   if (!PN_IS_NUM(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Number")
 
#define PN_CHECK_INT(obj)   if (!PN_IS_INT(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Integer")
 
#define PN_CHECK_DBL(obj)   if (!PN_IS_DBL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Double")
 
#define PN_CHECK_BOOL(obj)   if (!PN_IS_BOOL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Bool")
 
#define PN_CHECK_TUPLE(obj)   if (!PN_IS_TUPLE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Tuple")
 
#define PN_CHECK_CLOSURE(obj)   if (!PN_IS_CLOSURE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Closure")
 
#define PN_CHECK_TYPE(obj, type)   if (type != PN_TYPE(obj)) return potion_type_error(P, (PN)obj)
 
#define DBG_CHECK_TYPE(obj, type)
 
#define DBG_CHECK_NUM(obj)
 
#define DBG_CHECK_INT(obj)
 
#define DBG_CHECK_DBL(obj)
 
#define DBG_CHECK_TUPLE(obj)
 
#define PN_NUM(i)   ((PN)((((long)(i))<<1) + PN_FINTEGER))
 
#define PN_INT(x)   ((long)((long)(x))>>1)
 
#define PN_DBL(num)   (PN_IS_INT(num) ? (double)PN_INT(num) : ((struct PNDouble *)num)->value)
 
#define PN_PREC   16
 
#define PN_RAND()   PN_NUM(potion_rand_int())
 
#define PN_STR(x)   potion_str(P, x)
 
#define PN_STRN(x, l)   potion_str2(P, x, l)
 
#define PN_STRCAT(a, b)   potion_strcat(P, (a), (b))
 
#define PN_TOUCH(x)   potion_gc_update(P, (PN)(x))
 
#define PN_ALIGN(o, x)   (((((o) - 1) / (x)) + 1) * (x))
 
#define PN_OBJECT_HEADER
 
#define PN_FLEX(N, T)   typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[]; } N
 
#define PN_FLEX_AT(N, I)   ((PNFlex *)(N))->ptr[I]
 
#define PN_FLEX_SIZE(N)   ((PNFlex *)(N))->len
 
#define PN_NUMHASH(x)   (PNUniq)((x)>>33^(x)^(x)<<11)
 
#define PN_UNIQ(x)   (PN_IS_PTR(x) ? ((struct PNObject *)(x))->uniq : PN_NUMHASH(x))
 
#define AS_STR(x)   PN_STR_PTR(potion_send(x, PN_string))
 
#define DBG_t(...)
 
#define DBG_v(...)
 
#define DBG_vt(...)
 
#define DBG_vi(...)
 
#define DBG_c(...)
 
#define PN_MANTISSA(d, n)   d->real[1 + n]
 PN_MANTISSA the last part of ->real. More...
 
#define PN_QUICK_FWD(t, obj)
 PN_QUICK_FWD - doing a single fwd check after a possible realloc. More...
 
#define OP_MAX   50
 the jit More...
 
#define EXEC_BITS   4
 0-4 More...
 
#define POTION_INIT_STACK(x)   PN __##x = 0x571FF; void *x = (void *)&__##x
 
#define POTION_OK   0
 internal errors More...
 
#define POTION_NO_MEM   8910
 
#define potion_send(RCV, MSG, ARGS...)
 method caches (more great stuff from ian piumarta) More...
 
#define potion_method(RCV, MSG, FN, SIG)   potion_send(RCV, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))
 
#define potion_class_method(RCV, MSG, FN, SIG)   potion_send(((struct PNVtable *)(RCV))->meta, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))
 

Typedefs

typedef unsigned long _PN
 
typedef unsigned int PN_SIZE
 
typedef unsigned int PNType
 
typedef unsigned int PNUniq
 
typedef struct Potion_State Potion
 
typedef volatile _PN PN
 
typedef _PN(* PN_F )(Potion *, PN, PN,...)
 
typedef void(* OP_F )(Potion *P, struct PNProto *, PNAsm *volatile *,...)
 

Enumerations

enum  PN_AST {
  AST_CODE, AST_VALUE, AST_ASSIGN, AST_NOT,
  AST_OR, AST_AND, AST_CMP, AST_EQ,
  AST_NEQ, AST_GT, AST_GTE, AST_LT,
  AST_LTE, AST_PIPE, AST_CARET, AST_AMP,
  AST_WAVY, AST_BITL, AST_BITR, AST_PLUS,
  AST_MINUS, AST_INC, AST_TIMES, AST_DIV,
  AST_REM, AST_POW, AST_MSG, AST_PATH,
  AST_QUERY, AST_PATHQ, AST_EXPR, AST_LIST,
  AST_BLOCK, AST_LICK, AST_PROTO, AST_DEBUG
}
 An AST fragment, non-volatile. More...
 
enum  exec_mode_t {
  EXEC_VM = 0, EXEC_JIT = 1, EXEC_DEBUG = 2, EXEC_CHECK = 3,
  EXEC_COMPILE = 4, MAX_EXEC = 5
}
 the interpreter (one per thread, houses its own garbage collector) More...
 
enum  syntax_mode_t { MODE_STD = 1<<EXEC_BITS, MAX_SYNTAX = (1<<(EXEC_BITS+2))-1 }
 
enum  Potion_Flags { DEBUG_INSPECT = 1<<(EXEC_BITS+2), DEBUG_VERBOSE = 1<<(EXEC_BITS+3) }
 

Functions

static PN potion_fwd (PN)
 the potion type is the 't' in the vtable tuple (m,t) More...
 
static PNType potion_type (PN obj)
 either immediate (NUM,BOOL,NIL) or a fwd More...
 
static PNType potion_ptr_type (PN obj)
 if obj is guaranteed to be a PTR More...
 
static PNType potion_qptr_type (PN obj)
 if obj is guaranteed to be a PTR fwd only once, no loop. More...
 
static char * potion_str_ptr (PN s)
 quick access to either PNString or PNByte pointer More...
 
 PN_FLEX (PNFlex, PN)
 
void potion_garbagecollect (Potion *, int, int)
 
PN_SIZE potion_type_size (Potion *, const struct PNObject *)
 
unsigned long potion_rand_int ()
 generates a random number on [0,0xffffffff]-interval More...
 
double potion_rand_double ()
 generates a random number on [0,1) with 53-bit resolution More...
 
static void * potion_gc_alloc (Potion *P, PNType vt, int siz)
 quick inline allocation More...
 
static void * potion_gc_calloc (Potion *P, PNType vt, int siz)
 
static void potion_gc_update (Potion *P, PN x)
 
static void * potion_gc_realloc (Potion *P, PNType vt, struct PNObject *volatile obj, PN_SIZE sz)
 
static PN potion_type_default (char type)
 zero values per type More...
 
Potionpotion_create (void *)
 the potion API More...
 
void potion_destroy (Potion *)
 
PN potion_error (Potion *, PN, long, long, PN)
 
void potion_fatal (char *)
 
void potion_allocation_error (void)
 
PN potion_io_error (Potion *, const char *)
 
PN potion_type_error (Potion *, PN)
 
PN potion_type_error_want (Potion *, const char *, PN, const char *)
 
void potion_syntax_error (Potion *, struct PNSource *, const char *,...) __attribute__((format(printf
 
void PNType potion_kind_of (PN)
 
void potion_p (Potion *, PN)
 
PN potion_str (Potion *, const char *)
 
PN potion_str2 (Potion *, char *, size_t)
 
PN potion_strcat (Potion *P, char *str, char *str2)
 
PN potion_str_add (Potion *P, PN, PN, PN)
 
PN potion_str_format (Potion *, const char *,...) __attribute__((format(printf
 
PN PN potion_byte_str (Potion *, const char *)
 
PN potion_byte_str2 (Potion *, const char *, size_t len)
 
PN potion_bytes (Potion *, size_t)
 
PN potion_bytes_string (Potion *, PN, PN)
 
PN_SIZE pn_printf (Potion *, PN, const char *,...) __attribute__((format(printf
 
PN_SIZE void potion_bytes_obj_string (Potion *, PN, PN)
 
PN potion_bytes_append (Potion *, PN, PN, PN)
 
void potion_release (Potion *, PN)
 
PN potion_def_method (Potion *P, PN, PN, PN, PN)
 define a method for a class More...
 
PN potion_type_new (Potion *, PNType, PN)
 create a non-user type, derived from self More...
 
PN potion_type_new2 (Potion *, PNType, PN, PN)
 create a named type More...
 
void potion_type_call_is (PN, PN)
 sets the default call method of the PNVtable More...
 
void potion_type_callset_is (PN, PN)
 set default writer More...
 
void potion_type_constructor_is (PN, PN)
 set default constructor More...
 
char potion_type_char (PNType)
 valid signature types syntax.y: arg-type = ('s' | 'S' | 'n' | 'N' | 'b' | 'B' | 'k' | 't' | 'o' | 'O' | '-' | '&') valid signature modifiers: '|' optional, '. More...
 
PN potion_class (Potion *, PN, PN, PN)
 create a user-class (ie type) More...
 
PN potion_ivars (Potion *, PN, PN, PN)
 
PN potion_obj_get_call (Potion *, PN)
 get the default accessor (usually "at") More...
 
PN potion_obj_get_callset (Potion *, PN)
 get default writer More...
 
PN potion_obj_get (Potion *, PN, PN, PN)
 implements OP_GETPATH More...
 
PN potion_obj_set (Potion *, PN, PN, PN, PN)
 implements OP_SETPATH More...
 
PN potion_object_new (Potion *, PN, PN)
 
PN potion_delegated (Potion *, PN, PN)
 
PN potion_call (Potion *, PN, PN_SIZE, PN *volatile)
 
PN potion_lookup (Potion *, PN, PN, PN)
 used in bind and def_method More...
 
PN potion_bind (Potion *, PN, PN)
 find method for given receiver and message (method lookup) More...
 
PN potion_message (Potion *, PN, PN)
 
PN potion_closure_new (Potion *, PN_F, PN, PN_SIZE)
 
PN potion_callcc (Potion *, PN, PN)
 
PN potion_ref (Potion *, PN)
 
PN potion_sig (Potion *, char *)
 
int potion_sig_find (Potion *, PN, PN)
 
PN potion_double (Potion *, double)
 new PNDouble (double) More...
 
PN potion_strtod (Potion *, char *, int)
 Convert string to double. More...
 
PN potion_num_pow (Potion *, PN, PN, PN)
 
PN potion_num_rand (Potion *, PN, PN)
 
PN potion_srand (Potion *, PN, PN, PN)
 
PN potion_rand (Potion *, PN, PN)
 
PN potion_sig_at (Potion *, PN, int)
 
PN potion_sig_name_at (Potion *, PN, int)
 
int potion_sig_arity (Potion *, PN)
 number of args of sig tuple, implements the potion_closure_arity method. More...
 
int potion_sig_minargs (Potion *, PN)
 number of mandatory args, without any optional arguments More...
 
PN potion_closure_arity (Potion *, PN, PN)
 
PN potion_closure_minargs (Potion *, PN, PN)
 
void potion_define_global (Potion *, PN, PN)
 
PN potion_obj_add (Potion *, PN, PN)
 
PN potion_obj_sub (Potion *, PN, PN)
 
PN potion_obj_mult (Potion *, PN, PN)
 
PN potion_obj_div (Potion *, PN, PN)
 
PN potion_obj_rem (Potion *, PN, PN)
 
PN potion_obj_bitn (Potion *, PN)
 
PN potion_obj_bitl (Potion *, PN, PN)
 
PN potion_obj_bitr (Potion *, PN, PN)
 
PN potion_any_cmp (Potion *, PN, PN, PN)
 
PN potion_tuple_empty (Potion *)
 
PN potion_tuple_with_size (Potion *, unsigned long)
 
PN potion_tuple_new (Potion *, PN)
 
PN potion_tuple_push (Potion *, PN, PN)
 
PN_SIZE potion_tuple_push_unless (Potion *, PN, PN)
 
PN_SIZE potion_tuple_find (Potion *, PN, PN)
 Return index of found value or PN_NONE. More...
 
PN potion_tuple_at (Potion *, PN, PN, PN)
 
PN potion_tuple_shift (Potion *, PN, PN)
 
PN potion_tuple_bsearch (Potion *, PN, PN, PN)
 
PN potion_tuple_ins_sort (Potion *, PN, PN, PN)
 
PN potion_table_empty (Potion *)
 
PN potion_table_put (Potion *, PN, PN, PN, PN)
 
PN potion_table_set (Potion *, PN, PN, PN)
 helper function for potion_table_put:"put", accepts tuple or table More...
 
PN potion_table_at (Potion *, PN, PN, PN)
 
PN potion_lick (Potion *, PN, PN, PN)
 
PN potion_source_compile (Potion *, PN, PN, PN, PN)
 
PN potion_source_load (Potion *, PN, PN)
 
PN potion_source_dump (Potion *, PN, PN, PN, PN)
 
PN potion_source_dumpbc (Potion *, PN, PN, PN)
 
PN potion_greg_parse (Potion *, PN)
 
PN potion_sig_string (Potion *, PN, PN)
 
PN potion_filename_find (Potion *, PN)
 
PN potion_filename_push (Potion *, PN)
 
Potionpotion_gc_boot (void *)
 
void potion_lobby_init (Potion *)
 
void potion_object_init (Potion *)
 
void potion_error_init (Potion *)
 
void potion_primitive_init (Potion *)
 
void potion_num_init (Potion *)
 
void potion_str_hash_init (Potion *)
 
void potion_str_init (Potion *)
 
void potion_table_init (Potion *)
 
void potion_source_init (Potion *)
 
void potion_lick_init (Potion *)
 
void potion_compiler_init (Potion *)
 
void potion_vm_init (Potion *)
 
void potion_cont_init (Potion *)
 
void potion_file_init (Potion *)
 set Env global More...
 
void potion_loader_init (Potion *)
 
void potion_loader_add (Potion *, PN path)
 
PN potion_load (Potion *, PN, PN, PN)
 
char * potion_find_file (Potion *, char *str, PN_SIZE str_len)
 
PN potion_any_is_nil (Potion *, PN, PN)
 
void potion_dump_stack (Potion *)
 
PN potion_num_string (Potion *, PN, PN)
 
PN potion_gc_reserved (Potion *, PN, PN)
 
PN potion_gc_actual (Potion *, PN, PN)
 
PN potion_gc_fixed (Potion *, PN, PN)
 
PN potion_parse (Potion *, PN, char *)
 
PN potion_vm_proto (Potion *, PN, PN,...)
 entrypoint for all bytecode methods from the C api. More...
 
PN potion_vm_class (Potion *, PN, PN)
 implements the class op creates a class (or type) from a closure and parent class with obj ivars More...
 
PN potion_vm (Potion *, PN, PN, PN, PN_SIZE, PN *volatile)
 the bytecode run-loop More...
 
PN potion_eval (Potion *, PN)
 
PN potion_run (Potion *, PN, int)
 
PN_F potion_jit_proto (Potion *, PN)
 
PN potion_class_find (Potion *, PN)
 find class by name. At first only system metaclasses (types), no user classes yet. More...
 
PNType potion_class_type (Potion *, PN)
 

Variables

PN PN_allocate
 common method names in GC protected area More...
 
PN PN_break
 
PN PN_call
 
PN PN_class
 
PN PN_compile
 
PN PN_continue
 
PN PN_def
 
PN PN_delegated
 
PN PN_else
 
PN PN_elsif
 
PN PN_if
 
PN PN_lookup
 
PN PN_loop
 
PN PN_print
 
PN PN_return
 
PN PN_self
 
PN PN_string
 
PN PN_while
 
PN PN_add
 
PN PN_sub
 
PN PN_mult
 
PN PN_div
 
PN PN_rem
 
PN PN_bitn
 
PN PN_bitl
 
PN PN_bitr
 
PN PN_cmp
 
PN PN_number
 
PN PN_name
 
PN PN_length
 
PN PN_size
 
PN PN_STR0
 
PN PN_extern
 
PN PN_integer
 
PN pn_filenames
 

Detailed Description

The potion API.

(c) 2008 why the lucky stiff, the freelance professor (c) 2013-2015 perl11.org

Definition in file potion.h.

Macro Definition Documentation

#define POTION_SIG   "p\07\10n"

Definition at line 42 of file potion.h.

#define POTION_VMID   0x79

Definition at line 43 of file potion.h.

#define POTION_X86   0

Definition at line 45 of file potion.h.

#define POTION_PPC   1

Definition at line 46 of file potion.h.

#define POTION_ARM   2

Definition at line 47 of file potion.h.

#define DLLEXPORT

Definition at line 58 of file potion.h.

#define _XSTR (   s)    _STR(s)

Definition at line 61 of file potion.h.

#define _STR (   s)    #s

Definition at line 62 of file potion.h.

#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS   __attribute__((no_address_safety_analysis))

Definition at line 65 of file potion.h.

#define __WORDSIZE   64

Definition at line 101 of file potion.h.

#define PN_TNIL   0x250000

Definition at line 107 of file potion.h.

#define PN_TNUMBER   (1+PN_TNIL)

Definition at line 108 of file potion.h.

#define PN_TBOOLEAN   (2+PN_TNIL)

Definition at line 109 of file potion.h.

#define PN_TDOUBLE   (3+PN_TNIL)

Definition at line 110 of file potion.h.

#define PN_TINTEGER   (4+PN_TNIL)

Definition at line 111 of file potion.h.

#define PN_TSTRING   (5+PN_TNIL)

Definition at line 112 of file potion.h.

#define PN_TWEAK   (6+PN_TNIL)

Definition at line 113 of file potion.h.

#define PN_TCLOSURE   (7+PN_TNIL)

Definition at line 114 of file potion.h.

#define PN_TTUPLE   (8+PN_TNIL)

Definition at line 115 of file potion.h.

#define PN_TSTATE   (9+PN_TNIL)

Definition at line 116 of file potion.h.

#define PN_TFILE   (10+PN_TNIL)

Definition at line 117 of file potion.h.

#define PN_TOBJECT   (11+PN_TNIL)

Definition at line 118 of file potion.h.

#define PN_TVTABLE   (12+PN_TNIL)

Definition at line 119 of file potion.h.

#define PN_TSOURCE   (13+PN_TNIL)

Definition at line 120 of file potion.h.

#define PN_TBYTES   (14+PN_TNIL)

Definition at line 121 of file potion.h.

#define PN_TPROTO   (15+PN_TNIL)

Definition at line 122 of file potion.h.

#define PN_TLOBBY   (16+PN_TNIL)

Definition at line 123 of file potion.h.

#define PN_TTABLE   (17+PN_TNIL)

Definition at line 124 of file potion.h.

#define PN_TLICK   (18+PN_TNIL)

Definition at line 125 of file potion.h.

#define PN_TFLEX   (19+PN_TNIL)

Definition at line 126 of file potion.h.

#define PN_TSTRINGS   (20+PN_TNIL)

Definition at line 127 of file potion.h.

#define PN_TERROR   (21+PN_TNIL)

Definition at line 128 of file potion.h.

#define PN_TCONT   (22+PN_TNIL)

Definition at line 129 of file potion.h.

#define PN_TUSER   (23+PN_TNIL)

Definition at line 130 of file potion.h.

#define PN_TYPE (   x)    potion_type((PN)(x))

Definition at line 133 of file potion.h.

#define PN_VTYPE (   x)    (((struct PNObject *)(x))->vt)

Definition at line 134 of file potion.h.

#define PN_TYPE_ID (   t)    ((t)-PN_TNIL)

Definition at line 135 of file potion.h.

#define PN_VTABLE (   t)    (PN_FLEX_AT(P->vts, PN_TYPE_ID(t)))

Definition at line 136 of file potion.h.

#define PN_TYPECHECK (   t)    (PN_TYPE_ID(t) >= 0 && PN_TYPE_ID(t) < PN_FLEX_SIZE(P->vts))

Definition at line 137 of file potion.h.

#define PN_NIL   ((PN)0)

Definition at line 139 of file potion.h.

#define PN_ZERO   ((PN)1)

Definition at line 140 of file potion.h.

#define PN_FALSE   ((PN)2)

Definition at line 141 of file potion.h.

#define PN_TRUE   ((PN)6)

Definition at line 142 of file potion.h.

#define PN_PRIMITIVE   7

Definition at line 143 of file potion.h.

#define PN_REF_MASK   ~7

Definition at line 144 of file potion.h.

#define PN_NONE   ((PN_SIZE)-1)

Definition at line 145 of file potion.h.

#define POTION_FWD   0xFFFFFFFE

Definition at line 146 of file potion.h.

#define POTION_COPIED   0xFFFFFFFF

Definition at line 147 of file potion.h.

#define NIL_NAME   "nil"

Definition at line 149 of file potion.h.

#define NILKIND_NAME   "NilKind"

Definition at line 150 of file potion.h.

#define PN_FINTEGER   1

Definition at line 152 of file potion.h.

#define PN_FBOOLEAN   2

Definition at line 153 of file potion.h.

#define PN_TEST (   v)    ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)

Definition at line 162 of file potion.h.

#define PN_TEST1 (   v)    ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)

Definition at line 163 of file potion.h.

#define PN_BOOL (   v)    (PN_TEST(v) ? PN_TRUE : PN_FALSE)

Definition at line 167 of file potion.h.

#define PN_IS_PTR (   v)    (!PN_IS_INT(v) && ((PN)(v) & PN_REF_MASK))

Definition at line 168 of file potion.h.

#define PN_IS_NIL (   v)    ((PN)(v) == PN_NIL)

Definition at line 169 of file potion.h.

#define PN_IS_BOOL (   v)    ((PN)(v) & PN_FBOOLEAN)

Definition at line 170 of file potion.h.

#define PN_IS_INT (   v)    ((PN)(v) & PN_FINTEGER)

Definition at line 171 of file potion.h.

#define PN_IS_DBL (   v)    (PN_IS_PTR(v) && ({PNType _t = potion_qptr_type((PN)v); _t == PN_TNUMBER || _t == PN_TDOUBLE;}))

Definition at line 172 of file potion.h.

#define PN_IS_NUM (   v)    (PN_IS_INT(v) || PN_IS_DBL(v))

Definition at line 173 of file potion.h.

#define PN_IS_TUPLE (   v)    (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTUPLE))

Definition at line 174 of file potion.h.

#define PN_IS_STR (   v)    (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TSTRING))

Definition at line 175 of file potion.h.

#define PN_IS_TABLE (   v)    (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTABLE))

Definition at line 176 of file potion.h.

#define PN_IS_CLOSURE (   v)    (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TCLOSURE))

Definition at line 177 of file potion.h.

#define PN_IS_PROTO (   v)    (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TPROTO))

Definition at line 178 of file potion.h.

#define PN_IS_REF (   v)    (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TWEAK))

Definition at line 179 of file potion.h.

#define PN_IS_METACLASS (   v)    (((struct PNVtable *)v)->meta == PN_NIL)

Definition at line 180 of file potion.h.

#define PN_IS_FFIPTR (   p)
Value:
((PN_IS_PTR(p) && !(p >= (_PN)P->mem && p <= (_PN)P->mem->birth_hi)) \
|| (!PN_IS_PTR(p) && p > (_PN)P->mem->birth_hi))
unsigned long _PN
Definition: potion.h:78
#define PN_IS_PTR(v)
Definition: potion.h:168

Definition at line 181 of file potion.h.

#define PN_CHECK_STR (   obj)    if (!PN_IS_STR(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "String")

Definition at line 184 of file potion.h.

#define PN_CHECK_STRB (   obj)    if (!PN_IS_STR(obj) || (PN_TYPE(obj) != PN_TBYTES)) return potion_type_error_want(P, ""#obj, (PN)obj, "String or Bytes")

Definition at line 185 of file potion.h.

#define PN_CHECK_NUM (   obj)    if (!PN_IS_NUM(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Number")

Definition at line 186 of file potion.h.

#define PN_CHECK_INT (   obj)    if (!PN_IS_INT(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Integer")

Definition at line 187 of file potion.h.

#define PN_CHECK_DBL (   obj)    if (!PN_IS_DBL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Double")

Definition at line 188 of file potion.h.

#define PN_CHECK_BOOL (   obj)    if (!PN_IS_BOOL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Bool")

Definition at line 189 of file potion.h.

#define PN_CHECK_TUPLE (   obj)    if (!PN_IS_TUPLE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Tuple")

Definition at line 190 of file potion.h.

#define PN_CHECK_CLOSURE (   obj)    if (!PN_IS_CLOSURE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Closure")

Definition at line 191 of file potion.h.

#define PN_CHECK_TYPE (   obj,
  type 
)    if (type != PN_TYPE(obj)) return potion_type_error(P, (PN)obj)

Definition at line 193 of file potion.h.

#define DBG_CHECK_TYPE (   obj,
  type 
)

Definition at line 201 of file potion.h.

#define DBG_CHECK_NUM (   obj)

Definition at line 202 of file potion.h.

#define DBG_CHECK_INT (   obj)

Definition at line 203 of file potion.h.

#define DBG_CHECK_DBL (   obj)

Definition at line 204 of file potion.h.

#define DBG_CHECK_TUPLE (   obj)

Definition at line 205 of file potion.h.

#define PN_NUM (   i)    ((PN)((((long)(i))<<1) + PN_FINTEGER))

Definition at line 213 of file potion.h.

#define PN_INT (   x)    ((long)((long)(x))>>1)

Definition at line 214 of file potion.h.

#define PN_DBL (   num)    (PN_IS_INT(num) ? (double)PN_INT(num) : ((struct PNDouble *)num)->value)

Definition at line 215 of file potion.h.

#define PN_PREC   16

Definition at line 217 of file potion.h.

#define PN_RAND ( )    PN_NUM(potion_rand_int())

Definition at line 218 of file potion.h.

#define PN_STR (   x)    potion_str(P, x)

Definition at line 219 of file potion.h.

#define PN_STRN (   x,
 
)    potion_str2(P, x, l)

Definition at line 220 of file potion.h.

#define PN_STRCAT (   a,
 
)    potion_strcat(P, (a), (b))

Definition at line 221 of file potion.h.

#define PN_TOUCH (   x)    potion_gc_update(P, (PN)(x))

Definition at line 231 of file potion.h.

#define PN_ALIGN (   o,
 
)    (((((o) - 1) / (x)) + 1) * (x))

Definition at line 232 of file potion.h.

#define PN_OBJECT_HEADER
Value:
PNType vt; \
PNUniq uniq
unsigned int PNUniq
Definition: potion.h:79
unsigned int PNType
Definition: potion.h:79

Definition at line 234 of file potion.h.

#define PN_FLEX (   N,
 
)    typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[]; } N

Definition at line 238 of file potion.h.

#define PN_FLEX_AT (   N,
 
)    ((PNFlex *)(N))->ptr[I]

Definition at line 239 of file potion.h.

#define PN_FLEX_SIZE (   N)    ((PNFlex *)(N))->len

Definition at line 240 of file potion.h.

#define PN_NUMHASH (   x)    (PNUniq)((x)>>33^(x)^(x)<<11)

Definition at line 245 of file potion.h.

#define PN_UNIQ (   x)    (PN_IS_PTR(x) ? ((struct PNObject *)(x))->uniq : PN_NUMHASH(x))

Definition at line 247 of file potion.h.

#define AS_STR (   x)    PN_STR_PTR(potion_send(x, PN_string))

Definition at line 249 of file potion.h.

#define DBG_t (   ...)

Definition at line 262 of file potion.h.

#define DBG_v (   ...)

Definition at line 263 of file potion.h.

#define DBG_vt (   ...)

Definition at line 264 of file potion.h.

#define DBG_vi (   ...)

Definition at line 265 of file potion.h.

#define DBG_c (   ...)

Definition at line 266 of file potion.h.

#define PN_MANTISSA (   d,
 
)    d->real[1 + n]

PN_MANTISSA the last part of ->real.

Definition at line 355 of file potion.h.

#define PN_QUICK_FWD (   t,
  obj 
)
Value:
if (((struct PNFwd *)obj)->fwd == POTION_FWD) \
obj = (t)(((struct PNFwd *)obj)->ptr);
forwarding pointer (in case of reallocation)
Definition: potion.h:313
unsigned int fwd
Definition: potion.h:314
#define POTION_FWD
Definition: potion.h:146

PN_QUICK_FWD - doing a single fwd check after a possible realloc.

Definition at line 558 of file potion.h.

#define OP_MAX   50

the jit

Definition at line 591 of file potion.h.

#define EXEC_BITS   4

0-4

Definition at line 625 of file potion.h.

#define POTION_INIT_STACK (   x)    PN __##x = 0x571FF; void *x = (void *)&__##x

Definition at line 692 of file potion.h.

#define POTION_OK   0

internal errors

Definition at line 774 of file potion.h.

#define POTION_NO_MEM   8910

Definition at line 775 of file potion.h.

#define potion_send (   RCV,
  MSG,
  ARGS... 
)
Value:
({ \
PN r = (PN)(RCV); \
PN c = potion_bind(P, r, (MSG)); \
if (PN_IS_CLOSURE(c)) \
c = ((struct PNClosure *)c)->method(P, c, r, ##ARGS); \
c; \
})
a closure is an anonymous function, without closed values,
Definition: potion.h:381
#define PN_IS_CLOSURE(v)
Definition: potion.h:177
PN potion_bind(Potion *, PN, PN)
find method for given receiver and message (method lookup)
Definition: objmodel.c:408
volatile _PN PN
Definition: potion.h:81

method caches (more great stuff from ian piumarta)

Definition at line 781 of file potion.h.

#define potion_method (   RCV,
  MSG,
  FN,
  SIG 
)    potion_send(RCV, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))

Definition at line 789 of file potion.h.

#define potion_class_method (   RCV,
  MSG,
  FN,
  SIG 
)    potion_send(((struct PNVtable *)(RCV))->meta, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))

Definition at line 791 of file potion.h.

Typedef Documentation

typedef unsigned long _PN

Definition at line 78 of file potion.h.

typedef unsigned int PN_SIZE

Definition at line 79 of file potion.h.

typedef unsigned int PNType

Definition at line 79 of file potion.h.

typedef unsigned int PNUniq

Definition at line 79 of file potion.h.

typedef struct Potion_State Potion

Definition at line 80 of file potion.h.

typedef volatile _PN PN

Definition at line 81 of file potion.h.

typedef _PN(* PN_F)(Potion *, PN, PN,...)

Definition at line 216 of file potion.h.

typedef void(* OP_F)(Potion *P, struct PNProto *, PNAsm *volatile *,...)

Definition at line 593 of file potion.h.

Enumeration Type Documentation

enum PN_AST

An AST fragment, non-volatile.

Enumerator
AST_CODE 
AST_VALUE 
AST_ASSIGN 
AST_NOT 
AST_OR 
AST_AND 
AST_CMP 
AST_EQ 
AST_NEQ 
AST_GT 
AST_GTE 
AST_LT 
AST_LTE 
AST_PIPE 
AST_CARET 
AST_AMP 
AST_WAVY 
AST_BITL 
AST_BITR 
AST_PLUS 
AST_MINUS 
AST_INC 
AST_TIMES 
AST_DIV 
AST_REM 
AST_POW 
AST_MSG 
AST_PATH 
AST_QUERY 
AST_PATHQ 
AST_EXPR 
AST_LIST 
AST_BLOCK 
AST_LICK 
AST_PROTO 
AST_DEBUG 

Definition at line 395 of file potion.h.

the interpreter (one per thread, houses its own garbage collector)

Enumerator
EXEC_VM 

bytecode (switch or cgoto)

EXEC_JIT 

JIT if detected at config-time (x86, ppc)

EXEC_DEBUG 

-d: instrumented bytecode (line stepping) or just slow runloop?

EXEC_CHECK 

-c stop after compilation

EXEC_COMPILE 

to bytecode (dumpbc)

MAX_EXEC 

sanity-check (possible stack overwrites by callcc)

Definition at line 614 of file potion.h.

Enumerator
MODE_STD 

0x10 16 plain potion syntax

MAX_SYNTAX 

sanity-check

Definition at line 627 of file potion.h.

Enumerator
DEBUG_INSPECT 
DEBUG_VERBOSE 

Definition at line 637 of file potion.h.

Function Documentation

static PN potion_fwd ( PN  obj)
inlinestatic

the potion type is the 't' in the vtable tuple (m,t)

resolve forwarding pointers for mutable types (PNTuple, PNBytes, etc.)

Definition at line 570 of file potion.h.

static PNType potion_type ( PN  obj)
inlinestatic

either immediate (NUM,BOOL,NIL) or a fwd

Definition at line 532 of file potion.h.

static PNType potion_ptr_type ( PN  obj)
inlinestatic

if obj is guaranteed to be a PTR

Definition at line 549 of file potion.h.

static PNType potion_qptr_type ( PN  obj)
inlinestatic

if obj is guaranteed to be a PTR fwd only once, no loop.

Definition at line 564 of file potion.h.

static char* potion_str_ptr ( PN  s)
inlinestatic

quick access to either PNString or PNByte pointer

Definition at line 577 of file potion.h.

PN_FLEX ( PNFlex  ,
PN   
)
void potion_garbagecollect ( Potion ,
int  ,
int   
)

Definition at line 266 of file gc.c.

PN_SIZE potion_type_size ( Potion ,
const struct PNObject  
)

Definition at line 306 of file gc.c.

unsigned long potion_rand_int ( )

generates a random number on [0,0xffffffff]-interval

Definition at line 138 of file mt19937ar.c.

double potion_rand_double ( )

generates a random number on [0,1) with 53-bit resolution

Definition at line 154 of file mt19937ar.c.

static void* potion_gc_alloc ( Potion P,
PNType  vt,
int  siz 
)
inlinestatic

quick inline allocation

Definition at line 700 of file potion.h.

static void* potion_gc_calloc ( Potion P,
PNType  vt,
int  siz 
)
inlinestatic

Definition at line 724 of file potion.h.

static void potion_gc_update ( Potion P,
PN  x 
)
inlinestatic

Definition at line 728 of file potion.h.

static void* potion_gc_realloc ( Potion P,
PNType  vt,
struct PNObject *volatile  obj,
PN_SIZE  sz 
)
inlinestatic

Definition at line 740 of file potion.h.

static PN potion_type_default ( char  type)
inlinestatic

zero values per type

Definition at line 805 of file potion.h.

Potion* potion_create ( void *  )

the potion API

Definition at line 124 of file internal.c.

void potion_destroy ( Potion )

Definition at line 137 of file internal.c.

PN potion_error ( Potion ,
PN  ,
long  ,
long  ,
PN   
)

Definition at line 236 of file internal.c.

void potion_fatal ( char *  )

Definition at line 286 of file internal.c.

void potion_allocation_error ( void  )

Definition at line 305 of file internal.c.

PN potion_io_error ( Potion ,
const char *   
)

Definition at line 259 of file internal.c.

PN potion_type_error ( Potion ,
PN   
)

Definition at line 273 of file internal.c.

PN potion_type_error_want ( Potion ,
const char *  ,
PN  ,
const char *   
)

Definition at line 277 of file internal.c.

void potion_syntax_error ( Potion ,
struct PNSource ,
const char *  ,
  ... 
)
void PNType potion_kind_of ( PN  )

Definition at line 199 of file internal.c.

void potion_p ( Potion ,
PN   
)

Definition at line 310 of file internal.c.

PN potion_str ( Potion ,
const char *   
)

Definition at line 33 of file string.c.

PN potion_str2 ( Potion ,
char *  ,
size_t   
)

Definition at line 47 of file string.c.

PN potion_strcat ( Potion P,
char *  str,
char *  str2 
)

Definition at line 64 of file string.c.

PN potion_str_add ( Potion P,
PN  ,
PN  ,
PN   
)
PN potion_str_format ( Potion ,
const char *  ,
  ... 
)
PN PN potion_byte_str ( Potion ,
const char *   
)

Definition at line 331 of file string.c.

PN potion_byte_str2 ( Potion ,
const char *  ,
size_t  len 
)

Definition at line 335 of file string.c.

PN potion_bytes ( Potion ,
size_t   
)

Definition at line 342 of file string.c.

PN potion_bytes_string ( Potion ,
PN  ,
PN   
)
PN_SIZE pn_printf ( Potion ,
PN  ,
const char *  ,
  ... 
)
PN_SIZE void potion_bytes_obj_string ( Potion ,
PN  ,
PN   
)

Definition at line 384 of file string.c.

PN potion_bytes_append ( Potion ,
PN  ,
PN  ,
PN   
)
void potion_release ( Potion ,
PN   
)
PN potion_def_method ( Potion P,
PN  ,
PN  ,
PN  ,
PN   
)

define a method for a class

Definition at line 351 of file objmodel.c.

PN potion_type_new ( Potion ,
PNType  ,
PN   
)

create a non-user type, derived from self

Definition at line 212 of file objmodel.c.

PN potion_type_new2 ( Potion ,
PNType  ,
PN  ,
PN   
)

create a named type

Definition at line 224 of file objmodel.c.

void potion_type_call_is ( PN  ,
PN   
)

sets the default call method of the PNVtable

Definition at line 230 of file objmodel.c.

void potion_type_callset_is ( PN  ,
PN   
)

set default writer

Definition at line 240 of file objmodel.c.

void potion_type_constructor_is ( PN  ,
PN   
)

set default constructor

Definition at line 250 of file objmodel.c.

char potion_type_char ( PNType  type)

valid signature types syntax.y: arg-type = ('s' | 'S' | 'n' | 'N' | 'b' | 'B' | 'k' | 't' | 'o' | 'O' | '-' | '&') valid signature modifiers: '|' optional, '.

' end, ':' default

Definition at line 206 of file internal.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_ivars ( Potion ,
PN  ,
PN  ,
PN   
)

Definition at line 295 of file objmodel.c.

PN potion_obj_get_call ( Potion ,
PN   
)

get the default accessor (usually "at")

Definition at line 234 of file objmodel.c.

PN potion_obj_get_callset ( Potion ,
PN   
)

get default writer

Definition at line 244 of file objmodel.c.

PN potion_obj_get ( Potion ,
PN  ,
PN  ,
PN   
)

implements OP_GETPATH

Definition at line 327 of file objmodel.c.

PN potion_obj_set ( Potion ,
PN  ,
PN  ,
PN  ,
PN   
)

implements OP_SETPATH

Definition at line 334 of file objmodel.c.

PN potion_object_new ( Potion ,
PN  ,
PN   
)
PN potion_delegated ( Potion ,
PN  ,
PN   
)

Definition at line 141 of file internal.c.

PN potion_call ( Potion ,
PN  ,
PN_SIZE  ,
PN volatile 
)

Definition at line 147 of file internal.c.

PN potion_lookup ( Potion ,
PN  ,
PN  ,
PN   
)

used in bind and def_method

Definition at line 396 of file objmodel.c.

PN potion_bind ( Potion ,
PN  ,
PN   
)

find method for given receiver and message (method lookup)

Definition at line 408 of file objmodel.c.

PN potion_message ( Potion ,
PN  ,
PN   
)

Definition at line 429 of file objmodel.c.

PN potion_closure_new ( Potion ,
PN_F  ,
PN  ,
PN_SIZE   
)

Definition at line 17 of file objmodel.c.

PN potion_callcc ( Potion ,
PN  ,
PN   
)
PN potion_ref ( Potion ,
PN   
)
PN potion_sig ( Potion ,
char *   
)
int potion_sig_find ( Potion ,
PN  ,
PN   
)
PN potion_double ( Potion ,
double   
)

new PNDouble (double)

Definition at line 17 of file number.c.

PN potion_strtod ( Potion ,
char *  ,
int   
)

Convert string to double.

Definition at line 24 of file number.c.

PN potion_num_pow ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_num_rand ( Potion ,
PN  ,
PN   
)
PN potion_srand ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_rand ( Potion ,
PN  ,
PN   
)
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.

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_closure_arity ( Potion ,
PN  ,
PN   
)
PN potion_closure_minargs ( Potion ,
PN  ,
PN   
)
void potion_define_global ( Potion ,
PN  ,
PN   
)

Definition at line 628 of file objmodel.c.

PN potion_obj_add ( Potion ,
PN  ,
PN   
)

Definition at line 436 of file objmodel.c.

PN potion_obj_sub ( Potion ,
PN  ,
PN   
)

Definition at line 440 of file objmodel.c.

PN potion_obj_mult ( Potion ,
PN  ,
PN   
)

Definition at line 444 of file objmodel.c.

PN potion_obj_div ( Potion ,
PN  ,
PN   
)

Definition at line 448 of file objmodel.c.

PN potion_obj_rem ( Potion ,
PN  ,
PN   
)

Definition at line 452 of file objmodel.c.

PN potion_obj_bitn ( Potion ,
PN   
)

Definition at line 456 of file objmodel.c.

PN potion_obj_bitl ( Potion ,
PN  ,
PN   
)

Definition at line 460 of file objmodel.c.

PN potion_obj_bitr ( Potion ,
PN  ,
PN   
)

Definition at line 464 of file objmodel.c.

PN potion_any_cmp ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_tuple_empty ( Potion )

Definition at line 235 of file table.c.

PN potion_tuple_with_size ( Potion ,
unsigned  long 
)

Definition at line 242 of file table.c.

PN potion_tuple_new ( Potion ,
PN   
)

Definition at line 247 of file table.c.

PN potion_tuple_push ( Potion ,
PN  ,
PN   
)

Definition at line 254 of file table.c.

PN_SIZE potion_tuple_push_unless ( Potion P,
PN  tuple,
PN  value 
)
Parameters
tuplePNTuple
valuePN

Definition at line 290 of file table.c.

PN_SIZE potion_tuple_find ( Potion P,
PN  tuple,
PN  value 
)

Return index of found value or PN_NONE.

Parameters
tuplePNTuple
valuePN
Returns
int

Definition at line 280 of file table.c.

PN potion_tuple_at ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_tuple_shift ( Potion ,
PN  ,
PN   
)
PN potion_tuple_bsearch ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_tuple_ins_sort ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_table_empty ( Potion )
PN potion_table_put ( Potion ,
PN  ,
PN  ,
PN  ,
PN   
)
PN potion_table_set ( Potion P,
PN  self,
PN  key,
PN  value 
)

helper function for potion_table_put:"put", accepts tuple or table

Parameters
keyPN
valuePN
Returns
self PNTable

Definition at line 126 of file table.c.

PN potion_table_at ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_lick ( Potion ,
PN  ,
PN  ,
PN   
)

Definition at line 11 of file lick.c.

PN potion_source_compile ( Potion ,
PN  ,
PN  ,
PN  ,
PN   
)
PN potion_source_load ( Potion ,
PN  ,
PN   
)
PN potion_source_dump ( Potion ,
PN  ,
PN  ,
PN  ,
PN   
)
PN potion_source_dumpbc ( Potion ,
PN  ,
PN  ,
PN   
)
PN potion_greg_parse ( Potion ,
PN   
)
PN potion_sig_string ( Potion P,
PN  cl,
PN  sig 
)
Returns
string of the sig tuple. "arg1=o,arg2=o"

Definition at line 60 of file compile.c.

PN potion_filename_find ( Potion ,
PN   
)
PN potion_filename_push ( Potion ,
PN   
)
Potion* potion_gc_boot ( void *  sp)
Potion's GC is a generational copying GC. This is why the volatile keyword is used so liberally throughout the source code. PN types may suddenly move during any collection phase. They move from the birth area to the old area.

Potion actually begins by allocating an old area. This is for two reasons. First, the script may be too short to require an old area, so we want to avoid allocating two areas to start with. And second, since Potion loads its core classes into GC first, we save ourselves a severe promotion step by beginning with an automatic promotion to second generation. (Oh and this allows the core Potion struct pointer to be non-volatile.)

In short, this first page is never released, since the GC struct itself is on that page.

While this may pay a slight penalty in memory size for long-running scripts, perhaps I could add some occassional compaction to solve that as well.

See also
potion_init() which calls GC_PROTECT()

Definition at line 658 of file gc.c.

void potion_lobby_init ( Potion )

Definition at line 704 of file objmodel.c.

void potion_object_init ( Potion )

Definition at line 669 of file objmodel.c.

void potion_error_init ( Potion )

Definition at line 254 of file internal.c.

void potion_primitive_init ( Potion )

Definition at line 90 of file primitive.c.

void potion_num_init ( Potion )

Definition at line 439 of file number.c.

void potion_str_hash_init ( Potion )

Definition at line 487 of file string.c.

void potion_str_init ( Potion )

Definition at line 491 of file string.c.

void potion_table_init ( Potion )

Definition at line 824 of file table.c.

void potion_source_init ( Potion )

Definition at line 157 of file ast.c.

void potion_lick_init ( Potion )

Definition at line 68 of file lick.c.

void potion_compiler_init ( Potion )

Definition at line 1424 of file compile.c.

void potion_vm_init ( Potion )

Definition at line 129 of file vm.c.

void potion_cont_init ( Potion )

Definition at line 169 of file callcc.c.

void potion_file_init ( Potion )

set Env global

Definition at line 189 of file file.c.

void potion_loader_init ( Potion )

Definition at line 225 of file load.c.

void potion_loader_add ( Potion ,
PN  path 
)

Definition at line 221 of file load.c.

PN potion_load ( Potion ,
PN  ,
PN  ,
PN   
)

Definition at line 163 of file load.c.

char* potion_find_file ( Potion ,
char *  str,
PN_SIZE  str_len 
)

Definition at line 118 of file load.c.

PN potion_any_is_nil ( Potion ,
PN  ,
PN   
)
void potion_dump_stack ( Potion )
PN potion_num_string ( Potion ,
PN  ,
PN   
)
PN potion_gc_reserved ( Potion ,
PN  ,
PN   
)

Definition at line 732 of file gc.c.

PN potion_gc_actual ( Potion ,
PN  ,
PN   
)

Definition at line 714 of file gc.c.

PN potion_gc_fixed ( Potion ,
PN  ,
PN   
)

Definition at line 724 of file gc.c.

PN potion_parse ( Potion ,
PN  ,
char *   
)
PN potion_vm_proto ( Potion P,
PN  cl,
PN  self,
  ... 
)

entrypoint for all bytecode methods from the C api.

See also
potion_test_eval()
Parameters
clPNClosure to be called
selfPN - sets self (ignored for most user defined functions). if self is a int < 10 it defines the number of args provided
...- arguments to the cl
  add = potion_eval(P, potion_str(P, "(x=N|y=N): x + y."));
  addfn = PN_CLOSURE_F(add); // i.e. potion_vm_proto
  num = addfn(P, add, 2, PN_NUM(3), PN_NUM(5));
  num = addfn(P, add, 1, PN_NUM(3)); // 1 arg provided, 2nd arg=0

Note that methods with optional arguments ... are not very safe to call. potion_vm_proto() does not know the number of arguments on the stack. So it checks for all optional args the matching type. You can help by providing numargs as self argument if numargs < 10.

Definition at line 159 of file vm.c.

PN potion_vm_class ( Potion ,
PN  ,
PN   
)

implements the class op creates a class (or type) from a closure and parent class with obj ivars

Definition at line 203 of file vm.c.

PN potion_vm ( Potion ,
PN  ,
PN  ,
PN  ,
PN_SIZE  ,
PN volatile 
)

the bytecode run-loop

Definition at line 594 of file vm.c.

PN potion_eval ( Potion ,
PN   
)

Definition at line 1415 of file compile.c.

PN potion_run ( Potion ,
PN  ,
int   
)

Definition at line 1399 of file compile.c.

PN_F potion_jit_proto ( Potion ,
PN   
)

Definition at line 221 of file vm.c.

PN potion_class_find ( Potion ,
PN   
)

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.

Variable Documentation

PN PN_allocate

common method names in GC protected area

Definition at line 14 of file internal.c.

PN PN_break

Definition at line 14 of file internal.c.

PN PN_call

Definition at line 14 of file internal.c.

PN PN_class

Definition at line 14 of file internal.c.

PN PN_compile

Definition at line 14 of file internal.c.

PN PN_continue

Definition at line 14 of file internal.c.

PN PN_def

Definition at line 14 of file internal.c.

PN PN_delegated

Definition at line 14 of file internal.c.

PN PN_else

Definition at line 14 of file internal.c.

PN PN_elsif

Definition at line 14 of file internal.c.

PN PN_if

Definition at line 14 of file internal.c.

PN PN_lookup

Definition at line 14 of file internal.c.

PN PN_loop

Definition at line 14 of file internal.c.

PN PN_print

Definition at line 14 of file internal.c.

PN PN_return

Definition at line 14 of file internal.c.

PN PN_self

Definition at line 14 of file internal.c.

PN PN_string

Definition at line 14 of file internal.c.

PN PN_while

Definition at line 14 of file internal.c.

PN PN_add

Definition at line 17 of file internal.c.

PN PN_sub

Definition at line 17 of file internal.c.

PN PN_mult

Definition at line 17 of file internal.c.

PN PN_div

Definition at line 17 of file internal.c.

PN PN_rem

Definition at line 17 of file internal.c.

PN PN_bitn

Definition at line 17 of file internal.c.

PN PN_bitl

Definition at line 17 of file internal.c.

PN PN_bitr

Definition at line 17 of file internal.c.

PN PN_cmp

Definition at line 18 of file internal.c.

PN PN_number

Definition at line 18 of file internal.c.

PN PN_name

Definition at line 18 of file internal.c.

PN PN_length

Definition at line 18 of file internal.c.

PN PN_size

Definition at line 18 of file internal.c.

PN PN_STR0

Definition at line 18 of file internal.c.

PN PN_extern

Definition at line 19 of file internal.c.

PN PN_integer

Definition at line 19 of file internal.c.

PN pn_filenames

Definition at line 23 of file internal.c.