p2
0.0
|
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 | PNDecimal |
decimals 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 ordered list, volatile. 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 or ppc, arm later More... | |
struct | Potion_State |
the global interpreter state P. currently singleton (not threads yet) More... | |
struct | PNMemory |
the garbage collector More... |
Macros | |
#define | POTION_MAJOR 0 |
#define | POTION_MINOR 1 |
#define | POTION_SIG "p\07\10n" |
#define | POTION_VMID 0x79 |
#define | POTION_X86 0 |
#define | POTION_PPC 1 |
#define | POTION_ARM 2 |
#define | _XSTR(s) _STR(s) |
#define | _STR(s) #s |
#define | POTION_VERSION _XSTR(POTION_MAJOR) "." _XSTR(POTION_MINOR) |
#define | ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS |
#define | YY_DEBUG |
#define | __WORDSIZE 32 |
#define | PN_TNIL 0x250000 |
#define | PN_TNUMBER (1+PN_TNIL) |
#define | PN_TBOOLEAN (2+PN_TNIL) |
#define | PN_TSTRING (3+PN_TNIL) |
#define | PN_TWEAK (4+PN_TNIL) |
#define | PN_TCLOSURE (5+PN_TNIL) |
#define | PN_TTUPLE (6+PN_TNIL) |
#define | PN_TSTATE (7+PN_TNIL) |
#define | PN_TFILE (8+PN_TNIL) |
#define | PN_TOBJECT (9+PN_TNIL) |
#define | PN_TVTABLE (10+PN_TNIL) |
#define | PN_TSOURCE (11+PN_TNIL) |
#define | PN_TBYTES (12+PN_TNIL) |
#define | PN_TPROTO (13+PN_TNIL) |
#define | PN_TLOBBY (14+PN_TNIL) |
#define | PN_TTABLE (15+PN_TNIL) |
#define | PN_TLICK (16+PN_TNIL) |
#define | PN_TFLEX (17+PN_TNIL) |
#define | PN_TSTRINGS (18+PN_TNIL) |
#define | PN_TERROR (19+PN_TNIL) |
#define | PN_TCONT (20+PN_TNIL) |
#define | PN_TDECIMAL (21+PN_TNIL) |
#define | PN_TUSER (22+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 | PN_FNUMBER 1 |
#define | PN_FBOOLEAN 2 |
#define | PN_TEST(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_NUM(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_NUM(v) ((PN)(v) & PN_FNUMBER) |
#define | PN_IS_TUPLE(v) (PN_TYPE(v) == PN_TTUPLE) |
#define | PN_IS_STR(v) (PN_TYPE(v) == PN_TSTRING) |
#define | PN_IS_TABLE(v) (PN_TYPE(v) == PN_TTABLE) |
#define | PN_IS_CLOSURE(v) (PN_TYPE(v) == PN_TCLOSURE) |
#define | PN_IS_DECIMAL(v) (PN_IS_PTR(v) && PN_TYPE(v) == PN_TNUMBER) |
#define | PN_IS_PROTO(v) (PN_TYPE(v) == PN_TPROTO) |
#define | PN_IS_REF(v) (PN_TYPE(v) == PN_TWEAK) |
#define | PN_IS_METACLASS(v) (((struct PNVtable *)v)->meta == PN_NIL) |
#define | PN_NUM(i) ((PN)((((long)(i))<<1) + PN_FNUMBER)) |
#define | PN_INT(x) ((long)((long)(x))>>1) |
#define | PN_DBL(num) (PN_IS_NUM(num) ? (double)PN_INT(num) : ((struct PNDecimal *)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_STR_PTR(x) potion_str_ptr(x) |
#define | PN_STR_LEN(x) ((struct PNString *)(x))->len |
#define | PN_STR_B(x) potion_bytes_string(P, PN_NIL, x) |
#define | PN_CLOSURE(x) ((struct PNClosure *)(x)) |
#define | PN_CLOSURE_F(x) ((struct PNClosure *)(x))->method |
#define | PN_PROTO(x) ((struct PNProto *)(x)) |
#define | PN_FUNC(f, s) potion_closure_new(P, (PN_F)f, potion_sig(P, s), 0) |
#define | PN_DEREF(x) ((struct PNWeakRef *)(x))->data |
#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[0]; } 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(...) if (P->flags & DEBUG_TRACE) fprintf(stderr, __VA_ARGS__) |
#define | DBG_v(...) if (P->flags & DEBUG_VERBOSE) fprintf(stderr, __VA_ARGS__) |
#define | DBG_vt(...) if (P->flags & (DEBUG_VERBOSE|DEBUG_TRACE)) fprintf(stderr, __VA_ARGS__) |
#define | DBG_vi(...) if (P->flags & (DEBUG_VERBOSE|DEBUG_INSPECT)) fprintf(stderr, __VA_ARGS__) |
#define | DBG_c(...) if (P->flags & DEBUG_COMPILE) fprintf(stderr, __VA_ARGS__) |
#define | PN_IS_EMPTY(T) (PN_GET_TUPLE(T)->len == 0) |
#define | PN_TUP0() potion_tuple_empty(P) |
#define | PN_TUP(X) potion_tuple_new(P, X) |
#define | PN_PUSH(T, X) potion_tuple_push(P, T, (PN)X) |
#define | PN_GET(T, X) potion_tuple_find(P, T, X) |
#define | PN_PUT(T, X) potion_tuple_push_unless(P, T, X) |
#define | PN_GET_TUPLE(t) ((struct PNTuple *)potion_fwd((PN)t)) |
#define | PN_TUPLE_LEN(t) PN_GET_TUPLE(t)->len |
#define | PN_TUPLE_AT(t, n) PN_GET_TUPLE(t)->set[n] |
#define | PN_TUPLE_COUNT(T, I, B) |
#define | PN_TUPLE_EACH(T, I, V, B) |
#define | PN_MANTISSA(d, n) d->real[1 + n] |
PN_MANTISSA the last part of ->real. | |
#define | PN_QUICK_FWD(t, obj) |
PN_QUICK_FWD - doing a single fwd check after a possible realloc. | |
#define | OP_MAX 64 |
the jit | |
#define | EXEC_BITS 4 |
0-4 | |
#define | POTION_INIT_STACK(x) PN __##x = 0x571FF; void *x = (void *)&__##x |
#define | POTION_OK 0 |
internal errors | |
#define | POTION_NO_MEM 8910 |
#define | potion_send(RCV, MSG, ARGS...) |
method caches (more great stuff from ian piumarta) | |
#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, EXEC_DEBUG, EXEC_CHECK, EXEC_COMPILE, MAX_EXEC } |
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), DEBUG_TRACE = 1<<(EXEC_BITS+4), DEBUG_PARSE = 1<<(EXEC_BITS+5), DEBUG_PARSE_VERBOSE = 1<<(EXEC_BITS+6), DEBUG_COMPILE = 1<<(EXEC_BITS+7), DEBUG_GC = 1<<(EXEC_BITS+8), DEBUG_JIT = 1<<(EXEC_BITS+9) } |
Variables | |
PN | PN_allocate |
common method names in GC protected area | |
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 |
#define POTION_VERSION _XSTR(POTION_MAJOR) "." _XSTR(POTION_MINOR) |
#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_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_STR_PTR | ( | x | ) | potion_str_ptr(x) |
#define PN_FUNC | ( | f, | |
s | |||
) | potion_closure_new(P, (PN_F)f, potion_sig(P, s), 0) |
#define PN_FLEX | ( | N, | |
T | |||
) | typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[0]; } N; |
#define AS_STR | ( | x | ) | PN_STR_PTR(potion_send(x, PN_string)) |
#define DBG_t | ( | ... | ) | if (P->flags & DEBUG_TRACE) fprintf(stderr, __VA_ARGS__) |
#define DBG_v | ( | ... | ) | if (P->flags & DEBUG_VERBOSE) fprintf(stderr, __VA_ARGS__) |
#define DBG_vt | ( | ... | ) | if (P->flags & (DEBUG_VERBOSE|DEBUG_TRACE)) fprintf(stderr, __VA_ARGS__) |
#define DBG_vi | ( | ... | ) | if (P->flags & (DEBUG_VERBOSE|DEBUG_INSPECT)) fprintf(stderr, __VA_ARGS__) |
#define DBG_c | ( | ... | ) | if (P->flags & DEBUG_COMPILE) fprintf(stderr, __VA_ARGS__) |
#define PN_IS_EMPTY | ( | T | ) | (PN_GET_TUPLE(T)->len == 0) |
#define PN_TUP0 | ( | ) | potion_tuple_empty(P) |
#define PN_TUP | ( | X | ) | potion_tuple_new(P, X) |
#define PN_PUSH | ( | T, | |
X | |||
) | potion_tuple_push(P, T, (PN)X) |
#define PN_GET | ( | T, | |
X | |||
) | potion_tuple_find(P, T, X) |
#define PN_PUT | ( | T, | |
X | |||
) | potion_tuple_push_unless(P, T, X) |
#define PN_GET_TUPLE | ( | t | ) | ((struct PNTuple *)potion_fwd((PN)t)) |
#define PN_TUPLE_LEN | ( | t | ) | PN_GET_TUPLE(t)->len |
#define PN_TUPLE_COUNT | ( | T, | |
I, | |||
B | |||
) |
#define PN_TUPLE_EACH | ( | T, | |
I, | |||
V, | |||
B | |||
) |
#define PN_QUICK_FWD | ( | t, | |
obj | |||
) |
#define potion_send | ( | RCV, | |
MSG, | |||
ARGS... | |||
) |
#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)) |
typedef struct Potion_State Potion |
enum PN_AST |
An AST fragment, non-volatile.
enum exec_mode_t |
the interpreter (one per thread, houses its own garbage collector)
enum syntax_mode_t |
enum Potion_Flags |
|
inlinestatic |
PN_FLEX | ( | PNFlex | , |
PN | |||
) |
unsigned long potion_rand_int | ( | ) |
generates a random number on [0,0xffffffff]-interval
Definition at line 130 of file mt19937ar.c.
double potion_rand_double | ( | ) |
generates a random number on [0,1) with 53-bit resolution
Definition at line 146 of file mt19937ar.c.
Potion* potion_create | ( | void * | ) |
the potion API
Definition at line 108 of file internal.c.
void potion_destroy | ( | Potion * | ) |
Definition at line 120 of file internal.c.
void potion_fatal | ( | char * | ) |
Definition at line 243 of file internal.c.
void potion_allocation_error | ( | void | ) |
Definition at line 259 of file internal.c.
void potion_syntax_error | ( | Potion * | , |
const char * | , | ||
... | |||
) |
Definition at line 248 of file internal.c.
Definition at line 182 of file internal.c.
Definition at line 264 of file internal.c.
create a type derived from self
Definition at line 150 of file objmodel.c.
create a named type
Definition at line 162 of file objmodel.c.
sets the default call method of the PNVtable
Definition at line 168 of file objmodel.c.
set default writer
Definition at line 178 of file objmodel.c.
set default constructor
Definition at line 188 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 188 of file internal.c.
create a user-class (ie type)
cl,: | set the ctor |
self,: | lobby or another type |
ivars,: | object members |
Definition at line 195 of file objmodel.c.
get the default accessor (usually "at")
Definition at line 172 of file objmodel.c.
get default writer
Definition at line 182 of file objmodel.c.
implements OP_GETPATH
Definition at line 258 of file objmodel.c.
implements OP_SETPATH
Definition at line 265 of file objmodel.c.
Definition at line 130 of file internal.c.
used in bind and def_method
Definition at line 321 of file objmodel.c.
Definition at line 100 of file objmodel.c.
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 we will switch to VTable. default-value can be a value of any type and is prefixed with ':'
Definition at line 76 of file objmodel.c.
Definition at line 494 of file objmodel.c.
Definition at line 379 of file objmodel.c.
Potion* potion_gc_boot | ( | void * | sp | ) |
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.
void potion_lobby_init | ( | Potion * | ) |
Definition at line 551 of file objmodel.c.
void potion_object_init | ( | Potion * | ) |
Definition at line 535 of file objmodel.c.
void potion_error_init | ( | Potion * | ) |
Definition at line 235 of file internal.c.
void potion_primitive_init | ( | Potion * | ) |
Definition at line 88 of file primitive.c.
void potion_dump_stack | ( | Potion * | ) |
Definition at line 280 of file internal.c.
find class by name. At first only system metaclasses (types), no user classes yet.
Definition at line 218 of file objmodel.c.
PN PN_allocate |
common method names in GC protected area
Definition at line 15 of file internal.c.
PN PN_break |
Definition at line 15 of file internal.c.
PN PN_call |
Definition at line 15 of file internal.c.
PN PN_class |
Definition at line 15 of file internal.c.
PN PN_compile |
Definition at line 15 of file internal.c.
PN PN_continue |
Definition at line 15 of file internal.c.
PN PN_def |
Definition at line 15 of file internal.c.
PN PN_delegated |
Definition at line 15 of file internal.c.
PN PN_else |
Definition at line 15 of file internal.c.
PN PN_elsif |
Definition at line 15 of file internal.c.
PN PN_if |
Definition at line 15 of file internal.c.
PN PN_lookup |
Definition at line 15 of file internal.c.
PN PN_loop |
Definition at line 15 of file internal.c.
PN PN_print |
Definition at line 15 of file internal.c.
PN PN_return |
Definition at line 15 of file internal.c.
PN PN_self |
Definition at line 15 of file internal.c.
PN PN_string |
Definition at line 15 of file internal.c.
PN PN_while |
Definition at line 15 of file internal.c.
PN PN_add |
Definition at line 18 of file internal.c.
PN PN_sub |
Definition at line 18 of file internal.c.
PN PN_mult |
Definition at line 18 of file internal.c.
PN PN_div |
Definition at line 18 of file internal.c.
PN PN_rem |
Definition at line 18 of file internal.c.
PN PN_bitn |
Definition at line 18 of file internal.c.
PN PN_bitl |
Definition at line 18 of file internal.c.
PN PN_bitr |
Definition at line 18 of file internal.c.
PN PN_cmp |
Definition at line 19 of file internal.c.
PN PN_number |
Definition at line 19 of file internal.c.
PN PN_name |
Definition at line 19 of file internal.c.