myco 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/lib/myco/bootstrap/component.rb +2 -0
  3. data/lib/myco/bootstrap/evaluator.rb +58 -0
  4. data/lib/myco/bootstrap/instance.rb +1 -1
  5. data/lib/myco/bootstrap/meme.rb +4 -9
  6. data/lib/myco/bootstrap.my +1 -1
  7. data/lib/myco/bootstrap.my.rb +1 -1
  8. data/lib/myco/code_loader.rb +6 -1
  9. data/lib/myco/code_tools/AST/ArgumentAssembly.my +8 -12
  10. data/lib/myco/code_tools/AST/ArgumentAssembly.my.rb +12 -9
  11. data/lib/myco/code_tools/AST/ArrayAssembly.my +2 -3
  12. data/lib/myco/code_tools/AST/ArrayAssembly.my.rb +2 -5
  13. data/lib/myco/code_tools/AST/Block.my +4 -4
  14. data/lib/myco/code_tools/AST/Block.my.rb +3 -7
  15. data/lib/myco/code_tools/AST/BlockArgument.my +4 -5
  16. data/lib/myco/code_tools/AST/BlockArgument.my.rb +2 -5
  17. data/lib/myco/code_tools/AST/BlockLiteral.my +3 -4
  18. data/lib/myco/code_tools/AST/BlockLiteral.my.rb +6 -6
  19. data/lib/myco/code_tools/AST/BlockParameter.my +4 -11
  20. data/lib/myco/code_tools/AST/BlockParameter.my.rb +4 -13
  21. data/lib/myco/code_tools/AST/BranchOperator.my +2 -3
  22. data/lib/myco/code_tools/AST/BranchOperator.my.rb +4 -9
  23. data/lib/myco/code_tools/AST/ConstantAccess.my +11 -8
  24. data/lib/myco/code_tools/AST/ConstantAccess.my.rb +16 -12
  25. data/lib/myco/code_tools/AST/ConstantAssignment.my +13 -5
  26. data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +16 -11
  27. data/lib/myco/code_tools/AST/ConstantDefine.my +2 -3
  28. data/lib/myco/code_tools/AST/ConstantDefine.my.rb +3 -7
  29. data/lib/myco/code_tools/AST/DeclareCategory.my +4 -14
  30. data/lib/myco/code_tools/AST/DeclareCategory.my.rb +20 -36
  31. data/lib/myco/code_tools/AST/DeclareDecorator.my +2 -3
  32. data/lib/myco/code_tools/AST/DeclareDecorator.my.rb +3 -7
  33. data/lib/myco/code_tools/AST/DeclareExtension.my +22 -0
  34. data/lib/myco/code_tools/AST/DeclareExtension.my.rb +19 -0
  35. data/lib/myco/code_tools/AST/DeclareFile.my +4 -15
  36. data/lib/myco/code_tools/AST/DeclareFile.my.rb +34 -50
  37. data/lib/myco/code_tools/AST/DeclareMeme.my +5 -7
  38. data/lib/myco/code_tools/AST/DeclareMeme.my.rb +8 -17
  39. data/lib/myco/code_tools/AST/DeclareObject.my +6 -18
  40. data/lib/myco/code_tools/AST/DeclareObject.my.rb +41 -59
  41. data/lib/myco/code_tools/AST/DeclareString.my +2 -3
  42. data/lib/myco/code_tools/AST/DeclareString.my.rb +3 -7
  43. data/lib/myco/code_tools/AST/{MycoModuleScope.my → DeclaredScope.my} +15 -16
  44. data/lib/myco/code_tools/AST/{MycoModuleScope.my.rb → DeclaredScope.my.rb} +15 -20
  45. data/lib/myco/code_tools/AST/Invoke.my +8 -8
  46. data/lib/myco/code_tools/AST/Invoke.my.rb +13 -21
  47. data/lib/myco/code_tools/AST/InvokeMethod.my +2 -3
  48. data/lib/myco/code_tools/AST/InvokeMethod.my.rb +4 -9
  49. data/lib/myco/code_tools/AST/KeywordAssembly.my +3 -4
  50. data/lib/myco/code_tools/AST/KeywordAssembly.my.rb +2 -5
  51. data/lib/myco/code_tools/AST/KeywordOptionalParameter.my +16 -0
  52. data/lib/myco/code_tools/AST/KeywordOptionalParameter.my.rb +14 -0
  53. data/lib/myco/code_tools/AST/KeywordRequiredParameter.my +16 -0
  54. data/lib/myco/code_tools/AST/KeywordRequiredParameter.my.rb +13 -0
  55. data/lib/myco/code_tools/AST/KeywordRestParameter.my +16 -0
  56. data/lib/myco/code_tools/AST/KeywordRestParameter.my.rb +13 -0
  57. data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my +2 -3
  58. data/lib/myco/code_tools/AST/LocalVariableAccessAmbiguous.my.rb +2 -5
  59. data/lib/myco/code_tools/AST/LocalVariableAssignment.my +3 -3
  60. data/lib/myco/code_tools/AST/LocalVariableAssignment.my.rb +3 -7
  61. data/lib/myco/code_tools/AST/Node.my +32 -2
  62. data/lib/myco/code_tools/AST/Node.my.rb +34 -1
  63. data/lib/myco/code_tools/AST/NumericLiteral.my +15 -0
  64. data/lib/myco/code_tools/AST/NumericLiteral.my.rb +12 -0
  65. data/lib/myco/code_tools/AST/OptionalParameter.my +24 -0
  66. data/lib/myco/code_tools/AST/OptionalParameter.my.rb +19 -0
  67. data/lib/myco/code_tools/AST/ParameterAssembly.my +60 -103
  68. data/lib/myco/code_tools/AST/ParameterAssembly.my.rb +60 -121
  69. data/lib/myco/code_tools/AST/PipeOperator.my +2 -3
  70. data/lib/myco/code_tools/AST/PipeOperator.my.rb +3 -7
  71. data/lib/myco/code_tools/AST/Quest.my +8 -10
  72. data/lib/myco/code_tools/AST/Quest.my.rb +9 -13
  73. data/lib/myco/code_tools/AST/RequiredParameter.my +12 -0
  74. data/lib/myco/code_tools/AST/RequiredParameter.my.rb +10 -0
  75. data/lib/myco/code_tools/AST/RestParameter.my +12 -0
  76. data/lib/myco/code_tools/AST/RestParameter.my.rb +10 -0
  77. data/lib/myco/code_tools/AST/Script.my +4 -4
  78. data/lib/myco/code_tools/AST/Script.my.rb +3 -7
  79. data/lib/myco/code_tools/AST/Sequence.my +2 -3
  80. data/lib/myco/code_tools/AST/Sequence.my.rb +2 -5
  81. data/lib/myco/code_tools/AST/SplatValue.my +3 -4
  82. data/lib/myco/code_tools/AST/SplatValue.my.rb +2 -5
  83. data/lib/myco/code_tools/AST/{DynamicString.my → StringCompose.my} +3 -4
  84. data/lib/myco/code_tools/AST/{DynamicString.my.rb → StringCompose.my.rb} +4 -7
  85. data/lib/myco/code_tools/AST/StringLiteral.my +2 -3
  86. data/lib/myco/code_tools/AST/StringLiteral.my.rb +2 -5
  87. data/lib/myco/code_tools/AST/{DynamicSymbol.my → SymbolCompose.my} +3 -4
  88. data/lib/myco/code_tools/AST/{DynamicSymbol.my.rb → SymbolCompose.my.rb} +4 -7
  89. data/lib/myco/code_tools/AST/SymbolLiteral.my +2 -3
  90. data/lib/myco/code_tools/AST/SymbolLiteral.my.rb +2 -5
  91. data/lib/myco/code_tools/AST/ToRuby.my +40 -57
  92. data/lib/myco/code_tools/AST/ToRuby.my.rb +43 -52
  93. data/lib/myco/code_tools/AST/misc.my +19 -24
  94. data/lib/myco/code_tools/AST/misc.my.rb +18 -23
  95. data/lib/myco/code_tools/AST.my +17 -8
  96. data/lib/myco/code_tools/AST.my.rb +14 -7
  97. data/lib/myco/code_tools/Parser.my +1 -1
  98. data/lib/myco/code_tools/parser/MycoBuilder.my +3 -3
  99. data/lib/myco/code_tools/parser/MycoBuilder.my.rb +3 -3
  100. data/lib/myco/code_tools/parser/MycoGrammar.my +67 -74
  101. data/lib/myco/code_tools/parser/MycoGrammar.my.rb +211 -316
  102. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +3 -3
  103. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +2 -2
  104. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +9 -9
  105. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +9 -9
  106. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +2 -2
  107. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my.rb +4 -1
  108. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +2 -3
  109. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +2 -3
  110. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my +1 -1
  111. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +1 -1
  112. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +5 -5
  113. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +5 -5
  114. data/lib/myco/command.my +1 -1
  115. data/lib/myco/command.my.rb +1 -1
  116. data/lib/myco/core/BasicDecorators.my +10 -8
  117. data/lib/myco/core/BasicDecorators.my.rb +7 -7
  118. data/lib/myco/core/BasicObject.my +38 -7
  119. data/lib/myco/core/BasicObject.my.rb +23 -4
  120. data/lib/myco/tools/BasicCommand.my +1 -1
  121. data/lib/myco/tools/BasicCommand.my.rb +1 -1
  122. data/lib/myco/version.rb +1 -1
  123. data/lib/myco.rb +3 -0
  124. metadata +41 -26
  125. data/lib/myco/code_tools/AST/ConstantReopen.my +0 -29
  126. data/lib/myco/code_tools/AST/ConstantReopen.my.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ac82f91bb59e1b38407f56839dc6f9a8a747813
4
- data.tar.gz: d81314ee8a56b8950c7a42d253c77476ecef51e3
3
+ metadata.gz: 5c9a3ec14044d47105eb0c1448e65c08cebedfd9
4
+ data.tar.gz: b24c8a056f1df9e441dccc851b1eca9bd4293ad1
5
5
  SHA512:
6
- metadata.gz: d594ed1f2693c0445ab02729a0f435ed13ca18251d4e9fd72b2b1070594e0fee3c7d3aa606936f57852fa41c1591f4250163463db690c91463ddc35aab6115d6
7
- data.tar.gz: 2377868fe82a9a3fba6e5fdff7df63859d06c3514152661c32b89225f3d996501d5f363fa648645a727219b60441cfaa5a7536b0ee916adf162d182f33e03f91
6
+ metadata.gz: 59af162beb7b9ce35677eceba813cd1fbf35f73ce4630bac4e0afd87636f09a0e5973c1a3e7f600d99bcf07cffea296c915aa87d73f37360f0ac0f98d1c770b3
7
+ data.tar.gz: 37ad5495fa33dd8fa6afb55eff7fa27a221a138f61dcc30d053984c67ad340d3121af3b9b535f152c78f31bea4f6f7d8f7e445fb0887aeee86d7f64259d6ef9d
@@ -127,6 +127,8 @@ module Myco
127
127
  def include *others
128
128
  others.reverse_each do |other|
129
129
  Rubinius::Type.include_modules_from(other, self.origin)
130
+ # TODO: avoid touching singleton class that doesn't already exist?
131
+ Rubinius::Type.include_modules_from(other.singleton_class, self.singleton_class.origin)
130
132
  Rubinius::Type.infect(self, other)
131
133
  other.__send__ :included, self
132
134
  end
@@ -0,0 +1,58 @@
1
+
2
+ module Myco
3
+ class Evaluator
4
+
5
+ def self.evaluate(cscope, data)
6
+ type, *rest = representation
7
+ __send__(:"evaluate_#{type}", *rest)
8
+ end
9
+
10
+ def self.evaluate_component(cscope, types, create, contents)
11
+ component = ::Myco::Component.new(
12
+ types.map { |data| resolve_constant(cscope, *data) },
13
+ cscope.for_method_definition,
14
+ cscope.active_path.to_s,
15
+ line
16
+ )
17
+
18
+ inner_cscope = ::Rubinius::ConstantScope.new(component, cscope)
19
+ component.__last__ = evaluate_contents(inner_cscope, contents)
20
+
21
+ create ? component.instance : component
22
+ end
23
+
24
+ def self.evaluate_category(cscope, name, contents)
25
+ category = cscope.for_method_definition.__category__(name)
26
+
27
+ inner_cscope = ::Rubinius::ConstantScope.new(category, cscope)
28
+ evaluate_contents(inner_cscope, contents)
29
+ end
30
+
31
+ def self.evaluate_meme(cscope, name, decorations, body)
32
+ cscope.for_method_definition.declare_meme(name, decorations, &body)
33
+ end
34
+
35
+ def self.resolve_constant(cscope, toplevel, names)
36
+ first_name, *names = names
37
+ const = if toplevel
38
+ case first_name
39
+ when :Myco; ::Myco
40
+ when :Ruby; ::Object
41
+ when :Rubinius; Rubinius
42
+ else; ::Myco.const_get(first_name)
43
+ end
44
+ else
45
+ ::Myco.find_constant(first_name, cscope)
46
+ end
47
+
48
+ names.reduce(const) { |const, var| const.const_get(name) }
49
+ end
50
+
51
+ def self.evaluate_contents(cscope, contents)
52
+ last = nil
53
+ contents.each { |item| last = evaluate(inner_cscope, item) }
54
+ last
55
+ end
56
+
57
+ end
58
+ end
@@ -42,7 +42,7 @@ module Myco
42
42
  # prepend (::Module.new {
43
43
  def method_missing name, *args
44
44
  msg = "#{to_s} has no method called '#{name}'"
45
- ::Kernel.raise ::NoMethodError.new(msg, name, args)
45
+ ::Ruby::Kernel.raise ::NoMethodError.new(msg, name, args)
46
46
  end
47
47
  # })
48
48
 
@@ -264,12 +264,14 @@ module Myco
264
264
  g.pop
265
265
 
266
266
  ##
267
- # if @#{:"__#{@name}_defined__"}
267
+ # if instance_variable_defined?(#{name})
268
268
  # @#{name} = meme.body.invoke meme.name, @target, obj, [], nil
269
269
  # end
270
270
  # return @#{name}
271
271
  #
272
- g.push_ivar(:"__#{@name}_defined__")
272
+ g.push_self
273
+ g.push_literal(:"@#{@name}")
274
+ g.send(:instance_variable_defined?, 1)
273
275
  g.goto_if_true(get)
274
276
 
275
277
  g.push_local 1 # meme
@@ -282,9 +284,6 @@ module Myco
282
284
  g.send :invoke, 5
283
285
  g.set_ivar(:"@#{@name}")
284
286
 
285
- g.push_true
286
- g.set_ivar(:"__#{@name}_defined__")
287
- g.pop
288
287
  g.goto(ret)
289
288
 
290
289
  get.set!
@@ -314,10 +313,6 @@ module Myco
314
313
  g.total_args = 1
315
314
  g.local_count = 1
316
315
 
317
- g.push_true
318
- g.set_ivar(:"__#{@name}_defined__")
319
- g.pop
320
-
321
316
  g.push_local 0 # value
322
317
 
323
318
  # If this meme has a setter defined, use it
@@ -1,6 +1,6 @@
1
1
 
2
2
  ::Myco::RubyEval < EmptyObject {
3
- from_string: |string| ::Kernel.instance_method(:eval).bind(self).call(string)
3
+ from_string: |string| ::Ruby::Kernel.instance_method(:eval).bind(self).call(string)
4
4
  }
5
5
 
6
6
  RubyEval @@@
@@ -2,7 +2,7 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
4
4
  ::Myco::RubyEval = ::Myco::Component.new([::Myco.find_constant(: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| (::Kernel.instance_method(:eval).bind(self).call(string))})}}
5
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:from_string, [], nil, ::Myco.cscope.dup) { |string| (::Ruby::Kernel.instance_method(:eval).bind(self).call(string))})}}
6
6
  .tap { |__c__| __c__.__name__ = :RubyEval }
7
7
  ::Myco::Component.new([::Myco.find_constant(:RubyEval)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
8
8
  .tap { |__c__| __c__.__last__ = __c__.component_eval {nil}}.instance.from_string(" Myco.eval_file(\"core/Category.my\", [Myco::CoreLoadPath])\n Myco.eval_file(\"core/BasicDecorators.my\", [Myco::CoreLoadPath])\n Myco.eval_file(\"core/BasicObject.my\", [Myco::CoreLoadPath])\n Myco.eval_file(\"core/Decorator.my\", [Myco::CoreLoadPath])\n Myco.eval_file(\"core/Object.my\", [Myco::CoreLoadPath])\n Myco.eval_file(\"core/FileToplevel.my\", [Myco::CoreLoadPath])\n \n # Below are not necessary for bootstrapping; TODO: move out of RubyEval\n Myco.eval_file(\"core/Switch.my\", [Myco::CoreLoadPath])\n")
@@ -131,7 +131,12 @@ module Myco
131
131
  @string || make_string
132
132
 
133
133
  parser = new_parser
134
- ast = parser.parse_string(@string)
134
+ begin
135
+ ast = parser.parse_string(@string)
136
+ rescue Exception => e
137
+ full_message = "Error while parsing #{filename}:\n" + e.message
138
+ raise e.class, full_message, e.backtrace
139
+ end
135
140
 
136
141
  ast = ast_root_for(ast)
137
142
  ast.file = filename.to_sym
@@ -2,9 +2,9 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  ArgumentAssembly < Node {
5
- var body, var block
6
-
7
- Form: [:argass, :body]
5
+ node_type args
6
+ field body
7
+ var block # TODO: remove this unnecessary state
8
8
 
9
9
  setter body: |given_body| {
10
10
  given_body.last.is_a?(BlockArgument) && (self.block = given_body.pop)
@@ -20,15 +20,11 @@ CodeTools::AST << {
20
20
  self.body.drop_while |item| { !item.is_a?(SplatValue) }
21
21
 
22
22
  # Symbol of bytecode operation to use for send
23
- send_op: {
24
- self.body.detect |item| { item.is_a?(SplatValue) } &? (
25
- :send_with_splat
26
- ) ?? (self.block &? ( # TODO: better elsif construction
27
- :send_with_block
28
- ) ?? (
29
- :send
30
- ))
31
- }
23
+ send_op: cond(
24
+ self.body.detect |item| { item.is_a?(SplatValue) }, :send_with_splat,
25
+ self.block, :send_with_block,
26
+ :send,
27
+ )
32
28
 
33
29
  # Number of arguments to use for send operation
34
30
  send_count:
@@ -2,12 +2,9 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::ArgumentAssembly = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
5
+ declare_meme(:args, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:body, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
7
  declare_meme(:block, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
- ::Myco.cscope.for_method_definition::Form = ([
8
- :argass,
9
- :body
10
- ])
11
8
  declare_meme(:body, [[:setter, []]], nil, ::Myco.cscope.dup) { |given_body| (
12
9
  ::Myco.branch_op(:"&&", given_body.last.__send__(
13
10
  :is_a?,
@@ -26,10 +23,16 @@
26
23
  :is_a?,
27
24
  ::Myco.find_constant(:SplatValue)
28
25
  ).__send__(:!))})}
29
- declare_meme(:send_op, [], nil, ::Myco.cscope.dup) { |*| (::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.body.detect { |item| (item.__send__(
30
- :is_a?,
31
- ::Myco.find_constant(:SplatValue)
32
- ))}) {:send_with_splat}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.block) {:send_with_block}) {:send}})}
26
+ declare_meme(:send_op, [], nil, ::Myco.cscope.dup) { |*| (self.cond(
27
+ self.body.detect { |item| (item.__send__(
28
+ :is_a?,
29
+ ::Myco.find_constant(:SplatValue)
30
+ ))},
31
+ :send_with_splat,
32
+ self.block,
33
+ :send_with_block,
34
+ :send
35
+ ))}
33
36
  declare_meme(:send_count, [], nil, ::Myco.cscope.dup) { |*| (self.pre_group.size)}
34
37
  declare_meme(:splat_bytecode, [], nil, ::Myco.cscope.dup) { |g| (::Myco.find_constant(:ArrayAssembly).new({
35
38
  :line => self.line,
@@ -2,9 +2,8 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  ArrayAssembly < Node {
5
- var body
6
-
7
- Form: [:arrass, :body]
5
+ node_type array
6
+ field body
8
7
 
9
8
  bytecode: |g| {
10
9
  pos(g)
@@ -2,11 +2,8 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::ArrayAssembly = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
- ::Myco.cscope.for_method_definition::Form = ([
7
- :arrass,
8
- :body
9
- ])
5
+ declare_meme(:array, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:body, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
7
  declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
11
8
  self.pos(g)
12
9
  ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.body.__send__(:empty?)) {g.make_array(0)}) {(
@@ -2,15 +2,15 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  Block < CodeTools::Compiler::LocalVariables, Node {
5
- var parameters, var body
6
- var parent # TODO: investigate removing
5
+ node_type block
6
+ field parameters, field body
7
7
 
8
- Form: [:block, :parameters, :body]
8
+ var parent # TODO: investigate removing
9
9
 
10
10
  CompilerClass: CodeTools::Compiler # TODO: remove this
11
11
 
12
12
  setter parameters: |given| given || ParameterAssembly.new(line:self.line)
13
- setter body: |given| given || NullLiteral.new(line:self.line)
13
+ setter body: |given| given || NullLiteral.new(line:self.line)
14
14
 
15
15
  locals: self.body.?locals.?body.map(&:value) ?? null
16
16
 
@@ -5,14 +5,10 @@
5
5
  ::Myco.find_constant(:Node)
6
6
  ], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
7
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}
8
+ declare_meme(:block, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
9
+ declare_meme(:parameters, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
+ declare_meme(:body, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
11
  declare_meme(:parent, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
11
- ::Myco.cscope.for_method_definition::Form = ([
12
- :block,
13
- :parameters,
14
- :body
15
- ])
16
12
  ::Myco.cscope.for_method_definition::CompilerClass = (::Myco.find_constant(:CodeTools)::Compiler)
17
13
  declare_meme(:parameters, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (::Myco.branch_op(:"||", given) {::Myco.find_constant(:ParameterAssembly).new({:line => self.line})})}
18
14
  declare_meme(:body, [[:setter, []]], nil, ::Myco.cscope.dup) { |given| (::Myco.branch_op(:"||", given) {::Myco.find_constant(:NullLiteral).new({:line => self.line})})}
@@ -2,9 +2,8 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  BlockArgument < Node {
5
- var body
6
-
7
- Form: [:blkarg, :body]
5
+ node_type blkarg
6
+ field body
8
7
 
9
8
  bytecode: |g| {
10
9
  self.body.bytecode(g)
@@ -14,9 +13,9 @@ CodeTools::AST << {
14
13
  g.is_nil
15
14
  g.goto_if_true(done_label)
16
15
 
17
- g.push_cpath_top; g.find_const(:"Proc")
16
+ g.push_cpath_top; g.find_const(:Proc)
18
17
  g.swap
19
- g.send(:"__from_block__", 1)
18
+ g.send(:__from_block__, 1)
20
19
 
21
20
  done_label.set!
22
21
  }
@@ -2,11 +2,8 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::BlockArgument = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:body, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
- ::Myco.cscope.for_method_definition::Form = ([
7
- :blkarg,
8
- :body
9
- ])
5
+ declare_meme(:blkarg, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:body, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
7
  declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
11
8
  self.body.bytecode(g)
12
9
  done_label = g.new_label
@@ -2,14 +2,13 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  BlockLiteral < Node {
5
- var block
6
-
7
- Form: [:blklit, :block]
5
+ node_type blklit
6
+ field block
8
7
 
9
8
  implementation_receiver: ConstantAccess.new(
10
9
  line: self.line
11
10
  toplevel: true
12
- names: [:"Proc"]
11
+ names: [:Ruby, :Proc]
13
12
  )
14
13
 
15
14
  implementation: Invoke.new(
@@ -2,15 +2,15 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::BlockLiteral = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:block, [[:var, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
- ::Myco.cscope.for_method_definition::Form = ([
7
- :blklit,
8
- :block
9
- ])
5
+ declare_meme(:blklit, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:block, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
10
7
  declare_meme(:implementation_receiver, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:ConstantAccess).new({
11
8
  :line => self.line,
12
9
  :toplevel => true,
13
- :names => [:Proc]
10
+ :names => [
11
+ :Ruby,
12
+ :Proc
13
+ ]
14
14
  }))}
15
15
  declare_meme(:implementation, [], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Invoke).new({
16
16
  :line => self.line,
@@ -2,22 +2,15 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  BlockParameter < Node {
5
- var name
6
- var variable # TODO: remove
7
-
8
- Form: [:blkprm, :name]
5
+ node_type blkprm
6
+ field name
9
7
 
8
+ map_local: |scope| scope.new_local(self.name)
10
9
  bytecode: |g| {
11
10
  pos(g)
12
11
 
13
12
  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
-
13
+ g.state.scope.search_local(self.name).set_bytecode(g)
21
14
  g.pop
22
15
  }
23
16
  }
@@ -2,22 +2,13 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::BlockParameter = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
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::Form = ([
8
- :blkprm,
9
- :name
10
- ])
5
+ declare_meme(:blkprm, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:name, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:map_local, [], nil, ::Myco.cscope.dup) { |scope| (scope.new_local(self.name))}
11
8
  declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
12
9
  self.pos(g)
13
10
  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)}
11
+ g.state.scope.search_local(self.name).set_bytecode(g)
21
12
  g.pop
22
13
  )}
23
14
  )}}
@@ -2,9 +2,8 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  BranchOperator < Node {
5
- var type, var left, var right
6
-
7
- Form: [:branch_op, :type, :left, :right]
5
+ node_type branch_op
6
+ field type, field left, field right
8
7
 
9
8
  bytecode: |g| {
10
9
  pos(g)
@@ -2,15 +2,10 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::BranchOperator = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
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::Form = ([
9
- :branch_op,
10
- :type,
11
- :left,
12
- :right
13
- ])
5
+ declare_meme(:branch_op, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:type, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:left, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
8
+ declare_meme(:right, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
14
9
  declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
15
10
  self.pos(g)
16
11
  done_label = g.new_label
@@ -2,9 +2,8 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  ConstantAccess < Node {
5
- var toplevel, var names
6
-
7
- Form: [:const, :toplevel, :names]
5
+ node_type const
6
+ field toplevel, field names
8
7
 
9
8
  bytecode: |g| {
10
9
  pos(g)
@@ -13,8 +12,13 @@ CodeTools::AST << {
13
12
  first_name = name_list.shift
14
13
 
15
14
  self.toplevel &? (
16
- g.push_cpath_top
17
- g.find_const(first_name)
15
+ # The conceptual toplevel in Myco is the Myco namespace
16
+ first_name case(
17
+ :Myco, &{ g.push_myco },
18
+ :Ruby, &{ g.push_cpath_top },
19
+ :Rubinius, &{ g.push_rubinius },
20
+ &{ g.push_myco; g.find_const(first_name) }
21
+ )
18
22
  ) ?? (
19
23
  Myco.find_constant_bytecode(g, first_name)
20
24
  )
@@ -24,8 +28,7 @@ CodeTools::AST << {
24
28
 
25
29
  ::Myco::SingletonClass << {
26
30
  find_constant_bytecode: |g, name| {
27
- g.push_cpath_top
28
- g.find_const(:"Myco")
31
+ g.push_myco
29
32
  g.push_literal(name)
30
33
  g.push_scope
31
34
  g.send(:find_constant, 2)
@@ -61,7 +64,7 @@ CodeTools::AST << {
61
64
 
62
65
  # fail_label.set! # stack: myco_levels, mod
63
66
  # g.pop # stack: myco_levels
64
- # g.push_cpath_top; g.find_const(:"Myco") # stack: myco_levels, ::Myco
67
+ # g.push_myco # stack: myco_levels, Myco
65
68
  # g.push_literal(name)
66
69
  # g.send(:const_get, 1) # stack: myco_levels, result
67
70
 
@@ -2,20 +2,25 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::ConstantAccess = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
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::Form = ([
8
- :const,
9
- :toplevel,
10
- :names
11
- ])
5
+ declare_meme(:const, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:toplevel, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:names, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
12
8
  declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
13
9
  self.pos(g)
14
10
  name_list = self.names.map(&:to_sym)
15
11
  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)
12
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.toplevel) {self.case(
13
+ first_name,
14
+ :Myco,
15
+ ::Proc.new { || (g.push_myco)},
16
+ :Ruby,
17
+ ::Proc.new { || (g.push_cpath_top)},
18
+ :Rubinius,
19
+ ::Proc.new { || (g.push_rubinius)},
20
+ ::Proc.new { || (
21
+ g.push_myco
22
+ g.find_const(first_name)
23
+ )}
19
24
  )}) {::Myco.find_constant(:Myco).find_constant_bytecode(
20
25
  g,
21
26
  first_name
@@ -23,8 +28,7 @@
23
28
  name_list.each { |name| (g.find_const(name))}
24
29
  )}
25
30
  ::Myco::SingletonClass.component_eval {(declare_meme(:find_constant_bytecode, [], nil, ::Myco.cscope.dup) { |g, name| (
26
- g.push_cpath_top
27
- g.find_const(:Myco)
31
+ g.push_myco
28
32
  g.push_literal(name)
29
33
  g.push_scope
30
34
  g.send(
@@ -2,9 +2,8 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  ConstantAssignment < Node {
5
- var constant, var value
6
-
7
- Form: [:cdecl, :constant, :value]
5
+ node_type cdecl
6
+ field constant, field value
8
7
 
9
8
  bytecode: |g| {
10
9
  pos(g)
@@ -14,8 +13,17 @@ CodeTools::AST << {
14
13
  first_name = name_list.any? && name_list.shift
15
14
 
16
15
  self.constant.toplevel &? (
17
- g.push_cpath_top
18
- first_name && g.find_const(first_name)
16
+ first_name &? (
17
+ # The conceptual toplevel in Myco is the Myco namespace
18
+ first_name case(
19
+ :Myco, &{ g.push_myco },
20
+ :Ruby, &{ g.push_cpath_top },
21
+ :Rubinius, &{ g.push_rubinius },
22
+ &{ g.push_myco; g.find_const(first_name) }
23
+ )
24
+ ) ?? (
25
+ g.push_myco
26
+ )
19
27
  ) ?? (
20
28
  first_name &? (
21
29
  Myco.find_constant_bytecode(g, first_name)
@@ -2,22 +2,27 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco.find_constant(:CodeTools)::AST.component_eval {(::Myco.cscope.for_method_definition::ConstantAssignment = ::Myco::Component.new([::Myco.find_constant(:Node)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
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::Form = ([
8
- :cdecl,
9
- :constant,
10
- :value
11
- ])
5
+ declare_meme(:cdecl, [[:node_type, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:constant, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ declare_meme(:value, [[:field, []]], nil, ::Myco.cscope.dup) { |*| nil}
12
8
  declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |g| (
13
9
  self.pos(g)
14
10
  name_list = self.constant.names.map(&:to_sym)
15
11
  last_name = name_list.pop
16
12
  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) {::Myco.find_constant(:Myco).find_constant_bytecode(
13
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.constant.toplevel) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {self.case(
14
+ first_name,
15
+ :Myco,
16
+ ::Proc.new { || (g.push_myco)},
17
+ :Ruby,
18
+ ::Proc.new { || (g.push_cpath_top)},
19
+ :Rubinius,
20
+ ::Proc.new { || (g.push_rubinius)},
21
+ ::Proc.new { || (
22
+ g.push_myco
23
+ g.find_const(first_name)
24
+ )}
25
+ )}) {g.push_myco}}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", first_name) {::Myco.find_constant(:Myco).find_constant_bytecode(
21
26
  g,
22
27
  first_name
23
28
  )}) {(
@@ -2,9 +2,8 @@
2
2
  CodeTools::AST << {
3
3
 
4
4
  ConstantDefine < Node {
5
- var constant, var object
6
-
7
- Form: [:cdefn, :constant, :object]
5
+ node_type cdefn
6
+ field constant, field object
8
7
 
9
8
  implementation: ConstantAssignment.new(
10
9
  line: self.line