p2  0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lick.c
Go to the documentation of this file.
1 //
4 // (c) 2008 why the lucky stiff, the freelance professor
5 //
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "p2.h"
9 #include "internal.h"
10 
11 PN potion_lick(Potion *P, PN name, PN inner, PN attr) {
12  vPN(Lick) lk = PN_ALLOC(PN_TLICK, struct PNLick);
13  lk->name = name;
14  lk->attr = attr;
15  lk->inner = inner;
16  return (PN)lk;
17 }
18 
22 PN potion_lick_attr(Potion *P, PN cl, PN self) {
23  return ((struct PNLick *)self)->attr;
24 }
25 
29 PN potion_lick_licks(Potion *P, PN cl, PN self) {
30  PN licks = ((struct PNLick *)self)->inner;
31  if (PN_IS_TUPLE(licks)) return licks;
32  return PN_NIL;
33 }
34 
38 PN potion_lick_name(Potion *P, PN cl, PN self) {
39  return ((struct PNLick *)self)->name;
40 }
41 
45 PN potion_lick_text(Potion *P, PN cl, PN self) {
46  PN text = ((struct PNLick *)self)->inner;
47  if (PN_IS_STR(text)) return text;
48  return PN_NIL;
49 }
50 
54 PN potion_lick_string(Potion *P, PN cl, PN self) {
55  PN out = potion_byte_str(P, "");
56  potion_bytes_obj_string(P, out, ((struct PNLick *)self)->name);
57  if (((struct PNLick *)self)->inner != PN_NIL) {
58  pn_printf(P, out, " ");
59  potion_bytes_obj_string(P, out, ((struct PNLick *)self)->inner);
60  }
61  if (((struct PNLick *)self)->attr != PN_NIL) {
62  pn_printf(P, out, " ");
63  potion_bytes_obj_string(P, out, ((struct PNLick *)self)->attr);
64  }
65  return PN_STR_B(out);
66 }
67 
69  PN lk_vt = PN_VTABLE(PN_TLICK);
70  potion_method(lk_vt, "attr", potion_lick_attr, 0);
71  potion_method(lk_vt, "licks", potion_lick_licks, 0);
72  potion_method(lk_vt, "name", potion_lick_name, 0);
73  potion_method(lk_vt, "string", potion_lick_string, 0);
74  potion_method(lk_vt, "text", potion_lick_text, 0);
75 }
#define PN_IS_STR(v)
Definition: potion.h:175
PN potion_lick_name(Potion *P, PN cl, PN self)
Definition: lick.c:38
PN_SIZE void potion_bytes_obj_string(Potion *, PN, PN)
Definition: string.c:384
PN potion_lick_string(Potion *P, PN cl, PN self)
Definition: lick.c:54
#define PN_TLICK
Definition: potion.h:125
PN PN potion_byte_str(Potion *, const char *)
Definition: string.c:331
#define potion_method(RCV, MSG, FN, SIG)
Definition: potion.h:789
PN potion_lick_licks(Potion *P, PN cl, PN self)
Definition: lick.c:29
PN potion_lick_text(Potion *P, PN cl, PN self)
Definition: lick.c:45
#define PN_STR_B(x)
Definition: potion.h:224
a lick is a unit of generic tree data.
Definition: potion.h:508
PN inner
"licks" PNTuple or "text" PNString member
Definition: potion.h:512
void potion_lick_init(Potion *P)
Definition: lick.c:68
non-API internal parts
PN attr
PN.
Definition: potion.h:511
PN potion_lick(Potion *P, PN name, PN inner, PN attr)
Definition: lick.c:11
the global interpreter state P. currently singleton (not threads yet)
Definition: potion.h:653
#define PN_ALLOC(V, T)
Definition: internal.h:12
PN_SIZE pn_printf(Potion *, PN, const char *,...) __attribute__((format(printf
The p2 API.
PN potion_lick_attr(Potion *P, PN cl, PN self)
Definition: lick.c:22
const char * name
Definition: compile.c:30
#define vPN(t)
Definition: buffile.c:34
volatile _PN PN
Definition: potion.h:81
#define PN_NIL
Definition: potion.h:139
#define PN_IS_TUPLE(v)
Definition: potion.h:174
#define PN_VTABLE(t)
Definition: potion.h:136