potion  0.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
potion.h
Go to the documentation of this file.
1 
39 #ifndef POTION_H
40 #define POTION_H
41 
42 #define POTION_SIG "p\07\10n"
43 #define POTION_VMID 0x79
44 
45 #define POTION_X86 0
46 #define POTION_PPC 1
47 #define POTION_ARM 2
48 
49 #include <limits.h>
50 #include <string.h>
51 #include <fcntl.h>
52 #include <assert.h>
53 #include "config.h"
54 #if POTION_WIN32
55 # include <sys/stat.h>
56 # define DLLEXPORT __declspec(dllexport)
57 #else
58 # define DLLEXPORT
59 #endif
60 
61 #define _XSTR(s) _STR(s)
62 #define _STR(s) #s
63 
64 #if HAVE_ASAN_ATTR
65 # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS __attribute__((no_address_safety_analysis))
66 #else
67 # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
68 #endif
69 #ifdef DEBUG
70 # ifndef YY_DEBUG
71 # define YY_DEBUG
72 # endif
73 #endif
74 
75 //
76 // types
77 //
78 typedef unsigned long _PN;
79 typedef unsigned int PN_SIZE, PNType, PNUniq;
80 typedef struct Potion_State Potion;
81 typedef volatile _PN PN;
82 
83 struct PNObject;
84 struct PNFwd;
85 struct PNData;
86 struct PNString;
87 struct PNBytes;
88 struct PNDouble;
89 struct PNClosure;
90 struct PNProto;
91 struct PNTuple;
92 struct PNWeakRef;
93 struct PNError;
94 struct PNCont;
95 struct PNMemory;
96 struct PNVtable;
97 
98 /* patch for issue #1 supplied by joeatwork */
99 #ifndef __WORDSIZE
100 # if PN_SIZE_T == 8
101 # define __WORDSIZE 64
102 # else
103 # define __WORDSIZE 32
104 # endif
105 #endif
106 
107 #define PN_TNIL 0x250000
108 #define PN_TNUMBER (1+PN_TNIL)
109 #define PN_TBOOLEAN (2+PN_TNIL)
110 #define PN_TDOUBLE (3+PN_TNIL) //is a Number, no arbitrary prec. yet
111 #define PN_TINTEGER (4+PN_TNIL) //is a Number
112 #define PN_TSTRING (5+PN_TNIL)
113 #define PN_TWEAK (6+PN_TNIL)
114 #define PN_TCLOSURE (7+PN_TNIL)
115 #define PN_TTUPLE (8+PN_TNIL)
116 #define PN_TSTATE (9+PN_TNIL)
117 #define PN_TFILE (10+PN_TNIL) //0a
118 #define PN_TOBJECT (11+PN_TNIL) //0b
119 #define PN_TVTABLE (12+PN_TNIL) //0c
120 #define PN_TSOURCE (13+PN_TNIL) //0d
121 #define PN_TBYTES (14+PN_TNIL) //0e
122 #define PN_TPROTO (15+PN_TNIL) //0f
123 #define PN_TLOBBY (16+PN_TNIL) //10
124 #define PN_TTABLE (17+PN_TNIL) //11
125 #define PN_TLICK (18+PN_TNIL) //12
126 #define PN_TFLEX (19+PN_TNIL) //13
127 #define PN_TSTRINGS (20+PN_TNIL) //14
128 #define PN_TERROR (21+PN_TNIL) //15
129 #define PN_TCONT (22+PN_TNIL) //16
130 #define PN_TUSER (23+PN_TNIL) //17
131 
132 #define vPN(t) struct PN##t * volatile
133 #define PN_TYPE(x) potion_type((PN)(x))
134 #define PN_VTYPE(x) (((struct PNObject *)(x))->vt)
135 #define PN_TYPE_ID(t) ((t)-PN_TNIL)
136 #define PN_VTABLE(t) (PN_FLEX_AT(P->vts, PN_TYPE_ID(t)))
137 #define PN_TYPECHECK(t) (PN_TYPE_ID(t) >= 0 && PN_TYPE_ID(t) < PN_FLEX_SIZE(P->vts))
138 
139 #define PN_NIL ((PN)0)
140 #define PN_ZERO ((PN)1) //i.e. PN_NUM(0)
141 #define PN_FALSE ((PN)2)
142 #define PN_TRUE ((PN)6)
143 #define PN_PRIMITIVE 7
144 #define PN_REF_MASK ~7
145 #define PN_NONE ((PN_SIZE)-1)
146 #define POTION_FWD 0xFFFFFFFE
147 #define POTION_COPIED 0xFFFFFFFF
148 
149 #define NIL_NAME "nil" // "undef" in p2
150 #define NILKIND_NAME "NilKind"
151 
152 #define PN_FINTEGER 1
153 #define PN_FBOOLEAN 2
154 //Beware: TEST(PN_NUM(0)) vs BOOL(0<1) i.e. test1(1) vs test(1)
155 #define PN_TEST(v) ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)
156 #define PN_BOOL(v) ((v) ? PN_TRUE : PN_FALSE)
159 #define PN_IS_PTR(v) (!PN_IS_INT(v) && ((PN)(v) & PN_REF_MASK))
160 #define PN_IS_NIL(v) ((PN)(v) == PN_NIL)
161 #define PN_IS_BOOL(v) ((PN)(v) & PN_FBOOLEAN)
162 #define PN_IS_INT(v) ((PN)(v) & PN_FINTEGER)
163 #define PN_IS_DBL(v) (PN_IS_PTR(v) && ({PNType _t = potion_qptr_type((PN)v); _t == PN_TNUMBER || _t == PN_TDOUBLE;}))
164 #define PN_IS_NUM(v) (PN_IS_INT(v) || PN_IS_DBL(v))
165 #define PN_IS_TUPLE(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTUPLE))
166 #define PN_IS_STR(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TSTRING))
167 #define PN_IS_TABLE(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTABLE))
168 #define PN_IS_CLOSURE(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TCLOSURE))
169 #define PN_IS_PROTO(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TPROTO))
170 #define PN_IS_REF(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TWEAK))
171 #define PN_IS_METACLASS(v) (((struct PNVtable *)v)->meta == PN_NIL)
172 #define PN_IS_FFIPTR(p) ((PN_IS_PTR(p) && !(p >= (_PN)P->mem && p <= (_PN)P->mem->birth_hi)) \
173  || (!PN_IS_PTR(p) && p > (_PN)P->mem->birth_hi))
174 
175 #define PN_CHECK_STR(obj) if (!PN_IS_STR(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "String")
176 #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")
177 #define PN_CHECK_NUM(obj) if (!PN_IS_NUM(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Number")
178 #define PN_CHECK_INT(obj) if (!PN_IS_INT(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Integer")
179 #define PN_CHECK_DBL(obj) if (!PN_IS_DBL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Double")
180 #define PN_CHECK_BOOL(obj) if (!PN_IS_BOOL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Bool")
181 #define PN_CHECK_TUPLE(obj) if (!PN_IS_TUPLE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Tuple")
182 #define PN_CHECK_CLOSURE(obj) if (!PN_IS_CLOSURE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Closure")
183 //exact only. TODO check derived types, parents and mixins via bind
184 #define PN_CHECK_TYPE(obj,type) if (type != PN_TYPE(obj)) return potion_type_error(P, (PN)obj)
185 #ifdef DEBUG
186 #define DBG_CHECK_TYPE(obj,type) PN_CHECK_TYPE(obj,type)
187 #define DBG_CHECK_NUM(obj) PN_CHECK_NUM(obj)
188 #define DBG_CHECK_INT(obj) PN_CHECK_INT(obj)
189 #define DBG_CHECK_DBL(obj) PN_CHECK_DBL(obj)
190 #define DBG_CHECK_TUPLE(obj) PN_CHECK_TUPLE(obj)
191 #else
192 #define DBG_CHECK_TYPE(obj,type)
193 #define DBG_CHECK_NUM(obj)
194 #define DBG_CHECK_INT(obj)
195 #define DBG_CHECK_DBL(obj)
196 #define DBG_CHECK_TUPLE(obj)
197 #endif
198 
204 #define PN_NUM(i) ((PN)((((long)(i))<<1) + PN_FINTEGER))
205 #define PN_INT(x) ((long)((long)(x))>>1)
206 #define PN_DBL(num) (PN_IS_INT(num) ? (double)PN_INT(num) : ((struct PNDouble *)num)->value)
207 typedef _PN (*PN_F)(Potion *, PN, PN, ...);
208 #define PN_PREC 16
209 #define PN_RAND() PN_NUM(potion_rand_int())
210 #define PN_STR(x) potion_str(P, x)
211 #define PN_STRN(x, l) potion_str2(P, x, l)
212 #define PN_STRCAT(a, b) potion_strcat(P, (a), (b))
213 #define PN_STR_PTR(x) potion_str_ptr(x)
214 #define PN_STR_LEN(x) ((struct PNString *)(x))->len
215 #define PN_STR_B(x) potion_bytes_string(P, PN_NIL, x)
216 #define PN_CLOSURE(x) ((struct PNClosure *)(x))
217 #define PN_CLOSURE_F(x) ((struct PNClosure *)(x))->method
218 #define PN_PROTO(x) ((struct PNProto *)(x))
219 #define PN_FUNC(f, s) potion_closure_new(P, (PN_F)f, potion_sig(P, s), 0)
220 #define PN_DEREF(x) ((struct PNWeakRef *)(x))->data
221 #define PN_DATA(x) ((struct PNData *)(x))->data
222 #define PN_TOUCH(x) potion_gc_update(P, (PN)(x))
223 #define PN_ALIGN(o, x) (((((o) - 1) / (x)) + 1) * (x))
224 
225 #define PN_OBJECT_HEADER \
226  PNType vt; \
227  PNUniq uniq
228 
229 #define PN_FLEX(N, T) typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[]; } N
230 #define PN_FLEX_AT(N, I) ((PNFlex *)(N))->ptr[I]
231 #define PN_FLEX_SIZE(N) ((PNFlex *)(N))->len
232 
233 #if PN_SIZE_T == 4
234 #define PN_NUMHASH(x) x
235 #else
236 #define PN_NUMHASH(x) (PNUniq)((x)>>33^(x)^(x)<<11)
237 #endif
238 #define PN_UNIQ(x) (PN_IS_PTR(x) ? ((struct PNObject *)(x))->uniq : PN_NUMHASH(x))
239 
240 #define AS_STR(x) PN_STR_PTR(potion_send(x, PN_string))
241 #ifdef DEBUG
242 #define DBG_t(...) \
243  if (P->flags & DEBUG_TRACE) fprintf(stderr, __VA_ARGS__)
244 #define DBG_v(...) \
245  if (P->flags & DEBUG_VERBOSE) fprintf(stderr, __VA_ARGS__)
246 #define DBG_vt(...) \
247  if (P->flags & DEBUG_VERBOSE && P->flags & DEBUG_TRACE) fprintf(stderr, __VA_ARGS__)
248 #define DBG_vi(...) \
249  if (P->flags & DEBUG_VERBOSE && P->flags & DEBUG_INSPECT) fprintf(stderr, __VA_ARGS__)
250 #define DBG_c(...) \
251  if (P->flags & DEBUG_COMPILE) fprintf(stderr, __VA_ARGS__)
252 #else
253 #define DBG_t(...)
254 #define DBG_v(...)
255 #define DBG_vt(...)
256 #define DBG_vi(...)
257 #define DBG_c(...)
258 #endif
259 
260 #define PN_IS_EMPTY(T) (PN_TUPLE_LEN(T) == 0)
261 #define PN_TUP0() potion_tuple_empty(P)
262 #define PN_TUP(X) potion_tuple_new(P, X)
263 #define PN_PUSH(T, X) potion_tuple_push(P, T, (PN)X)
264 #define PN_SHIFT(T) potion_tuple_shift(P, 0, T)
265 #define PN_GET(T, X) potion_tuple_find(P, T, X)
266 #define PN_PUT(T, X) potion_tuple_push_unless(P, T, X)
267 #define PN_GET_TUPLE(t) ((struct PNTuple *)potion_fwd((PN)t))
268 #define PN_TUPLE_LEN(t) PN_GET_TUPLE(t)->len
269 #define PN_TUPLE_AT(t, n) PN_GET_TUPLE(t)->set[n]
270 #define PN_TUPLE_COUNT(T, I, B) ({ \
272  struct PNTuple * volatile __t##I = PN_GET_TUPLE(T); \
273  if (__t##I->len != 0) { \
274  PN_SIZE I; \
275  for (I = 0; I < __t##I->len; I++) B \
276  } \
277  })
278 #define PN_TUPLE_EACH(T, I, V, B) ({ \
280  struct PNTuple * volatile __t##V = PN_GET_TUPLE(T); \
281  if (__t##V->len != 0) { \
282  PN_SIZE I; \
283  for (I = 0; I < __t##V->len; I++) { \
284  PN V = __t##V->set[I]; \
285  B \
286  } \
287  } \
288  })
289 
295 struct PNObject {
298 };
299 
304 struct PNFwd {
305  unsigned int fwd;
308 };
309 
317 struct PNData {
320  char data[];
321 };
322 
328 struct PNString {
331  char chars[];
332 };
333 
338 struct PNBytes {
342  char chars[];
343 };
344 
346 #define PN_MANTISSA(d, n) d->real[1 + n]
347 
352 struct PNDouble {
354  double value;
355 };
356 
361 struct PNFile {
363  int fd;
365  mode_t mode;
366 };
367 
372 struct PNClosure {
375  PN sig;
376  int arity;
377  int minargs;
380  PN data[];
381 };
382 
386 enum PN_AST {
418  AST_LIST, /* for TABLE (=,..) and TUPLE (,...) */
420  AST_LICK, /* [...] */
423 };
424 struct PNSource {
426  enum PN_AST part;
427  struct PNSource * volatile a[3];
428  // luxury for reflection only: debugging, error messages
429  struct {
430 #if PN_SIZE_T != 8
431  PNType fileno:16;
432  PNType lineno:16;
433 #else
436 #endif
437  } loc;
439 };
440 
445 struct PNProto {
448  PN sig;
460  int arity;
462 };
463 
468 struct PNTuple {
472  PN set[];
473 };
474 
479 struct PNWeakRef {
482 };
483 
488 struct PNError {
494 };
495 
499 struct PNLick {
504 };
505 
510 struct PNCont {
513  PN stack[]; // [0] = head of potion stack
514  // [1] = current %rsp
515  // [2] = current %rbp
516  // [3+] = full stack dump, ascending
517 };
518 
520 static inline PN potion_fwd(PN);
521 
523 static inline PNType potion_type(PN obj) {
524  if (PN_IS_INT(obj)) return PN_TNUMBER;
525  if (PN_IS_BOOL(obj)) return PN_TBOOLEAN;
526  if (PN_IS_NIL(obj)) return PN_TNIL;
527 #if 1
528  while (1) {
529  struct PNFwd *o = (struct PNFwd *)obj;
530  if (o->fwd != POTION_FWD)
531  return ((struct PNObject *)o)->vt;
532  obj = o->ptr;
533  }
534 #else
535  return ((struct PNObject *)potion_fwd(obj))->vt;
536 #endif
537 }
538 
540 static inline PNType potion_ptr_type(PN obj) {
541  while (1) {
542  struct PNFwd *o = (struct PNFwd *)obj;
543  if (o->fwd != POTION_FWD)
544  return ((struct PNObject *)o)->vt;
545  obj = o->ptr;
546  }
547 }
549 #define PN_QUICK_FWD(t, obj) \
550  if (((struct PNFwd *)obj)->fwd == POTION_FWD) \
551  obj = (t)(((struct PNFwd *)obj)->ptr);
552 
555 static inline PNType potion_qptr_type(PN obj) {
556  PN_QUICK_FWD(PN, obj);
557  return ((struct PNObject *)obj)->vt;
558 }
559 
561 static inline PN potion_fwd(PN obj) {
562  while (PN_IS_PTR(obj) && ((struct PNFwd *)obj)->fwd == POTION_FWD)
563  obj = ((struct PNFwd *)obj)->ptr;
564  return obj;
565 }
566 
568 static inline char *potion_str_ptr(PN s) {
569  if (((struct PNString *)s)->vt == PN_TSTRING)
570  return ((struct PNString *)s)->chars;
571  s = potion_fwd(s);
572  return ((struct PNBytes *)s)->chars;
573 }
574 
575 PN_FLEX(PNFlex, PN);
576 //PN_FLEX(PNAsm, unsigned char);
577 typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; unsigned char ptr[]; } PNAsm;
578 
582 #define OP_MAX 50 // OP_DEBUG+1 was 64, statically allocated in Potion interpreter
583 
584 typedef void (*OP_F)(Potion *P, struct PNProto *, PNAsm * volatile *, ...);
585 
587 typedef struct {
588  void (*setup) (Potion *, struct PNProto * volatile, PNAsm * volatile *);
589  void (*stack) (Potion *, struct PNProto * volatile, PNAsm * volatile *, long);
590  void (*registers)(Potion *, struct PNProto * volatile, PNAsm * volatile *, long);
591  void (*local) (Potion *, struct PNProto * volatile, PNAsm * volatile *, long, long);
592  void (*upvals) (Potion *, struct PNProto * volatile, PNAsm * volatile *, long, long, int);
593  void (*jmpedit) (Potion *, struct PNProto * volatile, PNAsm * volatile *, unsigned char *, int);
595  void (*finish) (Potion *, struct PNProto * volatile, PNAsm * volatile *);
596  void (*mcache) (Potion *, struct PNVtable * volatile, PNAsm * volatile *);
597  void (*ivars) (Potion *, PN, PNAsm * volatile *);
598 } PNTarget;
599 
604 
605 typedef enum {
606  EXEC_VM = 0,
607  EXEC_JIT = 1,
611  MAX_EXEC = 5
612 } exec_mode_t;
613 
614 // we combine the exclusive enum 0-4 for exec, then the exclusive syntax modes 16-18,
615 // and finally the inclusive debugging modes
616 #define EXEC_BITS 4
617 
618 typedef enum {
620 #ifdef P2
621  MODE_P2 = MODE_STD+1,
622  MODE_P6 = MODE_STD+2,
623 #endif
624  // room for registered syntax modules 18-63 (45 modules: p5, p6, sql, c, ...)
625  MAX_SYNTAX = (1<<(EXEC_BITS+2))-1
626 } syntax_mode_t;
627 
628 typedef enum {
629  // exec + syntax + debug flags:
630  DEBUG_INSPECT = 1<<(EXEC_BITS+2), // 0x0040
631  DEBUG_VERBOSE = 1<<(EXEC_BITS+3) // 0x0080
632 #ifdef DEBUG
633  ,
634  DEBUG_TRACE = 1<<(EXEC_BITS+4), // 0x0100
635  DEBUG_PARSE = 1<<(EXEC_BITS+5), // 0x0200
636  DEBUG_PARSE_VERBOSE = 1<<(EXEC_BITS+6),// 0x0400
637  DEBUG_COMPILE = 1<<(EXEC_BITS+7), // 0x2000
638  DEBUG_GC = 1<<(EXEC_BITS+8), // 0x0800
639  DEBUG_JIT = 1<<(EXEC_BITS+9) // 0x1000
640 #endif
641 } Potion_Flags;
642 
644 struct Potion_State {
647  struct PNTable *strings;
649  PNFlex * volatile vts;
651  struct PNMemory *mem;
653  int prec;
654 
655  //parser-only:
657  int yypos;
658  PNAsm * volatile pbuf;
662 };
663 
667 struct PNMemory {
669  volatile void *birth_lo, *birth_hi, *birth_cur;
670  volatile void **birth_storeptr;
671 
673  volatile void *old_lo, *old_hi, *old_cur;
674 
675  volatile int collecting, dirty, pass, majors, minors;
676  void *cstack;
677  void *protect;
678 #ifdef DEBUG
679  double time;
680 #endif
681 };
682 
683 #define POTION_INIT_STACK(x) \
684  PN __##x = 0x571FF; void *x = (void *)&__##x
685 void potion_garbagecollect(Potion *, int, int);
686 PN_SIZE potion_type_size(Potion *, const struct PNObject *);
687 unsigned long potion_rand_int();
688 double potion_rand_double();
689 
691 static inline void *potion_gc_alloc(Potion *P, PNType vt, int siz) {
692  struct PNMemory *M = P->mem;
693  struct PNObject *res = 0;
694  if (siz < sizeof(struct PNFwd))
695  siz = sizeof(struct PNFwd);
696  siz = PN_ALIGN(siz, 8); // force 64-bit alignment
697  /*@ assert Value: mem_access: \valid_read(&M->dirty); */
698  /*@ assert
699  Value: ptr_comparison:
700  \pointer_comparable((char *)M->birth_cur+siz,
701  (char *)M->birth_storeptr-2); */
702  assert(M);
703  assert(M->birth_cur);
704  assert(M->birth_storeptr);
705  if (M->dirty || (char *)M->birth_cur + siz >= (char *)M->birth_storeptr - 2)
706  potion_garbagecollect(P, siz + 4 * sizeof(double), 0);
707  res = (struct PNObject *)M->birth_cur;
708  res->vt = vt;
709  res->uniq = (PNUniq)potion_rand_int();
710  M->birth_cur = (char *)res + siz;
711  return (void *)res;
712 }
713 
714 // TODO: mmap already inits to zero?
715 static inline void *potion_gc_calloc(Potion *P, PNType vt, int siz) {
716  return potion_gc_alloc(P, vt, siz);
717 }
718 
719 static inline void potion_gc_update(Potion *P, PN x) {
720  struct PNMemory *M = P->mem;
721  if ((x > (PN)M->birth_lo && x < (PN)M->birth_hi && (x < (PN)M || x >= (PN)M->protect)) ||
722  x == (PN)M->birth_storeptr[1] ||
723  x == (PN)M->birth_storeptr[2] ||
724  x == (PN)M->birth_storeptr[3])
725  return;
726  *(M->birth_storeptr--) = (void *)x;
727  if ((void **)M->birth_storeptr - 4 <= (void **)M->birth_cur)
729 }
730 
731 static inline void *potion_gc_realloc(Potion *P, PNType vt, struct PNObject * volatile obj, PN_SIZE sz) {
732  void *dst = 0;
733  PN_SIZE oldsz = 0;
734 
735  if (obj != NULL) {
736  oldsz = potion_type_size(P, (const struct PNObject *)obj);
737  if (oldsz >= sz)
738  return (void *)obj;
739  }
740 
741  dst = potion_gc_alloc(P, vt, sz);
742  if (obj != NULL) {
743  memcpy(dst, (void *)obj, oldsz);
744  ((struct PNFwd *)obj)->fwd = POTION_FWD;
745  ((struct PNFwd *)obj)->siz = oldsz;
746  ((struct PNFwd *)obj)->ptr = (PN)dst;
747  potion_gc_update(P, (PN)obj);
748  }
749 
750  return dst;
751 }
752 
756 static inline struct PNData *potion_data_alloc(Potion *P, int siz) {
757  struct PNData *data = potion_gc_alloc(P, PN_TUSER, sizeof(struct PNData) + siz);
758  data->siz = siz;
759  return data;
760 }
761 
765 #define POTION_OK 0
766 #define POTION_NO_MEM 8910
767 
772 #define potion_send(RCV, MSG, ARGS...) ({ \
773  PN r = (PN)(RCV); \
774  PN c = potion_bind(P, r, (MSG)); \
775  if (PN_IS_CLOSURE(c)) \
776  c = ((struct PNClosure *)c)->method(P, c, r, ##ARGS); \
777  c; \
778  })
779 
780 #define potion_method(RCV, MSG, FN, SIG) \
781  potion_send(RCV, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))
782 #define potion_class_method(RCV, MSG, FN, SIG) \
783  potion_send(((struct PNVtable *)(RCV))->meta, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))
784 
789  PN_while;
792 extern PN PN_extern, PN_integer;
793 extern PN pn_filenames;
794 
796 static inline PN potion_type_default(char type) {
797  return type == 'N' ? PN_ZERO
798  : type == 'I' ? PN_ZERO
799  : type == 'S' ? PN_STR0
800  : PN_NIL;
801 }
802 
806 Potion *potion_create(void *);
807 void potion_destroy(Potion *);
808 PN potion_error(Potion *, PN, long, long, PN);
809 void potion_fatal(char *);
810 void potion_allocation_error(void);
811 PN potion_io_error(Potion *, const char *);
813 PN potion_type_error_want(Potion *, const char *, PN, const char *);
814 void potion_syntax_error(Potion *, struct PNSource *, const char *, ...)
815  __attribute__ ((format (printf, 3, 4)));
817 void potion_p(Potion *, PN);
818 PN potion_str(Potion *, const char *);
819 PN potion_str2(Potion *, char *, size_t);
820 PN potion_strcat(Potion *P, char *str, char *str2);
821 PN potion_str_add(Potion *P, PN, PN, PN);
822 PN potion_str_format(Potion *, const char *, ...)
823  __attribute__ ((format (printf, 2, 3)));
824 PN potion_byte_str(Potion *, const char *);
825 PN potion_byte_str2(Potion *, const char *, size_t len);
826 PN potion_bytes(Potion *, size_t);
827 PN potion_bytes_string(Potion *, PN, PN);
828 PN_SIZE pn_printf(Potion *, PN, const char *, ...)
829  __attribute__ ((format (printf, 3, 4)));
830 void potion_bytes_obj_string(Potion *, PN, PN);
831 PN potion_bytes_append(Potion *, PN, PN, PN);
832 void potion_release(Potion *, PN);
833 PN potion_def_method(Potion *P, PN, PN, PN, PN);
834 PN potion_type_new(Potion *, PNType, PN);
835 PN potion_type_new2(Potion *, PNType, PN, PN);
836 void potion_type_call_is(PN, PN);
837 void potion_type_callset_is(PN, PN);
838 void potion_type_constructor_is(PN, PN);
839 char potion_type_char(PNType);
840 PN potion_class(Potion *, PN, PN, PN);
841 PN potion_ivars(Potion *, PN, PN, PN);
842 PN potion_obj_get_call(Potion *, PN);
843 PN potion_obj_get_callset(Potion *, PN);
844 PN potion_obj_get(Potion *, PN, PN, PN);
845 PN potion_obj_set(Potion *, PN, PN, PN, PN);
846 PN potion_object_new(Potion *, PN, PN);
847 PN potion_delegated(Potion *, PN, PN);
848 PN potion_call(Potion *, PN, PN_SIZE, PN * volatile);
849 PN potion_lookup(Potion *, PN, PN, PN);
850 PN potion_bind(Potion *, PN, PN);
851 PN potion_message(Potion *, PN, PN);
852 PN potion_closure_new(Potion *, PN_F, PN, PN_SIZE);
853 PN potion_callcc(Potion *, PN, PN);
854 PN potion_ref(Potion *, PN);
855 PN potion_sig(Potion *, char *);
856 int potion_sig_find(Potion *, PN, PN);
857 PN potion_double(Potion *, double);
858 PN potion_strtod(Potion *, char *, int);
859 PN potion_num_pow(Potion *, PN, PN, PN);
860 PN potion_num_rand(Potion *, PN, PN);
861 PN potion_srand(Potion *, PN, PN, PN);
862 PN potion_rand(Potion *, PN, PN);
863 PN potion_sig_at(Potion *, PN, int);
864 PN potion_sig_name_at(Potion *, PN, int);
865 int potion_sig_arity(Potion *, PN);
866 int potion_sig_minargs(Potion *, PN);
867 PN potion_closure_arity(Potion *, PN, PN);
868 PN potion_closure_minargs(Potion *, PN, PN);
869 void potion_define_global(Potion *, PN, PN);
870 
871 PN potion_obj_add(Potion *, PN, PN);
872 PN potion_obj_sub(Potion *, PN, PN);
873 PN potion_obj_mult(Potion *, PN, PN);
874 PN potion_obj_div(Potion *, PN, PN);
875 PN potion_obj_rem(Potion *, PN, PN);
876 PN potion_obj_bitn(Potion *, PN);
877 PN potion_obj_bitl(Potion *, PN, PN);
878 PN potion_obj_bitr(Potion *, PN, PN);
879 PN potion_any_cmp(Potion *, PN, PN, PN);
880 
881 PN potion_tuple_empty(Potion *);
882 PN potion_tuple_with_size(Potion *, unsigned long);
883 PN potion_tuple_new(Potion *, PN);
884 PN potion_tuple_push(Potion *, PN, PN);
885 PN_SIZE potion_tuple_push_unless(Potion *, PN, PN);
886 PN_SIZE potion_tuple_find(Potion *, PN, PN);
887 PN potion_tuple_at(Potion *, PN, PN, PN);
888 PN potion_tuple_shift(Potion *, PN, PN);
889 PN potion_tuple_bsearch(Potion *, PN, PN, PN);
890 PN potion_tuple_ins_sort(Potion *, PN, PN, PN);
891 PN potion_table_empty(Potion *);
892 PN potion_table_put(Potion *, PN, PN, PN, PN);
893 PN potion_table_set(Potion *, PN, PN, PN);
894 PN potion_table_at(Potion *, PN, PN, PN);
895 PN potion_lick(Potion *, PN, PN, PN);
896 PN potion_source_compile(Potion *, PN, PN, PN, PN);
897 PN potion_source_load(Potion *, PN, PN);
898 PN potion_source_dump(Potion *, PN, PN, PN, PN);
899 PN potion_source_dumpbc(Potion *, PN, PN, PN);
900 PN potion_greg_parse(Potion *, PN);
901 PN potion_sig_string(Potion *, PN, PN);
902 PN potion_filename_find(Potion *, PN);
903 PN potion_filename_push(Potion *, PN);
904 
905 Potion *potion_gc_boot(void *);
906 void potion_lobby_init(Potion *);
907 void potion_object_init(Potion *);
908 void potion_error_init(Potion *);
909 void potion_primitive_init(Potion *);
910 void potion_num_init(Potion *);
911 void potion_str_hash_init(Potion *);
912 void potion_str_init(Potion *);
913 void potion_table_init(Potion *);
914 void potion_source_init(Potion *);
915 void potion_lick_init(Potion *);
916 void potion_compiler_init(Potion *);
917 void potion_vm_init(Potion *);
918 void potion_cont_init(Potion *);
919 #ifndef SANDBOX
920 void potion_file_init(Potion *);
921 void potion_loader_init(Potion *);
922 void potion_loader_add(Potion *, PN path);
923 PN potion_load(Potion *, PN, PN, PN);
924 char *potion_find_file(Potion *, char *str, PN_SIZE str_len);
925 #endif
926 //XXX add this and the ext initializer dynamically to config.h
927 #if defined(STATIC) || defined(SANDBOX)
928 void Potion_Init_readline(Potion *);
929 void Potion_Init_buffile(Potion *);
930 void Potion_Init_aio(Potion *);
931 #endif
932 
933 void potion_dump_stack(Potion *);
934 PN potion_num_string(Potion *, PN, PN);
935 PN potion_gc_reserved(Potion *, PN, PN);
936 PN potion_gc_actual(Potion *, PN, PN);
937 PN potion_gc_fixed(Potion *, PN, PN);
938 
939 PN potion_parse(Potion *, PN, char*);
940 PN potion_vm_proto(Potion *, PN, PN, ...);
941 PN potion_vm_class(Potion *, PN, PN);
942 PN potion_vm(Potion *, PN, PN, PN, PN_SIZE, PN * volatile);
943 PN potion_eval(Potion *, PN);
944 PN potion_run(Potion *, PN, int);
945 PN_F potion_jit_proto(Potion *, PN);
946 
947 PN potion_class_find(Potion *, PN);
948 PNType potion_class_type(Potion *, PN);
949 
950 #endif
PN data
Definition: potion.h:481
volatile void * old_lo
the old region (TODO: consider making the old region common to all threads)
Definition: potion.h:673
void potion_allocation_error(void)
Definition: internal.c:301
void potion_fatal(char *)
Definition: internal.c:282
PN potion_obj_bitn(Potion *, PN)
Definition: objmodel.c:450
void potion_define_global(Potion *, PN, PN)
Definition: objmodel.c:622
PN potion_vm(Potion *, PN, PN, PN, PN_SIZE, PN *volatile)
the bytecode run-loop
Definition: vm.c:594
void potion_syntax_error(Potion *, struct PNSource *, const char *,...) __attribute__((format(printf
PN asmb
assembled instructions
Definition: potion.h:458
PN potion_bytes(Potion *, size_t)
Definition: string.c:342
PN potion_tuple_ins_sort(Potion *P, PN cl, PN self, PN cmp)
Definition: table.c:716
PN potion_sig_string(Potion *, PN, PN)
Definition: compile.c:60
PN PN_bitn
Definition: internal.c:17
PN upvals
variables in upper scopes
Definition: potion.h:452
PN potion_num_string(Potion *, PN, PN)
forwarding pointer (in case of reallocation)
Definition: potion.h:304
bytecode (switch or cgoto)
Definition: potion.h:606
PN_AST
An AST fragment, non-volatile.
Definition: potion.h:386
PN values
numbers, strings, etc.
Definition: potion.h:453
PN potion_rand(Potion *P, PN cl, PN self)
Definition: mt19937ar.c:173
PN name
Definition: potion.h:379
PN line
PNString of src line.
Definition: potion.h:438
void potion_object_init(Potion *)
Definition: objmodel.c:663
syntax_mode_t
Definition: potion.h:618
PN potion_str(Potion *, const char *)
Definition: string.c:33
PN PN_integer
Definition: internal.c:19
byte strings are raw character data, volatile, may be appended/changed.
Definition: potion.h:338
PN potion_load(Potion *, PN, PN, PN)
Definition: load.c:155
void potion_table_init(Potion *)
Definition: table.c:821
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:489
sanity-check
Definition: potion.h:625
#define PN_TSTRING
Definition: potion.h:112
PN_F potion_jit_proto(Potion *, PN)
double potion_rand_double()
generates a random number on [0,1) with 53-bit resolution
Definition: mt19937ar.c:154
PN unclosed
used by parser for named block endings
Definition: potion.h:661
exec_mode_t
the interpreter (one per thread, houses its own garbage collector)
Definition: potion.h:605
a tuple is an array of PNs.
Definition: potion.h:468
PN potion_str_add(Potion *P, PN cl, PN self, PN x)
Definition: string.c:279
PN potion_table_set(Potion *, PN, PN, PN)
helper function for potion_table_put:"put", accepts tuple or table
Definition: table.c:126
PN potion_filename_push(Potion *, PN)
PN PN_number
Definition: internal.c:18
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:645
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:318
static PNType potion_qptr_type(PN obj)
if obj is guaranteed to be a PTR fwd only once, no loop.
Definition: potion.h:555
void potion_compiler_init(Potion *)
Definition: compile.c:1308
volatile void * birth_hi
Definition: potion.h:669
PN PN_compile
Definition: internal.c:14
PN potion_type_new(Potion *, PNType, PN)
create a non-user type, derived from self
Definition: objmodel.c:207
PN PN_add
Definition: internal.c:17
char data[]
Definition: potion.h:320
Potion_Flags flags
vm flags: execution model and debug flags
Definition: potion.h:650
PN ptr
Definition: potion.h:307
unsigned long _PN
Definition: potion.h:78
a closure is an anonymous function, without closed values,
Definition: potion.h:372
the central vtable, see io http://www.piumarta.com/pepsi/objmodel.pdf
Definition: table.h:24
void potion_p(Potion *, PN)
Definition: internal.c:306
#define PN_TUSER
Definition: potion.h:130
PN PN_name
Definition: internal.c:18
PN PN_class
Definition: internal.c:14
PN PN_while
Definition: internal.c:14
PN sig
argument signature
Definition: potion.h:448
PN_SIZE void potion_bytes_obj_string(Potion *, PN, PN)
Definition: string.c:384
void potion_file_init(Potion *)
set Env global
Definition: file.c:189
PN PN_print
Definition: internal.c:14
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:480
struct to wrap arbitrary data that we may want to allocate from Potion.
Definition: potion.h:317
int potion_sig_find(Potion *, PN, PN)
PN potion_closure_new(Potion *, PN_F, PN, PN_SIZE)
Definition: objmodel.c:17
Definition: potion.h:396
PN potion_run(Potion *, PN, int)
Definition: compile.c:1283
PN potion_table_put(Potion *P, PN cl, PN self, PN key, PN value)
Definition: table.c:98
PN PN potion_byte_str(Potion *, const char *)
Definition: string.c:331
static PN potion_type_default(char type)
zero values per type
Definition: potion.h:796
PN potion_sig_name_at(Potion *, PN, int)
Definition: objmodel.c:165
PN potion_tuple_at(Potion *P, PN cl, PN self, PN index)
Definition: table.c:309
PN potion_source_dumpbc(Potion *P, PN cl, PN proto, PN options)
Definition: compile.c:1244
PNTarget target
the jit
Definition: potion.h:646
void potion_error_init(Potion *)
Definition: internal.c:250
PN parent
Definition: potion.h:490
PN potion_closure_arity(Potion *P, PN cl, PN self)
Definition: objmodel.c:64
PN potion_obj_mult(Potion *, PN, PN)
Definition: objmodel.c:438
void(* OP_F)(Potion *P, struct PNProto *, PNAsm *volatile *,...)
Definition: potion.h:584
PN potion_bytes_append(Potion *P, PN cl, PN self, PN str)
Definition: string.c:392
PN line
currently parsed line (for debug)
Definition: potion.h:659
PN potion_ref(Potion *P, PN data)
Definition: objmodel.c:467
PN potion_byte_str2(Potion *, const char *, size_t len)
Definition: string.c:335
#define OP_MAX
the jit
Definition: potion.h:582
#define PN_TNIL
Definition: potion.h:107
unsigned int PNUniq
Definition: potion.h:79
unsigned int PNType
Definition: potion.h:79
Potion_Flags
Definition: potion.h:628
static struct PNData * potion_data_alloc(Potion *P, int siz)
Definition: potion.h:756
static PN potion_fwd(PN)
the potion type is the 't' in the vtable tuple (m,t)
Definition: potion.h:561
PN data[]
PNString.
Definition: potion.h:380
PN PN_delegated
Definition: internal.c:14
int arity
cached number of declared args, including optional
Definition: potion.h:376
PN PN_sub
Definition: internal.c:17
void potion_num_init(Potion *)
Definition: number.c:439
static void potion_gc_update(Potion *P, PN x)
Definition: potion.h:719
PN_SIZE len
Definition: potion.h:330
PN potion_eval(Potion *, PN)
Definition: compile.c:1299
static void * potion_gc_alloc(Potion *P, PNType vt, int siz)
quick inline allocation
Definition: potion.h:691
Potion * potion_gc_boot(void *)
Definition: gc.c:658
struct PNMemory * mem
allocator/gc
Definition: potion.h:651
a file is wrapper around a file descriptor, non-volatile but mutable.
Definition: potion.h:361
PN_SIZE extra
0 or 1 if has code attached at data
Definition: potion.h:378
PN potion_ivars(Potion *, PN, PN, PN)
Definition: objmodel.c:290
PN pn_filenames
Definition: internal.c:23
PN potion_source_load(Potion *P, PN cl, PN buf)
Definition: compile.c:1171
PN potion_call(Potion *, PN, PN_SIZE, PN *volatile)
Definition: internal.c:143
PN PN_length
Definition: internal.c:18
void potion_destroy(Potion *)
Definition: internal.c:133
PN_SIZE fileno
currently parsed file
Definition: potion.h:660
Definition: potion.h:577
PN_F jit
jit function pointer
Definition: potion.h:459
PN potion_source_compile(Potion *P, PN cl, PN self, PN source, PN sig)
Definition: compile.c:1039
void potion_release(Potion *, PN)
void potion_lick_init(Potion *)
Definition: lick.c:68
#define PN_ALIGN(o, x)
Definition: potion.h:223
PN excerpt
Definition: potion.h:493
a weak ref is used for upvals, it acts as a memory slot, non-volatile but mutable.
Definition: potion.h:479
PN PN_div
Definition: internal.c:17
PN PN_else
Definition: internal.c:14
#define PN_ZERO
Definition: potion.h:140
definition of the jit targets: x86, ppc, arm
Definition: potion.h:587
volatile void * birth_lo
the birth region
Definition: potion.h:669
PN potion_source_dump(Potion *P, PN cl, PN self, PN backend, PN options)
Definition: compile.c:1265
void * cstack
machine stack start
Definition: potion.h:676
PN potion_num_pow(Potion *, PN, PN, PN)
PNAsm *volatile pbuf
parser buffer
Definition: potion.h:658
unsigned int PN_SIZE
Definition: potion.h:79
void potion_primitive_init(Potion *)
Definition: primitive.c:77
PN message
Definition: potion.h:491
PN potion_filename_find(Potion *, PN)
standard objects act like C structs the fields are defined by the type and it's a fixed size...
Definition: potion.h:295
void * protect
end of protected memory
Definition: potion.h:677
int arity
cached sig arity (number of args)
Definition: potion.h:460
#define PN_IS_NIL(v)
Definition: potion.h:160
void potion_lobby_init(Potion *)
Definition: objmodel.c:682
enum PN_AST part
AST type, avoid -Wswitch (aligned access: 4+4+8+4+24)
Definition: potion.h:426
PN_SIZE siz
Definition: potion.h:341
static PNType potion_ptr_type(PN obj)
if obj is guaranteed to be a PTR
Definition: potion.h:540
a continuation saves the stack and all stack pointers.
Definition: potion.h:510
PN_SIZE pathsize
Definition: potion.h:457
int prec
double precision
Definition: potion.h:653
PN potion_tuple_shift(Potion *P, PN cl, PN self)
Definition: table.c:503
char * potion_find_file(Potion *, char *str, PN_SIZE str_len)
Definition: load.c:111
PN lobby
root namespace
Definition: potion.h:648
PN potion_table_empty(Potion *P)
Definition: table.c:42
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:296
PN_SIZE len
Definition: potion.h:470
#define EXEC_BITS
0-4
Definition: potion.h:616
PN PN_elsif
Definition: internal.c:14
PN potion_type_error_want(Potion *, const char *, PN, const char *)
Definition: internal.c:273
PN potion_num_rand(Potion *P, PN cl, PN self)
Definition: mt19937ar.c:182
void potion_garbagecollect(Potion *, int, int)
Definition: gc.c:266
a lick is a unit of generic tree data.
Definition: potion.h:499
PN PN_string
Definition: internal.c:14
PN inner
"licks" PNTuple or "text" PNString member
Definition: potion.h:503
PN_SIZE siz
Definition: potion.h:577
PN potion_obj_get(Potion *, PN, PN, PN)
implements OP_GETPATH
Definition: objmodel.c:322
PN locals
local variables
Definition: potion.h:451
PN_F method
Definition: potion.h:374
#define M
Definition: mt19937ar.c:53
the garbage collector
Definition: potion.h:667
int potion_sig_arity(Potion *, PN)
number of args of sig tuple, implements the potion_closure_arity method.
Definition: objmodel.c:82
char chars[]
Definition: potion.h:331
#define PN_IS_BOOL(v)
Definition: potion.h:161
PN PN_cmp
Definition: internal.c:18
unsigned long potion_rand_int()
generates a random number on [0,0xffffffff]-interval
Definition: mt19937ar.c:138
the table class, based on khash
Definition: table.h:40
PN potion_tuple_new(Potion *, PN)
Definition: table.c:247
PN paths
paths (instance variables)
Definition: potion.h:450
PN potion_message(Potion *, PN, PN)
Definition: objmodel.c:423
PN potion_parse(Potion *, PN, char *)
volatile void * old_hi
Definition: potion.h:673
PN PN_rem
Definition: internal.c:17
PN potion_type_error(Potion *, PN)
Definition: internal.c:269
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:446
PN_SIZE len
Definition: potion.h:340
#define PN_TBOOLEAN
Definition: potion.h:109
PN potion_obj_div(Potion *, PN, PN)
Definition: objmodel.c:442
PN PN_allocate
common method names in GC protected area
Definition: internal.c:14
PN PN_bitl
Definition: internal.c:17
PN potion_io_error(Potion *, const char *)
Definition: internal.c:255
char potion_type_char(PNType)
valid signature types syntax.y: arg-type = ('s' | 'S' | 'n' | 'N' | 'b' | 'B' | 'k' | 't' | 'o' | 'O'...
Definition: internal.c:202
volatile void ** birth_storeptr
Definition: potion.h:670
PN_SIZE upvalsize
Definition: potion.h:457
PN potion_any_cmp(Potion *P, PN cl, PN self, PN value)
Definition: primitive.c:26
Potion * potion_create(void *)
the potion API
Definition: internal.c:120
PN potion_tuple_bsearch(Potion *P, PN cl, PN self, PN x)
Definition: table.c:614
PN potion_class(Potion *, PN, PN, PN)
create a user-class (ie type)
Definition: objmodel.c:252
unsigned int fwd
Definition: potion.h:305
PN_SIZE siz
Definition: potion.h:319
strings are immutable UTF-8, the ID is incremental and they may be garbage collected.
Definition: potion.h:328
PN potion_bytes_string(Potion *P, PN cl, PN self)
Definition: string.c:420
PN potion_vm_proto(Potion *, PN, PN,...)
entrypoint for all bytecode methods from the C api.
Definition: vm.c:159
void potion_source_init(Potion *)
Definition: ast.c:157
PN callset
generic call and setter
Definition: potion.h:652
PN PN_STR0
Definition: internal.c:18
PN potion_bind(Potion *, PN, PN)
find method for given receiver and message (method lookup)
Definition: objmodel.c:403
PN name
PNString.
Definition: potion.h:501
PN potion_class_find(Potion *, PN)
find class by name. At first only system metaclasses (types), no user classes yet.
Definition: objmodel.c:275
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:500
PN_SIZE potion_type_size(Potion *, const struct PNObject *)
Definition: gc.c:306
PN PN_call
Definition: internal.c:14
PN PN_loop
Definition: internal.c:14
PN potion_obj_set(Potion *, PN, PN, PN, PN)
implements OP_SETPATH
Definition: objmodel.c:329
double value
Definition: potion.h:354
double time
Definition: potion.h:679
PN potion_lookup(Potion *, PN, PN, PN)
used in bind and def_method
Definition: objmodel.c:391
PN potion_error(Potion *, PN, long, long, PN)
Definition: internal.c:232
PN potion_tuple_push(Potion *, PN, PN)
Definition: table.c:254
JIT if detected at config-time (x86, ppc)
Definition: potion.h:607
-c stop after compilation
Definition: potion.h:609
a prototype is compiled source code, a closure block (lambda) non-volatile.
Definition: potion.h:445
PN potion_table_at(Potion *P, PN cl, PN self, PN key)
Definition: table.c:70
PNType fileno
Definition: potion.h:434
PN potion_obj_add(Potion *, PN, PN)
Definition: objmodel.c:430
PNFlex *volatile vts
built in types
Definition: potion.h:649
PN potion_obj_bitl(Potion *, PN, PN)
Definition: objmodel.c:454
volatile int pass
Definition: potion.h:675
PN protos
nested closures
Definition: potion.h:454
an error, including a description, file location, a brief excerpt.
Definition: potion.h:488
#define PN_IS_PTR(v)
Definition: potion.h:159
PN PN_bitr
Definition: internal.c:17
ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS PN potion_callcc(Potion *P, PN cl, PN self)
Definition: callcc.c:102
PN potion_str_format(Potion *, const char *,...) __attribute__((format(printf
PN source
parser input and output (AST)
Definition: potion.h:656
Definition: potion.h:398
PN chr
Definition: potion.h:492
static char * potion_str_ptr(PN s)
quick access to either PNString or PNByte pointer
Definition: potion.h:568
volatile void * old_cur
Definition: potion.h:673
static void * potion_gc_calloc(Potion *P, PNType vt, int siz)
Definition: potion.h:715
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:339
PN line
Definition: potion.h:492
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: vm.c:203
PN potion_closure_minargs(Potion *P, PN cl, PN self)
Definition: objmodel.c:71
sanity-check (possible stack overwrites by callcc)
Definition: potion.h:611
PN attr
PN.
Definition: potion.h:502
PN potion_gc_fixed(Potion *, PN, PN)
Definition: gc.c:724
PN PN_size
Definition: internal.c:18
PN potion_delegated(Potion *, PN, PN)
Definition: internal.c:137
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:353
Definition: potion.h:391
PN PN_return
Definition: internal.c:14
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:362
Definition: potion.h:394
-d: instrumented bytecode (line stepping) or just slow runloop?
Definition: potion.h:608
PN path
Definition: potion.h:364
volatile void * birth_cur
Definition: potion.h:669
int potion_sig_minargs(Potion *, PN)
number of mandatory args, without any optional arguments
Definition: objmodel.c:107
int minargs
cached number of mandatory args, without optional
Definition: potion.h:377
PN potion_greg_parse(Potion *, PN)
PN_SIZE potion_tuple_find(Potion *, PN, PN)
Return index of found value or PN_NONE.
Definition: table.c:280
the global interpreter state P. currently singleton (not threads yet)
Definition: potion.h:644
volatile int majors
Definition: potion.h:675
PN_SIZE pn_printf(Potion *, PN, const char *,...) __attribute__((format(printf
PN potion_def_method(Potion *P, PN, PN, PN, PN)
define a method for a class
Definition: objmodel.c:346
PN sig
signature PNTuple
Definition: potion.h:375
PN potion_strtod(Potion *, char *, int)
Convert string to double.
Definition: number.c:24
PN_SIZE len
Definition: potion.h:512
PN potion_strcat(Potion *P, char *str, char *str2)
Definition: string.c:64
PN potion_tuple_empty(Potion *)
Definition: table.c:235
PN potion_obj_bitr(Potion *, PN, PN)
Definition: objmodel.c:458
PN potion_srand(Potion *P, PN cl, PN self, PN seed)
Definition: mt19937ar.c:163
#define PN_IS_INT(v)
Definition: potion.h:162
void potion_str_init(Potion *)
Definition: string.c:491
PN_SIZE potion_tuple_push_unless(Potion *, PN, PN)
Definition: table.c:290
void potion_type_callset_is(PN, PN)
set default writer
Definition: objmodel.c:235
void potion_str_hash_init(Potion *)
Definition: string.c:487
PN debugs
tree parts
Definition: potion.h:455
static PNType potion_type(PN obj)
either immediate (NUM,BOOL,NIL) or a fwd
Definition: potion.h:523
#define PN_QUICK_FWD(t, obj)
PN_QUICK_FWD - doing a single fwd check after a possible realloc.
Definition: potion.h:549
struct PNSource *volatile a[3]
PNTuple of 1-3 kids,.
Definition: potion.h:427
PN_SIZE localsize
Definition: potion.h:457
void potion_type_constructor_is(PN, PN)
set default constructor
Definition: objmodel.c:245
mode_t mode
Definition: potion.h:365
0x10 16 plain potion syntax
Definition: potion.h:619
PN PN_if
Definition: internal.c:14
_PN(* PN_F)(Potion *, PN, PN,...)
Definition: potion.h:207
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:329
PN stack
size of the stack
Definition: potion.h:449
PNType potion_class_type(Potion *, PN)
Definition: objmodel.c:285
PN_SIZE siz
Definition: potion.h:306
PN potion_str2(Potion *, char *, size_t)
Definition: string.c:47
doubles are floating point numbers stored as binary data.
Definition: potion.h:352
PN potion_gc_actual(Potion *, PN, PN)
Definition: gc.c:714
PN stack[]
Definition: potion.h:513
PN potion_double(Potion *, double)
new PNDouble (double)
Definition: number.c:17
PN potion_sig_at(Potion *, PN, int)
Definition: objmodel.c:131
PN potion_obj_rem(Potion *, PN, PN)
Definition: objmodel.c:446
#define POTION_PAGESIZE
Definition: config.h:36
PN_SIZE alloc
overallocate a bit
Definition: potion.h:471
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:511
void potion_cont_init(Potion *)
Definition: callcc.c:169
PN PN_lookup
Definition: internal.c:14
PN PN_def
Definition: internal.c:14
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:373
PN tree
abstract syntax tree
Definition: potion.h:456
PN PN_continue
Definition: internal.c:14
int yypos
parser buffer position
Definition: potion.h:657
#define PN_FLEX(N, T)
Definition: potion.h:229
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:469
volatile _PN PN
Definition: potion.h:81
PNType lineno
Definition: potion.h:435
volatile int dirty
Definition: potion.h:675
#define PN_NIL
Definition: potion.h:139
PN potion_obj_get_call(Potion *, PN)
get the default accessor (usually "at")
Definition: objmodel.c:229
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:425
#define PN_TNUMBER
Definition: potion.h:108
PN PN_extern
Definition: internal.c:19
static void * potion_gc_realloc(Potion *P, PNType vt, struct PNObject *volatile obj, PN_SIZE sz)
Definition: potion.h:731
PN source
program name or enclosing scope
Definition: potion.h:447
#define PN_OBJECT_HEADER
Definition: potion.h:225
#define POTION_FWD
Definition: potion.h:146
PN name
PNString.
Definition: potion.h:461
struct PNTable * strings
table of all strings
Definition: potion.h:647
PN potion_gc_reserved(Potion *, PN, PN)
Definition: gc.c:732
void PNType potion_kind_of(PN)
Definition: internal.c:195
PN potion_obj_get_callset(Potion *, PN)
get default writer
Definition: objmodel.c:239
PN PN_self
Definition: internal.c:14
struct PNSource::@1 loc
bitfield of fileno and lineno
void potion_loader_add(Potion *, PN path)
Definition: load.c:183
to bytecode (dumpbc)
Definition: potion.h:610
int fd
Definition: potion.h:363
PN potion_sig(Potion *, char *)
void potion_vm_init(Potion *)
Definition: vm.c:129
PN ivars[]
Definition: potion.h:297
PN potion_type_new2(Potion *, PNType, PN, PN)
create a named type
Definition: objmodel.c:219
PN set[]
Definition: potion.h:472
char chars[]
Definition: potion.h:342
volatile int minors
Definition: potion.h:675
void potion_dump_stack(Potion *)
Definition: internal.c:326
PN ivars
PNTuple of all our or the parents inherited vars.
Definition: table.h:30
PN potion_obj_sub(Potion *, PN, PN)
Definition: objmodel.c:434
void potion_loader_init(Potion *)
Definition: load.c:187
PN potion_lick(Potion *, PN, PN, PN)
Definition: lick.c:11
void potion_type_call_is(PN, PN)
sets the default call method of the PNVtable
Definition: objmodel.c:225
PN potion_object_new(Potion *P, PN cl, PN self)
Definition: objmodel.c:516
PN PN_mult
Definition: internal.c:17
PN potion_tuple_with_size(Potion *, unsigned long)
Definition: table.c:242
volatile int collecting
Definition: potion.h:675
PN PN_break
Definition: internal.c:14