summaryrefslogtreecommitdiff
path: root/template/id.h.tmpl
blob: 52c3685913cd2e33e48a194b577ca55c617ac28c (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%#  -*- c -*-
/* DO NOT EDIT THIS FILE DIRECTLY */
/**********************************************************************

  id.h -

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

  Copyright (C) 2007 Koichi Sasada

**********************************************************************/
<%
require 'optparse'
vpath = ["."]
input = nil
opt = OptionParser.new do |o|
  o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
  input, = o.order!(ARGV)
end or abort opt.opt_s

tokens = nil
vpath.find do |dir|
  begin
    if line = File.read(File.join(dir, input))[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1]
      tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m)
    end
  rescue Errno::ENOENT
    nil
  else
    true
  end
end

method_ids = %w[
  Intern
  MethodMissing
  Length
  Size
  Gets
  Succ
  Each
  Lambda
  Send
  __send__
  Initialize
  UScore
]
%>
#ifndef RUBY_ID_H
#define RUBY_ID_H

#define ID_SCOPE_SHIFT 3
#define ID_SCOPE_MASK 0x07
#define ID_LOCAL      0x00
#define ID_INSTANCE   0x01
#define ID_GLOBAL     0x03
#define ID_ATTRSET    0x04
#define ID_CONST      0x05
#define ID_CLASS      0x06
#define ID_JUNK       0x07
#define ID_INTERNAL   ID_JUNK

#ifdef USE_PARSE_H
#include "parse.h"
#endif

#include "vm_opts.h" /* for SUPPORT_JOKE */

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

#if !defined tLAST_TOKEN && defined YYTOKENTYPE
#define tLAST_TOKEN tLAST_TOKEN
#endif

enum ruby_method_ids {
#ifndef tLAST_TOKEN
% tokens.each do |token, value|
    <%=token%> = <%=value%>,
% end
#endif
    idDot2 = tDOT2,
    idDot3 = tDOT3,
    idUPlus = tUPLUS,
    idUMinus = tUMINUS,
    idPow = tPOW,
    idCmp = tCMP,
    idPLUS = '+',
    idMINUS = '-',
    idMULT = '*',
    idDIV = '/',
    idMOD = '%',
    idLT = '<',
    idLTLT = tLSHFT,
    idLE = tLEQ,
    idGT = '>',
    idGE = tGEQ,
    idEq = tEQ,
    idEqq = tEQQ,
    idNeq = tNEQ,
    idNot = '!',
    idBackquote = '`',
    idEqTilde = tMATCH,
    idNeqTilde = tNMATCH,
    idAREF = tAREF,
    idASET = tASET,
    idLAST_TOKEN = tLAST_TOKEN >> ID_SCOPE_SHIFT,
% method_ids.each do |token|
    t<%=token%>,
% end
#if SUPPORT_JOKE
    tBitblt,
    tAnswer,
#endif
    tLAST_ID,
#define TOKEN2ID(n) id##n = ((t##n<<ID_SCOPE_SHIFT)|ID_LOCAL)
#if SUPPORT_JOKE
    TOKEN2ID(Bitblt),
    TOKEN2ID(Answer),
#endif
% method_ids.each do |token|
    TOKEN2ID(<%=token%>),
% end
    TOKEN2ID(LAST_ID)
};

#ifdef tLAST_TOKEN
struct ruby_method_ids_check {
#define ruby_method_id_check_for(name, value) \
    int checking_for_##name[name == (value) ? 1 : -1]
% tokens.map do |token, value|
ruby_method_id_check_for(<%=token%>, <%=value%>);
% end
};
#endif

#endif /* RUBY_ID_H */