myco 0.1.7 → 0.1.8
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/add_method.rb +38 -0
- data/lib/myco/bootstrap/component.rb +43 -21
- data/lib/myco/bootstrap/find_constant.rb +73 -25
- data/lib/myco/bootstrap/instance.rb +96 -25
- data/lib/myco/bootstrap/meme.rb +18 -12
- data/lib/myco/bootstrap/tuple.rb +13 -0
- data/lib/myco/bootstrap/undefined.rb +9 -0
- data/lib/myco/bootstrap/void.rb +5 -4
- data/lib/myco/bootstrap.my +24 -13
- data/lib/myco/bootstrap.my.rb +41 -4
- data/lib/myco/bootstrap.rb +4 -0
- data/lib/myco/code_loader.rb +11 -9
- data/lib/myco/code_tools/AST/Block.my.rb +2 -2
- data/lib/myco/code_tools/AST/ConstantAccess.my.rb +4 -4
- data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +4 -4
- data/lib/myco/code_tools/AST/Invoke.my +1 -1
- data/lib/myco/code_tools/AST/Invoke.my.rb +1 -1
- data/lib/myco/code_tools/AST/Node.my +2 -4
- data/lib/myco/code_tools/AST/Node.my.rb +3 -3
- data/lib/myco/code_tools/AST/PipeOperator.my.rb +1 -1
- data/lib/myco/code_tools/AST/ToRuby.my.rb +8 -8
- data/lib/myco/code_tools/AST/misc.my.rb +1 -1
- data/lib/myco/code_tools/Parser.my +8 -15
- data/lib/myco/code_tools/Parser.my.rb +8 -14
- data/lib/myco/code_tools/parser/MycoBuilder.my +3 -4
- data/lib/myco/code_tools/parser/MycoBuilder.my.rb +5 -6
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +8 -4
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +5 -5
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +2 -2
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +12 -12
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +54 -44
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my.rb +69 -83
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +18 -8
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +24 -10
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +1 -1
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my +1 -1
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my.rb +1 -2
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my +1 -1
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my.rb +1 -1
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +3 -3
- data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +5 -6
- data/lib/myco/code_tools/parser/pegleromyces/spec/BasicSpec.my +35 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/BasicSpec.my.rb +35 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my +10 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my.rb +9 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my +10 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my.rb +9 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeParser.test.my +81 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeParser.test.my.rb +209 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my +229 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my.rb +663 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Grammar.test.my +10 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Grammar.test.my.rb +9 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my +10 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my.rb +9 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my +13 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my.rb +20 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my +54 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my.rb +215 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my +156 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my.rb +334 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Processor.test.my +10 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/Processor.test.my.rb +9 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/run.my +20 -0
- data/lib/myco/code_tools/parser/pegleromyces/spec/run.my.rb +16 -0
- data/lib/myco/core/BasicDecorators.my +19 -11
- data/lib/myco/core/BasicDecorators.my.rb +24 -20
- data/lib/myco/core/BasicObject.my +12 -7
- data/lib/myco/core/BasicObject.my.rb +50 -44
- data/lib/myco/core/Category.my +12 -2
- data/lib/myco/core/Category.my.rb +15 -7
- data/lib/myco/core/Decorator.my +1 -1
- data/lib/myco/core/Decorator.my.rb +8 -10
- data/lib/myco/core/FileToplevel.my +3 -3
- data/lib/myco/core/FileToplevel.my.rb +4 -6
- data/lib/myco/core/Object.my +7 -10
- data/lib/myco/core/Object.my.rb +11 -17
- data/lib/myco/core/Ruby.my +6 -0
- data/lib/myco/core/Ruby.my.rb +16 -0
- data/lib/myco/core/Switch.my +1 -1
- data/lib/myco/core/Switch.my.rb +1 -1
- data/lib/myco/core.my +4 -0
- data/lib/myco/core.my.rb +7 -0
- data/lib/myco/dev/call_sites.rb +39 -0
- data/lib/myco/dev/counter.rb +26 -0
- data/lib/myco/dev.rb +3 -0
- data/lib/myco/eval.rb +1 -1
- data/lib/myco/tools/BasicCommand.my.rb +1 -1
- data/lib/myco/version.rb +1 -1
- data/lib/myco.rb +2 -3
- metadata +53 -20
- data/lib/myco/bootstrap/evaluator.rb +0 -58
data/lib/myco/bootstrap.my.rb
CHANGED
@@ -1,9 +1,46 @@
|
|
1
1
|
|
2
2
|
::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
3
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
4
|
-
::Myco::RubyEval = ::Myco::Component.new([::Myco
|
5
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:from_string, [], nil, ::Myco.cscope.dup) { |string| (::
|
4
|
+
::Myco::RubyEval = ::Myco::Component.new([::Myco::EmptyObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
5
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:from_string, [], nil, ::Myco.cscope.dup) { |string| (::Object.__send__(
|
6
|
+
:eval,
|
7
|
+
string
|
8
|
+
))})}}
|
6
9
|
.tap { |__c__| __c__.__name__ = :RubyEval }
|
7
|
-
::Myco::Component.new([::Myco
|
8
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
10
|
+
::Myco::Category = ::Myco::Component.new([::Myco::EmptyObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
11
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
12
|
+
.tap { |__c__| __c__.__name__ = :Category }
|
13
|
+
::Myco::BasicDecorators = ::Myco::Component.new([::Myco::EmptyObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
14
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
15
|
+
.tap { |__c__| __c__.__name__ = :BasicDecorators }
|
16
|
+
::Myco::BasicObject = ::Myco::Component.new([
|
17
|
+
::Myco::EmptyObject,
|
18
|
+
::Myco::BasicDecorators
|
19
|
+
], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
20
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
21
|
+
.tap { |__c__| __c__.__name__ = :BasicObject }
|
22
|
+
::Myco::Decorator = ::Myco::Component.new([::Myco::BasicObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
23
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
24
|
+
.tap { |__c__| __c__.__name__ = :Decorator }
|
25
|
+
::Myco::FileToplevel = ::Myco::Component.new([::Myco::BasicObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
26
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}
|
27
|
+
.tap { |__c__| __c__.__name__ = :FileToplevel }
|
28
|
+
__category__(:decorators).component_eval {(
|
29
|
+
declare_meme(:load, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:LoadDecorator))}
|
30
|
+
::Myco.cscope.for_method_definition::LoadDecorator = (::Myco::Component.new([::Myco::Decorator], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
31
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
32
|
+
declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (::Myco.eval_file(
|
33
|
+
meme.name.to_s,
|
34
|
+
[::Myco::CoreLoadPath]
|
35
|
+
))}
|
36
|
+
__category__(:transforms).component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |*| nil})}
|
37
|
+
)}}.instance)
|
38
|
+
)}
|
39
|
+
__category__(:main).component_eval {(
|
40
|
+
declare_meme(:"core/Category.my", [[:load, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
41
|
+
declare_meme(:"core/Decorator.my", [[:load, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
42
|
+
declare_meme(:"core/BasicDecorators.my", [[:load, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
43
|
+
declare_meme(:"core/BasicObject.my", [[:load, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
44
|
+
declare_meme(:"core/FileToplevel.my", [[:load, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
45
|
+
)}
|
9
46
|
)}}.instance
|
data/lib/myco/bootstrap.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
require_relative 'bootstrap/find_constant'
|
3
3
|
|
4
4
|
require_relative 'bootstrap/void'
|
5
|
+
require_relative 'bootstrap/undefined'
|
6
|
+
require_relative 'bootstrap/tuple'
|
7
|
+
|
8
|
+
require_relative 'bootstrap/add_method'
|
5
9
|
require_relative 'bootstrap/meme'
|
6
10
|
require_relative 'bootstrap/instance'
|
7
11
|
require_relative 'bootstrap/component'
|
data/lib/myco/code_loader.rb
CHANGED
@@ -85,10 +85,12 @@ module Myco
|
|
85
85
|
# If cscope or vscope or receiver are nil, they are pulled from
|
86
86
|
# the given call_depth, corresponding to one of the calling frames.
|
87
87
|
#
|
88
|
-
|
88
|
+
# TODO: fix rubinius JIT issue and use "call_depth:1, **kwargs" here
|
89
|
+
def self.load path, load_paths, kwargs={}
|
90
|
+
kwargs[:call_depth] ||= 1
|
89
91
|
begin
|
90
92
|
loader = loader_for_file(path, load_paths)
|
91
|
-
loader.bind_to(call_depth:call_depth+1
|
93
|
+
loader.bind_to(kwargs.merge(call_depth: kwargs[:call_depth] + 1))
|
92
94
|
loader.compile
|
93
95
|
loader.emit_rb! if self.emit_rb
|
94
96
|
loader.emit_rbc! if self.emit_rbc
|
@@ -113,12 +115,12 @@ module Myco
|
|
113
115
|
@line = line
|
114
116
|
end
|
115
117
|
|
116
|
-
|
117
|
-
|
118
|
-
loc = Rubinius::VM.backtrace(call_depth, true).first
|
119
|
-
@constant_scope = cscope || loc.constant_scope
|
120
|
-
@variable_scope = vscope || loc.variables
|
121
|
-
@receiver = receiver || loc.instance_variable_get(:@receiver)
|
118
|
+
# TODO: fix rubinius JIT issue and use "cscope:nil, vscope:nil, receiver:nil, call_depth:1" here
|
119
|
+
def bind_to kwargs={}
|
120
|
+
loc = Rubinius::VM.backtrace(kwargs.fetch(:call_depth, 1), true).first
|
121
|
+
@constant_scope = kwargs[:cscope] || loc.constant_scope
|
122
|
+
@variable_scope = kwargs[:vscope] || loc.variables
|
123
|
+
@receiver = kwargs[:receiver] || loc.instance_variable_get(:@receiver)
|
122
124
|
|
123
125
|
self
|
124
126
|
end
|
@@ -253,7 +255,7 @@ module Myco
|
|
253
255
|
end
|
254
256
|
|
255
257
|
def new_parser
|
256
|
-
Myco::ToolSet::Parser
|
258
|
+
Myco::ToolSet::Parser
|
257
259
|
end
|
258
260
|
|
259
261
|
def new_generator
|
@@ -12,8 +12,8 @@
|
|
12
12
|
::Myco.cscope.for_method_definition::CompilerClass = (::Myco.find_constant(:CodeTools)::Compiler)
|
13
13
|
declare_meme(:parameters, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (::Myco.branch_op(:"||", given) {::Myco.find_constant(:ParameterAssembly).new({:line => self.line})})}
|
14
14
|
declare_meme(:body, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (::Myco.branch_op(:"||", given) {::Myco.find_constant(:NullLiteral).new({:line => self.line})})}
|
15
|
-
declare_meme(:locals, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"??", ((self.body
|
16
|
-
declare_meme(:block_local?, [], nil, ::Myco.cscope.dup) { |name| (::Myco.branch_op(:"??", (self.locals
|
15
|
+
declare_meme(:locals, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?((Rubinius::Type.object_respond_to?(self.body, :locals).false? ? ::Myco::Void : self.body.locals), :body).false? ? ::Myco::Void : (Rubinius::Type.object_respond_to?(self.body, :locals).false? ? ::Myco::Void : self.body.locals).body).map(&:value)) {nil})}
|
16
|
+
declare_meme(:block_local?, [], nil, ::Myco.cscope.dup) { |name| (::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(self.locals, :include?).false? ? ::Myco::Void : self.locals.__send__(
|
17
17
|
:include?,
|
18
18
|
name
|
19
19
|
))) {false})}
|
@@ -12,12 +12,12 @@
|
|
12
12
|
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.toplevel) {self.case(
|
13
13
|
first_name,
|
14
14
|
:Myco,
|
15
|
-
::Proc.new { || (g.push_myco)},
|
15
|
+
::Object::Proc.new { || (g.push_myco)},
|
16
16
|
:Ruby,
|
17
|
-
::Proc.new { || (g.push_cpath_top)},
|
17
|
+
::Object::Proc.new { || (g.push_cpath_top)},
|
18
18
|
:Rubinius,
|
19
|
-
::Proc.new { || (g.push_rubinius)},
|
20
|
-
::Proc.new { || (
|
19
|
+
::Object::Proc.new { || (g.push_rubinius)},
|
20
|
+
::Object::Proc.new { || (
|
21
21
|
g.push_myco
|
22
22
|
g.find_const(first_name)
|
23
23
|
)}
|
@@ -13,12 +13,12 @@
|
|
13
13
|
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.constant.toplevel) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {self.case(
|
14
14
|
first_name,
|
15
15
|
:Myco,
|
16
|
-
::Proc.new { || (g.push_myco)},
|
16
|
+
::Object::Proc.new { || (g.push_myco)},
|
17
17
|
:Ruby,
|
18
|
-
::Proc.new { || (g.push_cpath_top)},
|
18
|
+
::Object::Proc.new { || (g.push_cpath_top)},
|
19
19
|
:Rubinius,
|
20
|
-
::Proc.new { || (g.push_rubinius)},
|
21
|
-
::Proc.new { || (
|
20
|
+
::Object::Proc.new { || (g.push_rubinius)},
|
21
|
+
::Object::Proc.new { || (
|
22
22
|
g.push_myco
|
23
23
|
g.find_const(first_name)
|
24
24
|
)}
|
@@ -23,7 +23,7 @@
|
|
23
23
|
self.block
|
24
24
|
)
|
25
25
|
)}
|
26
|
-
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", ::Myco.branch_op(:"&&", self.receiver.__send__(
|
26
|
+
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", ::Myco.branch_op(:"&&", self.receiver.__send__(:!)) {use_args.__send__(:!)}) {::Myco.find_constant(:LocalVariableAccessAmbiguous).new({
|
27
27
|
:line => self.line,
|
28
28
|
:name => self.name
|
29
29
|
})}) {::Myco.find_constant(:InvokeMethod).new({
|
@@ -43,15 +43,13 @@ CodeTools::AST << {
|
|
43
43
|
|
44
44
|
[decorators]
|
45
45
|
|
46
|
-
|
47
|
-
var node_type: Decorator {
|
46
|
+
const node_type: Decorator {
|
48
47
|
apply: |meme| meme.target.node_type = meme.name
|
49
48
|
[transforms]
|
50
49
|
expose: false
|
51
50
|
}
|
52
51
|
|
53
|
-
|
54
|
-
var field: Decorator {
|
52
|
+
const field: Decorator {
|
55
53
|
apply: |meme| meme.target.fields.push(meme.name)
|
56
54
|
[transforms]
|
57
55
|
var: true
|
@@ -50,11 +50,11 @@
|
|
50
50
|
self.line,
|
51
51
|
*self.fields.map { |name| (
|
52
52
|
value = self.__send__(name)
|
53
|
-
::Myco.branch_op(:"??", ::Myco.branch_op(:"??", (
|
53
|
+
::Myco.branch_op(:"??", ::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(value, :map).false? ? ::Myco::Void : value.map { |value| (::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(value, :representation).false? ? ::Myco::Void : value.representation)) {value})})) {(Rubinius::Type.object_respond_to?(value, :representation).false? ? ::Myco::Void : value.representation)}) {value}
|
54
54
|
)}
|
55
55
|
])}
|
56
56
|
__category__(:decorators).component_eval {(
|
57
|
-
declare_meme(:node_type, [[:
|
57
|
+
declare_meme(:node_type, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
58
58
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
59
59
|
declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (meme.target.__send__(
|
60
60
|
:node_type=,
|
@@ -62,7 +62,7 @@
|
|
62
62
|
))}
|
63
63
|
__category__(:transforms).component_eval {(declare_meme(:expose, [], nil, ::Myco.cscope.dup) { |*| (false)})}
|
64
64
|
)}}.instance)}
|
65
|
-
declare_meme(:field, [[:
|
65
|
+
declare_meme(:field, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
66
66
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
67
67
|
declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (meme.target.fields.push(meme.name))}
|
68
68
|
__category__(:transforms).component_eval {(declare_meme(:var, [], nil, ::Myco.cscope.dup) { |*| (true)})}
|
@@ -9,7 +9,7 @@
|
|
9
9
|
:line => self.line,
|
10
10
|
:body => [self.value].__send__(
|
11
11
|
:+,
|
12
|
-
::Myco.branch_op(:"??", (self.invoke.arguments
|
12
|
+
::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(self.invoke.arguments, :body).false? ? ::Myco::Void : self.invoke.arguments.body)) {[]}
|
13
13
|
)
|
14
14
|
}))}
|
15
15
|
declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Invoke).new({
|
@@ -152,12 +152,12 @@
|
|
152
152
|
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.toplevel) {self.case(
|
153
153
|
first_name,
|
154
154
|
:Myco,
|
155
|
-
::Proc.new { || (g.add("::Myco"))},
|
155
|
+
::Object::Proc.new { || (g.add("::Myco"))},
|
156
156
|
:Ruby,
|
157
|
-
::Proc.new { || (g.add("::Object"))},
|
157
|
+
::Object::Proc.new { || (g.add("::Object"))},
|
158
158
|
:Rubinius,
|
159
|
-
::Proc.new { || (g.add("::Rubinius"))},
|
160
|
-
::Proc.new { || (g.add("::Myco::#{first_name}"))}
|
159
|
+
::Object::Proc.new { || (g.add("::Rubinius"))},
|
160
|
+
::Object::Proc.new { || (g.add("::Myco::#{first_name}"))}
|
161
161
|
)}) {g.add("::Myco.find_constant(#{first_name.inspect})")}
|
162
162
|
name_list.each { |name| (g.add("::#{name}"))}
|
163
163
|
)})}
|
@@ -168,12 +168,12 @@
|
|
168
168
|
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.constant.toplevel) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {self.case(
|
169
169
|
first_name,
|
170
170
|
:Myco,
|
171
|
-
::Proc.new { || (g.add("::Myco"))},
|
171
|
+
::Object::Proc.new { || (g.add("::Myco"))},
|
172
172
|
:Ruby,
|
173
|
-
::Proc.new { || (g.add("::Object"))},
|
173
|
+
::Object::Proc.new { || (g.add("::Object"))},
|
174
174
|
:Rubinius,
|
175
|
-
::Proc.new { || (g.add("::Rubinius"))},
|
176
|
-
::Proc.new { || (g.add("::Myco::#{first_name}"))}
|
175
|
+
::Object::Proc.new { || (g.add("::Rubinius"))},
|
176
|
+
::Object::Proc.new { || (g.add("::Myco::#{first_name}"))}
|
177
177
|
)}) {g.add("::Myco")}}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {g.add("::Myco.find_constant(#{first_name.inspect})")}) {g.add("::Myco.cscope.for_method_definition")}}
|
178
178
|
name_list.each { |name| (g.add("::#{name}"))}
|
179
179
|
g.add("::#{last_name} = ")
|
@@ -57,7 +57,7 @@
|
|
57
57
|
)}
|
58
58
|
)}}
|
59
59
|
.tap { |__c__| __c__.__name__ = :FalseLiteral }
|
60
|
-
::Myco.cscope.for_method_definition::EVALUATE_NOW = (::Myco.find_constant(:CodeTools)::AST.component_eval { || (self.constants.select { |const_name| (::Myco.branch_op(:"??", (self.const_get(const_name)
|
60
|
+
::Myco.cscope.for_method_definition::EVALUATE_NOW = (::Myco.find_constant(:CodeTools)::AST.component_eval { || (self.constants.select { |const_name| (::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(self.const_get(const_name), :node_type).false? ? ::Myco::Void : self.const_get(const_name).node_type)) {nil})}.each { |const_name| (
|
61
61
|
component = self.const_get(const_name)
|
62
62
|
node_type = component.node_type
|
63
63
|
fields = component.fields
|
@@ -2,23 +2,16 @@
|
|
2
2
|
# TODO: include Pegleromyces library in a better way than clone into subdir
|
3
3
|
import as(:Pegleromyces) 'parser/pegleromyces/lib/pegleromyces.my'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
import 'parser/MycoGrammar.my'
|
6
|
+
import 'parser/MycoBuilder.my'
|
7
7
|
|
8
|
-
CodeTools::Parser
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
MycoParser: Pegleromyces::BytecodeParser {
|
13
|
-
var grammar: MycoGrammar
|
14
|
-
# TODO: re-evaluate design that returns an existing builder as 'new_builder'
|
15
|
-
new_builder: MycoBuilder
|
16
|
-
}
|
8
|
+
CodeTools::Parser: Pegleromyces::BytecodeParser {
|
9
|
+
const grammar: MycoGrammar
|
10
|
+
const builder: MycoBuilder
|
17
11
|
|
18
12
|
parse_string: |string| {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
parser.result.fetch(:root) ?? parser.raise_error
|
13
|
+
state = parse(string)
|
14
|
+
state.result &?
|
15
|
+
state.result.fetch(:root) ?? state.raise_error
|
23
16
|
}
|
24
17
|
}
|
@@ -5,21 +5,15 @@
|
|
5
5
|
[:as, [:Pegleromyces]],
|
6
6
|
[:import, []]
|
7
7
|
], nil, ::Myco.cscope.dup) { |*| nil}
|
8
|
-
|
9
|
-
|
8
|
+
declare_meme(:"parser/MycoGrammar.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
9
|
+
declare_meme(:"parser/MycoBuilder.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
10
|
+
::Myco.find_constant(:CodeTools)::Parser = (::Myco::Component.new([::Myco.find_constant(:Pegleromyces)::BytecodeParser], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
10
11
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
11
|
-
::Myco.cscope.
|
12
|
-
::Myco.cscope.
|
13
|
-
::Myco.cscope.for_method_definition::MycoParser = (::Myco::Component.new([::Myco.find_constant(:Pegleromyces)::BytecodeParser], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
14
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
15
|
-
declare_meme(:grammar, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:MycoGrammar))}
|
16
|
-
declare_meme(:new_builder, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:MycoBuilder))}
|
17
|
-
)}}.instance)
|
12
|
+
declare_meme(:grammar, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:MycoGrammar))}
|
13
|
+
declare_meme(:builder, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:MycoBuilder))}
|
18
14
|
declare_meme(:parse_string, [], nil, ::Myco.cscope.dup) { |string| (
|
19
|
-
|
20
|
-
|
21
|
-
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", parser.result) {parser.result.fetch(:root)}) {parser.raise_error}
|
15
|
+
state = self.parse(string)
|
16
|
+
::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", state.result) {state.result.fetch(:root)}) {state.raise_error}
|
22
17
|
)}
|
23
|
-
)}}
|
24
|
-
.tap { |__c__| __c__.__name__ = :Parser }
|
18
|
+
)}}.instance)
|
25
19
|
)}}.instance
|
@@ -1,10 +1,9 @@
|
|
1
1
|
|
2
|
-
BasicObject {
|
2
|
+
MycoBuilder: BasicObject {
|
3
3
|
# TODO: be more clever here
|
4
|
-
|
5
|
-
var ast: ASTBuilder
|
4
|
+
const ast: CodeTools::AST::Builder.new
|
6
5
|
|
7
|
-
|
6
|
+
const escape_encodings: {
|
8
7
|
hash = ::Ruby::Hash.new
|
9
8
|
hash["\\a"] = 7.chr # \a 0x07 Bell or alert
|
10
9
|
hash["\\b"] = 8.chr # \b 0x08 Backspace
|
@@ -1,11 +1,10 @@
|
|
1
1
|
|
2
2
|
::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.cscope.for_method_definition::MycoBuilder = (::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
4
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
-
::Myco.cscope.
|
6
|
-
declare_meme(:
|
7
|
-
|
8
|
-
hash = ::Ruby::Hash.new
|
5
|
+
declare_meme(:ast, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:CodeTools)::AST::Builder.new)}
|
6
|
+
declare_meme(:escape_encodings, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (
|
7
|
+
hash = ::Object::Hash.new
|
9
8
|
hash.__send__(
|
10
9
|
:[]=,
|
11
10
|
"\\a",
|
@@ -96,4 +95,4 @@
|
|
96
95
|
output.push(input.shift)
|
97
96
|
input.replace(output)
|
98
97
|
)}
|
99
|
-
)}}.instance)}}.instance
|
98
|
+
)}}.instance))}}.instance
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
BytecodeHelpers <
|
2
|
+
BytecodeHelpers < BasicDecorators {
|
3
3
|
##
|
4
4
|
# Bytecode Generation Helper Methods
|
5
5
|
|
@@ -37,8 +37,8 @@ BytecodeHelpers < BasicObject {
|
|
37
37
|
push_subject_at_idx:
|
38
38
|
g.push_subject; g.push_idx; g.send(:chr_at, 1)
|
39
39
|
|
40
|
-
|
41
|
-
g.
|
40
|
+
push_new_table:
|
41
|
+
g.push_rubinius; g.find_const(:LookupTable); g.send(:new, 0)
|
42
42
|
|
43
43
|
# Set the memo ivar to a new hash if it doesn't already exist
|
44
44
|
memo_or_eq_new_hash: |name| {
|
@@ -46,7 +46,7 @@ BytecodeHelpers < BasicObject {
|
|
46
46
|
|
47
47
|
g.push_memo_for(name)
|
48
48
|
g.goto_if_true(memo_exists_label)
|
49
|
-
g.
|
49
|
+
g.push_new_table
|
50
50
|
g.set_memo_for(name)
|
51
51
|
g.pop # ivar
|
52
52
|
memo_exists_label.set!
|
@@ -113,6 +113,8 @@ BytecodeHelpers < BasicObject {
|
|
113
113
|
|
114
114
|
g.local_count = 2
|
115
115
|
g.local_names = [:subject, :idx]
|
116
|
+
|
117
|
+
# g.puts_string("trying.. "g.name"") # TODO: enable with debug flag
|
116
118
|
}
|
117
119
|
|
118
120
|
# Wrap up a compiled parser method
|
@@ -121,11 +123,13 @@ BytecodeHelpers < BasicObject {
|
|
121
123
|
|
122
124
|
# end
|
123
125
|
g.push_idx
|
126
|
+
# g.puts_string("SUCCESS! "g.name"") # TODO: enable with debug flag
|
124
127
|
g.goto(overall_done)
|
125
128
|
|
126
129
|
# fail
|
127
130
|
g.overall_fail.set!
|
128
131
|
g.push_nil
|
132
|
+
# g.puts_string("failure: "g.name"") # TODO: enable with debug flag
|
129
133
|
|
130
134
|
overall_done.set!
|
131
135
|
g.ret
|
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
3
|
-
.tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.cscope.for_method_definition::BytecodeHelpers = ::Myco::Component.new([::Myco.find_constant(:
|
3
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.cscope.for_method_definition::BytecodeHelpers = ::Myco::Component.new([::Myco.find_constant(:BasicDecorators)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
4
|
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
5
|
declare_meme(:overall_fail, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (self.new_label)}
|
6
6
|
declare_meme(:g, [], nil, ::Myco.cscope.dup) { |*| (self)}
|
@@ -64,9 +64,9 @@
|
|
64
64
|
1
|
65
65
|
)
|
66
66
|
)}
|
67
|
-
declare_meme(:
|
68
|
-
self.g.
|
69
|
-
self.g.find_const(:
|
67
|
+
declare_meme(:push_new_table, [], nil, ::Myco.cscope.dup) { |*| (
|
68
|
+
self.g.push_rubinius
|
69
|
+
self.g.find_const(:LookupTable)
|
70
70
|
self.g.send(
|
71
71
|
:new,
|
72
72
|
0
|
@@ -76,7 +76,7 @@
|
|
76
76
|
memo_exists_label = self.g.new_label
|
77
77
|
self.g.push_memo_for(name)
|
78
78
|
self.g.goto_if_true(memo_exists_label)
|
79
|
-
self.g.
|
79
|
+
self.g.push_new_table
|
80
80
|
self.g.set_memo_for(name)
|
81
81
|
self.g.pop
|
82
82
|
memo_exists_label.__send__(:set!)
|
@@ -351,10 +351,10 @@ BytecodeInstructions < BasicObject {
|
|
351
351
|
g.overall_fail = old_fail # reset fail
|
352
352
|
g.goto(g.overall_fail)
|
353
353
|
|
354
|
-
# Failure => Success, backtrack index
|
354
|
+
# Failure => Success, backtrack index and cannot keep captures either (incomplete)
|
355
355
|
local_fail.set!
|
356
356
|
g.pop_to_set_idx
|
357
|
-
if(inner_can_capture) { g.
|
357
|
+
if(inner_can_capture) { g.pop_to_reject_captures }
|
358
358
|
g.overall_fail = old_fail
|
359
359
|
}
|
360
360
|
|
@@ -17,35 +17,35 @@
|
|
17
17
|
m.set(codes.map(&:chr).join)
|
18
18
|
)})}
|
19
19
|
::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.neg_predicate(
|
20
|
-
::Proc.new { || (self.inner.bytecode(m))},
|
20
|
+
::Object::Proc.new { || (self.inner.bytecode(m))},
|
21
21
|
self.inner.bytecode_can_capture
|
22
22
|
))})}
|
23
23
|
::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.pos_predicate(
|
24
|
-
::Proc.new { || (self.inner.bytecode(m))},
|
24
|
+
::Object::Proc.new { || (self.inner.bytecode(m))},
|
25
25
|
self.inner.bytecode_can_capture
|
26
26
|
))})}
|
27
27
|
::Myco.find_constant(:OneOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.many(
|
28
|
-
::Proc.new { || (
|
28
|
+
::Object::Proc.new { || (
|
29
29
|
self.inner.bytecode(m)
|
30
|
-
(self.inlaid
|
30
|
+
(Rubinius::Type.object_respond_to?(self.inlaid, :call).false? ? ::Myco::Void : self.inlaid.call)
|
31
31
|
)},
|
32
32
|
self.inner.bytecode_can_capture
|
33
33
|
))})}
|
34
34
|
::Myco.find_constant(:ZeroOrOne).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.choice(
|
35
|
-
::Proc.new { || (self.inner.bytecode(m))},
|
36
|
-
::Proc.new { || nil},
|
35
|
+
::Object::Proc.new { || (self.inner.bytecode(m))},
|
36
|
+
::Object::Proc.new { || nil},
|
37
37
|
self.inner.bytecode_can_capture
|
38
38
|
))})}
|
39
39
|
::Myco.find_constant(:ZeroOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.kleene(
|
40
|
-
::Proc.new { || (
|
40
|
+
::Object::Proc.new { || (
|
41
41
|
self.inner.bytecode(m)
|
42
|
-
(self.inlaid
|
42
|
+
(Rubinius::Type.object_respond_to?(self.inlaid, :call).false? ? ::Myco::Void : self.inlaid.call)
|
43
43
|
)},
|
44
44
|
self.inner.bytecode_can_capture
|
45
45
|
))})}
|
46
46
|
::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.choice(
|
47
|
-
::Proc.new { || (self.first.bytecode(m))},
|
48
|
-
::Proc.new { || (self.second.bytecode(m))},
|
47
|
+
::Object::Proc.new { || (self.first.bytecode(m))},
|
48
|
+
::Object::Proc.new { || (self.second.bytecode(m))},
|
49
49
|
self.first.bytecode_can_capture
|
50
50
|
))})}
|
51
51
|
::Myco.find_constant(:Concatenation).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
|
@@ -61,7 +61,7 @@
|
|
61
61
|
)}) {(
|
62
62
|
self.inner.__send__(
|
63
63
|
:inlaid=,
|
64
|
-
::Proc.new { || (m.capture(
|
64
|
+
::Object::Proc.new { || (m.capture(
|
65
65
|
:m_split,
|
66
66
|
self.captargs
|
67
67
|
))}
|
@@ -347,7 +347,7 @@
|
|
347
347
|
self.__send__(
|
348
348
|
:if,
|
349
349
|
inner_can_capture
|
350
|
-
) { || (self.g.
|
350
|
+
) { || (self.g.pop_to_reject_captures)}
|
351
351
|
self.g.__send__(
|
352
352
|
:overall_fail=,
|
353
353
|
old_fail
|