theLib 10.0
Loading...
Searching...
No Matches
rl_mox.h
Go to the documentation of this file.
1
9#pragma once
10
11// ===================================================================================
12// RL
13
14#define RL(num) RL_data[num]
15#define RL_RT (*moxrt)
16
17#define RL_init(max, ref, code) \
18 /* check if data is valid */ \
19 static_assert(max == sizeof(RL_RT.ref)/sizeof(MOX_OBJ_T), \
20 "RL_init(max," #ref ",..) is NOT in sync with REGISTRY."); \
21 /* init "num" to max */ \
22 int RL_num=max; \
23 /* FAST assess to "RL_RT.ref" without deref */ \
24 MOX_OBJ_T *RL_data = RL_RT.ref; \
25 /* FIRST? - do initialize */ \
26 if (RL_data[0] == NULL) { \
27 { code; } \
28 }
29
30#define RL_ref(num,code) do { \
31/*printV("num<%d>,code<%p|%s>",num,code,VAL2STR(code));*/ \
32 if (RL_data[num] != NULL) Tcl_DecrRefCount(RL_data[num]); \
33 RL_data[num] = (code); \
34 assert(RL_data[num] != NULL); \
35 Tcl_IncrRefCount(RL_data[num]); \
36} while (0)
37
38#define RL_NewS(num,s) RL_ref(num,s ? STR2VAL(s) : Tcl_NewObj())
39#define RL_NewL(num,c,v) RL_ref(num,c ? Tcl_NewListObj(c,v) : Tcl_NewObj())
40#define RL_T(num,t) RL_ref(num,RL_RT.t)
41#define RL_O(num,l) RL_ref(num,l ? l : Tcl_NewObj())
42#define RL_NewC(num,s) RL_ref(num,STR2VAL(#s))
43#define RL_NewI(num,i) RL_ref(num,INT2VAL(i))
44
45#define RL_args(start,_c,_v) do { \
46 int c = _c; const MOX_OBJ_T * v = _v ; \
47 if (c+start > RL_num) { \
48 Tcl_SetObjResult(interp,Tcl_ObjPrintf( \
49 "[%s:%d] error: overflow in 'RL_args', get '%d' items but only space for '%d' items is available", \
50 __func__, __LINE__, c, RL_num-start) \
51 ); \
52 Tcl_SetErrorCode(interp, "MYOOX", "EVAL", "OVERFLOW", NULL); \
53 return TCL_ERROR; \
54 } \
55 for (int i=0,j=start; i<c; i++, j++) RL_ref(j,v[i]); \
56 RL_num=(start)+(c); \
57} while(0)
58
59
60// TCL_EVAL_DIRECT, TCL_EVAL_GLOBAL
61#define RL_EvalEx(f) ({ \
62 /* RL_debug; */ \
63 Tcl_EvalObjv(interp, RL_num, RL_data, (f)); \
64})
65#define RL_EvalDirect(cmd) (cmd)(&RL_RT,interp,RL_num,RL_data)
66
67#define RL_debug printAry2("RL_debug",RL_num,RL_data)
68