w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

proc.h
Go to the documentation of this file.
1 /**
2 ** @file mruby/proc.h - Proc class
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifndef MRUBY_PROC_H
8 #define MRUBY_PROC_H
9 
10 #include "common.h"
11 #include <mruby/irep.h>
12 
13 /**
14  * Proc class
15  */
17 
18 struct REnv {
21  struct mrb_context *cxt;
23 };
24 
25 /* flags (21bits): 1(close):1(touched):1(heap):8(cioff/bidx):8(stack_len) */
26 #define MRB_ENV_SET_LEN(e,len) ((e)->flags = (((e)->flags & ~0xff)|((unsigned int)(len) & 0xff)))
27 #define MRB_ENV_LEN(e) ((mrb_int)((e)->flags & 0xff))
28 #define MRB_ENV_CLOSED (1<<20)
29 #define MRB_ENV_TOUCHED (1<<19)
30 #define MRB_ENV_HEAPED (1<<18)
31 #define MRB_ENV_CLOSE(e) ((e)->flags |= MRB_ENV_CLOSED)
32 #define MRB_ENV_TOUCH(e) ((e)->flags |= MRB_ENV_TOUCHED)
33 #define MRB_ENV_HEAP(e) ((e)->flags |= MRB_ENV_HEAPED)
34 #define MRB_ENV_HEAP_P(e) ((e)->flags & MRB_ENV_HEAPED)
35 #define MRB_ENV_ONSTACK_P(e) (((e)->flags & MRB_ENV_CLOSED) == 0)
36 #define MRB_ENV_BIDX(e) (((e)->flags >> 8) & 0xff)
37 #define MRB_ENV_SET_BIDX(e,idx) ((e)->flags = (((e)->flags & ~(0xff<<8))|((unsigned int)(idx) & 0xff)<<8))
38 
39 void mrb_env_unshare(mrb_state*, struct REnv*);
40 
41 struct RProc {
43  union {
44  const mrb_irep *irep;
46  } body;
47  const struct RProc *upper;
48  union {
50  struct REnv *env;
51  } e;
52 };
53 
54 /* aspec access */
55 #define MRB_ASPEC_REQ(a) (((a) >> 18) & 0x1f)
56 #define MRB_ASPEC_OPT(a) (((a) >> 13) & 0x1f)
57 #define MRB_ASPEC_REST(a) (((a) >> 12) & 0x1)
58 #define MRB_ASPEC_POST(a) (((a) >> 7) & 0x1f)
59 #define MRB_ASPEC_KEY(a) (((a) >> 2) & 0x1f)
60 #define MRB_ASPEC_KDICT(a) (((a) >> 1) & 0x1)
61 #define MRB_ASPEC_BLOCK(a) ((a) & 1)
62 
63 #define MRB_PROC_CFUNC_FL 128
64 #define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC_FL) != 0)
65 #define MRB_PROC_CFUNC(p) (p)->body.func
66 #define MRB_PROC_STRICT 256
67 #define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0)
68 #define MRB_PROC_ORPHAN 512
69 #define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0)
70 #define MRB_PROC_ENVSET 1024
71 #define MRB_PROC_ENV_P(p) (((p)->flags & MRB_PROC_ENVSET) != 0)
72 #define MRB_PROC_ENV(p) (MRB_PROC_ENV_P(p) ? (p)->e.env : NULL)
73 #define MRB_PROC_TARGET_CLASS(p) (MRB_PROC_ENV_P(p) ? (p)->e.env->c : (p)->e.target_class)
74 #define MRB_PROC_SET_TARGET_CLASS(p,tc) do {\
75  if (MRB_PROC_ENV_P(p)) {\
76  (p)->e.env->c = (tc);\
77  mrb_field_write_barrier(mrb, (struct RBasic*)(p)->e.env, (struct RBasic*)(tc));\
78  }\
79  else {\
80  (p)->e.target_class = (tc);\
81  mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)(tc));\
82  }\
83 } while (0)
84 #define MRB_PROC_SCOPE 2048
85 #define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0)
86 
87 #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
88 
89 struct RProc *mrb_proc_new(mrb_state*, const mrb_irep*);
90 struct RProc *mrb_closure_new(mrb_state*, const mrb_irep*);
92 MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals);
93 void mrb_proc_copy(struct RProc *a, struct RProc *b);
94 mrb_int mrb_proc_arity(const struct RProc *p);
95 
96 /* following functions are defined in mruby-proc-ext so please include it when using */
99 /* old name */
100 #define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx)
101 
102 #define MRB_METHOD_FUNC_FL 1
103 #define MRB_METHOD_NOARG_FL 2
104 
105 #ifndef MRB_USE_METHOD_T_STRUCT
106 
107 #define MRB_METHOD_FUNC_P(m) (((uintptr_t)(m))&MRB_METHOD_FUNC_FL)
108 #define MRB_METHOD_NOARG_P(m) ((((uintptr_t)(m))&MRB_METHOD_NOARG_FL)?1:0)
109 #define MRB_METHOD_NOARG_SET(m) ((m)=(mrb_method_t)(((uintptr_t)(m))|MRB_METHOD_NOARG_FL))
110 #define MRB_METHOD_FUNC(m) ((mrb_func_t)((uintptr_t)(m)>>2))
111 #define MRB_METHOD_FROM_FUNC(m,fn) ((m)=(mrb_method_t)((((uintptr_t)(fn))<<2)|MRB_METHOD_FUNC_FL))
112 #define MRB_METHOD_FROM_PROC(m,pr) ((m)=(mrb_method_t)(pr))
113 #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
114 #define MRB_METHOD_PROC(m) ((struct RProc*)(m))
115 #define MRB_METHOD_UNDEF_P(m) ((m)==0)
116 
117 #else
118 
119 #define MRB_METHOD_FUNC_P(m) ((m).flags&MRB_METHOD_FUNC_FL)
120 #define MRB_METHOD_NOARG_P(m) (((m).flags&MRB_METHOD_NOARG_FL)?1:0)
121 #define MRB_METHOD_FUNC(m) ((m).func)
122 #define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
123 #define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).func=(fn);}while(0)
124 #define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).proc=(pr);}while(0)
125 #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
126 #define MRB_METHOD_PROC(m) ((m).proc)
127 #define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL)
128 
129 #endif /* MRB_USE_METHOD_T_STRUCT */
130 
131 #define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m)?TRUE:(MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE))
132 #define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):((MRB_METHOD_PROC(m)&&MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m)))?MRB_PROC_CFUNC(MRB_METHOD_PROC(m)):NULL))
133 
134 
135 #include <mruby/khash.h>
136 
137 MRB_API mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc);
138 
139 static inline void
141 {
142  ci->proc = p;
143  ci->pc = (p && !MRB_PROC_CFUNC_P(p)) ? p->body.irep->iseq : NULL;
144 }
145 
146 static inline struct RClass *
148 {
149  if (ci->u.env && ci->u.env->tt == MRB_TT_ENV) {
150  return ci->u.env->c;
151  }
152  else {
153  return ci->u.target_class;
154  }
155 }
156 
157 static inline void
159 {
160  struct REnv *e = ci->u.env;
161  if (e) {
162  if (e->tt == MRB_TT_ENV) {
163  e->c = tc;
164  }
165  else {
166  ci->u.target_class = tc;
167  }
168  }
169 }
170 
171 static inline struct REnv *
173 {
174  if (ci->u.env && ci->u.env->tt == MRB_TT_ENV) {
175  return ci->u.env;
176  }
177  else {
178  return NULL;
179  }
180 }
181 
182 static inline void
184 {
185  if (ci->u.env) {
186  if (ci->u.env->tt == MRB_TT_ENV) {
187  if (e) {
188  e->c = ci->u.env->c;
189  ci->u.env = e;
190  }
191  else {
192  ci->u.target_class = ci->u.env->c;
193  }
194  }
195  else {
196  if (e) {
197  e->c = ci->u.target_class;
198  ci->u.env = e;
199  }
200  }
201  }
202  else {
203  ci->u.env = e;
204  }
205 }
206 
208 
209 #endif /* MRUBY_PROC_H */
#define b
Definition: jpegint.h:372
#define a(n)
Definition: gpos-common.c:148
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
FT_UInt idx
Definition: cffcmap.c:135
static luaL_Reg func[]
Definition: except.c:32
mrb_value(* mrb_func_t)(struct mrb_state *mrb, mrb_value self)
Definition: mruby.h:203
#define MRB_OBJECT_HEADER
Definition: object.h:10
#define MRB_END_DECL
Definition: common.h:28
#define MRB_BEGIN_DECL
Definition: common.h:26
#define MRB_API
Definition: common.h:73
struct RProc * mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const mrb_value *argv)
Definition: proc.c:132
struct RProc * mrb_proc_new_cfunc(mrb_state *, mrb_func_t)
Definition: proc.c:118
void mrb_env_unshare(mrb_state *, struct REnv *)
Definition: vm.c:278
static void mrb_vm_ci_proc_set(mrb_callinfo *ci, const struct RProc *p)
Definition: proc.h:140
mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc)
Definition: load.c:666
static struct RClass * mrb_vm_ci_target_class(const mrb_callinfo *ci)
Definition: proc.h:147
#define MRB_PROC_CFUNC_P(p)
Definition: proc.h:64
mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx)
Definition: proc.c:166
static struct REnv * mrb_vm_ci_env(const mrb_callinfo *ci)
Definition: proc.h:172
struct RProc * mrb_proc_new(mrb_state *, const mrb_irep *)
Definition: proc.c:37
struct RProc * mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals)
Definition: proc.c:160
static void mrb_vm_ci_target_class_set(mrb_callinfo *ci, struct RClass *tc)
Definition: proc.h:158
static void mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e)
Definition: proc.h:183
struct RProc * mrb_closure_new(mrb_state *, const mrb_irep *)
Definition: proc.c:109
void mrb_proc_copy(struct RProc *a, struct RProc *b)
Definition: proc.c:187
mrb_int mrb_proc_arity(const struct RProc *p)
Definition: proc.c:275
ShellFileEnvironment e
Definition: sh6.c:388
Definition: class.h:17
Definition: proc.h:18
struct mrb_context * cxt
Definition: proc.h:21
struct RClass * c
Definition: proc.h:19
mrb_value * stack
Definition: proc.h:20
mrb_sym mid
Definition: proc.h:22
enum mrb_vtype tt
Definition: proc.h:19
Definition: proc.h:41
union RProc::@1663 body
const mrb_irep * irep
Definition: proc.h:44
struct RClass * target_class
Definition: proc.h:49
const struct RProc * upper
Definition: proc.h:47
union RProc::@1664 e
mrb_func_t func
Definition: proc.h:45
struct REnv * env
Definition: proc.h:50
Definition: obx.h:103
union mrb_callinfo::@1650 u
struct REnv * env
Definition: mruby.h:159
const mrb_code * pc
Definition: mruby.h:157
const struct RProc * proc
Definition: mruby.h:155
struct RClass * target_class
Definition: mruby.h:160
Definition: irep.h:56
int32_t mrb_int
Definition: value.h:35
@ MRB_TT_ENV
Definition: value.h:127
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269