p2  0.0
 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 #ifdef P2
155 // in perl there is lot more false: undef,0,"",(), but {} is true
156 //Beware: TEST1(PN_NUM(0)) vs TEST(0<1) i.e. test1(1) vs test(1)
157 #define PN_TEST(v) ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)
158 #define PN_TEST1(v) ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL \
159  && (PN)(v) != PN_ZERO && (PN)(v) != PN_STR0 \
160  && (!PN_IS_TUPLE(v) || PN_IS_EMPTY(v)))
161 #else
162 #define PN_TEST(v) ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)
163 #define PN_TEST1(v) ((PN)(v) != PN_FALSE && (PN)(v) != PN_NIL)
164 #endif
165 #define PN_BOOL(v) (PN_TEST(v) ? PN_TRUE : PN_FALSE)
168 #define PN_IS_PTR(v) (!PN_IS_INT(v) && ((PN)(v) & PN_REF_MASK))
169 #define PN_IS_NIL(v) ((PN)(v) == PN_NIL)
170 #define PN_IS_BOOL(v) ((PN)(v) & PN_FBOOLEAN)
171 #define PN_IS_INT(v) ((PN)(v) & PN_FINTEGER)
172 #define PN_IS_DBL(v) (PN_IS_PTR(v) && ({PNType _t = potion_qptr_type((PN)v); _t == PN_TNUMBER || _t == PN_TDOUBLE;}))
173 #define PN_IS_NUM(v) (PN_IS_INT(v) || PN_IS_DBL(v))
174 #define PN_IS_TUPLE(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTUPLE))
175 #define PN_IS_STR(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TSTRING))
176 #define PN_IS_TABLE(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TTABLE))
177 #define PN_IS_CLOSURE(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TCLOSURE))
178 #define PN_IS_PROTO(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TPROTO))
179 #define PN_IS_REF(v) (PN_IS_PTR(v) && (potion_ptr_type((PN)v) == PN_TWEAK))
180 #define PN_IS_METACLASS(v) (((struct PNVtable *)v)->meta == PN_NIL)
181 #define PN_IS_FFIPTR(p) ((PN_IS_PTR(p) && !(p >= (_PN)P->mem && p <= (_PN)P->mem->birth_hi)) \
182  || (!PN_IS_PTR(p) && p > (_PN)P->mem->birth_hi))
183 
184 #define PN_CHECK_STR(obj) if (!PN_IS_STR(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "String")
185 #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")
186 #define PN_CHECK_NUM(obj) if (!PN_IS_NUM(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Number")
187 #define PN_CHECK_INT(obj) if (!PN_IS_INT(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Integer")
188 #define PN_CHECK_DBL(obj) if (!PN_IS_DBL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Double")
189 #define PN_CHECK_BOOL(obj) if (!PN_IS_BOOL(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Bool")
190 #define PN_CHECK_TUPLE(obj) if (!PN_IS_TUPLE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Tuple")
191 #define PN_CHECK_CLOSURE(obj) if (!PN_IS_CLOSURE(obj)) return potion_type_error_want(P, ""#obj, (PN)obj, "Closure")
192 //exact only. TODO check derived types, parents and mixins via bind
193 #define PN_CHECK_TYPE(obj,type) if (type != PN_TYPE(obj)) return potion_type_error(P, (PN)obj)
194 #ifdef DEBUG
195 #define DBG_CHECK_TYPE(obj,type) PN_CHECK_TYPE(obj,type)
196 #define DBG_CHECK_NUM(obj) PN_CHECK_NUM(obj)
197 #define DBG_CHECK_INT(obj) PN_CHECK_INT(obj)
198 #define DBG_CHECK_DBL(obj) PN_CHECK_DBL(obj)
199 #define DBG_CHECK_TUPLE(obj) PN_CHECK_TUPLE(obj)
200 #else
201 #define DBG_CHECK_TYPE(obj,type)
202 #define DBG_CHECK_NUM(obj)
203 #define DBG_CHECK_INT(obj)
204 #define DBG_CHECK_DBL(obj)
205 #define DBG_CHECK_TUPLE(obj)
206 #endif
207 
213 #define PN_NUM(i) ((PN)((((long)(i))<<1) + PN_FINTEGER))
214 #define PN_INT(x) ((long)((long)(x))>>1)
215 #define PN_DBL(num) (PN_IS_INT(num) ? (double)PN_INT(num) : ((struct PNDouble *)num)->value)
216 typedef _PN (*PN_F)(Potion *, PN, PN, ...);
217 #define PN_PREC 16
218 #define PN_RAND() PN_NUM(potion_rand_int())
219 #define PN_STR(x) potion_str(P, x)
220 #define PN_STRN(x, l) potion_str2(P, x, l)
221 #define PN_STRCAT(a, b) potion_strcat(P, (a), (b))
222 #define PN_STR_PTR(x) potion_str_ptr(x)
223 #define PN_STR_LEN(x) ((struct PNString *)(x))->len
224 #define PN_STR_B(x) potion_bytes_string(P, PN_NIL, x)
225 #define PN_CLOSURE(x) ((struct PNClosure *)(x))
226 #define PN_CLOSURE_F(x) ((struct PNClosure *)(x))->method
227 #define PN_PROTO(x) ((struct PNProto *)(x))
228 #define PN_FUNC(f, s) potion_closure_new(P, (PN_F)f, potion_sig(P, s), 0)
229 #define PN_DEREF(x) ((struct PNWeakRef *)(x))->data
230 #define PN_DATA(x) ((struct PNData *)(x))->data
231 #define PN_TOUCH(x) potion_gc_update(P, (PN)(x))
232 #define PN_ALIGN(o, x) (((((o) - 1) / (x)) + 1) * (x))
233 
234 #define PN_OBJECT_HEADER \
235  PNType vt; \
236  PNUniq uniq
237 
238 #define PN_FLEX(N, T) typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; T ptr[]; } N
239 #define PN_FLEX_AT(N, I) ((PNFlex *)(N))->ptr[I]
240 #define PN_FLEX_SIZE(N) ((PNFlex *)(N))->len
241 
242 #if PN_SIZE_T == 4
243 #define PN_NUMHASH(x) x
244 #else
245 #define PN_NUMHASH(x) (PNUniq)((x)>>33^(x)^(x)<<11)
246 #endif
247 #define PN_UNIQ(x) (PN_IS_PTR(x) ? ((struct PNObject *)(x))->uniq : PN_NUMHASH(x))
248 
249 #define AS_STR(x) PN_STR_PTR(potion_send(x, PN_string))
250 #ifdef DEBUG
251 #define DBG_t(...) \
252  if (P->flags & DEBUG_TRACE) fprintf(stderr, __VA_ARGS__)
253 #define DBG_v(...) \
254  if (P->flags & DEBUG_VERBOSE) fprintf(stderr, __VA_ARGS__)
255 #define DBG_vt(...) \
256  if (P->flags & DEBUG_VERBOSE && P->flags & DEBUG_TRACE) fprintf(stderr, __VA_ARGS__)
257 #define DBG_vi(...) \
258  if (P->flags & DEBUG_VERBOSE && P->flags & DEBUG_INSPECT) fprintf(stderr, __VA_ARGS__)
259 #define DBG_c(...) \
260  if (P->flags & DEBUG_COMPILE) fprintf(stderr, __VA_ARGS__)
261 #else
262 #define DBG_t(...)
263 #define DBG_v(...)
264 #define DBG_vt(...)
265 #define DBG_vi(...)
266 #define DBG_c(...)
267 #endif
268 
269 #define PN_IS_EMPTY(T) (PN_TUPLE_LEN(T) == 0)
270 #define PN_TUP0() potion_tuple_empty(P)
271 #define PN_TUP(X) potion_tuple_new(P, X)
272 #define PN_PUSH(T, X) potion_tuple_push(P, T, (PN)X)
273 #define PN_SHIFT(T) potion_tuple_shift(P, 0, T)
274 #define PN_GET(T, X) potion_tuple_find(P, T, X)
275 #define PN_PUT(T, X) potion_tuple_push_unless(P, T, X)
276 #define PN_GET_TUPLE(t) ((struct PNTuple *)potion_fwd((PN)t))
277 #define PN_TUPLE_LEN(t) PN_GET_TUPLE(t)->len
278 #define PN_TUPLE_AT(t, n) PN_GET_TUPLE(t)->set[n]
279 #define PN_TUPLE_COUNT(T, I, B) ({ \
281  struct PNTuple * volatile __t##I = PN_GET_TUPLE(T); \
282  if (__t##I->len != 0) { \
283  PN_SIZE I; \
284  for (I = 0; I < __t##I->len; I++) B \
285  } \
286  })
287 #define PN_TUPLE_EACH(T, I, V, B) ({ \
289  struct PNTuple * volatile __t##V = PN_GET_TUPLE(T); \
290  if (__t##V->len != 0) { \
291  PN_SIZE I; \
292  for (I = 0; I < __t##V->len; I++) { \
293  PN V = __t##V->set[I]; \
294  B \
295  } \
296  } \
297  })
298 
304 struct PNObject {
307 };
308 
313 struct PNFwd {
314  unsigned int fwd;
317 };
318 
326 struct PNData {
329  char data[];
330 };
331 
337 struct PNString {
340  char chars[];
341 };
342 
347 struct PNBytes {
351  char chars[];
352 };
353 
355 #define PN_MANTISSA(d, n) d->real[1 + n]
356 
361 struct PNDouble {
363  double value;
364 };
365 
370 struct PNFile {
372  int fd;
374  mode_t mode;
375 };
376 
381 struct PNClosure {
384  PN sig;
385  int arity;
386  int minargs;
389  PN data[];
390 };
391 
395 enum PN_AST {
427  AST_LIST, /* for TABLE (=,..) and TUPLE (,...) */
429  AST_LICK, /* [...] */
432 };
433 struct PNSource {
435  enum PN_AST part;
436  struct PNSource * volatile a[3];
437  // luxury for reflection only: debugging, error messages
438  struct {
439 #if PN_SIZE_T != 8
440  PNType fileno:16;
441  PNType lineno:16;
442 #else
445 #endif
446  } loc;
448 };
449 
454 struct PNProto {
457  PN sig;
469  int arity;
471 };
472 
477 struct PNTuple {
481  PN set[];
482 };
483 
488 struct PNWeakRef {
491 };
492 
497 struct PNError {
503 };
504 
508 struct PNLick {
513 };
514 
519 struct PNCont {
522  PN stack[]; // [0] = head of potion stack
523  // [1] = current %rsp
524  // [2] = current %rbp
525  // [3+] = full stack dump, ascending
526 };
527 
529 static inline PN potion_fwd(PN);
530 
532 static inline PNType potion_type(PN obj) {
533  if (PN_IS_INT(obj)) return PN_TNUMBER;
534  if (PN_IS_BOOL(obj)) return PN_TBOOLEAN;
535  if (PN_IS_NIL(obj)) return PN_TNIL;
536 #if 1
537  while (1) {
538  struct PNFwd *o = (struct PNFwd *)obj;
539  if (o->fwd != POTION_FWD)
540  return ((struct PNObject *)o)->vt;
541  obj = o->ptr;
542  }
543 #else
544  return ((struct PNObject *)potion_fwd(obj))->vt;
545 #endif
546 }
547 
549 static inline PNType potion_ptr_type(PN obj) {
550  while (1) {
551  struct PNFwd *o = (struct PNFwd *)obj;
552  if (o->fwd != POTION_FWD)
553  return ((struct PNObject *)o)->vt;
554  obj = o->ptr;
555  }
556 }
558 #define PN_QUICK_FWD(t, obj) \
559  if (((struct PNFwd *)obj)->fwd == POTION_FWD) \
560  obj = (t)(((struct PNFwd *)obj)->ptr);
561 
564 static inline PNType potion_qptr_type(PN obj) {
565  PN_QUICK_FWD(PN, obj);
566  return ((struct PNObject *)obj)->vt;
567 }
568 
570 static inline PN potion_fwd(PN obj) {
571  while (PN_IS_PTR(obj) && ((struct PNFwd *)obj)->fwd == POTION_FWD)
572  obj = ((struct PNFwd *)obj)->ptr;
573  return obj;
574 }
575 
577 static inline char *potion_str_ptr(PN s) {
578  if (((struct PNString *)s)->vt == PN_TSTRING)
579  return ((struct PNString *)s)->chars;
580  s = potion_fwd(s);
581  return ((struct PNBytes *)s)->chars;
582 }
583 
584 PN_FLEX(PNFlex, PN);
585 //PN_FLEX(PNAsm, unsigned char);
586 typedef struct { PN_OBJECT_HEADER; PN_SIZE len; PN_SIZE siz; unsigned char ptr[]; } PNAsm;
587 
591 #define OP_MAX 50 // OP_DEBUG+1 was 64, statically allocated in Potion interpreter
592 
593 typedef void (*OP_F)(Potion *P, struct PNProto *, PNAsm * volatile *, ...);
594 
596 typedef struct {
597  void (*setup) (Potion *, struct PNProto * volatile, PNAsm * volatile *);
598  void (*stack) (Potion *, struct PNProto * volatile, PNAsm * volatile *, long);
599  void (*registers)(Potion *, struct PNProto * volatile, PNAsm * volatile *, long);
600  void (*local) (Potion *, struct PNProto * volatile, PNAsm * volatile *, long, long);
601  void (*upvals) (Potion *, struct PNProto * volatile, PNAsm * volatile *, long, long, int);
602  void (*jmpedit) (Potion *, struct PNProto * volatile, PNAsm * volatile *, unsigned char *, int);
604  void (*finish) (Potion *, struct PNProto * volatile, PNAsm * volatile *);
605  void (*mcache) (Potion *, struct PNVtable * volatile, PNAsm * volatile *);
606  void (*ivars) (Potion *, PN, PNAsm * volatile *);
607 } PNTarget;
608 
613 
614 typedef enum {
615  EXEC_VM = 0,
616  EXEC_JIT = 1,
620  MAX_EXEC = 5
621 } exec_mode_t;
622 
623 // we combine the exclusive enum 0-4 for exec, then the exclusive syntax modes 16-18,
624 // and finally the inclusive debugging modes
625 #define EXEC_BITS 4
626 
627 typedef enum {
629 #ifdef P2
630  MODE_P2 = MODE_STD+1,
631  MODE_P6 = MODE_STD+2,
632 #endif
633  // room for registered syntax modules 18-63 (45 modules: p5, p6, sql, c, ...)
634  MAX_SYNTAX = (1<<(EXEC_BITS+2))-1
635 } syntax_mode_t;
636 
637 typedef enum {
638  // exec + syntax + debug flags:
639  DEBUG_INSPECT = 1<<(EXEC_BITS+2), // 0x0040
640  DEBUG_VERBOSE = 1<<(EXEC_BITS+3) // 0x0080
641 #ifdef DEBUG
642  ,
643  DEBUG_TRACE = 1<<(EXEC_BITS+4), // 0x0100
644  DEBUG_PARSE = 1<<(EXEC_BITS+5), // 0x0200
645  DEBUG_PARSE_VERBOSE = 1<<(EXEC_BITS+6),// 0x0400
646  DEBUG_COMPILE = 1<<(EXEC_BITS+7), // 0x2000
647  DEBUG_GC = 1<<(EXEC_BITS+8), // 0x0800
648  DEBUG_JIT = 1<<(EXEC_BITS+9) // 0x1000
649 #endif
650 } Potion_Flags;
651 
653 struct Potion_State {
656  struct PNTable *strings;
658  PNFlex * volatile vts;
660  struct PNMemory *mem;
662  int prec;
663 
664  //parser-only:
666  int yypos;
667  PNAsm * volatile pbuf;
671 };
672 
676 struct PNMemory {
678  volatile void *birth_lo, *birth_hi, *birth_cur;
679  volatile void **birth_storeptr;
680 
682  volatile void *old_lo, *old_hi, *old_cur;
683 
684  volatile int collecting, dirty, pass, majors, minors;
685  void *cstack;
686  void *protect;
687 #ifdef DEBUG
688  double time;
689 #endif
690 };
691 
692 #define POTION_INIT_STACK(x) \
693  PN __##x = 0x571FF; void *x = (void *)&__##x
694 void potion_garbagecollect(Potion *, int, int);
695 PN_SIZE potion_type_size(Potion *, const struct PNObject *);
696 unsigned long potion_rand_int();
697 double potion_rand_double();
698 
700 static inline void *potion_gc_alloc(Potion *P, PNType vt, int siz) {
701  struct PNMemory *M = P->mem;
702  struct PNObject *res = 0;
703  if (siz < sizeof(struct PNFwd))
704  siz = sizeof(struct PNFwd);
705  siz = PN_ALIGN(siz, 8); // force 64-bit alignment
706  /*@ assert Value: mem_access: \valid_read(&M->dirty); */
707  /*@ assert
708  Value: ptr_comparison:
709  \pointer_comparable((char *)M->birth_cur+siz,
710  (char *)M->birth_storeptr-2); */
711  assert(M);
712  assert(M->birth_cur);
713  assert(M->birth_storeptr);
714  if (M->dirty || (char *)M->birth_cur + siz >= (char *)M->birth_storeptr - 2)
715  potion_garbagecollect(P, siz + 4 * sizeof(double), 0);
716  res = (struct PNObject *)M->birth_cur;
717  res->vt = vt;
718  res->uniq = (PNUniq)potion_rand_int();
719  M->birth_cur = (char *)res + siz;
720  return (void *)res;
721 }
722 
723 // TODO: mmap already inits to zero?
724 static inline void *potion_gc_calloc(Potion *P, PNType vt, int siz) {
725  return potion_gc_alloc(P, vt, siz);
726 }
727 
728 static inline void potion_gc_update(Potion *P, PN x) {
729  struct PNMemory *M = P->mem;
730  if ((x > (PN)M->birth_lo && x < (PN)M->birth_hi && (x < (PN)M || x >= (PN)M->protect)) ||
731  x == (PN)M->birth_storeptr[1] ||
732  x == (PN)M->birth_storeptr[2] ||
733  x == (PN)M->birth_storeptr[3])
734  return;
735  *(M->birth_storeptr--) = (void *)x;
736  if ((void **)M->birth_storeptr - 4 <= (void **)M->birth_cur)
738 }
739 
740 static inline void *potion_gc_realloc(Potion *P, PNType vt, struct PNObject * volatile obj, PN_SIZE sz) {
741  void *dst = 0;
742  PN_SIZE oldsz = 0;
743 
744  if (obj != NULL) {
745  oldsz = potion_type_size(P, (const struct PNObject *)obj);
746  if (oldsz >= sz)
747  return (void *)obj;
748  }
749 
750  dst = potion_gc_alloc(P, vt, sz);
751  if (obj != NULL) {
752  memcpy(dst, (void *)obj, oldsz);
753  ((struct PNFwd *)obj)->fwd = POTION_FWD;
754  ((struct PNFwd *)obj)->siz = oldsz;
755  ((struct PNFwd *)obj)->ptr = (PN)dst;
756  potion_gc_update(P, (PN)obj);
757  }
758 
759  return dst;
760 }
761 
765 static inline struct PNData *potion_data_alloc(Potion *P, int siz) {
766  struct PNData *data = potion_gc_alloc(P, PN_TUSER, sizeof(struct PNData) + siz);
767  data->siz = siz;
768  return data;
769 }
770 
774 #define POTION_OK 0
775 #define POTION_NO_MEM 8910
776 
781 #define potion_send(RCV, MSG, ARGS...) ({ \
782  PN r = (PN)(RCV); \
783  PN c = potion_bind(P, r, (MSG)); \
784  if (PN_IS_CLOSURE(c)) \
785  c = ((struct PNClosure *)c)->method(P, c, r, ##ARGS); \
786  c; \
787  })
788 
789 #define potion_method(RCV, MSG, FN, SIG) \
790  potion_send(RCV, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))
791 #define potion_class_method(RCV, MSG, FN, SIG) \
792  potion_send(((struct PNVtable *)(RCV))->meta, PN_def, potion_str(P, MSG), PN_FUNC(FN, SIG))
793 
798  PN_while;
801 extern PN PN_extern, PN_integer;
802 extern PN pn_filenames;
803 
805 static inline PN potion_type_default(char type) {
806  return type == 'N' ? PN_ZERO
807  : type == 'I' ? PN_ZERO
808  : type == 'S' ? PN_STR0
809  : PN_NIL;
810 }
811 
815 Potion *potion_create(void *);
816 void potion_destroy(Potion *);
817 PN potion_error(Potion *, PN, long, long, PN);
818 void potion_fatal(char *);
819 void potion_allocation_error(void);
820 PN potion_io_error(Potion *, const char *);
822 PN potion_type_error_want(Potion *, const char *, PN, const char *);
823 void potion_syntax_error(Potion *, struct PNSource *, const char *, ...)
824  __attribute__ ((format (printf, 3, 4)));
826 void potion_p(Potion *, PN);
827 PN potion_str(Potion *, const char *);
828 PN potion_str2(Potion *, char *, size_t);
829 PN potion_strcat(Potion *P, char *str, char *str2);
830 PN potion_str_add(Potion *P, PN, PN, PN);
831 PN potion_str_format(Potion *, const char *, ...)
832  __attribute__ ((format (printf, 2, 3)));
833 PN potion_byte_str(Potion *, const char *);
834 PN potion_byte_str2(Potion *, const char *, size_t len);
835 PN potion_bytes(Potion *, size_t);
836 PN potion_bytes_string(Potion *, PN, PN);
837 PN_SIZE pn_printf(Potion *, PN, const char *, ...)
838  __attribute__ ((format (printf, 3, 4)));
839 void potion_bytes_obj_string(Potion *, PN, PN);
840 PN potion_bytes_append(Potion *, PN, PN, PN);
841 void potion_release(Potion *, PN);
842 PN potion_def_method(Potion *P, PN, PN, PN, PN);
843 PN potion_type_new(Potion *, PNType, PN);
844 PN potion_type_new2(Potion *, PNType, PN, PN);
845 void potion_type_call_is(PN, PN);
846 void potion_type_callset_is(PN, PN);
847 void potion_type_constructor_is(PN, PN);
848 char potion_type_char(PNType);
849 PN potion_class(Potion *, PN, PN, PN);
850 PN potion_ivars(Potion *, PN, PN, PN);
851 PN potion_obj_get_call(Potion *, PN);
852 PN potion_obj_get_callset(Potion *, PN);
853 PN potion_obj_get(Potion *, PN, PN, PN);
854 PN potion_obj_set(Potion *, PN, PN, PN, PN);
855 PN potion_object_new(Potion *, PN, PN);
856 PN potion_delegated(Potion *, PN, PN);
857 PN potion_call(Potion *, PN, PN_SIZE, PN * volatile);
858 PN potion_lookup(Potion *, PN, PN, PN);
859 PN potion_bind(Potion *, PN, PN);
860 PN potion_message(Potion *, PN, PN);
861 PN potion_closure_new(Potion *, PN_F, PN, PN_SIZE);
862 PN potion_callcc(Potion *, PN, PN);
863 PN potion_ref(Potion *, PN);
864 PN potion_sig(Potion *, char *);
865 int potion_sig_find(Potion *, PN, PN);
866 PN potion_double(Potion *, double);
867 PN potion_strtod(Potion *, char *, int);
868 PN potion_num_pow(Potion *, PN, PN, PN);
869 PN potion_num_rand(Potion *, PN, PN);
870 PN potion_srand(Potion *, PN, PN, PN);
871 PN potion_rand(Potion *, PN, PN);
872 PN potion_sig_at(Potion *, PN, int);
873 PN potion_sig_name_at(Potion *, PN, int);
874 int potion_sig_arity(Potion *, PN);
875 int potion_sig_minargs(Potion *, PN);
876 PN potion_closure_arity(Potion *, PN, PN);
877 PN potion_closure_minargs(Potion *, PN, PN);
878 void potion_define_global(Potion *, PN, PN);
879 
880 PN potion_obj_add(Potion *, PN, PN);
881 PN potion_obj_sub(Potion *, PN, PN);
882 PN potion_obj_mult(Potion *, PN, PN);
883 PN potion_obj_div(Potion *, PN, PN);
884 PN potion_obj_rem(Potion *, PN, PN);
885 PN potion_obj_bitn(Potion *, PN);
886 PN potion_obj_bitl(Potion *, PN, PN);
887 PN potion_obj_bitr(Potion *, PN, PN);
888 PN potion_any_cmp(Potion *, PN, PN, PN);
889 
890 PN potion_tuple_empty(Potion *);
891 PN potion_tuple_with_size(Potion *, unsigned long);
892 PN potion_tuple_new(Potion *, PN);
893 PN potion_tuple_push(Potion *, PN, PN);
894 PN_SIZE potion_tuple_push_unless(Potion *, PN, PN);
895 PN_SIZE potion_tuple_find(Potion *, PN, PN);
896 PN potion_tuple_at(Potion *, PN, PN, PN);
897 PN potion_tuple_shift(Potion *, PN, PN);
898 PN potion_tuple_bsearch(Potion *, PN, PN, PN);
899 PN potion_tuple_ins_sort(Potion *, PN, PN, PN);
900 PN potion_table_empty(Potion *);
901 PN potion_table_put(Potion *, PN, PN, PN, PN);
902 PN potion_table_set(Potion *, PN, PN, PN);
903 PN potion_table_at(Potion *, PN, PN, PN);
904 PN potion_lick(Potion *, PN, PN, PN);
905 PN potion_source_compile(Potion *, PN, PN, PN, PN);
906 PN potion_source_load(Potion *, PN, PN);
907 PN potion_source_dump(Potion *, PN, PN, PN, PN);
908 PN potion_source_dumpbc(Potion *, PN, PN, PN);
909 PN potion_greg_parse(Potion *, PN);
910 PN potion_sig_string(Potion *, PN, PN);
911 PN potion_filename_find(Potion *, PN);
912 PN potion_filename_push(Potion *, PN);
913 
914 Potion *potion_gc_boot(void *);
915 void potion_lobby_init(Potion *);
916 void potion_object_init(Potion *);
917 void potion_error_init(Potion *);
918 void potion_primitive_init(Potion *);
919 void potion_num_init(Potion *);
920 void potion_str_hash_init(Potion *);
921 void potion_str_init(Potion *);
922 void potion_table_init(Potion *);
923 void potion_source_init(Potion *);
924 void potion_lick_init(Potion *);
925 void potion_compiler_init(Potion *);
926 void potion_vm_init(Potion *);
927 void potion_cont_init(Potion *);
928 #ifndef SANDBOX
929 void potion_file_init(Potion *);
930 void potion_loader_init(Potion *);
931 void potion_loader_add(Potion *, PN path);
932 PN potion_load(Potion *, PN, PN, PN);
933 char *potion_find_file(Potion *, char *str, PN_SIZE str_len);
934 #endif
935 //XXX add this and the ext initializer dynamically to config.h
936 #if defined(STATIC) || defined(SANDBOX)
937 void Potion_Init_readline(Potion *);
938 void Potion_Init_buffile(Potion *);
939 void Potion_Init_aio(Potion *);
940 #endif
941 
942 PN potion_any_is_nil(Potion *, PN, PN);
943 
944 void potion_dump_stack(Potion *);
945 PN potion_num_string(Potion *, PN, PN);
946 PN potion_gc_reserved(Potion *, PN, PN);
947 PN potion_gc_actual(Potion *, PN, PN);
948 PN potion_gc_fixed(Potion *, PN, PN);
949 
950 PN potion_parse(Potion *, PN, char*);
951 PN potion_vm_proto(Potion *, PN, PN, ...);
952 PN potion_vm_class(Potion *, PN, PN);
953 PN potion_vm(Potion *, PN, PN, PN, PN_SIZE, PN * volatile);
954 PN potion_eval(Potion *, PN);
955 PN potion_run(Potion *, PN, int);
956 PN_F potion_jit_proto(Potion *, PN);
957 
958 PN potion_class_find(Potion *, PN);
959 PNType potion_class_type(Potion *, PN);
960 
961 #endif
PN data
Definition: potion.h:490
volatile void * old_lo
the old region (TODO: consider making the old region common to all threads)
Definition: potion.h:682
void potion_allocation_error(void)
Definition: internal.c:305
void potion_fatal(char *)
Definition: internal.c:286
PN potion_obj_bitn(Potion *, PN)
Definition: objmodel.c:456
void potion_define_global(Potion *, PN, PN)
Definition: objmodel.c:628
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:467
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:719
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:461
PN potion_num_string(Potion *, PN, PN)
forwarding pointer (in case of reallocation)
Definition: potion.h:313
bytecode (switch or cgoto)
Definition: potion.h:615
PN_AST
An AST fragment, non-volatile.
Definition: potion.h:395
PN values
numbers, strings, etc.
Definition: potion.h:462
PN potion_rand(Potion *P, PN cl, PN self)
Definition: mt19937ar.c:173
PN name
Definition: potion.h:388
PN line
PNString of src line.
Definition: potion.h:447
void potion_object_init(Potion *)
Definition: objmodel.c:669
syntax_mode_t
Definition: potion.h:627
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:347
void Potion_Init_readline(Potion *P)
Definition: readline.c:22
PN potion_load(Potion *, PN, PN, PN)
Definition: load.c:163
void potion_table_init(Potion *)
Definition: table.c:824
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:498
sanity-check
Definition: potion.h:634
#define PN_TSTRING
Definition: potion.h:112
PN_F potion_jit_proto(Potion *, PN)
Definition: vm.c:221
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:670
exec_mode_t
the interpreter (one per thread, houses its own garbage collector)
Definition: potion.h:614
a tuple is an array of PNs.
Definition: potion.h:477
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:654
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:327
static PNType potion_qptr_type(PN obj)
if obj is guaranteed to be a PTR fwd only once, no loop.
Definition: potion.h:564
void potion_compiler_init(Potion *)
Definition: compile.c:1424
volatile void * birth_hi
Definition: potion.h:678
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:212
PN PN_add
Definition: internal.c:17
char data[]
Definition: potion.h:329
Potion_Flags flags
vm flags: execution model and debug flags
Definition: potion.h:659
PN ptr
Definition: potion.h:316
unsigned long _PN
Definition: potion.h:78
a closure is an anonymous function, without closed values,
Definition: potion.h:381
the central vtable, see io http://www.piumarta.com/pepsi/objmodel.pdf
Definition: table.h:24
void potion_p(Potion *, PN)
Definition: internal.c:310
#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:457
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:489
struct to wrap arbitrary data that we may want to allocate from Potion.
Definition: potion.h:326
int potion_sig_find(Potion *, PN, PN)
PN potion_closure_new(Potion *, PN_F, PN, PN_SIZE)
Definition: objmodel.c:17
Definition: potion.h:405
PN potion_run(Potion *, PN, int)
Definition: compile.c:1399
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:805
PN potion_sig_name_at(Potion *, PN, int)
Definition: objmodel.c:170
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:1360
PNTarget target
the jit
Definition: potion.h:655
void potion_error_init(Potion *)
Definition: internal.c:254
PN parent
Definition: potion.h:499
PN potion_closure_arity(Potion *P, PN cl, PN self)
Definition: objmodel.c:69
PN potion_obj_mult(Potion *, PN, PN)
Definition: objmodel.c:444
void(* OP_F)(Potion *P, struct PNProto *, PNAsm *volatile *,...)
Definition: potion.h:593
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:668
PN potion_any_is_nil(Potion *, PN, PN)
PN potion_ref(Potion *P, PN data)
Definition: objmodel.c:473
PN potion_byte_str2(Potion *, const char *, size_t len)
Definition: string.c:335
#define OP_MAX
the jit
Definition: potion.h:591
#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:637
static struct PNData * potion_data_alloc(Potion *P, int siz)
Definition: potion.h:765
static PN potion_fwd(PN)
the potion type is the 't' in the vtable tuple (m,t)
Definition: potion.h:570
PN data[]
PNString.
Definition: potion.h:389
PN PN_delegated
Definition: internal.c:14
int arity
cached number of declared args, including optional
Definition: potion.h:385
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:728
PN_SIZE len
Definition: potion.h:339
PN potion_eval(Potion *, PN)
Definition: compile.c:1415
static void * potion_gc_alloc(Potion *P, PNType vt, int siz)
quick inline allocation
Definition: potion.h:700
Potion * potion_gc_boot(void *)
Definition: gc.c:658
struct PNMemory * mem
allocator/gc
Definition: potion.h:660
a file is wrapper around a file descriptor, non-volatile but mutable.
Definition: potion.h:370
PN_SIZE extra
0 or 1 if has code attached at data
Definition: potion.h:387
PN potion_ivars(Potion *, PN, PN, PN)
Definition: objmodel.c:295
PN pn_filenames
Definition: internal.c:23
PN potion_source_load(Potion *P, PN cl, PN buf)
Definition: compile.c:1287
PN potion_call(Potion *, PN, PN_SIZE, PN *volatile)
Definition: internal.c:147
PN PN_length
Definition: internal.c:18
void potion_destroy(Potion *)
Definition: internal.c:137
PN_SIZE fileno
currently parsed file
Definition: potion.h:669
Definition: potion.h:586
PN_F jit
jit function pointer
Definition: potion.h:468
PN potion_source_compile(Potion *P, PN cl, PN self, PN source, PN sig)
Definition: compile.c:1155
void potion_release(Potion *, PN)
void potion_lick_init(Potion *)
Definition: lick.c:68
#define PN_ALIGN(o, x)
Definition: potion.h:232
PN excerpt
Definition: potion.h:502
a weak ref is used for upvals, it acts as a memory slot, non-volatile but mutable.
Definition: potion.h:488
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:596
volatile void * birth_lo
the birth region
Definition: potion.h:678
PN potion_source_dump(Potion *P, PN cl, PN self, PN backend, PN options)
Definition: compile.c:1381
void * cstack
machine stack start
Definition: potion.h:685
PN potion_num_pow(Potion *, PN, PN, PN)
PNAsm *volatile pbuf
parser buffer
Definition: potion.h:667
unsigned int PN_SIZE
Definition: potion.h:79
void potion_primitive_init(Potion *)
Definition: primitive.c:90
PN message
Definition: potion.h:500
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:304
void * protect
end of protected memory
Definition: potion.h:686
int arity
cached sig arity (number of args)
Definition: potion.h:469
#define PN_IS_NIL(v)
Definition: potion.h:169
void potion_lobby_init(Potion *)
Definition: objmodel.c:704
enum PN_AST part
AST type, avoid -Wswitch (aligned access: 4+4+8+4+24)
Definition: potion.h:435
PN_SIZE siz
Definition: potion.h:350
static PNType potion_ptr_type(PN obj)
if obj is guaranteed to be a PTR
Definition: potion.h:549
a continuation saves the stack and all stack pointers.
Definition: potion.h:519
PN_SIZE pathsize
Definition: potion.h:466
int prec
double precision
Definition: potion.h:662
PN potion_tuple_shift(Potion *P, PN cl, PN self)
Definition: table.c:506
char * potion_find_file(Potion *, char *str, PN_SIZE str_len)
Definition: load.c:118
PN lobby
root namespace
Definition: potion.h:657
PN potion_table_empty(Potion *P)
Definition: table.c:42
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:305
PN_SIZE len
Definition: potion.h:479
#define EXEC_BITS
0-4
Definition: potion.h:625
PN PN_elsif
Definition: internal.c:14
PN potion_type_error_want(Potion *, const char *, PN, const char *)
Definition: internal.c:277
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:508
PN PN_string
Definition: internal.c:14
PN inner
"licks" PNTuple or "text" PNString member
Definition: potion.h:512
PN_SIZE siz
Definition: potion.h:586
PN potion_obj_get(Potion *, PN, PN, PN)
implements OP_GETPATH
Definition: objmodel.c:327
PN locals
local variables
Definition: potion.h:460
PN_F method
Definition: potion.h:383
#define M
Definition: mt19937ar.c:53
the garbage collector
Definition: potion.h:676
int potion_sig_arity(Potion *, PN)
number of args of sig tuple, implements the potion_closure_arity method.
Definition: objmodel.c:87
DLLEXPORT void Potion_Init_buffile(Potion *P)
Definition: buffile.c:296
char chars[]
Definition: potion.h:340
#define PN_IS_BOOL(v)
Definition: potion.h:170
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:459
PN potion_message(Potion *, PN, PN)
Definition: objmodel.c:429
PN potion_parse(Potion *, PN, char *)
volatile void * old_hi
Definition: potion.h:682
PN PN_rem
Definition: internal.c:17
PN potion_type_error(Potion *, PN)
Definition: internal.c:273
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:455
PN_SIZE len
Definition: potion.h:349
#define PN_TBOOLEAN
Definition: potion.h:109
PN potion_obj_div(Potion *, PN, PN)
Definition: objmodel.c:448
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:259
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:206
volatile void ** birth_storeptr
Definition: potion.h:679
PN_SIZE upvalsize
Definition: potion.h:466
PN potion_any_cmp(Potion *P, PN cl, PN self, PN value)
Definition: primitive.c:39
Potion * potion_create(void *)
the potion API
Definition: internal.c:124
PN potion_tuple_bsearch(Potion *P, PN cl, PN self, PN x)
Definition: table.c:617
PN potion_class(Potion *, PN, PN, PN)
create a user-class (ie type)
Definition: objmodel.c:257
unsigned int fwd
Definition: potion.h:314
PN_SIZE siz
Definition: potion.h:328
strings are immutable UTF-8, the ID is incremental and they may be garbage collected.
Definition: potion.h:337
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:661
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:408
PN name
PNString.
Definition: potion.h:510
PN potion_class_find(Potion *, PN)
find class by name. At first only system metaclasses (types), no user classes yet.
Definition: objmodel.c:280
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:509
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:334
double value
Definition: potion.h:363
PN potion_lookup(Potion *, PN, PN, PN)
used in bind and def_method
Definition: objmodel.c:396
PN potion_error(Potion *, PN, long, long, PN)
Definition: internal.c:236
PN potion_tuple_push(Potion *, PN, PN)
Definition: table.c:254
JIT if detected at config-time (x86, ppc)
Definition: potion.h:616
-c stop after compilation
Definition: potion.h:618
a prototype is compiled source code, a closure block (lambda) non-volatile.
Definition: potion.h:454
PN potion_table_at(Potion *P, PN cl, PN self, PN key)
Definition: table.c:70
PNType fileno
Definition: potion.h:443
PN potion_obj_add(Potion *, PN, PN)
Definition: objmodel.c:436
PNFlex *volatile vts
built in types
Definition: potion.h:658
PN potion_obj_bitl(Potion *, PN, PN)
Definition: objmodel.c:460
volatile int pass
Definition: potion.h:684
PN protos
nested closures
Definition: potion.h:463
an error, including a description, file location, a brief excerpt.
Definition: potion.h:497
#define PN_IS_PTR(v)
Definition: potion.h:168
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:665
Definition: potion.h:407
DLLEXPORT void Potion_Init_aio(Potion *P)
Definition: aio.c:1809
PN chr
Definition: potion.h:501
static char * potion_str_ptr(PN s)
quick access to either PNString or PNByte pointer
Definition: potion.h:577
volatile void * old_cur
Definition: potion.h:682
static void * potion_gc_calloc(Potion *P, PNType vt, int siz)
Definition: potion.h:724
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:348
PN line
Definition: potion.h:501
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:76
sanity-check (possible stack overwrites by callcc)
Definition: potion.h:620
PN attr
PN.
Definition: potion.h:511
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:141
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:362
Definition: potion.h:400
PN PN_return
Definition: internal.c:14
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:371
Definition: potion.h:403
-d: instrumented bytecode (line stepping) or just slow runloop?
Definition: potion.h:617
PN path
Definition: potion.h:373
volatile void * birth_cur
Definition: potion.h:678
int potion_sig_minargs(Potion *, PN)
number of mandatory args, without any optional arguments
Definition: objmodel.c:112
int minargs
cached number of mandatory args, without optional
Definition: potion.h:386
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:653
volatile int majors
Definition: potion.h:684
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:351
PN sig
signature PNTuple
Definition: potion.h:384
PN potion_strtod(Potion *, char *, int)
Convert string to double.
Definition: number.c:24
PN_SIZE len
Definition: potion.h:521
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:464
PN potion_srand(Potion *P, PN cl, PN self, PN seed)
Definition: mt19937ar.c:163
#define PN_IS_INT(v)
Definition: potion.h:171
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:240
void potion_str_hash_init(Potion *)
Definition: string.c:487
PN debugs
tree parts
Definition: potion.h:464
static PNType potion_type(PN obj)
either immediate (NUM,BOOL,NIL) or a fwd
Definition: potion.h:532
#define PN_QUICK_FWD(t, obj)
PN_QUICK_FWD - doing a single fwd check after a possible realloc.
Definition: potion.h:558
struct PNSource *volatile a[3]
PNTuple of 1-3 kids,.
Definition: potion.h:436
PN_SIZE localsize
Definition: potion.h:466
void potion_type_constructor_is(PN, PN)
set default constructor
Definition: objmodel.c:250
mode_t mode
Definition: potion.h:374
0x10 16 plain potion syntax
Definition: potion.h:628
PN PN_if
Definition: internal.c:14
_PN(* PN_F)(Potion *, PN, PN,...)
Definition: potion.h:216
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:338
PN stack
size of the stack
Definition: potion.h:458
PNType potion_class_type(Potion *, PN)
Definition: objmodel.c:290
PN_SIZE siz
Definition: potion.h:315
PN potion_str2(Potion *, char *, size_t)
Definition: string.c:47
doubles are floating point numbers stored as binary data.
Definition: potion.h:361
PN potion_gc_actual(Potion *, PN, PN)
Definition: gc.c:714
PN stack[]
Definition: potion.h:522
PN potion_double(Potion *, double)
new PNDouble (double)
Definition: number.c:17
PN potion_sig_at(Potion *, PN, int)
Definition: objmodel.c:136
PN potion_obj_rem(Potion *, PN, PN)
Definition: objmodel.c:452
#define POTION_PAGESIZE
Definition: config.h:34
PN_SIZE alloc
overallocate a bit
Definition: potion.h:480
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:520
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:382
PN tree
abstract syntax tree
Definition: potion.h:465
PN PN_continue
Definition: internal.c:14
int yypos
parser buffer position
Definition: potion.h:666
#define PN_FLEX(N, T)
Definition: potion.h:238
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:478
volatile _PN PN
Definition: potion.h:81
PNType lineno
Definition: potion.h:444
volatile int dirty
Definition: potion.h:684
#define PN_NIL
Definition: potion.h:139
PN potion_obj_get_call(Potion *, PN)
get the default accessor (usually "at")
Definition: objmodel.c:234
PN_OBJECT_HEADER
PNType vt; PNUniq uniq.
Definition: potion.h:434
#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:740
PN source
program name or enclosing scope
Definition: potion.h:456
#define PN_OBJECT_HEADER
Definition: potion.h:234
#define POTION_FWD
Definition: potion.h:146
PN name
PNString.
Definition: potion.h:470
struct PNTable * strings
table of all strings
Definition: potion.h:656
PN potion_gc_reserved(Potion *, PN, PN)
Definition: gc.c:732
void PNType potion_kind_of(PN)
Definition: internal.c:199
PN potion_obj_get_callset(Potion *, PN)
get default writer
Definition: objmodel.c:244
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:221
to bytecode (dumpbc)
Definition: potion.h:619
int fd
Definition: potion.h:372
PN potion_sig(Potion *, char *)
void potion_vm_init(Potion *)
Definition: vm.c:129
PN ivars[]
Definition: potion.h:306
PN potion_type_new2(Potion *, PNType, PN, PN)
create a named type
Definition: objmodel.c:224
PN set[]
Definition: potion.h:481
char chars[]
Definition: potion.h:351
volatile int minors
Definition: potion.h:684
void potion_dump_stack(Potion *)
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:440
void potion_loader_init(Potion *)
Definition: load.c:225
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:230
PN potion_object_new(Potion *P, PN cl, PN self)
Definition: objmodel.c:522
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:684
PN PN_break
Definition: internal.c:14