node.h


DEFINITIONS

This source file includes following functions.


   1  /**********************************************************************
   2  
   3    node.h -
   4  
   5    $Author: michal $
   6    $Date: 2002/08/27 08:27:11 $
   7    created at: Fri May 28 15:14:02 JST 1993
   8  
   9    Copyright (C) 1993-2002 Yukihiro Matsumoto
  10  
  11  **********************************************************************/
  12  
  13  #ifndef NODE_H
  14  #define NODE_H
  15  
  16  #if defined(__cplusplus)
  17  extern "C" {
  18  #endif
  19  
  20  enum node_type {
  21      NODE_METHOD,
  22      NODE_FBODY,
  23      NODE_CFUNC,
  24      NODE_SCOPE,
  25      NODE_BLOCK,
  26      NODE_IF,
  27      NODE_CASE,
  28      NODE_WHEN,
  29      NODE_OPT_N,
  30      NODE_WHILE,
  31      NODE_UNTIL,
  32      NODE_ITER,
  33      NODE_FOR,
  34      NODE_BREAK,
  35      NODE_NEXT,
  36      NODE_REDO,
  37      NODE_RETRY,
  38      NODE_BEGIN,
  39      NODE_RESCUE,
  40      NODE_RESBODY,
  41      NODE_ENSURE,
  42      NODE_AND,
  43      NODE_OR,
  44      NODE_NOT,
  45      NODE_MASGN,
  46      NODE_LASGN,
  47      NODE_DASGN,
  48      NODE_DASGN_CURR,
  49      NODE_GASGN,
  50      NODE_IASGN,
  51      NODE_CDECL,
  52      NODE_CVASGN,
  53      NODE_CVDECL,
  54      NODE_OP_ASGN1,
  55      NODE_OP_ASGN2,
  56      NODE_OP_ASGN_AND,
  57      NODE_OP_ASGN_OR,
  58      NODE_CALL,
  59      NODE_FCALL,
  60      NODE_VCALL,
  61      NODE_SUPER,
  62      NODE_ZSUPER,
  63      NODE_ARRAY,
  64      NODE_ZARRAY,
  65      NODE_HASH,
  66      NODE_RETURN,
  67      NODE_YIELD,
  68      NODE_LVAR,
  69      NODE_DVAR,
  70      NODE_GVAR,
  71      NODE_IVAR,
  72      NODE_CONST,
  73      NODE_CVAR,
  74      NODE_NTH_REF,
  75      NODE_BACK_REF,
  76      NODE_MATCH,
  77      NODE_MATCH2,
  78      NODE_MATCH3,
  79      NODE_LIT,
  80      NODE_STR,
  81      NODE_DSTR,
  82      NODE_XSTR,
  83      NODE_DXSTR,
  84      NODE_EVSTR,
  85      NODE_DREGX,
  86      NODE_DREGX_ONCE,
  87      NODE_ARGS,
  88      NODE_ARGSCAT,
  89      NODE_ARGSPUSH,
  90      NODE_RESTARGS,
  91      NODE_RESTARY,
  92      NODE_REXPAND,
  93      NODE_BLOCK_ARG,
  94      NODE_BLOCK_PASS,
  95      NODE_DEFN,
  96      NODE_DEFS,
  97      NODE_ALIAS,
  98      NODE_VALIAS,
  99      NODE_UNDEF,
 100      NODE_CLASS,
 101      NODE_MODULE,
 102      NODE_SCLASS,
 103      NODE_COLON2,
 104      NODE_COLON3,
 105      NODE_CREF,
 106      NODE_DOT2,
 107      NODE_DOT3,
 108      NODE_FLIP2,
 109      NODE_FLIP3,
 110      NODE_ATTRSET,
 111      NODE_SELF,
 112      NODE_NIL,
 113      NODE_TRUE,
 114      NODE_FALSE,
 115      NODE_DEFINED,
 116      NODE_NEWLINE,
 117      NODE_POSTEXE,
 118  #ifdef C_ALLOCA
 119      NODE_ALLOCA,
 120  #endif
 121      NODE_DMETHOD,
 122      NODE_BMETHOD,
 123      NODE_MEMO,
 124      NODE_IFUNC,
 125      NODE_LAST
 126  };
 127  
 128  typedef struct RNode {
 129      unsigned long flags;
 130      char *nd_file;
 131      union {
 132          struct RNode *node;
 133          ID id;
 134          VALUE value;
 135          VALUE (*cfunc)(ANYARGS);
 136          ID *tbl;
 137      } u1;
 138      union {
 139          struct RNode *node;
 140          ID id;
 141          int argc;
 142          VALUE value;
 143      } u2;
 144      union {
 145          struct RNode *node;
 146          ID id;
 147          long state;
 148          struct global_entry *entry;
 149          long cnt;
 150          VALUE value;
 151      } u3;
 152  } NODE;
 153  
 154  #define RNODE(obj)  (R_CAST(RNode)(obj))
 155  
 156  #define nd_type(n) (((RNODE(n))->flags>>FL_USHIFT)&0xff)
 157  #define nd_set_type(n,t) \
 158      RNODE(n)->flags=((RNODE(n)->flags&~FL_UMASK)|(((t)<<FL_USHIFT)&FL_UMASK))
 159  
 160  #define NODE_LSHIFT (FL_USHIFT+8)
 161  #define NODE_LMASK  (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
 162  #define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
 163  #define nd_set_line(n,l) \
 164      RNODE(n)->flags=((RNODE(n)->flags&~(-1<<NODE_LSHIFT))|(((l)&NODE_LMASK)<<NODE_LSHIFT))
 165  
 166  #define nd_head  u1.node
 167  #define nd_alen  u2.argc
 168  #define nd_next  u3.node
 169  
 170  #define nd_cond  u1.node
 171  #define nd_body  u2.node
 172  #define nd_else  u3.node
 173  
 174  #define nd_orig  u3.value
 175  
 176  #define nd_resq  u2.node
 177  #define nd_ensr  u3.node
 178  
 179  #define nd_1st   u1.node
 180  #define nd_2nd   u2.node
 181  
 182  #define nd_stts  u1.node
 183  
 184  #define nd_entry u3.entry
 185  #define nd_vid   u1.id
 186  #define nd_cflag u2.id
 187  #define nd_cval  u3.value
 188  
 189  #define nd_cnt   u3.cnt
 190  #define nd_tbl   u1.tbl
 191  
 192  #define nd_var   u1.node
 193  #define nd_ibdy  u2.node
 194  #define nd_iter  u3.node
 195  
 196  #define nd_value u2.node
 197  #define nd_aid   u3.id
 198  
 199  #define nd_lit   u1.value
 200  
 201  #define nd_frml  u1.node
 202  #define nd_rest  u2.argc
 203  #define nd_opt   u1.node
 204  
 205  #define nd_recv  u1.node
 206  #define nd_mid   u2.id
 207  #define nd_args  u3.node
 208  
 209  #define nd_noex  u1.id
 210  #define nd_defn  u3.node
 211  
 212  #define nd_old   u1.id
 213  #define nd_new   u2.id
 214  
 215  #define nd_cfnc  u1.cfunc
 216  #define nd_argc  u2.argc
 217  
 218  #define nd_cname u1.id
 219  #define nd_super u3.node
 220  
 221  #define nd_modl  u1.id
 222  #define nd_clss  u1.value
 223  
 224  #define nd_beg   u1.node
 225  #define nd_end   u2.node
 226  #define nd_state u3.state
 227  #define nd_rval  u2.value
 228  
 229  #define nd_nth   u2.argc
 230  
 231  #define nd_tag   u1.id
 232  #define nd_tval  u2.value
 233  
 234  #define NEW_METHOD(n,x) rb_node_newnode(NODE_METHOD,x,n,0)
 235  #define NEW_FBODY(n,i,o) rb_node_newnode(NODE_FBODY,n,i,o)
 236  #define NEW_DEFN(i,a,d,p) rb_node_newnode(NODE_DEFN,p,i,NEW_RFUNC(a,d))
 237  #define NEW_DEFS(r,i,a,d) rb_node_newnode(NODE_DEFS,r,i,NEW_RFUNC(a,d))
 238  #define NEW_CFUNC(f,c) rb_node_newnode(NODE_CFUNC,f,c,0)
 239  #define NEW_IFUNC(f,c) rb_node_newnode(NODE_IFUNC,f,c,0)
 240  #define NEW_RFUNC(b1,b2) NEW_SCOPE(block_append(b1,b2))
 241  #define NEW_SCOPE(b) rb_node_newnode(NODE_SCOPE,local_tbl(),0,(b))
 242  #define NEW_BLOCK(a) rb_node_newnode(NODE_BLOCK,a,0,0)
 243  #define NEW_IF(c,t,e) rb_node_newnode(NODE_IF,c,t,e)
 244  #define NEW_UNLESS(c,t,e) NEW_IF(c,e,t)
 245  #define NEW_CASE(h,b) rb_node_newnode(NODE_CASE,h,b,0)
 246  #define NEW_WHEN(c,t,e) rb_node_newnode(NODE_WHEN,c,t,e)
 247  #define NEW_OPT_N(b) rb_node_newnode(NODE_OPT_N,0,b,0)
 248  #define NEW_WHILE(c,b,n) rb_node_newnode(NODE_WHILE,c,b,n)
 249  #define NEW_UNTIL(c,b,n) rb_node_newnode(NODE_UNTIL,c,b,n)
 250  #define NEW_FOR(v,i,b) rb_node_newnode(NODE_FOR,v,b,i)
 251  #define NEW_ITER(v,i,b) rb_node_newnode(NODE_ITER,v,b,i)
 252  #define NEW_BREAK(s) rb_node_newnode(NODE_BREAK,s,0,0)
 253  #define NEW_NEXT(s) rb_node_newnode(NODE_NEXT,s,0,0)
 254  #define NEW_REDO() rb_node_newnode(NODE_REDO,0,0,0)
 255  #define NEW_RETRY() rb_node_newnode(NODE_RETRY,0,0,0)
 256  #define NEW_BEGIN(b) rb_node_newnode(NODE_BEGIN,0,b,0)
 257  #define NEW_RESCUE(b,res,e) rb_node_newnode(NODE_RESCUE,b,res,e)
 258  #define NEW_RESBODY(a,ex,n) rb_node_newnode(NODE_RESBODY,n,ex,a)
 259  #define NEW_ENSURE(b,en) rb_node_newnode(NODE_ENSURE,b,0,en)
 260  #define NEW_RETURN(s) rb_node_newnode(NODE_RETURN,s,0,0)
 261  #define NEW_YIELD(a) rb_node_newnode(NODE_YIELD,a,0,0)
 262  #define NEW_LIST(a)  NEW_ARRAY(a)
 263  #define NEW_ARRAY(a) rb_node_newnode(NODE_ARRAY,a,1,0)
 264  #define NEW_ZARRAY() rb_node_newnode(NODE_ZARRAY,0,0,0)
 265  #define NEW_HASH(a)  rb_node_newnode(NODE_HASH,a,0,0)
 266  #define NEW_NOT(a)   rb_node_newnode(NODE_NOT,0,a,0)
 267  #define NEW_MASGN(l,r)   rb_node_newnode(NODE_MASGN,l,0,r)
 268  #define NEW_GASGN(v,val) rb_node_newnode(NODE_GASGN,v,val,rb_global_entry(v))
 269  #define NEW_LASGN(v,val) rb_node_newnode(NODE_LASGN,v,val,local_cnt(v))
 270  #define NEW_DASGN(v,val) rb_node_newnode(NODE_DASGN,v,val,0)
 271  #define NEW_DASGN_CURR(v,val) rb_node_newnode(NODE_DASGN_CURR,v,val,0)
 272  #define NEW_IASGN(v,val) rb_node_newnode(NODE_IASGN,v,val,0)
 273  #define NEW_CDECL(v,val) rb_node_newnode(NODE_CDECL,v,val,0)
 274  #define NEW_CVASGN(v,val) rb_node_newnode(NODE_CVASGN,v,val,0)
 275  #define NEW_CVDECL(v,val) rb_node_newnode(NODE_CVDECL,v,val,0)
 276  #define NEW_OP_ASGN1(p,id,a) rb_node_newnode(NODE_OP_ASGN1,p,id,a)
 277  #define NEW_OP_ASGN2(r,i,o,val) rb_node_newnode(NODE_OP_ASGN2,r,val,NEW_OP_ASGN22(i,o))
 278  #define NEW_OP_ASGN22(i,o) rb_node_newnode(NODE_OP_ASGN2,i,o,rb_id_attrset(i))
 279  #define NEW_OP_ASGN_OR(i,val) rb_node_newnode(NODE_OP_ASGN_OR,i,val,0)
 280  #define NEW_OP_ASGN_AND(i,val) rb_node_newnode(NODE_OP_ASGN_AND,i,val,0)
 281  #define NEW_GVAR(v) rb_node_newnode(NODE_GVAR,v,0,rb_global_entry(v))
 282  #define NEW_LVAR(v) rb_node_newnode(NODE_LVAR,v,0,local_cnt(v))
 283  #define NEW_DVAR(v) rb_node_newnode(NODE_DVAR,v,0,0);
 284  #define NEW_IVAR(v) rb_node_newnode(NODE_IVAR,v,0,0)
 285  #define NEW_CONST(v) rb_node_newnode(NODE_CONST,v,0,0)
 286  #define NEW_CVAR(v) rb_node_newnode(NODE_CVAR,v,0,0)
 287  #define NEW_NTH_REF(n)  rb_node_newnode(NODE_NTH_REF,0,n,local_cnt('~'))
 288  #define NEW_BACK_REF(n) rb_node_newnode(NODE_BACK_REF,0,n,local_cnt('~'))
 289  #define NEW_MATCH(c) rb_node_newnode(NODE_MATCH,c,0,0)
 290  #define NEW_MATCH2(n1,n2) rb_node_newnode(NODE_MATCH2,n1,n2,0)
 291  #define NEW_MATCH3(r,n2) rb_node_newnode(NODE_MATCH3,r,n2,0)
 292  #define NEW_LIT(l) rb_node_newnode(NODE_LIT,l,0,0)
 293  #define NEW_STR(s) rb_node_newnode(NODE_STR,s,0,0)
 294  #define NEW_DSTR(s) rb_node_newnode(NODE_DSTR,s,0,0)
 295  #define NEW_XSTR(s) rb_node_newnode(NODE_XSTR,s,0,0)
 296  #define NEW_DXSTR(s) rb_node_newnode(NODE_DXSTR,s,0,0)
 297  #define NEW_EVSTR(n) rb_node_newnode(NODE_EVSTR,0,(n),0)
 298  #define NEW_CALL(r,m,a) rb_node_newnode(NODE_CALL,r,m,a)
 299  #define NEW_FCALL(m,a) rb_node_newnode(NODE_FCALL,0,m,a)
 300  #define NEW_VCALL(m) rb_node_newnode(NODE_VCALL,0,m,0)
 301  #define NEW_SUPER(a) rb_node_newnode(NODE_SUPER,0,0,a)
 302  #define NEW_ZSUPER() rb_node_newnode(NODE_ZSUPER,0,0,0)
 303  #define NEW_ARGS(f,o,r) rb_node_newnode(NODE_ARGS,o,r,f)
 304  #define NEW_ARGSCAT(a,b) rb_node_newnode(NODE_ARGSCAT,a,b,0)
 305  #define NEW_ARGSPUSH(a,b) rb_node_newnode(NODE_ARGSPUSH,a,b,0)
 306  #define NEW_RESTARGS(a) rb_node_newnode(NODE_RESTARGS,a,0,0)
 307  #define NEW_RESTARY(a) rb_node_newnode(NODE_RESTARY,a,0,0)
 308  #define NEW_REXPAND(a) rb_node_newnode(NODE_REXPAND,a,0,0)
 309  #define NEW_BLOCK_ARG(v) rb_node_newnode(NODE_BLOCK_ARG,v,0,local_cnt(v))
 310  #define NEW_BLOCK_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0)
 311  #define NEW_ALIAS(n,o) rb_node_newnode(NODE_ALIAS,o,n,0)
 312  #define NEW_VALIAS(n,o) rb_node_newnode(NODE_VALIAS,o,n,0)
 313  #define NEW_UNDEF(i) rb_node_newnode(NODE_UNDEF,0,i,0)
 314  #define NEW_CLASS(n,b,s) rb_node_newnode(NODE_CLASS,n,NEW_SCOPE(b),(s))
 315  #define NEW_SCLASS(r,b) rb_node_newnode(NODE_SCLASS,r,NEW_SCOPE(b),0)
 316  #define NEW_MODULE(n,b) rb_node_newnode(NODE_MODULE,n,NEW_SCOPE(b),0)
 317  #define NEW_COLON2(c,i) rb_node_newnode(NODE_COLON2,c,i,0)
 318  #define NEW_COLON3(i) rb_node_newnode(NODE_COLON3,0,i,0)
 319  #define NEW_CREF(c) (rb_node_newnode(NODE_CREF,0,0,c))
 320  #define NEW_DOT2(b,e) rb_node_newnode(NODE_DOT2,b,e,0)
 321  #define NEW_DOT3(b,e) rb_node_newnode(NODE_DOT3,b,e,0)
 322  #define NEW_ATTRSET(a) rb_node_newnode(NODE_ATTRSET,a,0,0)
 323  #define NEW_SELF() rb_node_newnode(NODE_SELF,0,0,0)
 324  #define NEW_NIL() rb_node_newnode(NODE_NIL,0,0,0)
 325  #define NEW_TRUE() rb_node_newnode(NODE_TRUE,0,0,0)
 326  #define NEW_FALSE() rb_node_newnode(NODE_FALSE,0,0,0)
 327  #define NEW_DEFINED(e) rb_node_newnode(NODE_DEFINED,e,0,0)
 328  #define NEW_NEWLINE(n) rb_node_newnode(NODE_NEWLINE,0,0,n)
 329  #define NEW_PREEXE(b) NEW_SCOPE(b)
 330  #define NEW_POSTEXE() rb_node_newnode(NODE_POSTEXE,0,0,0)
 331  #define NEW_DMETHOD(b) rb_node_newnode(NODE_DMETHOD,0,0,b)
 332  #define NEW_BMETHOD(b) rb_node_newnode(NODE_BMETHOD,0,0,b)
 333  
 334  #define NOEX_PUBLIC    0
 335  #define NOEX_UNDEF     1
 336  #define NOEX_CFUNC     1
 337  #define NOEX_PRIVATE   2
 338  #define NOEX_PROTECTED 4 
 339  
 340  NODE *rb_compile_cstr _((const char*, const char*, int, int));
 341  NODE *rb_compile_string _((const char*, VALUE, int));
 342  NODE *rb_compile_file _((const char*, VALUE, int));
 343  
 344  void rb_add_method _((VALUE, ID, NODE *, int));
 345  NODE *rb_node_newnode(ANYARGS);
 346  
 347  struct global_entry *rb_global_entry _((ID));
 348  VALUE rb_gvar_get _((struct global_entry *));
 349  VALUE rb_gvar_set _((struct global_entry *, VALUE));
 350  VALUE rb_gvar_defined _((struct global_entry *));
 351  
 352  #if defined(__cplusplus)
 353  }  /* extern "C" { */
 354  #endif
 355  
 356  #endif