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,126 @@
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(:BlockLiteral, ::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(:parameters, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
9
+ declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
+ declare_meme(:parent, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
11
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
12
+ :blklit,
13
+ :parameters,
14
+ :body
15
+ ]))
16
+ ::Myco.cscope.for_method_definition.const_set(:CompilerClass, (::Myco.find_constant(:CodeTools)::Compiler))
17
+ declare_meme(:parameters, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (::Myco.branch_op(:"||", given) {::Myco.find_constant(:ParameterAssembly).new({:line => self.line})})}
18
+ declare_meme(:body, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (::Myco.branch_op(:"||", given) {::Myco.find_constant(:NullLiteral).new({:line => self.line})})}
19
+ declare_meme(:locals, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"??", ((self.body.respond_to?(:locals).false? ? ::Myco::Void : self.body.locals).respond_to?(:body).false? ? ::Myco::Void : (self.body.respond_to?(:locals).false? ? ::Myco::Void : self.body.locals).body).map(&:value)) {nil})}
20
+ declare_meme(:block_local?, [], nil, ::Myco.cscope.dup) { |name| (::Myco.branch_op(:"??", (self.locals.respond_to?(:include?).false? ? ::Myco::Void : self.locals.__send__(
21
+ :include?,
22
+ name
23
+ ))) {false})}
24
+ declare_meme(:module?, [], nil, ::Myco.cscope.dup) { |*| (false)}
25
+ declare_meme(:nest_scope, [], nil, ::Myco.cscope.dup) { |scope| (scope.__send__(
26
+ :parent=,
27
+ self
28
+ ))}
29
+ declare_meme(:search_local, [], nil, ::Myco.cscope.dup) { |name| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", variable = self.variables.__send__(
30
+ :[],
31
+ name
32
+ )) {variable.nested_reference}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.__send__(
33
+ :block_local?,
34
+ name
35
+ )) {self.new_local(name)}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", reference = self.parent.search_local(name)) {(
36
+ reference.__send__(
37
+ :depth=,
38
+ reference.depth.__send__(
39
+ :+,
40
+ 1
41
+ )
42
+ )
43
+ reference
44
+ )}) {nil}}})}
45
+ declare_meme(:assign_local_reference, [], nil, ::Myco.cscope.dup) { |var| (var.__send__(
46
+ :variable=,
47
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", variable = self.variables.__send__(
48
+ :[],
49
+ var.name
50
+ )) {variable.reference}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.__send__(
51
+ :block_local?,
52
+ var.name
53
+ )) {(
54
+ variable = self.new_local(var.name)
55
+ variable.reference
56
+ )}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", reference = self.parent.search_local(var.name)) {(
57
+ reference.__send__(
58
+ :depth=,
59
+ reference.depth.__send__(
60
+ :+,
61
+ 1
62
+ )
63
+ )
64
+ reference
65
+ )}) {(
66
+ variable = self.new_local(var.name)
67
+ variable.reference
68
+ )}}}
69
+ ))}
70
+ declare_meme(:new_local, [], nil, ::Myco.cscope.dup) { |name| (self.variables.__send__(
71
+ :[]=,
72
+ name,
73
+ ::Myco.branch_op(:"||", self.variables.__send__(
74
+ :[],
75
+ name
76
+ )) {::Myco.find_constant(:CompilerClass)::LocalVariable.new(self.allocate_slot)}
77
+ ))}
78
+ declare_meme(:new_nested_local, [], nil, ::Myco.cscope.dup) { |name| (self.new_local(name).nested_reference)}
79
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
80
+ self.pos(g)
81
+ state = g.state
82
+ state.scope.nest_scope(self)
83
+ blk = self.new_block_generator(
84
+ g,
85
+ self.parameters
86
+ )
87
+ blk.push_state(self)
88
+ blk.definition_line(self.line)
89
+ blk.state.push_super(state.super)
90
+ blk.state.push_eval(state.eval)
91
+ blk.state.push_name(blk.name)
92
+ self.pos(blk)
93
+ self.parameters.bytecode(blk)
94
+ blk.state.push_block
95
+ blk.push_modifiers
96
+ blk.__send__(
97
+ :break=,
98
+ nil
99
+ )
100
+ blk.__send__(
101
+ :next=,
102
+ nil
103
+ )
104
+ blk.__send__(
105
+ :redo=,
106
+ blk.new_label
107
+ )
108
+ blk.redo.__send__(:set!)
109
+ self.body.bytecode(blk)
110
+ blk.pop_modifiers
111
+ blk.state.pop_block
112
+ blk.ret
113
+ blk.close
114
+ blk.pop_state
115
+ blk.__send__(
116
+ :local_count=,
117
+ self.local_count
118
+ )
119
+ blk.__send__(
120
+ :local_names=,
121
+ self.local_names
122
+ )
123
+ g.create_block(blk)
124
+ )}
125
+ )}})
126
+ .tap { |__c__| __c__.__name__ = :BlockLiteral })})}}.instance
@@ -0,0 +1,25 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ BlockParameter < Node {
5
+ var name
6
+ var variable # TODO: remove
7
+
8
+ Form: [:blkprm, :name]
9
+
10
+ bytecode: |g| {
11
+ pos(g)
12
+
13
+ g.push_proc
14
+
15
+ (self.variable.?depth > 0) &? (
16
+ g.set_local_depth(self.variable.depth, self.variable.slot)
17
+ ) ?? (
18
+ g.set_local(self.variable.slot)
19
+ )
20
+
21
+ g.pop
22
+ }
23
+ }
24
+
25
+ }
@@ -0,0 +1,24 @@
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(:BlockParameter, ::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(:variable, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
8
+ :blkprm,
9
+ :name
10
+ ]))
11
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
12
+ self.pos(g)
13
+ g.push_proc
14
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", (self.variable.respond_to?(:depth).false? ? ::Myco::Void : self.variable.depth).__send__(
15
+ :>,
16
+ 0
17
+ )) {g.set_local_depth(
18
+ self.variable.depth,
19
+ self.variable.slot
20
+ )}) {g.set_local(self.variable.slot)}
21
+ g.pop
22
+ )}
23
+ )}})
24
+ .tap { |__c__| __c__.__name__ = :BlockParameter })})}}.instance
@@ -0,0 +1,18 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ Body < Node {
5
+ var array
6
+
7
+ Form: [:block, :array]
8
+
9
+ bytecode: |g| {
10
+ ary = self.array.dup
11
+ last = ary.pop
12
+
13
+ ary.each |item| { item.bytecode(g); g.pop }
14
+ last.bytecode(g)
15
+ }
16
+ }
17
+
18
+ }
@@ -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(:Body, ::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(:array, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
7
+ :block,
8
+ :array
9
+ ]))
10
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
11
+ ary = self.array.dup
12
+ last = ary.pop
13
+ ary.each { |item| (
14
+ item.bytecode(g)
15
+ g.pop
16
+ )}
17
+ last.bytecode(g)
18
+ )}
19
+ )}})
20
+ .tap { |__c__| __c__.__name__ = :Body })})}}.instance
@@ -0,0 +1,59 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ BranchOperator < Node {
5
+ var type, var left, var right
6
+
7
+ Form: [:branch_op, :type, :left, :right]
8
+
9
+ bytecode: |g| {
10
+ pos(g)
11
+
12
+ done_label = g.new_label
13
+ right_label = g.new_label
14
+ otherwise_push_void = false
15
+
16
+ self.left.bytecode(g)
17
+
18
+ type == :"&&" && (
19
+ g.dup_top
20
+ g.send(:"false?", 0)
21
+ g.goto_if_true(done_label)
22
+ g.pop
23
+ )
24
+ type == :"||" && (
25
+ g.dup_top
26
+ g.send(:"false?", 0)
27
+ g.goto_if_false(done_label)
28
+ g.pop
29
+ )
30
+ type == :"??" && (
31
+ g.dup_top
32
+ g.send(:"void?", 0)
33
+ g.goto_if_false(done_label)
34
+ g.pop
35
+ )
36
+ type == :"&?" && (
37
+ g.send(:"false?", 0)
38
+ g.goto_if_false(right_label)
39
+ otherwise_push_void = true
40
+ )
41
+ type == :"|?" && (
42
+ g.send(:"false?", 0)
43
+ g.goto_if_true(right_label)
44
+ otherwise_push_void = true
45
+ )
46
+
47
+ otherwise_push_void && (
48
+ g.push_void
49
+ g.goto(done_label)
50
+
51
+ right_label.set!
52
+ )
53
+
54
+ self.right.bytecode(g)
55
+ done_label.set!
56
+ }
57
+ }
58
+
59
+ }
@@ -0,0 +1,87 @@
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(:BranchOperator, ::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(:type, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:left, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:right, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
8
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
9
+ :branch_op,
10
+ :type,
11
+ :left,
12
+ :right
13
+ ]))
14
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
15
+ self.pos(g)
16
+ done_label = g.new_label
17
+ right_label = g.new_label
18
+ otherwise_push_void = false
19
+ self.left.bytecode(g)
20
+ ::Myco.branch_op(:"&&", self.type.__send__(
21
+ :==,
22
+ :"&&"
23
+ )) {(
24
+ g.dup_top
25
+ g.send(
26
+ :false?,
27
+ 0
28
+ )
29
+ g.goto_if_true(done_label)
30
+ g.pop
31
+ )}
32
+ ::Myco.branch_op(:"&&", self.type.__send__(
33
+ :==,
34
+ :"||"
35
+ )) {(
36
+ g.dup_top
37
+ g.send(
38
+ :false?,
39
+ 0
40
+ )
41
+ g.goto_if_false(done_label)
42
+ g.pop
43
+ )}
44
+ ::Myco.branch_op(:"&&", self.type.__send__(
45
+ :==,
46
+ :"??"
47
+ )) {(
48
+ g.dup_top
49
+ g.send(
50
+ :void?,
51
+ 0
52
+ )
53
+ g.goto_if_false(done_label)
54
+ g.pop
55
+ )}
56
+ ::Myco.branch_op(:"&&", self.type.__send__(
57
+ :==,
58
+ :"&?"
59
+ )) {(
60
+ g.send(
61
+ :false?,
62
+ 0
63
+ )
64
+ g.goto_if_false(right_label)
65
+ otherwise_push_void = true
66
+ )}
67
+ ::Myco.branch_op(:"&&", self.type.__send__(
68
+ :==,
69
+ :"|?"
70
+ )) {(
71
+ g.send(
72
+ :false?,
73
+ 0
74
+ )
75
+ g.goto_if_true(right_label)
76
+ otherwise_push_void = true
77
+ )}
78
+ ::Myco.branch_op(:"&&", otherwise_push_void) {(
79
+ g.push_void
80
+ g.goto(done_label)
81
+ right_label.__send__(:set!)
82
+ )}
83
+ self.right.bytecode(g)
84
+ done_label.__send__(:set!)
85
+ )}
86
+ )}})
87
+ .tap { |__c__| __c__.__name__ = :BranchOperator })})}}.instance
@@ -0,0 +1,30 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ ConstantAccess < Node {
5
+ var toplevel, var names
6
+
7
+ Form: [:const, :toplevel, :names]
8
+
9
+ bytecode: |g| {
10
+ pos(g)
11
+
12
+ name_list = self.names.map(&:to_sym)
13
+ first_name = name_list.shift
14
+
15
+ self.toplevel &? (
16
+ g.push_cpath_top
17
+ g.find_const(first_name)
18
+ ) ?? (
19
+ g.push_cpath_top
20
+ g.find_const(:"Myco")
21
+ g.push_literal(first_name)
22
+ g.push_scope
23
+ g.send(:find_constant, 2)
24
+ )
25
+
26
+ name_list.each |name| { g.find_const(name) }
27
+ }
28
+ }
29
+
30
+ }
@@ -0,0 +1,32 @@
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(:ConstantAccess, ::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(:toplevel, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:names, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
8
+ :const,
9
+ :toplevel,
10
+ :names
11
+ ]))
12
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
13
+ self.pos(g)
14
+ name_list = self.names.map(&:to_sym)
15
+ first_name = name_list.shift
16
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.toplevel) {(
17
+ g.push_cpath_top
18
+ g.find_const(first_name)
19
+ )}) {(
20
+ g.push_cpath_top
21
+ g.find_const(:Myco)
22
+ g.push_literal(first_name)
23
+ g.push_scope
24
+ g.send(
25
+ :find_constant,
26
+ 2
27
+ )
28
+ )}
29
+ name_list.each { |name| (g.find_const(name))}
30
+ )}
31
+ )}})
32
+ .tap { |__c__| __c__.__name__ = :ConstantAccess })})}}.instance
@@ -0,0 +1,40 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ ConstantAssignment < Node {
5
+ var constant, var value
6
+
7
+ Form: [:cdecl, :constant, :value]
8
+
9
+ bytecode: |g| {
10
+ pos(g)
11
+
12
+ name_list = self.constant.names.map(&:to_sym)
13
+ last_name = name_list.pop
14
+ first_name = name_list.any? && name_list.shift
15
+
16
+ self.constant.toplevel &? (
17
+ g.push_cpath_top
18
+ first_name && g.find_const(first_name)
19
+ ) ?? (
20
+ first_name &? (
21
+ g.push_cpath_top
22
+ g.find_const(:"Myco")
23
+ g.push_literal(first_name)
24
+ g.push_scope
25
+ g.send(:find_constant, 2)
26
+ ) ?? (
27
+ g.push_scope
28
+ g.send(:for_method_definition, 0)
29
+ )
30
+ )
31
+
32
+ name_list.each |name| { g.find_const(name) }
33
+
34
+ g.push_literal(last_name)
35
+ self.value.bytecode(g)
36
+ g.send(:const_set, 2)
37
+ }
38
+ }
39
+
40
+ }
@@ -0,0 +1,45 @@
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(:ConstantAssignment, ::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(:constant, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:value, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
8
+ :cdecl,
9
+ :constant,
10
+ :value
11
+ ]))
12
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
13
+ self.pos(g)
14
+ name_list = self.constant.names.map(&:to_sym)
15
+ last_name = name_list.pop
16
+ first_name = ::Myco.branch_op(:"&&", name_list.__send__(:any?)) {name_list.shift}
17
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.constant.toplevel) {(
18
+ g.push_cpath_top
19
+ ::Myco.branch_op(:"&&", first_name) {g.find_const(first_name)}
20
+ )}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {(
21
+ g.push_cpath_top
22
+ g.find_const(:Myco)
23
+ g.push_literal(first_name)
24
+ g.push_scope
25
+ g.send(
26
+ :find_constant,
27
+ 2
28
+ )
29
+ )}) {(
30
+ g.push_scope
31
+ g.send(
32
+ :for_method_definition,
33
+ 0
34
+ )
35
+ )}}
36
+ name_list.each { |name| (g.find_const(name))}
37
+ g.push_literal(last_name)
38
+ self.value.bytecode(g)
39
+ g.send(
40
+ :const_set,
41
+ 2
42
+ )
43
+ )}
44
+ )}})
45
+ .tap { |__c__| __c__.__name__ = :ConstantAssignment })})}}.instance
@@ -0,0 +1,30 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ ConstantDefine < Node {
5
+ var constant, var object
6
+
7
+ Form: [:cdefn, :constant, :object]
8
+
9
+ implementation: ConstantAssignment.new(
10
+ line: self.line
11
+ constant: self.constant
12
+ value: self.object
13
+ )
14
+
15
+ # TODO: don't set AST state from here
16
+ setter object: |given| given.create = false; given
17
+
18
+ bytecode: |g| {
19
+ pos(g)
20
+
21
+ implementation.bytecode(g)
22
+
23
+ g.dup_top
24
+ g.push_literal(self.constant.names.last)
25
+ g.send(:"__name__=", 1)
26
+ g.pop
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(:ConstantDefine, ::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(:constant, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:object, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ ::Myco.cscope.for_method_definition.const_set(:Form, ([
8
+ :cdefn,
9
+ :constant,
10
+ :object
11
+ ]))
12
+ declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:ConstantAssignment).new({
13
+ :line => self.line,
14
+ :constant => self.constant,
15
+ :value => self.object
16
+ }))}
17
+ declare_meme(:object, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (
18
+ given.__send__(
19
+ :create=,
20
+ false
21
+ )
22
+ given
23
+ )}
24
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
25
+ self.pos(g)
26
+ self.implementation.bytecode(g)
27
+ g.dup_top
28
+ g.push_literal(self.constant.names.last)
29
+ g.send(
30
+ :__name__=,
31
+ 1
32
+ )
33
+ g.pop
34
+ )}
35
+ )}})
36
+ .tap { |__c__| __c__.__name__ = :ConstantDefine })})}}.instance
@@ -0,0 +1,29 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ ConstantReopenScope < 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
+ ConstantReopen < Node {
15
+ var constant, var body
16
+
17
+ Form: [:copen, :constant, :body]
18
+
19
+ bytecode: |g| {
20
+ pos(g)
21
+
22
+ scope = ConstantReopenScope.new(line:self.line, body:self.body)
23
+
24
+ self.constant.bytecode(g)
25
+ scope.bytecode(g)
26
+ }
27
+ }
28
+
29
+ }
@@ -0,0 +1,35 @@
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(:ConstantReopenScope, ::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__ = :ConstantReopenScope }
15
+ ::Myco.cscope.for_method_definition.const_set(:ConstantReopen, ::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(:constant, [[: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
+ :copen,
21
+ :constant,
22
+ :body
23
+ ]))
24
+ declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
25
+ self.pos(g)
26
+ scope = ::Myco.find_constant(:ConstantReopenScope).new({
27
+ :line => self.line,
28
+ :body => self.body
29
+ })
30
+ self.constant.bytecode(g)
31
+ scope.bytecode(g)
32
+ )}
33
+ )}})
34
+ .tap { |__c__| __c__.__name__ = :ConstantReopen }
35
+ )})}}.instance
@@ -0,0 +1,35 @@
1
+
2
+ CodeTools::AST << {
3
+
4
+ DeclareCategoryScope < MycoModuleScope {
5
+ body_bytecode: |g| {
6
+ g.push_scope
7
+ g.send(:set_myco_category, 0)
8
+ g.pop
9
+
10
+ self.body.bytecode(g)
11
+ }
12
+ }
13
+
14
+ DeclareCategory < Node {
15
+ var name, var body
16
+
17
+ Form: [:category, :name, :body]
18
+
19
+ scope_implementation: DeclareCategoryScope.new(
20
+ line: self.line
21
+ body: self.body
22
+ )
23
+
24
+ bytecode: |g| {
25
+ pos(g)
26
+
27
+ g.push_self
28
+ g.push_literal(self.name)
29
+ g.send(:__category__, 1)
30
+
31
+ scope_implementation.bytecode(g)
32
+ }
33
+ }
34
+
35
+ }