mutant-melbourne 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +25 -0
- data/README.md +69 -0
- data/Rakefile +14 -0
- data/ext/melbourne/.gitignore +3 -0
- data/ext/melbourne/bstring-license.txt +29 -0
- data/ext/melbourne/bstrlib.c +2687 -0
- data/ext/melbourne/bstrlib.h +267 -0
- data/ext/melbourne/encoding_compat.cpp +188 -0
- data/ext/melbourne/encoding_compat.hpp +57 -0
- data/ext/melbourne/extconf.rb +87 -0
- data/ext/melbourne/grammar18.cpp +11280 -0
- data/ext/melbourne/grammar18.hpp +13 -0
- data/ext/melbourne/grammar18.y +6088 -0
- data/ext/melbourne/grammar19.cpp +12420 -0
- data/ext/melbourne/grammar19.hpp +11 -0
- data/ext/melbourne/grammar19.y +7113 -0
- data/ext/melbourne/lex.c.blt +152 -0
- data/ext/melbourne/lex.c.tab +136 -0
- data/ext/melbourne/local_state.hpp +43 -0
- data/ext/melbourne/melbourne.cpp +88 -0
- data/ext/melbourne/melbourne.hpp +19 -0
- data/ext/melbourne/node18.hpp +262 -0
- data/ext/melbourne/node19.hpp +271 -0
- data/ext/melbourne/node_types.rb +304 -0
- data/ext/melbourne/node_types18.cpp +255 -0
- data/ext/melbourne/node_types18.hpp +129 -0
- data/ext/melbourne/node_types19.cpp +249 -0
- data/ext/melbourne/node_types19.hpp +126 -0
- data/ext/melbourne/parser_state18.hpp +181 -0
- data/ext/melbourne/parser_state19.hpp +251 -0
- data/ext/melbourne/quark.cpp +42 -0
- data/ext/melbourne/quark.hpp +45 -0
- data/ext/melbourne/symbols.cpp +224 -0
- data/ext/melbourne/symbols.hpp +119 -0
- data/ext/melbourne/var_table18.cpp +83 -0
- data/ext/melbourne/var_table18.hpp +33 -0
- data/ext/melbourne/var_table19.cpp +65 -0
- data/ext/melbourne/var_table19.hpp +35 -0
- data/ext/melbourne/visitor18.cpp +963 -0
- data/ext/melbourne/visitor18.hpp +12 -0
- data/ext/melbourne/visitor19.cpp +960 -0
- data/ext/melbourne/visitor19.hpp +15 -0
- data/lib/compiler/ast/constants.rb +81 -0
- data/lib/compiler/ast/control_flow.rb +290 -0
- data/lib/compiler/ast/data.rb +14 -0
- data/lib/compiler/ast/definitions.rb +749 -0
- data/lib/compiler/ast/encoding.rb +18 -0
- data/lib/compiler/ast/exceptions.rb +138 -0
- data/lib/compiler/ast/file.rb +11 -0
- data/lib/compiler/ast/grapher.rb +89 -0
- data/lib/compiler/ast/literals.rb +207 -0
- data/lib/compiler/ast/node.rb +362 -0
- data/lib/compiler/ast/operators.rb +106 -0
- data/lib/compiler/ast/self.rb +15 -0
- data/lib/compiler/ast/sends.rb +615 -0
- data/lib/compiler/ast/transforms.rb +298 -0
- data/lib/compiler/ast/values.rb +88 -0
- data/lib/compiler/ast/variables.rb +351 -0
- data/lib/compiler/ast.rb +20 -0
- data/lib/compiler/locals.rb +109 -0
- data/lib/melbourne/processor.rb +651 -0
- data/lib/melbourne/version.rb +3 -0
- data/lib/melbourne.rb +143 -0
- metadata +112 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
# -*- encoding: us-ascii -*-
|
2
|
+
|
3
|
+
module Rubinius
|
4
|
+
module AST
|
5
|
+
class Begin < Node
|
6
|
+
attr_accessor :rescue
|
7
|
+
|
8
|
+
def initialize(line, body)
|
9
|
+
@line = line
|
10
|
+
@rescue = body || NilLiteral.new(line)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_sexp
|
14
|
+
@rescue.to_sexp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
EnsureType = 1
|
19
|
+
|
20
|
+
class Ensure < Node
|
21
|
+
attr_accessor :body, :ensure
|
22
|
+
|
23
|
+
def initialize(line, body, ensr)
|
24
|
+
@line = line
|
25
|
+
@body = body || NilLiteral.new(line)
|
26
|
+
@ensure = ensr
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_sexp
|
30
|
+
[:ensure, @body.to_sexp, @ensure.to_sexp]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
RescueType = 0
|
35
|
+
|
36
|
+
class Rescue < Node
|
37
|
+
attr_accessor :body, :rescue, :else
|
38
|
+
|
39
|
+
def initialize(line, body, rescue_body, else_body)
|
40
|
+
@line = line
|
41
|
+
@body = body
|
42
|
+
@rescue = rescue_body
|
43
|
+
@else = else_body
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_sexp
|
47
|
+
sexp = [:rescue, @body.to_sexp, @rescue.to_sexp]
|
48
|
+
sexp << @else.to_sexp if @else
|
49
|
+
sexp
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class RescueCondition < Node
|
54
|
+
attr_accessor :conditions, :assignment, :body, :next, :splat
|
55
|
+
|
56
|
+
def initialize(line, conditions, body, nxt)
|
57
|
+
@line = line
|
58
|
+
@next = nxt
|
59
|
+
@splat = nil
|
60
|
+
@assignment = nil
|
61
|
+
|
62
|
+
case conditions
|
63
|
+
when ArrayLiteral
|
64
|
+
@conditions = conditions
|
65
|
+
when ConcatArgs
|
66
|
+
@conditions = conditions.array
|
67
|
+
@splat = RescueSplat.new line, conditions.rest
|
68
|
+
when SplatValue
|
69
|
+
@splat = RescueSplat.new line, conditions.value
|
70
|
+
when nil
|
71
|
+
condition = ConstantAccess.new line, :StandardError
|
72
|
+
@conditions = ArrayLiteral.new line, [condition]
|
73
|
+
end
|
74
|
+
|
75
|
+
case body
|
76
|
+
when Block
|
77
|
+
@assignment = body.array.shift if assignment? body.array.first
|
78
|
+
@body = body
|
79
|
+
when nil
|
80
|
+
@body = NilLiteral.new line
|
81
|
+
else
|
82
|
+
if assignment? body
|
83
|
+
@assignment = body
|
84
|
+
@body = NilLiteral.new line
|
85
|
+
else
|
86
|
+
@body = body
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def assignment?(node)
|
92
|
+
case node
|
93
|
+
when VariableAssignment
|
94
|
+
value = node.value
|
95
|
+
when AttributeAssignment
|
96
|
+
value = node.arguments.array.last
|
97
|
+
else
|
98
|
+
return false
|
99
|
+
end
|
100
|
+
|
101
|
+
return true if value.kind_of? CurrentException
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_sexp
|
105
|
+
array = @conditions.to_sexp
|
106
|
+
array << @assignment.to_sexp if @assignment
|
107
|
+
array << @splat.to_sexp if @splat
|
108
|
+
|
109
|
+
sexp = [:resbody, array]
|
110
|
+
case @body
|
111
|
+
when Block
|
112
|
+
sexp << (@body ? @body.array.map { |x| x.to_sexp } : nil)
|
113
|
+
when nil
|
114
|
+
sexp << nil
|
115
|
+
else
|
116
|
+
sexp << @body.to_sexp
|
117
|
+
end
|
118
|
+
|
119
|
+
sexp << @next.to_sexp if @next
|
120
|
+
|
121
|
+
sexp
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class RescueSplat < Node
|
126
|
+
attr_accessor :value
|
127
|
+
|
128
|
+
def initialize(line, value)
|
129
|
+
@line = line
|
130
|
+
@value = value
|
131
|
+
end
|
132
|
+
|
133
|
+
def to_sexp
|
134
|
+
[:splat, @value.to_sexp]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# -*- encoding: us-ascii -*-
|
2
|
+
|
3
|
+
module Rubinius
|
4
|
+
module AST
|
5
|
+
class AsciiGrapher
|
6
|
+
def initialize(ast, node_kind=Node)
|
7
|
+
@ast = ast
|
8
|
+
@node_kind = node_kind
|
9
|
+
end
|
10
|
+
|
11
|
+
def print
|
12
|
+
graph_node @ast
|
13
|
+
end
|
14
|
+
|
15
|
+
def indented_print(level, value)
|
16
|
+
puts "#{" " * level}#{value}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def print_node(node, level, idx=nil)
|
20
|
+
name = node.class.to_s.split("::").last
|
21
|
+
|
22
|
+
name = "#{name} [#{idx}]" if idx
|
23
|
+
|
24
|
+
indented_print level, name
|
25
|
+
end
|
26
|
+
|
27
|
+
def graph_node(node, level=0, idx=nil)
|
28
|
+
print_node node, level, idx
|
29
|
+
level += 2
|
30
|
+
|
31
|
+
nodes = []
|
32
|
+
node.instance_variables.each do |v|
|
33
|
+
next if v == "@compiler"
|
34
|
+
|
35
|
+
value = node.instance_variable_get v
|
36
|
+
|
37
|
+
# lame, yes. remove when Node doesn't have @body by default
|
38
|
+
next if v == "@body" and value.nil? and not v.respond_to? :body=
|
39
|
+
|
40
|
+
if value.kind_of? @node_kind
|
41
|
+
nodes << [v, value]
|
42
|
+
else
|
43
|
+
graph_value v, value, level
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
nodes.each do |name, n|
|
48
|
+
puts "#{" " * level}#{name}: \\"
|
49
|
+
graph_node n, level + 2
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def graph_simple(name, value, level)
|
54
|
+
puts "#{" " * level}#{name}: #{value}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def graph_value(name, value, level)
|
58
|
+
case value
|
59
|
+
when NilClass, String
|
60
|
+
graph_simple name, value.inspect, level
|
61
|
+
when Symbol
|
62
|
+
puts "#{" " * level}#{name}: :#{value}"
|
63
|
+
when TrueClass, FalseClass, Fixnum
|
64
|
+
graph_simple name, value, level
|
65
|
+
when Array
|
66
|
+
if value.empty?
|
67
|
+
puts "#{" " * level}#{name}: []"
|
68
|
+
else
|
69
|
+
puts "#{" " * level}#{name}: ["
|
70
|
+
nodes = []
|
71
|
+
value.each_with_index do |v,i|
|
72
|
+
if v.kind_of? @node_kind
|
73
|
+
nodes << [v, i]
|
74
|
+
else
|
75
|
+
graph_value "[#{i}] ", v, level + 2
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
nodes.each { |n| graph_node n[0], level + 2, n[1] }
|
80
|
+
|
81
|
+
puts "#{' ' * level}]"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
graph_simple name, value.class, level
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
# -*- encoding: us-ascii -*-
|
2
|
+
|
3
|
+
module Rubinius
|
4
|
+
module AST
|
5
|
+
class ArrayLiteral < Node
|
6
|
+
attr_accessor :body
|
7
|
+
|
8
|
+
def initialize(line, array)
|
9
|
+
@line = line
|
10
|
+
@body = array
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_sexp
|
14
|
+
@body.inject([:array]) { |s, x| s << x.to_sexp }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class EmptyArray < Node
|
19
|
+
def to_sexp
|
20
|
+
[:array]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class FalseLiteral < Node
|
25
|
+
def to_sexp
|
26
|
+
[:false]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class TrueLiteral < Node
|
31
|
+
def to_sexp
|
32
|
+
[:true]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class FloatLiteral < Node
|
37
|
+
attr_accessor :value
|
38
|
+
|
39
|
+
def initialize(line, str)
|
40
|
+
@line = line
|
41
|
+
@value = str.to_f
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_sexp
|
45
|
+
[:lit, @value]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class HashLiteral < Node
|
50
|
+
attr_accessor :array
|
51
|
+
|
52
|
+
def initialize(line, array)
|
53
|
+
@line = line
|
54
|
+
@array = array
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_sexp
|
58
|
+
@array.inject([:hash]) { |s, x| s << x.to_sexp }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class SymbolLiteral < Node
|
63
|
+
attr_accessor :value
|
64
|
+
|
65
|
+
def initialize(line, sym)
|
66
|
+
@line = line
|
67
|
+
@value = sym
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_sexp
|
71
|
+
[:lit, @value]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class NilLiteral < Node
|
76
|
+
def to_sexp
|
77
|
+
[:nil]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class NumberLiteral < Node
|
82
|
+
attr_accessor :value
|
83
|
+
|
84
|
+
def initialize(line, value)
|
85
|
+
@line = line
|
86
|
+
@value = value
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_sexp
|
90
|
+
[:lit, @value]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class FixnumLiteral < NumberLiteral
|
95
|
+
def initialize(line, value)
|
96
|
+
@line = line
|
97
|
+
@value = value
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class Range < Node
|
102
|
+
attr_accessor :start, :finish
|
103
|
+
|
104
|
+
def initialize(line, start, finish)
|
105
|
+
@line = line
|
106
|
+
@start = start
|
107
|
+
@finish = finish
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_sexp
|
111
|
+
[:dot2, @start.to_sexp, @finish.to_sexp]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class RangeExclude < Range
|
116
|
+
def initialize(line, start, finish)
|
117
|
+
@line = line
|
118
|
+
@start = start
|
119
|
+
@finish = finish
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_sexp
|
123
|
+
[:dot3, @start.to_sexp, @finish.to_sexp]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class RegexLiteral < Node
|
128
|
+
attr_accessor :source, :options
|
129
|
+
|
130
|
+
def initialize(line, str, flags)
|
131
|
+
@line = line
|
132
|
+
@source = str
|
133
|
+
@options = flags
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_sexp
|
137
|
+
[:regex, @source, @options]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class StringLiteral < Node
|
142
|
+
attr_accessor :string
|
143
|
+
|
144
|
+
def initialize(line, str)
|
145
|
+
@line = line
|
146
|
+
@string = str
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_sexp
|
150
|
+
[:str, @string]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
class DynamicString < StringLiteral
|
155
|
+
attr_accessor :array, :options
|
156
|
+
|
157
|
+
def initialize(line, str, array)
|
158
|
+
@line = line
|
159
|
+
@string = str
|
160
|
+
@array = array
|
161
|
+
end
|
162
|
+
|
163
|
+
def sexp_name
|
164
|
+
:dstr
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_sexp
|
168
|
+
@array.inject([sexp_name, @string]) { |s, x| s << x.to_sexp }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class DynamicSymbol < DynamicString
|
173
|
+
def sexp_name
|
174
|
+
:dsym
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class DynamicExecuteString < DynamicString
|
179
|
+
def sexp_name
|
180
|
+
:dxstr
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class DynamicRegex < DynamicString
|
185
|
+
def initialize(line, str, array, flags)
|
186
|
+
super line, str, array
|
187
|
+
@options = flags || 0
|
188
|
+
end
|
189
|
+
|
190
|
+
def sexp_name
|
191
|
+
:dregx
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
class DynamicOnceRegex < DynamicRegex
|
196
|
+
def sexp_name
|
197
|
+
:dregx_once
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class ExecuteString < StringLiteral
|
202
|
+
def to_sexp
|
203
|
+
[:xstr, @string]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|