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
@@ -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 {(::Myco.find_constant(:CodeTools)::AST.component_eval {(
|
4
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareCategoryScope, ::Myco::Component.new([::Myco.find_constant(:MycoModuleScope)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
5
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:body_bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
6
|
+
g.push_scope
|
7
|
+
g.send(
|
8
|
+
:set_myco_category,
|
9
|
+
0
|
10
|
+
)
|
11
|
+
g.pop
|
12
|
+
self.body.bytecode(g)
|
13
|
+
)})}})
|
14
|
+
.tap { |__c__| __c__.__name__ = :DeclareCategoryScope }
|
15
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareCategory, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
16
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
17
|
+
declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
18
|
+
declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
19
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
20
|
+
:category,
|
21
|
+
:name,
|
22
|
+
:body
|
23
|
+
]))
|
24
|
+
declare_meme(:scope_implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:DeclareCategoryScope).new({
|
25
|
+
:line => self.line,
|
26
|
+
:body => self.body
|
27
|
+
}))}
|
28
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
29
|
+
self.pos(g)
|
30
|
+
g.push_self
|
31
|
+
g.push_literal(self.name)
|
32
|
+
g.send(
|
33
|
+
:__category__,
|
34
|
+
1
|
35
|
+
)
|
36
|
+
self.scope_implementation.bytecode(g)
|
37
|
+
)}
|
38
|
+
)}})
|
39
|
+
.tap { |__c__| __c__.__name__ = :DeclareCategory }
|
40
|
+
)})}}.instance
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DeclareDecorator < Node {
|
5
|
+
var name, var arguments
|
6
|
+
|
7
|
+
setter arguments: |x|
|
8
|
+
x || ArrayAssembly.new(line:self.line, body:[])
|
9
|
+
|
10
|
+
Form: [:deco, :name, :arguments]
|
11
|
+
|
12
|
+
implementation: ArrayAssembly.new(
|
13
|
+
line:self.line
|
14
|
+
body:[self.name, self.arguments]
|
15
|
+
)
|
16
|
+
|
17
|
+
bytecode: |g| pos(g); implementation.bytecode(g)
|
18
|
+
}
|
19
|
+
|
20
|
+
}
|
@@ -0,0 +1,28 @@
|
|
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 {(::Myco.cscope.for_method_definition.const_set(:DeclareDecorator, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
+
declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
6
|
+
declare_meme(:arguments, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
7
|
+
declare_meme(:arguments, [[:setter, []]], nil, ::Myco.cscope.dup) { |x| (::Myco.branch_op(:"||", x) {::Myco.find_constant(:ArrayAssembly).new({
|
8
|
+
:line => self.line,
|
9
|
+
:body => []
|
10
|
+
})})}
|
11
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
12
|
+
:deco,
|
13
|
+
:name,
|
14
|
+
:arguments
|
15
|
+
]))
|
16
|
+
declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:ArrayAssembly).new({
|
17
|
+
:line => self.line,
|
18
|
+
:body => [
|
19
|
+
self.name,
|
20
|
+
self.arguments
|
21
|
+
]
|
22
|
+
}))}
|
23
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
24
|
+
self.pos(g)
|
25
|
+
self.implementation.bytecode(g)
|
26
|
+
)}
|
27
|
+
)}})
|
28
|
+
.tap { |__c__| __c__.__name__ = :DeclareDecorator })})}}.instance
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DeclareFileScope < MycoModuleScope {
|
5
|
+
body_bytecode: |g| {
|
6
|
+
g.push_scope
|
7
|
+
g.send(:set_myco_file, 0)
|
8
|
+
g.pop
|
9
|
+
|
10
|
+
self.body.bytecode(g)
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
DeclareFile < Node {
|
15
|
+
var body
|
16
|
+
|
17
|
+
Form: [:declfile, :body]
|
18
|
+
|
19
|
+
# Use minimal inspect to avoid huge inspect output for inner AST nodes
|
20
|
+
# that store a reference to a DeclareFile in an instance variable.
|
21
|
+
inspect: to_s
|
22
|
+
|
23
|
+
implementation: {
|
24
|
+
type = ConstantAccess.new(line:self.line, toplevel:true, names:[:"Myco", :"FileToplevel"])
|
25
|
+
types = ArrayAssembly.new(line:self.line, body:[type])
|
26
|
+
decl = DeclareObject.new(line:self.line, types:types, body:self.body)
|
27
|
+
decl.scope_type = DeclareFileScope
|
28
|
+
decl
|
29
|
+
}
|
30
|
+
|
31
|
+
bytecode: |g| {
|
32
|
+
pos(g)
|
33
|
+
|
34
|
+
implementation.bytecode(g)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
}
|
@@ -0,0 +1,53 @@
|
|
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
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareFileScope, ::Myco::Component.new([::Myco.find_constant(:MycoModuleScope)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
5
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:body_bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
6
|
+
g.push_scope
|
7
|
+
g.send(
|
8
|
+
:set_myco_file,
|
9
|
+
0
|
10
|
+
)
|
11
|
+
g.pop
|
12
|
+
self.body.bytecode(g)
|
13
|
+
)})}})
|
14
|
+
.tap { |__c__| __c__.__name__ = :DeclareFileScope }
|
15
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareFile, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
16
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
17
|
+
declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
18
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
19
|
+
:declfile,
|
20
|
+
:body
|
21
|
+
]))
|
22
|
+
declare_meme(:inspect, [], nil, ::Myco.cscope.dup) { |*| (self.to_s)}
|
23
|
+
declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (
|
24
|
+
type = ::Myco.find_constant(:ConstantAccess).new({
|
25
|
+
:line => self.line,
|
26
|
+
:toplevel => true,
|
27
|
+
:names => [
|
28
|
+
:Myco,
|
29
|
+
:FileToplevel
|
30
|
+
]
|
31
|
+
})
|
32
|
+
types = ::Myco.find_constant(:ArrayAssembly).new({
|
33
|
+
:line => self.line,
|
34
|
+
:body => [type]
|
35
|
+
})
|
36
|
+
decl = ::Myco.find_constant(:DeclareObject).new({
|
37
|
+
:line => self.line,
|
38
|
+
:types => types,
|
39
|
+
:body => self.body
|
40
|
+
})
|
41
|
+
decl.__send__(
|
42
|
+
:scope_type=,
|
43
|
+
::Myco.find_constant(:DeclareFileScope)
|
44
|
+
)
|
45
|
+
decl
|
46
|
+
)}
|
47
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
48
|
+
self.pos(g)
|
49
|
+
self.implementation.bytecode(g)
|
50
|
+
)}
|
51
|
+
)}})
|
52
|
+
.tap { |__c__| __c__.__name__ = :DeclareFile }
|
53
|
+
)})}}.instance
|
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DeclareMemeBody < BlockLiteral {
|
5
|
+
var name
|
6
|
+
|
7
|
+
bytecode: |g| {
|
8
|
+
pos(g)
|
9
|
+
|
10
|
+
g.state.scope.nest_scope(self)
|
11
|
+
|
12
|
+
meth = new_generator(g, self.name, self.parameters)
|
13
|
+
|
14
|
+
meth.push_state(self)
|
15
|
+
meth.state.push_super(self)
|
16
|
+
meth.definition_line(self.line)
|
17
|
+
|
18
|
+
meth.state.push_name(self.name.to_sym)
|
19
|
+
|
20
|
+
self.parameters.bytecode(meth)
|
21
|
+
self.body.bytecode(meth)
|
22
|
+
|
23
|
+
meth.state.pop_name
|
24
|
+
|
25
|
+
meth.local_count = local_count
|
26
|
+
meth.local_names = local_names
|
27
|
+
|
28
|
+
meth.ret
|
29
|
+
meth.close
|
30
|
+
meth.pop_state
|
31
|
+
|
32
|
+
g.push_scope
|
33
|
+
g.send(:for_method_definition, 0)
|
34
|
+
g.add_scope
|
35
|
+
|
36
|
+
# Create the BlockEnvironment from the meth Generator
|
37
|
+
g.create_block(meth)
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
DeclareMeme < Node {
|
42
|
+
var name, var decorations, var parameters, var body
|
43
|
+
|
44
|
+
Form: [:meme, :name, :decorations, :parameters, :body]
|
45
|
+
|
46
|
+
setter name: |x|
|
47
|
+
x.value
|
48
|
+
setter decorations: |x|
|
49
|
+
x || ArrayAssembly.new(line:line, body:[])
|
50
|
+
setter parameters: |x|
|
51
|
+
x || ParameterAssembly.new(line:line, required:[], splat:true)
|
52
|
+
setter body: |x|
|
53
|
+
x || NullLiteral.new(line:line)
|
54
|
+
|
55
|
+
body_implementation: DeclareMemeBody.new(
|
56
|
+
line: self.line
|
57
|
+
name: self.name
|
58
|
+
parameters: self.parameters
|
59
|
+
body: self.body
|
60
|
+
)
|
61
|
+
|
62
|
+
bytecode: |g| {
|
63
|
+
pos(g)
|
64
|
+
|
65
|
+
##
|
66
|
+
# module = scope.for_method_definition
|
67
|
+
# module.send :declare_meme, self.name, self.decorations,
|
68
|
+
# BlockEnvironment(body_implementation)
|
69
|
+
#
|
70
|
+
g.push_scope
|
71
|
+
g.send(:for_method_definition, 0)
|
72
|
+
g.push_literal(self.name)
|
73
|
+
self.decorations.bytecode(g)
|
74
|
+
body_implementation.bytecode(g)
|
75
|
+
g.send(:declare_meme, 3)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
}
|
@@ -0,0 +1,90 @@
|
|
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
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareMemeBody, ::Myco::Component.new([::Myco.find_constant(:BlockLiteral)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
5
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
6
|
+
declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
7
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
8
|
+
self.pos(g)
|
9
|
+
g.state.scope.nest_scope(self)
|
10
|
+
meth = self.new_generator(
|
11
|
+
g,
|
12
|
+
self.name,
|
13
|
+
self.parameters
|
14
|
+
)
|
15
|
+
meth.push_state(self)
|
16
|
+
meth.state.push_super(self)
|
17
|
+
meth.definition_line(self.line)
|
18
|
+
meth.state.push_name(self.name.to_sym)
|
19
|
+
self.parameters.bytecode(meth)
|
20
|
+
self.body.bytecode(meth)
|
21
|
+
meth.state.pop_name
|
22
|
+
meth.__send__(
|
23
|
+
:local_count=,
|
24
|
+
self.local_count
|
25
|
+
)
|
26
|
+
meth.__send__(
|
27
|
+
:local_names=,
|
28
|
+
self.local_names
|
29
|
+
)
|
30
|
+
meth.ret
|
31
|
+
meth.close
|
32
|
+
meth.pop_state
|
33
|
+
g.push_scope
|
34
|
+
g.send(
|
35
|
+
:for_method_definition,
|
36
|
+
0
|
37
|
+
)
|
38
|
+
g.add_scope
|
39
|
+
g.create_block(meth)
|
40
|
+
)}
|
41
|
+
)}})
|
42
|
+
.tap { |__c__| __c__.__name__ = :DeclareMemeBody }
|
43
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareMeme, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
44
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
45
|
+
declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
46
|
+
declare_meme(:decorations, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
47
|
+
declare_meme(:parameters, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
48
|
+
declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
49
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
50
|
+
:meme,
|
51
|
+
:name,
|
52
|
+
:decorations,
|
53
|
+
:parameters,
|
54
|
+
:body
|
55
|
+
]))
|
56
|
+
declare_meme(:name, [[:setter, []]], nil, ::Myco.cscope.dup) { |x| (x.value)}
|
57
|
+
declare_meme(:decorations, [[:setter, []]], nil, ::Myco.cscope.dup) { |x| (::Myco.branch_op(:"||", x) {::Myco.find_constant(:ArrayAssembly).new({
|
58
|
+
:line => self.line,
|
59
|
+
:body => []
|
60
|
+
})})}
|
61
|
+
declare_meme(:parameters, [[:setter, []]], nil, ::Myco.cscope.dup) { |x| (::Myco.branch_op(:"||", x) {::Myco.find_constant(:ParameterAssembly).new({
|
62
|
+
:line => self.line,
|
63
|
+
:required => [],
|
64
|
+
:splat => true
|
65
|
+
})})}
|
66
|
+
declare_meme(:body, [[:setter, []]], nil, ::Myco.cscope.dup) { |x| (::Myco.branch_op(:"||", x) {::Myco.find_constant(:NullLiteral).new({:line => self.line})})}
|
67
|
+
declare_meme(:body_implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:DeclareMemeBody).new({
|
68
|
+
:line => self.line,
|
69
|
+
:name => self.name,
|
70
|
+
:parameters => self.parameters,
|
71
|
+
:body => self.body
|
72
|
+
}))}
|
73
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
74
|
+
self.pos(g)
|
75
|
+
g.push_scope
|
76
|
+
g.send(
|
77
|
+
:for_method_definition,
|
78
|
+
0
|
79
|
+
)
|
80
|
+
g.push_literal(self.name)
|
81
|
+
self.decorations.bytecode(g)
|
82
|
+
self.body_implementation.bytecode(g)
|
83
|
+
g.send(
|
84
|
+
:declare_meme,
|
85
|
+
3
|
86
|
+
)
|
87
|
+
)}
|
88
|
+
)}})
|
89
|
+
.tap { |__c__| __c__.__name__ = :DeclareMeme }
|
90
|
+
)})}}.instance
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DeclareObjectScope < MycoModuleScope {
|
5
|
+
body_bytecode: |g| {
|
6
|
+
g.push_scope
|
7
|
+
g.send(:set_myco_component, 0)
|
8
|
+
g.pop
|
9
|
+
|
10
|
+
self.body.bytecode(g)
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
DeclareObject < Node {
|
15
|
+
var types, var body
|
16
|
+
|
17
|
+
Form: [:declobj, :types, :body]
|
18
|
+
|
19
|
+
var create: true
|
20
|
+
var scope_type: DeclareObjectScope
|
21
|
+
|
22
|
+
var scope_implementation: self.scope_type.new(
|
23
|
+
line: self.line
|
24
|
+
body: self.body
|
25
|
+
)
|
26
|
+
|
27
|
+
bytecode: |g| {
|
28
|
+
pos(g)
|
29
|
+
|
30
|
+
# ::Myco::Component.new types, parent, filename
|
31
|
+
g.push_cpath_top
|
32
|
+
g.find_const(:"Myco")
|
33
|
+
g.find_const(:"Component")
|
34
|
+
self.types.bytecode(g)
|
35
|
+
g.push_scope; g.send(:for_method_definition, 0)
|
36
|
+
g.push_scope; g.send(:active_path, 0); g.meta_to_s
|
37
|
+
g.push_int(self.line)
|
38
|
+
g.send(:new, 4)
|
39
|
+
|
40
|
+
# The return value of Component.new at the top of the stack
|
41
|
+
# will be consumed by self.scope.bytecode, so save two copies of it.
|
42
|
+
g.dup_top # One for sending :__last__= to
|
43
|
+
g.dup_top # One for sending :instance to (or returning, if !self.create)
|
44
|
+
|
45
|
+
# Compile the inner scope,
|
46
|
+
# leaving the last object in the scope at the top of the stack.
|
47
|
+
scope_implementation.bytecode(g)
|
48
|
+
|
49
|
+
# component.__last__ = (value left on stack from self.scope.bytecode)
|
50
|
+
g.send(:"__last__=", 1)
|
51
|
+
g.pop
|
52
|
+
|
53
|
+
# return (self.create ? component.instance : component)
|
54
|
+
self.create && g.send(:instance, 0)
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
}
|
@@ -0,0 +1,67 @@
|
|
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
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareObjectScope, ::Myco::Component.new([::Myco.find_constant(:MycoModuleScope)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
5
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:body_bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
6
|
+
g.push_scope
|
7
|
+
g.send(
|
8
|
+
:set_myco_component,
|
9
|
+
0
|
10
|
+
)
|
11
|
+
g.pop
|
12
|
+
self.body.bytecode(g)
|
13
|
+
)})}})
|
14
|
+
.tap { |__c__| __c__.__name__ = :DeclareObjectScope }
|
15
|
+
::Myco.cscope.for_method_definition.const_set(:DeclareObject, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
16
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
17
|
+
declare_meme(:types, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
18
|
+
declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
19
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
20
|
+
:declobj,
|
21
|
+
:types,
|
22
|
+
:body
|
23
|
+
]))
|
24
|
+
declare_meme(:create, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (true)}
|
25
|
+
declare_meme(:scope_type, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:DeclareObjectScope))}
|
26
|
+
declare_meme(:scope_implementation, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (self.scope_type.new({
|
27
|
+
:line => self.line,
|
28
|
+
:body => self.body
|
29
|
+
}))}
|
30
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
31
|
+
self.pos(g)
|
32
|
+
g.push_cpath_top
|
33
|
+
g.find_const(:Myco)
|
34
|
+
g.find_const(:Component)
|
35
|
+
self.types.bytecode(g)
|
36
|
+
g.push_scope
|
37
|
+
g.send(
|
38
|
+
:for_method_definition,
|
39
|
+
0
|
40
|
+
)
|
41
|
+
g.push_scope
|
42
|
+
g.send(
|
43
|
+
:active_path,
|
44
|
+
0
|
45
|
+
)
|
46
|
+
g.meta_to_s
|
47
|
+
g.push_int(self.line)
|
48
|
+
g.send(
|
49
|
+
:new,
|
50
|
+
4
|
51
|
+
)
|
52
|
+
g.dup_top
|
53
|
+
g.dup_top
|
54
|
+
self.scope_implementation.bytecode(g)
|
55
|
+
g.send(
|
56
|
+
:__last__=,
|
57
|
+
1
|
58
|
+
)
|
59
|
+
g.pop
|
60
|
+
::Myco.branch_op(:"&&", self.create) {g.send(
|
61
|
+
:instance,
|
62
|
+
0
|
63
|
+
)}
|
64
|
+
)}
|
65
|
+
)}})
|
66
|
+
.tap { |__c__| __c__.__name__ = :DeclareObject }
|
67
|
+
)})}}.instance
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DeclareString < Node {
|
5
|
+
var types, var string
|
6
|
+
|
7
|
+
Form: [:declstr, :types, :string]
|
8
|
+
|
9
|
+
implementation: InvokeMethod.new(
|
10
|
+
line: self.string.line
|
11
|
+
name: :from_string
|
12
|
+
arguments: ArgumentAssembly.new(
|
13
|
+
line: self.string.line,
|
14
|
+
body: [self.string]
|
15
|
+
)
|
16
|
+
receiver: DeclareObject.new(
|
17
|
+
line: self.line
|
18
|
+
types: self.types
|
19
|
+
body: NullLiteral.new(line:self.line)
|
20
|
+
)
|
21
|
+
)
|
22
|
+
|
23
|
+
bytecode: |g| pos(g); implementation.bytecode(g)
|
24
|
+
}
|
25
|
+
|
26
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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 {(::Myco.cscope.for_method_definition.const_set(:DeclareString, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
+
declare_meme(:types, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
6
|
+
declare_meme(:string, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
7
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
8
|
+
:declstr,
|
9
|
+
:types,
|
10
|
+
:string
|
11
|
+
]))
|
12
|
+
declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:InvokeMethod).new({
|
13
|
+
:line => self.string.line,
|
14
|
+
:name => :from_string,
|
15
|
+
:arguments => ::Myco.find_constant(:ArgumentAssembly).new({
|
16
|
+
:line => self.string.line,
|
17
|
+
:body => [self.string]
|
18
|
+
}),
|
19
|
+
:receiver => ::Myco.find_constant(:DeclareObject).new({
|
20
|
+
:line => self.line,
|
21
|
+
:types => self.types,
|
22
|
+
:body => ::Myco.find_constant(:NullLiteral).new({:line => self.line})
|
23
|
+
})
|
24
|
+
}))}
|
25
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
26
|
+
self.pos(g)
|
27
|
+
self.implementation.bytecode(g)
|
28
|
+
)}
|
29
|
+
)}})
|
30
|
+
.tap { |__c__| __c__.__name__ = :DeclareString })})}}.instance
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DynamicString < Node {
|
5
|
+
var body
|
6
|
+
|
7
|
+
Form: [:dstr, :body]
|
8
|
+
|
9
|
+
bytecode: |g| {
|
10
|
+
pos(g)
|
11
|
+
|
12
|
+
self.body.each_slice(2) |string, other| {
|
13
|
+
g.push_literal(string.value.to_s)
|
14
|
+
other && (other.bytecode(g); g.meta_to_s)
|
15
|
+
}
|
16
|
+
|
17
|
+
g.string_build(self.body.size)
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
}
|
@@ -0,0 +1,22 @@
|
|
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 {(::Myco.cscope.for_method_definition.const_set(:DynamicString, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
+
declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
6
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
7
|
+
:dstr,
|
8
|
+
:body
|
9
|
+
]))
|
10
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
11
|
+
self.pos(g)
|
12
|
+
self.body.each_slice(2) { |string, other| (
|
13
|
+
g.push_literal(string.value.to_s)
|
14
|
+
::Myco.branch_op(:"&&", other) {(
|
15
|
+
other.bytecode(g)
|
16
|
+
g.meta_to_s
|
17
|
+
)}
|
18
|
+
)}
|
19
|
+
g.string_build(self.body.size)
|
20
|
+
)}
|
21
|
+
)}})
|
22
|
+
.tap { |__c__| __c__.__name__ = :DynamicString })})}}.instance
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
DynamicSymbol < Node {
|
5
|
+
var body
|
6
|
+
|
7
|
+
Form: [:dsym, :body]
|
8
|
+
|
9
|
+
bytecode: |g| {
|
10
|
+
pos(g)
|
11
|
+
|
12
|
+
self.body.each_slice(2) |string, other| {
|
13
|
+
g.push_literal(string.value.to_s)
|
14
|
+
other && (other.bytecode(g); g.meta_to_s)
|
15
|
+
}
|
16
|
+
|
17
|
+
g.string_build(self.body.size)
|
18
|
+
g.send(:to_sym, 0)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
}
|
@@ -0,0 +1,26 @@
|
|
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 {(::Myco.cscope.for_method_definition.const_set(:DynamicSymbol, ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
|
4
|
+
.tap { |__c__| __c__.__last__ = __c__.component_eval {(
|
5
|
+
declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
|
6
|
+
::Myco.cscope.for_method_definition.const_set(:Form, ([
|
7
|
+
:dsym,
|
8
|
+
:body
|
9
|
+
]))
|
10
|
+
declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
|
11
|
+
self.pos(g)
|
12
|
+
self.body.each_slice(2) { |string, other| (
|
13
|
+
g.push_literal(string.value.to_s)
|
14
|
+
::Myco.branch_op(:"&&", other) {(
|
15
|
+
other.bytecode(g)
|
16
|
+
g.meta_to_s
|
17
|
+
)}
|
18
|
+
)}
|
19
|
+
g.string_build(self.body.size)
|
20
|
+
g.send(
|
21
|
+
:to_sym,
|
22
|
+
0
|
23
|
+
)
|
24
|
+
)}
|
25
|
+
)}})
|
26
|
+
.tap { |__c__| __c__.__name__ = :DynamicSymbol })})}}.instance
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
CodeTools::AST << {
|
3
|
+
|
4
|
+
Invoke < Node {
|
5
|
+
var receiver, var name, var arguments, var block_params, var block
|
6
|
+
|
7
|
+
Form: [:invoke, :receiver, :name, :arguments, :block_params, :block]
|
8
|
+
|
9
|
+
bytecode: |g| pos(g); implementation.bytecode(g)
|
10
|
+
|
11
|
+
implementation: {
|
12
|
+
# TODO: error if passing both block argument and block literal
|
13
|
+
# Currently, this fails silently and ignores the block argument
|
14
|
+
# TODO: don't change AST state from here
|
15
|
+
self.block && (
|
16
|
+
self.arguments = self.arguments || ArgumentAssembly.new(line:self.line, body:[])
|
17
|
+
self.block_params = self.block_params || ParameterAssembly.new(line:self.line)
|
18
|
+
self.arguments.block = BlockLiteral.new(line:self.line, parameters:self.block_params, body:self.block)
|
19
|
+
)
|
20
|
+
|
21
|
+
self.receiver.nil? && self.arguments.nil? &? (
|
22
|
+
LocalVariableAccessAmbiguous.new(
|
23
|
+
line: self.line
|
24
|
+
name: self.name
|
25
|
+
)
|
26
|
+
) ?? (
|
27
|
+
InvokeMethod.new(
|
28
|
+
line: self.line
|
29
|
+
receiver: self.receiver || Self.new(line:self.line)
|
30
|
+
name: self.name
|
31
|
+
arguments: self.arguments || ArgumentAssembly.new(line:self.line, body:[])
|
32
|
+
)
|
33
|
+
)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|