myco 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/myco/bootstrap/component.rb +6 -7
- data/lib/myco/bootstrap/instance.rb +14 -9
- data/lib/myco/bootstrap/meme.rb +34 -3
- data/lib/myco/code_loader.rb +17 -34
- data/lib/myco/code_tools/AST/ArgumentAssembly.my +60 -0
- data/lib/myco/code_tools/AST/ArgumentAssembly.my.rb +55 -0
- data/lib/myco/code_tools/AST/ArrayAssembly.my +43 -0
- data/lib/myco/code_tools/AST/ArrayAssembly.my.rb +37 -0
- data/lib/myco/code_tools/AST/BlockArgument.my +25 -0
- data/lib/myco/code_tools/AST/BlockArgument.my.rb +26 -0
- data/lib/myco/code_tools/AST/BlockLiteral.my +104 -0
- data/lib/myco/code_tools/AST/BlockLiteral.my.rb +126 -0
- data/lib/myco/code_tools/AST/BlockParameter.my +25 -0
- data/lib/myco/code_tools/AST/BlockParameter.my.rb +24 -0
- data/lib/myco/code_tools/AST/Body.my +18 -0
- data/lib/myco/code_tools/AST/Body.my.rb +20 -0
- data/lib/myco/code_tools/AST/BranchOperator.my +59 -0
- data/lib/myco/code_tools/AST/BranchOperator.my.rb +87 -0
- data/lib/myco/code_tools/AST/ConstantAccess.my +30 -0
- data/lib/myco/code_tools/AST/ConstantAccess.my.rb +32 -0
- data/lib/myco/code_tools/AST/ConstantAssignment.my +40 -0
- data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +45 -0
- data/lib/myco/code_tools/AST/ConstantDefine.my +30 -0
- data/lib/myco/code_tools/AST/ConstantDefine.my.rb +36 -0
- data/lib/myco/code_tools/AST/ConstantReopen.my +29 -0
- data/lib/myco/code_tools/AST/ConstantReopen.my.rb +35 -0
- data/lib/myco/code_tools/AST/DeclareCategory.my +35 -0
- data/lib/myco/code_tools/AST/DeclareCategory.my.rb +40 -0
- data/lib/myco/code_tools/AST/DeclareDecorator.my +20 -0
- data/lib/myco/code_tools/AST/DeclareDecorator.my.rb +28 -0
- data/lib/myco/code_tools/AST/DeclareFile.my +38 -0
- data/lib/myco/code_tools/AST/DeclareFile.my.rb +53 -0
- data/lib/myco/code_tools/AST/DeclareMeme.my +79 -0
- data/lib/myco/code_tools/AST/DeclareMeme.my.rb +90 -0
- data/lib/myco/code_tools/AST/DeclareObject.my +58 -0
- data/lib/myco/code_tools/AST/DeclareObject.my.rb +67 -0
- data/lib/myco/code_tools/AST/DeclareString.my +26 -0
- data/lib/myco/code_tools/AST/DeclareString.my.rb +30 -0
- data/lib/myco/code_tools/AST/DynamicString.my +21 -0
- data/lib/myco/code_tools/AST/DynamicString.my.rb +22 -0
- data/lib/myco/code_tools/AST/DynamicSymbol.my +22 -0
- data/lib/myco/code_tools/AST/DynamicSymbol.my.rb +26 -0
- data/lib/myco/code_tools/AST/Invoke.my +37 -0
- data/lib/myco/code_tools/AST/Invoke.my.rb +58 -0
- data/lib/myco/code_tools/AST/InvokeMethod.my +19 -0
- data/lib/myco/code_tools/AST/InvokeMethod.my.rb +25 -0
- data/lib/myco/code_tools/AST/KeywordAssembly.my +30 -0
- data/lib/myco/code_tools/AST/KeywordAssembly.my.rb +36 -0
- data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my +22 -0
- data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my.rb +22 -0
- data/lib/myco/code_tools/AST/LocalVariableAssignment.my +20 -0
- data/lib/myco/code_tools/AST/LocalVariableAssignment.my.rb +20 -0
- data/lib/myco/{parser/ast/myco_module_scope.rb → code_tools/AST/MycoModuleScope.my} +32 -39
- data/lib/myco/code_tools/AST/MycoModuleScope.my.rb +82 -0
- data/lib/myco/code_tools/AST/Node.my +67 -0
- data/lib/myco/code_tools/AST/Node.my.rb +84 -0
- data/lib/myco/code_tools/AST/ParameterAssembly.my +248 -0
- data/lib/myco/code_tools/AST/ParameterAssembly.my.rb +314 -0
- data/lib/myco/code_tools/AST/Quest.my +61 -0
- data/lib/myco/code_tools/AST/Quest.my.rb +51 -0
- data/lib/myco/code_tools/AST/Script.my +27 -0
- data/lib/myco/code_tools/AST/Script.my.rb +33 -0
- data/lib/myco/code_tools/AST/SplatValue.my +23 -0
- data/lib/myco/code_tools/AST/SplatValue.my.rb +25 -0
- data/lib/myco/code_tools/AST/StringLiteral.my +17 -0
- data/lib/myco/code_tools/AST/StringLiteral.my.rb +16 -0
- data/lib/myco/code_tools/AST/SymbolLiteral.my +16 -0
- data/lib/myco/code_tools/AST/SymbolLiteral.my.rb +15 -0
- data/lib/myco/{parser/ast → code_tools/AST}/ToRuby.my +89 -90
- data/lib/myco/{parser/ast → code_tools/AST}/ToRuby.my.rb +89 -101
- data/lib/myco/code_tools/AST/misc.my +57 -0
- data/lib/myco/code_tools/AST/misc.my.rb +81 -0
- data/lib/myco/code_tools/AST.my +52 -0
- data/lib/myco/code_tools/AST.my.rb +40 -0
- data/lib/myco/{parser → code_tools/parser}/peg_parser.rb +107 -199
- data/lib/myco/{parser.rb → code_tools/parser.rb} +0 -17
- data/lib/myco/code_tools.rb +5 -0
- data/lib/myco/core/BasicDecorators.my +47 -0
- data/lib/myco/core/BasicDecorators.my.rb +66 -0
- data/lib/myco/core/FileToplevel.my +14 -3
- data/lib/myco/core/FileToplevel.my.rb +27 -12
- data/lib/myco/eval.rb +7 -37
- data/lib/myco/version.rb +1 -4
- data/lib/myco.rb +20 -22
- metadata +74 -66
- data/lib/myco/parser/ast/argument_assembly.rb +0 -76
- data/lib/myco/parser/ast/array_assembly.rb +0 -57
- data/lib/myco/parser/ast/branch_operator.rb +0 -73
- data/lib/myco/parser/ast/constant_access.rb +0 -15
- data/lib/myco/parser/ast/constant_define.rb +0 -40
- data/lib/myco/parser/ast/constant_reopen.rb +0 -46
- data/lib/myco/parser/ast/declare_category.rb +0 -53
- data/lib/myco/parser/ast/declare_decorator.rb +0 -35
- data/lib/myco/parser/ast/declare_file.rb +0 -54
- data/lib/myco/parser/ast/declare_meme.rb +0 -86
- data/lib/myco/parser/ast/declare_object.rb +0 -77
- data/lib/myco/parser/ast/declare_string.rb +0 -37
- data/lib/myco/parser/ast/invoke.rb +0 -48
- data/lib/myco/parser/ast/invoke_method.rb +0 -28
- data/lib/myco/parser/ast/local_variable_access_ambiguous.rb +0 -34
- data/lib/myco/parser/ast/misc.rb +0 -156
- data/lib/myco/parser/ast/quest.rb +0 -82
- data/lib/myco/parser/ast.rb +0 -21
@@ -91,31 +91,51 @@
|
|
91
91
|
::Myco.find_constant(:VoidLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add("::Myco::Void"))})}
|
92
92
|
::Myco.find_constant(:TrueLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add("true"))})}
|
93
93
|
::Myco.find_constant(:FalseLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add("false"))})}
|
94
|
-
::Myco.find_constant(:StringLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add(self.
|
94
|
+
::Myco.find_constant(:StringLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add(self.value.inspect))})}
|
95
95
|
::Myco.find_constant(:SymbolLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add(self.value.inspect))})}
|
96
96
|
::Myco.find_constant(:DynamicString).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
97
|
-
inspect_escape = ::Myco.find_constant(:Proc).new { |str| (str.inspect.slice(::Range.new(
|
98
|
-
1,
|
99
|
-
-2
|
100
|
-
)))}
|
101
97
|
g.add("\"")
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
98
|
+
self.body.each_slice(2) { |string, to_string| (
|
99
|
+
g.add(string.value.to_s.inspect.slice(::Range.new(
|
100
|
+
1,
|
101
|
+
-2
|
102
|
+
)))
|
103
|
+
::Myco.branch_op(:"&&", to_string) {(
|
104
|
+
g.add("\#{")
|
105
|
+
g.add(to_string)
|
106
|
+
g.add("}")
|
107
|
+
)}
|
108
108
|
)}
|
109
109
|
g.add("\"")
|
110
110
|
)})}
|
111
111
|
::Myco.find_constant(:DynamicSymbol).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
112
|
-
g.add("
|
113
|
-
|
112
|
+
g.add(":\"")
|
113
|
+
self.body.each_slice(2) { |string, to_string| (
|
114
|
+
g.add(string.value.to_s.inspect.slice(::Range.new(
|
115
|
+
1,
|
116
|
+
-2
|
117
|
+
)))
|
118
|
+
::Myco.branch_op(:"&&", to_string) {(
|
119
|
+
g.add("\#{")
|
120
|
+
g.add(to_string)
|
121
|
+
g.add("}")
|
122
|
+
)}
|
123
|
+
)}
|
124
|
+
g.add("\"")
|
125
|
+
)})}
|
126
|
+
::Myco.find_constant(:ArrayAssembly).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
127
|
+
g.add("[")
|
128
|
+
g.list(
|
129
|
+
self.body,
|
130
|
+
",",
|
131
|
+
{:auto_lines => true}
|
132
|
+
)
|
133
|
+
g.add("]")
|
114
134
|
)})}
|
115
|
-
::Myco.find_constant(:
|
135
|
+
::Myco.find_constant(:KeywordAssembly).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
116
136
|
g.add("{")
|
117
137
|
g.list(
|
118
|
-
self.
|
138
|
+
self.body.each_slice(2).to_a,
|
119
139
|
",",
|
120
140
|
{:auto_lines => true}
|
121
141
|
) { |pair| (g.add(
|
@@ -125,60 +145,35 @@
|
|
125
145
|
))}
|
126
146
|
g.add("}")
|
127
147
|
)})}
|
128
|
-
::Myco.find_constant(:
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
148
|
+
::Myco.find_constant(:ConstantAccess).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
149
|
+
name_list = self.names.map(&:to_sym)
|
150
|
+
first_name = name_list.shift
|
151
|
+
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.toplevel) {g.add("::#{first_name}")}) {g.add("::Myco.find_constant(#{first_name.inspect})")}
|
152
|
+
name_list.each { |name| (g.add("::#{name}"))}
|
153
|
+
)})}
|
154
|
+
::Myco.find_constant(:ConstantAssignment).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
155
|
+
name_list = self.constant.names.map(&:to_sym)
|
156
|
+
last_name = name_list.pop
|
157
|
+
first_name = ::Myco.branch_op(:"&&", name_list.__send__(:any?)) {name_list.shift}
|
158
|
+
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.constant.toplevel) {::Myco.branch_op(:"&&", first_name) {g.add("::#{first_name}")}}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {g.add("::Myco.find_constant(#{first_name.inspect})")}) {g.add("::Myco.cscope.for_method_definition")}}
|
159
|
+
name_list.each { |name| (g.add("::#{name}"))}
|
160
|
+
g.add("::#{last_name} = ")
|
161
|
+
g.add(self.value)
|
136
162
|
)})}
|
137
|
-
::Myco.find_constant(:ScopedConstant).component_eval {(
|
138
|
-
declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
139
|
-
g.add(self.parent)
|
140
|
-
g.add("::#{self.name}")
|
141
|
-
)}
|
142
|
-
declare_meme(:to_ruby_assign, [], nil, ::Myco.cscope.dup) { |g, value| (
|
143
|
-
self.to_ruby(g)
|
144
|
-
g.add(" = ")
|
145
|
-
g.add(value)
|
146
|
-
)}
|
147
|
-
)}
|
148
|
-
::Myco.find_constant(:ToplevelConstant).component_eval {(
|
149
|
-
declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add("::#{self.name}"))}
|
150
|
-
declare_meme(:to_ruby_assign, [], nil, ::Myco.cscope.dup) { |g, value| (
|
151
|
-
self.to_ruby(g)
|
152
|
-
g.add(" = ")
|
153
|
-
g.add(value)
|
154
|
-
)}
|
155
|
-
)}
|
156
|
-
::Myco.find_constant(:ConstantAccess).component_eval {(
|
157
|
-
declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add("::Myco.find_constant(#{self.name.inspect})"))}
|
158
|
-
declare_meme(:to_ruby_assign, [], nil, ::Myco.cscope.dup) { |g, value| (
|
159
|
-
g.add("::Myco.cscope.for_method_definition.const_set(#{self.name.inspect}, ")
|
160
|
-
g.add(value)
|
161
|
-
g.add(")")
|
162
|
-
)}
|
163
|
-
)}
|
164
|
-
::Myco.find_constant(:ConstantAssignment).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (self.constant.to_ruby_assign(
|
165
|
-
g,
|
166
|
-
self.value
|
167
|
-
))})}
|
168
163
|
::Myco.find_constant(:ConstantDefine).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
169
164
|
g.add(self.implementation)
|
170
165
|
g.line(".tap { |__c__| __c__.__name__ = ")
|
171
|
-
g.add(self.
|
166
|
+
g.add(self.constant.names.last.inspect)
|
172
167
|
g.add(" }")
|
173
168
|
)})}
|
174
169
|
::Myco.find_constant(:ConstantReopen).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
175
|
-
g.add(self.
|
170
|
+
g.add(self.constant)
|
176
171
|
g.add(".component_eval {")
|
177
172
|
g.add(self.body)
|
178
173
|
g.add("}")
|
179
174
|
)})}
|
180
175
|
::Myco.find_constant(:MycoModuleScope).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.with_nested_var_scope(self) { || (g.add(self.body))})})}
|
181
|
-
::Myco.find_constant(:
|
176
|
+
::Myco.find_constant(:Script).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add(self.body))})}
|
182
177
|
::Myco.find_constant(:DeclareFile).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
183
178
|
g.line
|
184
179
|
self.implementation.to_ruby(g)
|
@@ -195,19 +190,19 @@
|
|
195
190
|
)})}
|
196
191
|
::Myco.find_constant(:DeclareString).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add(self.implementation))})}
|
197
192
|
::Myco.find_constant(:DeclareCategory).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
198
|
-
g.add("__category__(#{self.name.
|
193
|
+
g.add("__category__(#{self.name.inspect})")
|
199
194
|
g.add(".component_eval {")
|
200
195
|
g.add(self.body)
|
201
196
|
g.add("}")
|
202
197
|
)})}
|
203
198
|
::Myco.find_constant(:DeclareMeme).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.with_nested_var_scope(self.body_implementation) { || (
|
204
|
-
g.var_scope_declare_locals(*self.
|
199
|
+
g.var_scope_declare_locals(*self.parameters.names)
|
205
200
|
g.add("declare_meme(")
|
206
201
|
g.add("#{self.name.inspect}, ")
|
207
202
|
g.add(self.decorations)
|
208
203
|
g.add(", nil, ::Myco.cscope.dup)")
|
209
204
|
g.add(" { ")
|
210
|
-
g.add(self.
|
205
|
+
g.add(self.parameters)
|
211
206
|
g.add(" ")
|
212
207
|
g.add(self.body)
|
213
208
|
g.add("}")
|
@@ -217,11 +212,12 @@
|
|
217
212
|
g.add(self.arguments)
|
218
213
|
g.add("]")
|
219
214
|
)})}
|
220
|
-
::Myco.find_constant(:
|
215
|
+
::Myco.find_constant(:BlockParameter).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.add("&#{self.name}"))})}
|
216
|
+
::Myco.find_constant(:ParameterAssembly).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
221
217
|
list = []
|
222
218
|
list_add = ::Myco.find_constant(:Proc).new { |&blk| (list.push(::Myco.find_constant(:Proc).new(&blk)))}
|
223
219
|
self.required.each { |item| (list_add.call { || (g.add(item.to_s))})}
|
224
|
-
|
220
|
+
self.optional.each { |asgn| (
|
225
221
|
name = asgn.name
|
226
222
|
value = asgn.value
|
227
223
|
list_add.call { || (
|
@@ -234,32 +230,31 @@
|
|
234
230
|
:*
|
235
231
|
)}) {g.add(value)}
|
236
232
|
)}
|
237
|
-
)}
|
233
|
+
)}
|
238
234
|
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.splat.__send__(
|
239
235
|
:==,
|
240
|
-
|
236
|
+
true
|
241
237
|
)) {list_add.call { || (g.add("*"))}}) {::Myco.branch_op(:"&?", self.splat) {list_add.call { || (g.add("*#{self.splat}"))}}}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
)}
|
238
|
+
self.post.each { |item| (list_add.call { || (g.add(item.to_s))})}
|
239
|
+
self.kwargs.each { |asgn| (
|
240
|
+
name = asgn.name
|
241
|
+
value = asgn.value
|
242
|
+
list_add.call { || (
|
243
|
+
g.add("#{name}:")
|
244
|
+
::Myco.branch_op(:"||", ::Myco.branch_op(:"&&", value.__send__(
|
245
|
+
:is_a?,
|
246
|
+
::Myco.find_constant(:SymbolLiteral)
|
247
|
+
)) {value.value.__send__(
|
248
|
+
:==,
|
249
|
+
:*
|
250
|
+
)}) {g.add(value)}
|
256
251
|
)}
|
257
|
-
::Myco.branch_op(:"&?", ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.keywords.kwrest.__send__(
|
258
|
-
:==,
|
259
|
-
true
|
260
|
-
)) {list_add.call { || (g.add("**"))}}) {self.keywords.kwrest}) {list_add.call { || (g.add("**#{self.keywords.kwrest.name}"))}}
|
261
252
|
)}
|
262
|
-
::Myco.branch_op(:"
|
253
|
+
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.kwrest.__send__(
|
254
|
+
:==,
|
255
|
+
true
|
256
|
+
)) {list_add.call { || (g.add("**"))}}) {::Myco.branch_op(:"&?", self.kwrest) {list_add.call { || (g.add("**#{self.kwrest}"))}}}
|
257
|
+
::Myco.branch_op(:"&&", self.block) {list_add.call { || (g.add(self.block))}}
|
263
258
|
g.add("|")
|
264
259
|
g.list(
|
265
260
|
list,
|
@@ -267,7 +262,7 @@
|
|
267
262
|
) { |proc| (proc.call)}
|
268
263
|
g.add("|")
|
269
264
|
)})}
|
270
|
-
::Myco.find_constant(:
|
265
|
+
::Myco.find_constant(:Body).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
271
266
|
g.add("(")
|
272
267
|
g.list(
|
273
268
|
self.array,
|
@@ -281,7 +276,7 @@
|
|
281
276
|
list = ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.arguments) {self.arguments.body.dup}) {[]}
|
282
277
|
::Myco.branch_op(:"&&", self.arguments.block.__send__(
|
283
278
|
:is_a?,
|
284
|
-
::Myco.find_constant(:
|
279
|
+
::Myco.find_constant(:BlockArgument)
|
285
280
|
)) {list.push(self.arguments.block)}
|
286
281
|
g.add(self.receiver)
|
287
282
|
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", g.__send__(
|
@@ -289,10 +284,10 @@
|
|
289
284
|
self.name
|
290
285
|
)) {g.add(".#{self.name}")}) {(
|
291
286
|
g.add(".__send__")
|
292
|
-
list.unshift(::Myco.find_constant(:SymbolLiteral).new(
|
293
|
-
self.line,
|
294
|
-
self.name
|
295
|
-
))
|
287
|
+
list.unshift(::Myco.find_constant(:SymbolLiteral).new({
|
288
|
+
:line => self.line,
|
289
|
+
:value => self.name
|
290
|
+
}))
|
296
291
|
)}
|
297
292
|
::Myco.branch_op(:"&&", list.__send__(:any?)) {(
|
298
293
|
g.add("(")
|
@@ -305,7 +300,7 @@
|
|
305
300
|
)}
|
306
301
|
::Myco.branch_op(:"&&", self.arguments.block.__send__(
|
307
302
|
:is_a?,
|
308
|
-
::Myco.find_constant(:
|
303
|
+
::Myco.find_constant(:BlockLiteral)
|
309
304
|
)) {(
|
310
305
|
g.add(" {")
|
311
306
|
g.add(self.arguments.block)
|
@@ -340,17 +335,14 @@
|
|
340
335
|
g.add("*")
|
341
336
|
self.value.to_ruby(g)
|
342
337
|
)})})}
|
343
|
-
::Myco.find_constant(:
|
344
|
-
::Myco.find_constant(:ConcatArgs).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| nil})}
|
345
|
-
::Myco.find_constant(:PushArgs).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| nil})}
|
346
|
-
::Myco.find_constant(:BlockPass).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
338
|
+
::Myco.find_constant(:BlockArgument).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
347
339
|
g.add("&")
|
348
340
|
g.add(self.body)
|
349
341
|
)})}
|
350
|
-
::Myco.find_constant(:
|
351
|
-
g.var_scope_declare_locals(*self.
|
342
|
+
::Myco.find_constant(:BlockLiteral).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (g.with_nested_var_scope(self) { || (
|
343
|
+
g.var_scope_declare_locals(*self.parameters.names)
|
352
344
|
g.add(" ")
|
353
|
-
g.add(self.
|
345
|
+
g.add(self.parameters)
|
354
346
|
g.add(" ")
|
355
347
|
g.add(self.body)
|
356
348
|
)})})}
|
@@ -376,8 +368,4 @@
|
|
376
368
|
g.add(self.right)
|
377
369
|
g.add("}")
|
378
370
|
)})}
|
379
|
-
::Myco.find_constant(:Return).component_eval {(declare_meme(:to_ruby, [], nil, ::Myco.cscope.dup) { |g| (
|
380
|
-
g.add("return ")
|
381
|
-
g.add(self.value)
|
382
|
-
)})}
|
383
371
|
)})}}.instance
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
# Helper methods for bytecode generation
|
5
|
+
::CodeTools::Generator << {
|
6
|
+
push_myco: push_cpath_top; find_const(:"Myco")
|
7
|
+
push_void: push_myco; find_const(:"Void")
|
8
|
+
push_null: push_nil
|
9
|
+
}
|
10
|
+
|
11
|
+
Self < Node {
|
12
|
+
Form: [:self]
|
13
|
+
bytecode: |g| pos(g); g.push_self
|
14
|
+
}
|
15
|
+
|
16
|
+
NullLiteral < Node {
|
17
|
+
Form: [:null]
|
18
|
+
bytecode: |g| pos(g); g.push_null
|
19
|
+
}
|
20
|
+
|
21
|
+
VoidLiteral < Node {
|
22
|
+
Form: [:void]
|
23
|
+
bytecode: |g| pos(g); g.push_void
|
24
|
+
}
|
25
|
+
|
26
|
+
TrueLiteral < Node {
|
27
|
+
Form: [:true]
|
28
|
+
bytecode: |g| pos(g); g.push_true
|
29
|
+
}
|
30
|
+
|
31
|
+
FalseLiteral < Node {
|
32
|
+
Form: [:false]
|
33
|
+
bytecode: |g| pos(g); g.push_false
|
34
|
+
}
|
35
|
+
|
36
|
+
# TODO: use some other way to be eager
|
37
|
+
EVALUATE_NOW: ::CodeTools::AST.component_eval {
|
38
|
+
constants.select |const_name| {
|
39
|
+
const_get(const_name).constants.include?(:"Form")
|
40
|
+
}.each |const_name| {
|
41
|
+
component = const_get(const_name)
|
42
|
+
form = component.const_get(:"Form").dup
|
43
|
+
form_name = form.shift
|
44
|
+
|
45
|
+
BuilderMethods.declare_meme(form_name) |*args| {
|
46
|
+
inst = component.new
|
47
|
+
loc = args.shift
|
48
|
+
inst.line = loc.line
|
49
|
+
form.zip(args).each |key, value| {
|
50
|
+
inst.send(:""key"=", value)
|
51
|
+
}
|
52
|
+
inst
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(
|
4
|
+
::CodeTools::Generator.component_eval {(
|
5
|
+
declare_meme(:push_myco, [], nil, ::Myco.cscope.dup) { |*| (
|
6
|
+
self.push_cpath_top
|
7
|
+
self.find_const(:Myco)
|
8
|
+
)}
|
9
|
+
declare_meme(:push_void, [], nil, ::Myco.cscope.dup) { |*| (
|
10
|
+
self.push_myco
|
11
|
+
self.find_const(:Void)
|
12
|
+
)}
|
13
|
+
declare_meme(:push_null, [], nil, ::Myco.cscope.dup) { |*| (self.push_nil)}
|
14
|
+
)}
|
15
|
+
::Myco.cscope.for_method_definition.const_set(:Self, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
16
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
17
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([:self]))
|
18
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
19
|
+
self.pos(g)
|
20
|
+
g.push_self
|
21
|
+
)}
|
22
|
+
)}})
|
23
|
+
.tap { |__c__| __c__.__name__ = :Self }
|
24
|
+
::Myco.cscope.for_method_definition.const_set(:NullLiteral, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
25
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
26
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([:null]))
|
27
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
28
|
+
self.pos(g)
|
29
|
+
g.push_null
|
30
|
+
)}
|
31
|
+
)}})
|
32
|
+
.tap { |__c__| __c__.__name__ = :NullLiteral }
|
33
|
+
::Myco.cscope.for_method_definition.const_set(:VoidLiteral, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
34
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
35
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([:void]))
|
36
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
37
|
+
self.pos(g)
|
38
|
+
g.push_void
|
39
|
+
)}
|
40
|
+
)}})
|
41
|
+
.tap { |__c__| __c__.__name__ = :VoidLiteral }
|
42
|
+
::Myco.cscope.for_method_definition.const_set(:TrueLiteral, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
43
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
44
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([:true]))
|
45
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
46
|
+
self.pos(g)
|
47
|
+
g.push_true
|
48
|
+
)}
|
49
|
+
)}})
|
50
|
+
.tap { |__c__| __c__.__name__ = :TrueLiteral }
|
51
|
+
::Myco.cscope.for_method_definition.const_set(:FalseLiteral, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
52
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
53
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([:false]))
|
54
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
55
|
+
self.pos(g)
|
56
|
+
g.push_false
|
57
|
+
)}
|
58
|
+
)}})
|
59
|
+
.tap { |__c__| __c__.__name__ = :FalseLiteral }
|
60
|
+
::Myco.cscope.for_method_definition.const_set(:EVALUATE_NOW, (::CodeTools::AST.component_eval { || (self.constants.select { |const_name| (self.const_get(const_name).constants.__send__(
|
61
|
+
:include?,
|
62
|
+
:Form
|
63
|
+
))}.each { |const_name| (
|
64
|
+
component = self.const_get(const_name)
|
65
|
+
form = component.const_get(:Form).dup
|
66
|
+
form_name = form.shift
|
67
|
+
::Myco.find_constant(:BuilderMethods).declare_meme(form_name) { |*args| (
|
68
|
+
inst = component.new
|
69
|
+
loc = args.shift
|
70
|
+
inst.__send__(
|
71
|
+
:line=,
|
72
|
+
loc.line
|
73
|
+
)
|
74
|
+
form.zip(args).each { |key, value| (inst.send(
|
75
|
+
:"#{key}=",
|
76
|
+
value
|
77
|
+
))}
|
78
|
+
inst
|
79
|
+
)}
|
80
|
+
)})}))
|
81
|
+
)})}}.instance
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
BuilderMethods: Module.new { } # TODO: move out of this file
|
4
|
+
}
|
5
|
+
|
6
|
+
import 'AST/Node.my'
|
7
|
+
|
8
|
+
import 'AST/Script.my'
|
9
|
+
|
10
|
+
import 'AST/StringLiteral.my'
|
11
|
+
import 'AST/SymbolLiteral.my'
|
12
|
+
import 'AST/DynamicString.my'
|
13
|
+
import 'AST/DynamicSymbol.my'
|
14
|
+
|
15
|
+
import 'AST/Body.my'
|
16
|
+
|
17
|
+
import 'AST/SplatValue.my'
|
18
|
+
import 'AST/ArrayAssembly.my'
|
19
|
+
import 'AST/KeywordAssembly.my'
|
20
|
+
import 'AST/ArgumentAssembly.my'
|
21
|
+
import 'AST/BlockArgument.my'
|
22
|
+
import 'AST/BlockLiteral.my'
|
23
|
+
|
24
|
+
import 'AST/BlockParameter.my'
|
25
|
+
import 'AST/ParameterAssembly.my'
|
26
|
+
|
27
|
+
import 'AST/MycoModuleScope.my'
|
28
|
+
|
29
|
+
import 'AST/ConstantAccess.my'
|
30
|
+
import 'AST/ConstantAssignment.my'
|
31
|
+
import 'AST/ConstantDefine.my'
|
32
|
+
import 'AST/ConstantReopen.my'
|
33
|
+
import 'AST/DeclareCategory.my'
|
34
|
+
import 'AST/DeclareDecorator.my'
|
35
|
+
import 'AST/DeclareFile.my'
|
36
|
+
import 'AST/DeclareMeme.my'
|
37
|
+
import 'AST/DeclareObject.my'
|
38
|
+
import 'AST/DeclareString.my'
|
39
|
+
|
40
|
+
import 'AST/Invoke.my'
|
41
|
+
import 'AST/InvokeMethod.my'
|
42
|
+
import 'AST/LocalVariableAccessAmbiguous.my'
|
43
|
+
import 'AST/LocalVariableAssignment.my'
|
44
|
+
import 'AST/BlockLiteral.my'
|
45
|
+
|
46
|
+
import 'AST/Quest.my'
|
47
|
+
import 'AST/BranchOperator.my'
|
48
|
+
|
49
|
+
# TODO: refactor and break out misc
|
50
|
+
import "AST/misc.my"
|
51
|
+
|
52
|
+
import 'AST/ToRuby.my'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
4
|
+
::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition.const_set(:BuilderMethods, (::Myco.find_constant(:Module).new { || nil})))}
|
5
|
+
declare_meme(:"AST/Node.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
6
|
+
declare_meme(:"AST/Script.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
7
|
+
declare_meme(:"AST/StringLiteral.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
8
|
+
declare_meme(:"AST/SymbolLiteral.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
9
|
+
declare_meme(:"AST/DynamicString.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
10
|
+
declare_meme(:"AST/DynamicSymbol.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
11
|
+
declare_meme(:"AST/Body.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
12
|
+
declare_meme(:"AST/SplatValue.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
13
|
+
declare_meme(:"AST/ArrayAssembly.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
14
|
+
declare_meme(:"AST/KeywordAssembly.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
15
|
+
declare_meme(:"AST/ArgumentAssembly.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
16
|
+
declare_meme(:"AST/BlockArgument.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
17
|
+
declare_meme(:"AST/BlockLiteral.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
18
|
+
declare_meme(:"AST/BlockParameter.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
19
|
+
declare_meme(:"AST/ParameterAssembly.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
20
|
+
declare_meme(:"AST/MycoModuleScope.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
21
|
+
declare_meme(:"AST/ConstantAccess.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
22
|
+
declare_meme(:"AST/ConstantAssignment.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
23
|
+
declare_meme(:"AST/ConstantDefine.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
24
|
+
declare_meme(:"AST/ConstantReopen.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
25
|
+
declare_meme(:"AST/DeclareCategory.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
26
|
+
declare_meme(:"AST/DeclareDecorator.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
27
|
+
declare_meme(:"AST/DeclareFile.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
28
|
+
declare_meme(:"AST/DeclareMeme.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
29
|
+
declare_meme(:"AST/DeclareObject.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
30
|
+
declare_meme(:"AST/DeclareString.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
31
|
+
declare_meme(:"AST/Invoke.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
32
|
+
declare_meme(:"AST/InvokeMethod.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
33
|
+
declare_meme(:"AST/LocalVariableAccessAmbiguous.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
34
|
+
declare_meme(:"AST/LocalVariableAssignment.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
35
|
+
declare_meme(:"AST/BlockLiteral.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
36
|
+
declare_meme(:"AST/Quest.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
37
|
+
declare_meme(:"AST/BranchOperator.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
38
|
+
declare_meme(:"AST/misc.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
39
|
+
declare_meme(:"AST/ToRuby.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
40
|
+
)}}.instance
|