myco 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/lib/myco/bootstrap/component.rb +6 -7
  3. data/lib/myco/bootstrap/instance.rb +14 -9
  4. data/lib/myco/bootstrap/meme.rb +34 -3
  5. data/lib/myco/code_loader.rb +17 -34
  6. data/lib/myco/code_tools/AST/ArgumentAssembly.my +60 -0
  7. data/lib/myco/code_tools/AST/ArgumentAssembly.my.rb +55 -0
  8. data/lib/myco/code_tools/AST/ArrayAssembly.my +43 -0
  9. data/lib/myco/code_tools/AST/ArrayAssembly.my.rb +37 -0
  10. data/lib/myco/code_tools/AST/BlockArgument.my +25 -0
  11. data/lib/myco/code_tools/AST/BlockArgument.my.rb +26 -0
  12. data/lib/myco/code_tools/AST/BlockLiteral.my +104 -0
  13. data/lib/myco/code_tools/AST/BlockLiteral.my.rb +126 -0
  14. data/lib/myco/code_tools/AST/BlockParameter.my +25 -0
  15. data/lib/myco/code_tools/AST/BlockParameter.my.rb +24 -0
  16. data/lib/myco/code_tools/AST/Body.my +18 -0
  17. data/lib/myco/code_tools/AST/Body.my.rb +20 -0
  18. data/lib/myco/code_tools/AST/BranchOperator.my +59 -0
  19. data/lib/myco/code_tools/AST/BranchOperator.my.rb +87 -0
  20. data/lib/myco/code_tools/AST/ConstantAccess.my +30 -0
  21. data/lib/myco/code_tools/AST/ConstantAccess.my.rb +32 -0
  22. data/lib/myco/code_tools/AST/ConstantAssignment.my +40 -0
  23. data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +45 -0
  24. data/lib/myco/code_tools/AST/ConstantDefine.my +30 -0
  25. data/lib/myco/code_tools/AST/ConstantDefine.my.rb +36 -0
  26. data/lib/myco/code_tools/AST/ConstantReopen.my +29 -0
  27. data/lib/myco/code_tools/AST/ConstantReopen.my.rb +35 -0
  28. data/lib/myco/code_tools/AST/DeclareCategory.my +35 -0
  29. data/lib/myco/code_tools/AST/DeclareCategory.my.rb +40 -0
  30. data/lib/myco/code_tools/AST/DeclareDecorator.my +20 -0
  31. data/lib/myco/code_tools/AST/DeclareDecorator.my.rb +28 -0
  32. data/lib/myco/code_tools/AST/DeclareFile.my +38 -0
  33. data/lib/myco/code_tools/AST/DeclareFile.my.rb +53 -0
  34. data/lib/myco/code_tools/AST/DeclareMeme.my +79 -0
  35. data/lib/myco/code_tools/AST/DeclareMeme.my.rb +90 -0
  36. data/lib/myco/code_tools/AST/DeclareObject.my +58 -0
  37. data/lib/myco/code_tools/AST/DeclareObject.my.rb +67 -0
  38. data/lib/myco/code_tools/AST/DeclareString.my +26 -0
  39. data/lib/myco/code_tools/AST/DeclareString.my.rb +30 -0
  40. data/lib/myco/code_tools/AST/DynamicString.my +21 -0
  41. data/lib/myco/code_tools/AST/DynamicString.my.rb +22 -0
  42. data/lib/myco/code_tools/AST/DynamicSymbol.my +22 -0
  43. data/lib/myco/code_tools/AST/DynamicSymbol.my.rb +26 -0
  44. data/lib/myco/code_tools/AST/Invoke.my +37 -0
  45. data/lib/myco/code_tools/AST/Invoke.my.rb +58 -0
  46. data/lib/myco/code_tools/AST/InvokeMethod.my +19 -0
  47. data/lib/myco/code_tools/AST/InvokeMethod.my.rb +25 -0
  48. data/lib/myco/code_tools/AST/KeywordAssembly.my +30 -0
  49. data/lib/myco/code_tools/AST/KeywordAssembly.my.rb +36 -0
  50. data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my +22 -0
  51. data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my.rb +22 -0
  52. data/lib/myco/code_tools/AST/LocalVariableAssignment.my +20 -0
  53. data/lib/myco/code_tools/AST/LocalVariableAssignment.my.rb +20 -0
  54. data/lib/myco/{parser/ast/myco_module_scope.rb → code_tools/AST/MycoModuleScope.my} +32 -39
  55. data/lib/myco/code_tools/AST/MycoModuleScope.my.rb +82 -0
  56. data/lib/myco/code_tools/AST/Node.my +67 -0
  57. data/lib/myco/code_tools/AST/Node.my.rb +84 -0
  58. data/lib/myco/code_tools/AST/ParameterAssembly.my +248 -0
  59. data/lib/myco/code_tools/AST/ParameterAssembly.my.rb +314 -0
  60. data/lib/myco/code_tools/AST/Quest.my +61 -0
  61. data/lib/myco/code_tools/AST/Quest.my.rb +51 -0
  62. data/lib/myco/code_tools/AST/Script.my +27 -0
  63. data/lib/myco/code_tools/AST/Script.my.rb +33 -0
  64. data/lib/myco/code_tools/AST/SplatValue.my +23 -0
  65. data/lib/myco/code_tools/AST/SplatValue.my.rb +25 -0
  66. data/lib/myco/code_tools/AST/StringLiteral.my +17 -0
  67. data/lib/myco/code_tools/AST/StringLiteral.my.rb +16 -0
  68. data/lib/myco/code_tools/AST/SymbolLiteral.my +16 -0
  69. data/lib/myco/code_tools/AST/SymbolLiteral.my.rb +15 -0
  70. data/lib/myco/{parser/ast → code_tools/AST}/ToRuby.my +89 -90
  71. data/lib/myco/{parser/ast → code_tools/AST}/ToRuby.my.rb +89 -101
  72. data/lib/myco/code_tools/AST/misc.my +57 -0
  73. data/lib/myco/code_tools/AST/misc.my.rb +81 -0
  74. data/lib/myco/code_tools/AST.my +52 -0
  75. data/lib/myco/code_tools/AST.my.rb +40 -0
  76. data/lib/myco/{parser → code_tools/parser}/peg_parser.rb +107 -199
  77. data/lib/myco/{parser.rb → code_tools/parser.rb} +0 -17
  78. data/lib/myco/code_tools.rb +5 -0
  79. data/lib/myco/core/BasicDecorators.my +47 -0
  80. data/lib/myco/core/BasicDecorators.my.rb +66 -0
  81. data/lib/myco/core/FileToplevel.my +14 -3
  82. data/lib/myco/core/FileToplevel.my.rb +27 -12
  83. data/lib/myco/eval.rb +7 -37
  84. data/lib/myco/version.rb +1 -4
  85. data/lib/myco.rb +20 -22
  86. metadata +74 -66
  87. data/lib/myco/parser/ast/argument_assembly.rb +0 -76
  88. data/lib/myco/parser/ast/array_assembly.rb +0 -57
  89. data/lib/myco/parser/ast/branch_operator.rb +0 -73
  90. data/lib/myco/parser/ast/constant_access.rb +0 -15
  91. data/lib/myco/parser/ast/constant_define.rb +0 -40
  92. data/lib/myco/parser/ast/constant_reopen.rb +0 -46
  93. data/lib/myco/parser/ast/declare_category.rb +0 -53
  94. data/lib/myco/parser/ast/declare_decorator.rb +0 -35
  95. data/lib/myco/parser/ast/declare_file.rb +0 -54
  96. data/lib/myco/parser/ast/declare_meme.rb +0 -86
  97. data/lib/myco/parser/ast/declare_object.rb +0 -77
  98. data/lib/myco/parser/ast/declare_string.rb +0 -37
  99. data/lib/myco/parser/ast/invoke.rb +0 -48
  100. data/lib/myco/parser/ast/invoke_method.rb +0 -28
  101. data/lib/myco/parser/ast/local_variable_access_ambiguous.rb +0 -34
  102. data/lib/myco/parser/ast/misc.rb +0 -156
  103. data/lib/myco/parser/ast/quest.rb +0 -82
  104. data/lib/myco/parser/ast.rb +0 -21
@@ -0,0 +1,58 @@
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(:Invoke, ::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(:receiver, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:arguments, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
8
+ declare_meme(:block_params, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
9
+ declare_meme(:block, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
11
+ :invoke,
12
+ :receiver,
13
+ :name,
14
+ :arguments,
15
+ :block_params,
16
+ :block
17
+ ]))
18
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
19
+ self.pos(g)
20
+ self.implementation.bytecode(g)
21
+ )}
22
+ declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (
23
+ ::Myco.branch_op(:"&&", self.block) {(
24
+ self.__send__(
25
+ :arguments=,
26
+ ::Myco.branch_op(:"||", self.arguments) {::Myco.find_constant(:ArgumentAssembly).new({
27
+ :line => self.line,
28
+ :body => []
29
+ })}
30
+ )
31
+ self.__send__(
32
+ :block_params=,
33
+ ::Myco.branch_op(:"||", self.block_params) {::Myco.find_constant(:ParameterAssembly).new({:line => self.line})}
34
+ )
35
+ self.arguments.__send__(
36
+ :block=,
37
+ ::Myco.find_constant(:BlockLiteral).new({
38
+ :line => self.line,
39
+ :parameters => self.block_params,
40
+ :body => self.block
41
+ })
42
+ )
43
+ )}
44
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", ::Myco.branch_op(:"&&", self.receiver.__send__(:nil?)) {self.arguments.__send__(:nil?)}) {::Myco.find_constant(:LocalVariableAccessAmbiguous).new({
45
+ :line => self.line,
46
+ :name => self.name
47
+ })}) {::Myco.find_constant(:InvokeMethod).new({
48
+ :line => self.line,
49
+ :receiver => ::Myco.branch_op(:"||", self.receiver) {::Myco.find_constant(:Self).new({:line => self.line})},
50
+ :name => self.name,
51
+ :arguments => ::Myco.branch_op(:"||", self.arguments) {::Myco.find_constant(:ArgumentAssembly).new({
52
+ :line => self.line,
53
+ :body => []
54
+ })}
55
+ })}
56
+ )}
57
+ )}})
58
+ .tap { |__c__| __c__.__name__ = :Invoke })})}}.instance
@@ -0,0 +1,19 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ InvokeMethod < Node {
5
+ var receiver, var name, var arguments
6
+
7
+ Form: [:call, :receiver, :name, :arguments]
8
+
9
+ bytecode: |g| {
10
+ self.receiver.bytecode(g)
11
+ self.arguments.bytecode(g)
12
+
13
+ pos(g)
14
+
15
+ g.__send__(self.arguments.send_op, self.name, self.arguments.send_count)
16
+ }
17
+ }
18
+
19
+ }
@@ -0,0 +1,25 @@
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(:InvokeMethod, ::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(:receiver, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:arguments, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
8
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
9
+ :call,
10
+ :receiver,
11
+ :name,
12
+ :arguments
13
+ ]))
14
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
15
+ self.receiver.bytecode(g)
16
+ self.arguments.bytecode(g)
17
+ self.pos(g)
18
+ g.__send__(
19
+ self.arguments.send_op,
20
+ self.name,
21
+ self.arguments.send_count
22
+ )
23
+ )}
24
+ )}})
25
+ .tap { |__c__| __c__.__name__ = :InvokeMethod })})}}.instance
@@ -0,0 +1,30 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ KeywordAssembly < Node {
5
+ var body
6
+
7
+ Form: [:hash, :body]
8
+
9
+ bytecode: |g| {
10
+ pos(g)
11
+
12
+ g.push_cpath_top
13
+ g.find_const(:"Hash")
14
+ g.push(self.body.size / 2)
15
+ g.send(:new_from_literal, 1)
16
+
17
+ self.body.each_slice(2) |pair| {
18
+ key = pair.first
19
+ value = pair.last
20
+
21
+ g.dup
22
+ key.bytecode(g)
23
+ value.bytecode(g)
24
+ g.send(:"[]=", 2)
25
+ g.pop
26
+ }
27
+ }
28
+ }
29
+
30
+ }
@@ -0,0 +1,36 @@
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(:KeywordAssembly, ::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
+ :hash,
8
+ :body
9
+ ]))
10
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
11
+ self.pos(g)
12
+ g.push_cpath_top
13
+ g.find_const(:Hash)
14
+ g.push(self.body.size.__send__(
15
+ :/,
16
+ 2
17
+ ))
18
+ g.send(
19
+ :new_from_literal,
20
+ 1
21
+ )
22
+ self.body.each_slice(2) { |pair| (
23
+ key = pair.first
24
+ value = pair.last
25
+ g.dup
26
+ key.bytecode(g)
27
+ value.bytecode(g)
28
+ g.send(
29
+ :[]=,
30
+ 2
31
+ )
32
+ g.pop
33
+ )}
34
+ )}
35
+ )}})
36
+ .tap { |__c__| __c__.__name__ = :KeywordAssembly })})}}.instance
@@ -0,0 +1,22 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ LocalVariableAccessAmbiguous < Node {
5
+ var name
6
+
7
+ Form: [:lambig, :name]
8
+
9
+ bytecode: |g| {
10
+ pos(g)
11
+
12
+ local = g.state.scope.search_local(self.name)
13
+ local &? (
14
+ local.get_bytecode(g)
15
+ ) ?? (
16
+ g.push_self
17
+ g.send(self.name, 0)
18
+ )
19
+ }
20
+ }
21
+
22
+ }
@@ -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(:LocalVariableAccessAmbiguous, ::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
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
7
+ :lambig,
8
+ :name
9
+ ]))
10
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
11
+ self.pos(g)
12
+ local = g.state.scope.search_local(self.name)
13
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", local) {local.get_bytecode(g)}) {(
14
+ g.push_self
15
+ g.send(
16
+ self.name,
17
+ 0
18
+ )
19
+ )}
20
+ )}
21
+ )}})
22
+ .tap { |__c__| __c__.__name__ = :LocalVariableAccessAmbiguous })})}}.instance
@@ -0,0 +1,20 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ LocalVariableAssignment < Node {
5
+ var name, var value
6
+ var variable # TODO: remove
7
+
8
+ Form: [:lasgn, :name, :value]
9
+
10
+ bytecode: |g| {
11
+ var = g.state.scope.assign_local_reference(self)
12
+
13
+ self.value && self.value.bytecode(g)
14
+
15
+ pos(g)
16
+ var.set_bytecode(g)
17
+ }
18
+ }
19
+
20
+ }
@@ -0,0 +1,20 @@
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(:LocalVariableAssignment, ::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(:value, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:variable, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
8
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
9
+ :lasgn,
10
+ :name,
11
+ :value
12
+ ]))
13
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
14
+ var = g.state.scope.assign_local_reference(self)
15
+ ::Myco.branch_op(:"&&", self.value) {self.value.bytecode(g)}
16
+ self.pos(g)
17
+ var.set_bytecode(g)
18
+ )}
19
+ )}})
20
+ .tap { |__c__| __c__.__name__ = :LocalVariableAssignment })})}}.instance
@@ -1,40 +1,38 @@
1
1
 
2
- module CodeTools::AST
2
+ CodeTools::AST << {
3
3
 
4
- class MycoModuleScope < ModuleScope
5
- def initialize(line, body)
6
- @line = line
7
- @name = :MycoModuleScope # TODO: remove/fix
8
- @body = body
9
- end
4
+ # TODO: rename to something else
5
+ MycoModuleScope < CodeTools::Compiler::LocalVariables, Node {
6
+ var name, var body
10
7
 
11
- def bytecode(g)
8
+ bytecode: |g| {
12
9
  pos(g)
13
10
 
14
11
  # Register in the AST as a scope for local variable lookup
15
12
  # Right now, this just sets @parent to g.state.scope
16
13
  # (Necessary to pass local variables from above to memes below)
17
- g.state.scope.nest_scope self
14
+ g.state.scope.nest_scope(self)
18
15
 
19
- attach_and_call g, :__myco_module_init__, true
20
- end
16
+ attach_and_call(g, :__myco_module_init__, true)
17
+ }
21
18
 
22
19
  # TODO: figure out how to keep in sync with ClosedScope#attach_and_call impl
23
- def attach_and_call(g, arg_name, scoped=false, pass_block=false)
24
- name = @name || arg_name
20
+ attach_and_call: |g, arg_name, scoped=false, pass_block=false| {
21
+ self.name = :"MycoModuleScope" # TODO: remove/fix
22
+ name = self.name || arg_name
25
23
  meth = new_generator(g, name)
26
24
 
27
- meth.push_state self
25
+ meth.push_state(self)
28
26
  meth.for_module_body = true
29
27
 
30
- if scoped
28
+ scoped && (
31
29
  meth.push_self
32
30
  meth.add_scope
33
- end
31
+ )
34
32
 
35
- meth.state.push_name name
33
+ meth.state.push_name(name.to_sym)
36
34
 
37
- body_bytecode meth # (@body.bytecode meth) in original implementation
35
+ body_bytecode(meth) # (@body.bytecode meth) in original implementation
38
36
 
39
37
  meth.state.pop_name
40
38
 
@@ -46,39 +44,34 @@ module CodeTools::AST
46
44
 
47
45
  meth.pop_state
48
46
 
49
- g.create_block meth
47
+ g.create_block(meth)
50
48
  g.swap
51
49
  g.push_scope
52
50
  g.push_true
53
- g.send :call_under, 3
51
+ g.send(:call_under, 3)
54
52
 
55
- return meth
56
- end
53
+ meth
54
+ }
57
55
 
58
- def body_bytecode g
59
- @body.bytecode g
60
- end
61
-
62
- include CodeTools::Compiler::LocalVariables
56
+ body_bytecode: |g| self.body.bytecode(g)
63
57
 
64
58
  # Become the AST scope parent of the given AST scope Node .
65
59
  # This is only for the benefit of LocalVariableAccessAmbiguous
66
60
  # being able to call search_local, and has nothing to do with
67
61
  # the scope referenced by g.push_scope or g.add_scope
68
- def nest_scope scope
69
- scope.parent = self
70
- end
62
+ nest_scope: |scope| scope.parent = self
71
63
 
72
- attr_accessor :parent
64
+ var parent
73
65
 
74
- # This is an abbreviated form of Iter#search_local
66
+ # This is an abbreviated form of BlockLiteral#search_local
75
67
  # because no locals can be assigned within the MycoModuleScope
76
- def search_local name
77
- if reference = @parent.search_local(name)
78
- reference.depth += 1
68
+ search_local: |name| {
69
+ reference = self.parent.search_local(name)
70
+ reference && (
71
+ reference.depth = reference.depth + 1
79
72
  reference
80
- end
81
- end
82
- end
73
+ )
74
+ }
75
+ }
83
76
 
84
- end
77
+ }
@@ -0,0 +1,82 @@
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(:MycoModuleScope, ::Myco::Component.new([
4
+ ::Myco.find_constant(:CodeTools)::Compiler::LocalVariables,
5
+ ::Myco.find_constant(:Node)
6
+ ], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
7
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
8
+ declare_meme(:name, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
9
+ declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
11
+ self.pos(g)
12
+ g.state.scope.nest_scope(self)
13
+ self.attach_and_call(
14
+ g,
15
+ :__myco_module_init__,
16
+ true
17
+ )
18
+ )}
19
+ declare_meme(:attach_and_call, [], nil, ::Myco.cscope.dup) { |g, arg_name, scoped=false, pass_block=false| (
20
+ self.__send__(
21
+ :name=,
22
+ :MycoModuleScope
23
+ )
24
+ name = ::Myco.branch_op(:"||", self.name) {arg_name}
25
+ meth = self.new_generator(
26
+ g,
27
+ name
28
+ )
29
+ meth.push_state(self)
30
+ meth.__send__(
31
+ :for_module_body=,
32
+ true
33
+ )
34
+ ::Myco.branch_op(:"&&", scoped) {(
35
+ meth.push_self
36
+ meth.add_scope
37
+ )}
38
+ meth.state.push_name(name.to_sym)
39
+ self.body_bytecode(meth)
40
+ meth.state.pop_name
41
+ meth.ret
42
+ meth.close
43
+ meth.__send__(
44
+ :local_count=,
45
+ self.local_count
46
+ )
47
+ meth.__send__(
48
+ :local_names=,
49
+ self.local_names
50
+ )
51
+ meth.pop_state
52
+ g.create_block(meth)
53
+ g.swap
54
+ g.push_scope
55
+ g.push_true
56
+ g.send(
57
+ :call_under,
58
+ 3
59
+ )
60
+ meth
61
+ )}
62
+ declare_meme(:body_bytecode, [], nil, ::Myco.cscope.dup) { |g| (self.body.bytecode(g))}
63
+ declare_meme(:nest_scope, [], nil, ::Myco.cscope.dup) { |scope| (scope.__send__(
64
+ :parent=,
65
+ self
66
+ ))}
67
+ declare_meme(:parent, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
68
+ declare_meme(:search_local, [], nil, ::Myco.cscope.dup) { |name| (
69
+ reference = self.parent.search_local(name)
70
+ ::Myco.branch_op(:"&&", reference) {(
71
+ reference.__send__(
72
+ :depth=,
73
+ reference.depth.__send__(
74
+ :+,
75
+ 1
76
+ )
77
+ )
78
+ reference
79
+ )}
80
+ )}
81
+ )}})
82
+ .tap { |__c__| __c__.__name__ = :MycoModuleScope })})}}.instance
@@ -0,0 +1,67 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ Node < BasicObject {
5
+ var line
6
+
7
+ pos: |g| g.set_line(self.line)
8
+
9
+ new_block_generator: |g, parameters| {
10
+ blk = g.class.new
11
+ blk.name = g.state.name || :"__block__"
12
+ blk.file = g.file
13
+ blk.for_block = true
14
+
15
+ parameters.generator_setup(blk)
16
+
17
+ blk
18
+ }
19
+
20
+ new_generator: |g, name, parameters=null| {
21
+ meth = g.class.new
22
+ meth.name = name
23
+ meth.file = g.file
24
+
25
+ parameters && parameters.generator_setup(meth)
26
+
27
+ meth
28
+ }
29
+ }
30
+
31
+ # TODO: move this out of Node.my ?
32
+ State < BasicObject {
33
+ var scope
34
+
35
+ # TODO: decouple rubinius-compiler from rubinius-ast and remove this hack
36
+ sclass new: |scope| {
37
+ obj = allocate
38
+ obj.scope = scope
39
+ obj
40
+ }
41
+
42
+ var names: [] # stack of names
43
+ push_name: |x| self.names.push(x)
44
+ pop_name: self.names.pop
45
+ name: self.names.last
46
+
47
+ # TODO: investigate the possibility of removing
48
+ var supers: [] # stack of supers
49
+ push_super: |x| self.supers.push(x)
50
+ pop_super: self.supers.pop
51
+ super: self.supers.last
52
+
53
+ # TODO: investigate the possibility of removing
54
+ var evals: [] # stack of evals
55
+ push_eval: |x| self.evals.push(x)
56
+ pop_eval: self.evals.pop
57
+ eval: self.evals.last
58
+
59
+ # TODO: investigate the possibility of removing
60
+ var block: 0 # count block levels
61
+ push_block: self.block = self.block + 1
62
+ pop_block: (self.block > 0) && (self.block = self.block - 1)
63
+
64
+ # TODO: investigate the possibility of removing
65
+ var check_for_locals: true
66
+ }
67
+ }
@@ -0,0 +1,84 @@
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(:Node, ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
5
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
6
+ declare_meme(:line, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:pos, [], nil, ::Myco.cscope.dup) { |g| (g.set_line(self.line))}
8
+ declare_meme(:new_block_generator, [], nil, ::Myco.cscope.dup) { |g, parameters| (
9
+ blk = g.__send__(:class).new
10
+ blk.__send__(
11
+ :name=,
12
+ ::Myco.branch_op(:"||", g.state.name) {:__block__}
13
+ )
14
+ blk.__send__(
15
+ :file=,
16
+ g.file
17
+ )
18
+ blk.__send__(
19
+ :for_block=,
20
+ true
21
+ )
22
+ parameters.generator_setup(blk)
23
+ blk
24
+ )}
25
+ declare_meme(:new_generator, [], nil, ::Myco.cscope.dup) { |g, name, parameters=nil| (
26
+ meth = g.__send__(:class).new
27
+ meth.__send__(
28
+ :name=,
29
+ name
30
+ )
31
+ meth.__send__(
32
+ :file=,
33
+ g.file
34
+ )
35
+ ::Myco.branch_op(:"&&", parameters) {parameters.generator_setup(meth)}
36
+ meth
37
+ )}
38
+ )}})
39
+ .tap { |__c__| __c__.__name__ = :Node }
40
+ ::Myco.cscope.for_method_definition.const_set(:State, ::Myco::Component.new([::Myco.find_constant(:BasicObject)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
41
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
42
+ declare_meme(:scope, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
43
+ declare_meme(:new, [[:sclass, []]], nil, ::Myco.cscope.dup) { |scope| (
44
+ obj = self.allocate
45
+ obj.__send__(
46
+ :scope=,
47
+ scope
48
+ )
49
+ obj
50
+ )}
51
+ declare_meme(:names, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
52
+ declare_meme(:push_name, [], nil, ::Myco.cscope.dup) { |x| (self.names.push(x))}
53
+ declare_meme(:pop_name, [], nil, ::Myco.cscope.dup) { |*| (self.names.pop)}
54
+ declare_meme(:name, [], nil, ::Myco.cscope.dup) { |*| (self.names.last)}
55
+ declare_meme(:supers, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
56
+ declare_meme(:push_super, [], nil, ::Myco.cscope.dup) { |x| (self.supers.push(x))}
57
+ declare_meme(:pop_super, [], nil, ::Myco.cscope.dup) { |*| (self.supers.pop)}
58
+ declare_meme(:super, [], nil, ::Myco.cscope.dup) { |*| (self.supers.last)}
59
+ declare_meme(:evals, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
60
+ declare_meme(:push_eval, [], nil, ::Myco.cscope.dup) { |x| (self.evals.push(x))}
61
+ declare_meme(:pop_eval, [], nil, ::Myco.cscope.dup) { |*| (self.evals.pop)}
62
+ declare_meme(:eval, [], nil, ::Myco.cscope.dup) { |*| (self.evals.last)}
63
+ declare_meme(:block, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (0)}
64
+ declare_meme(:push_block, [], nil, ::Myco.cscope.dup) { |*| (self.__send__(
65
+ :block=,
66
+ self.block.__send__(
67
+ :+,
68
+ 1
69
+ )
70
+ ))}
71
+ declare_meme(:pop_block, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"&&", self.block.__send__(
72
+ :>,
73
+ 0
74
+ )) {self.__send__(
75
+ :block=,
76
+ self.block.__send__(
77
+ :-,
78
+ 1
79
+ )
80
+ )})}
81
+ declare_meme(:check_for_locals, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (true)}
82
+ )}})
83
+ .tap { |__c__| __c__.__name__ = :State }
84
+ )})}}.instance