summaryrefslogtreecommitdiff
path: root/template/id.h.tmpl
blob: 687cbbbe4072f2410271761b5fc4d3b558090177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%#  -*- c -*-
/* DO NOT EDIT THIS FILE DIRECTLY */
/**********************************************************************

  id.h -

  $Author$
  created at: Sun Oct 19 21:12:51 2008

  Copyright (C) 2007 Koichi Sasada

**********************************************************************/
<%
op_id_offset = 128

defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
ids = eval(File.read(defs), binding, defs)
types = ids.keys.grep(/^[A-Z]/)
%>
#ifndef RUBY_ID_H
#define RUBY_ID_H

enum ruby_id_types {
    RUBY_ID_STATIC_SYM  = 0x01,
    RUBY_ID_LOCAL       = 0x00,
    RUBY_ID_INSTANCE    = (0x01<<1),
    RUBY_ID_GLOBAL      = (0x03<<1),
    RUBY_ID_ATTRSET     = (0x04<<1),
    RUBY_ID_CONST       = (0x05<<1),
    RUBY_ID_CLASS       = (0x06<<1),
    RUBY_ID_JUNK        = (0x07<<1),
    RUBY_ID_INTERNAL    = RUBY_ID_JUNK,
    RUBY_ID_SCOPE_SHIFT = 4,
    RUBY_ID_SCOPE_MASK  = (~(~0U<<(RUBY_ID_SCOPE_SHIFT-1))<<1)
};

#define ID_STATIC_SYM  RUBY_ID_STATIC_SYM
#define ID_SCOPE_SHIFT RUBY_ID_SCOPE_SHIFT
#define ID_SCOPE_MASK  RUBY_ID_SCOPE_MASK
#define ID_LOCAL       RUBY_ID_LOCAL
#define ID_INSTANCE    RUBY_ID_INSTANCE
#define ID_GLOBAL      RUBY_ID_GLOBAL
#define ID_ATTRSET     RUBY_ID_ATTRSET
#define ID_CONST       RUBY_ID_CONST
#define ID_CLASS       RUBY_ID_CLASS
#define ID_JUNK        RUBY_ID_JUNK
#define ID_INTERNAL    RUBY_ID_INTERNAL

#define symIFUNC ID2SYM(idIFUNC)
#define symCFUNC ID2SYM(idCFUNC)

% index = op_id_offset
% ids[:token_op].each do |_id, _op, token|
%   next unless token
#define RUBY_TOKEN_<%=token%> <%=index%>
%   index += 1
% end
#define RUBY_TOKEN(t) RUBY_TOKEN_##t

#define RUBY_TOKEN2ID_TYPE(tok, type) ((tok<<RUBY_ID_SCOPE_SHIFT)|type|RUBY_ID_STATIC_SYM)
% types.each do |type|
#define TOKEN2<%=type%>ID(tok) RUBY_TOKEN2ID_TYPE(tok, RUBY_ID_<%=type%>)
% end

enum ruby_method_ids {
% ids[:token_op].uniq {|_, op| op}.each do |id, op, token|
    id<%=id%> = <%=token ? "RUBY_TOKEN(#{token})" : "'#{op}'"%>,
% end
    tPRESERVED_ID_BEGIN = <%=index-1%>,
% ids[:preserved].each do |token|
    id<%=token%>,
% end
    tPRESERVED_ID_END,
% prev = 'tPRESERVED_ID_END'
% types.each do |type|
%   tokens = ids[type]
    tTOKEN_<%=type%>_BEGIN = <%=prev%>-1,
%   tokens.each do |token|
    t<%=token%>,
%   end
%   prev = "tTOKEN_#{type}_END"
    <%=prev%>,
% end
    tNEXT_ID = <%=prev%>,
% types.each do |type|
%   tokens = ids[type]
#define DEFINE_<%=type%>ID_FROM_TOKEN(n) id##n = TOKEN2<%=type%>ID(t##n)
%   tokens or next
%   tokens.each do |token|
    DEFINE_<%=type%>ID_FROM_TOKEN(<%=token%>),
%   end
% end
    tLAST_OP_ID = tPRESERVED_ID_END-1,
    idLAST_OP_ID = tLAST_OP_ID >> ID_SCOPE_SHIFT
};

#endif /* RUBY_ID_H */