* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / template / id.h.tmpl
blob687cbbbe4072f2410271761b5fc4d3b558090177
1 %#  -*- c -*-
2 /* DO NOT EDIT THIS FILE DIRECTLY */
3 /**********************************************************************
5   id.h -
7   $Author$
8   created at: Sun Oct 19 21:12:51 2008
10   Copyright (C) 2007 Koichi Sasada
12 **********************************************************************/
14 op_id_offset = 128
16 defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
17 ids = eval(File.read(defs), binding, defs)
18 types = ids.keys.grep(/^[A-Z]/)
20 #ifndef RUBY_ID_H
21 #define RUBY_ID_H
23 enum ruby_id_types {
24     RUBY_ID_STATIC_SYM  = 0x01,
25     RUBY_ID_LOCAL       = 0x00,
26     RUBY_ID_INSTANCE    = (0x01<<1),
27     RUBY_ID_GLOBAL      = (0x03<<1),
28     RUBY_ID_ATTRSET     = (0x04<<1),
29     RUBY_ID_CONST       = (0x05<<1),
30     RUBY_ID_CLASS       = (0x06<<1),
31     RUBY_ID_JUNK        = (0x07<<1),
32     RUBY_ID_INTERNAL    = RUBY_ID_JUNK,
33     RUBY_ID_SCOPE_SHIFT = 4,
34     RUBY_ID_SCOPE_MASK  = (~(~0U<<(RUBY_ID_SCOPE_SHIFT-1))<<1)
37 #define ID_STATIC_SYM  RUBY_ID_STATIC_SYM
38 #define ID_SCOPE_SHIFT RUBY_ID_SCOPE_SHIFT
39 #define ID_SCOPE_MASK  RUBY_ID_SCOPE_MASK
40 #define ID_LOCAL       RUBY_ID_LOCAL
41 #define ID_INSTANCE    RUBY_ID_INSTANCE
42 #define ID_GLOBAL      RUBY_ID_GLOBAL
43 #define ID_ATTRSET     RUBY_ID_ATTRSET
44 #define ID_CONST       RUBY_ID_CONST
45 #define ID_CLASS       RUBY_ID_CLASS
46 #define ID_JUNK        RUBY_ID_JUNK
47 #define ID_INTERNAL    RUBY_ID_INTERNAL
49 #define symIFUNC ID2SYM(idIFUNC)
50 #define symCFUNC ID2SYM(idCFUNC)
52 % index = op_id_offset
53 % ids[:token_op].each do |_id, _op, token|
54 %   next unless token
55 #define RUBY_TOKEN_<%=token%> <%=index%>
56 %   index += 1
57 % end
58 #define RUBY_TOKEN(t) RUBY_TOKEN_##t
60 #define RUBY_TOKEN2ID_TYPE(tok, type) ((tok<<RUBY_ID_SCOPE_SHIFT)|type|RUBY_ID_STATIC_SYM)
61 % types.each do |type|
62 #define TOKEN2<%=type%>ID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_<%=type%>)
63 % end
65 enum ruby_method_ids {
66 % ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
67     id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
68 % end
69     tPRESERVED_ID_BEGIN = <%=index-1%>,
70 % ids[:preserved].each do |token|
71     id<%=token%>,
72 % end
73     tPRESERVED_ID_END,
74 % prev = 'tPRESERVED_ID_END'
75 % types.each do |type|
76 %   tokens = ids[type]
77     tTOKEN_<%=type%>_BEGIN = <%=prev%>-1,
78 %   tokens.each do |token|
79     t<%=token%>,
80 %   end
81 %   prev = "tTOKEN_#{type}_END"
82     <%=prev%>,
83 % end
84     tNEXT_ID = <%=prev%>,
85 % types.each do |type|
86 %   tokens = ids[type]
87 #define DEFINE_<%=type%>ID_FROM_TOKEN(n) id##n = TOKEN2<%=type%>ID(t##n)
88 %   tokens or next
89 %   tokens.each do |token|
90     DEFINE_<%=type%>ID_FROM_TOKEN(<%=token%>),
91 %   end
92 % end
93     tLAST_OP_ID = tPRESERVED_ID_END-1,
94     idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT
97 #endif /* RUBY_ID_H */