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
@@ -1,53 +0,0 @@
1
-
2
- require_relative 'myco_module_scope'
3
-
4
-
5
- module CodeTools::AST
6
-
7
- module BuilderMethods
8
- def category loc, name, body
9
- DeclareCategory.new loc.line, name, body
10
- end
11
- end
12
-
13
- class DeclareCategoryScope < MycoModuleScope
14
- def body_bytecode g
15
- g.push_scope
16
- g.send :set_myco_category, 0
17
- g.pop
18
-
19
- @body.bytecode g
20
- end
21
- end
22
-
23
- class DeclareCategory < Node
24
- attr_accessor :name, :body
25
-
26
- def initialize line, name, body
27
- @line = line
28
- @name = name
29
- @body = body
30
- end
31
-
32
- def to_sexp
33
- [:category, @name.value, @body.to_sexp]
34
- end
35
-
36
- def scope_implementation
37
- DeclareCategoryScope.new @line, @body
38
- end
39
-
40
- def bytecode g
41
- pos(g)
42
-
43
- ##
44
- # category = self.__category__ @name
45
- g.push_self
46
- g.push_literal @name.value
47
- g.send :__category__, 1
48
-
49
- scope_implementation.bytecode g
50
- end
51
- end
52
-
53
- end
@@ -1,35 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def deco loc, name, arguments
6
- DeclareDecorator.new loc.line, name, arguments
7
- end
8
- end
9
-
10
- class DeclareDecorator < Node
11
- attr_accessor :line, :name, :arguments
12
-
13
- def initialize line, name, arguments
14
- @line = line
15
- @name = name
16
- @arguments = arguments || ArrayAssembly.new(@line, [])
17
- end
18
-
19
- def to_sexp
20
- args_sexp = @arguments.to_sexp
21
- args_sexp[0] = :arglist
22
- sexp = [:deco, @name.value]
23
- sexp.push args_sexp unless @arguments.body.empty?
24
- sexp
25
- end
26
-
27
- def bytecode g
28
- pos(g)
29
-
30
- ary = ArrayLiteral.new @line, [@name, @arguments]
31
- ary.bytecode g
32
- end
33
- end
34
-
35
- end
@@ -1,54 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def declfile loc, body
6
- DeclareFile.new loc.line, body
7
- end
8
- end
9
-
10
- class DeclareFileScope < MycoModuleScope
11
- def body_bytecode g
12
- g.push_scope
13
- g.send :set_myco_file, 0
14
- g.pop
15
-
16
- @body.bytecode g
17
- end
18
- end
19
-
20
- class DeclareFile < Node
21
- attr_accessor :body
22
-
23
- # Use minimal inspect to avoid huge inspect output for inner AST nodes
24
- # that store a reference to a DeclareFile in an instance variable.
25
- def inspect
26
- to_s
27
- end
28
-
29
- def initialize line, body
30
- @line = line
31
- @body = body
32
- end
33
-
34
- def to_sexp
35
- [:declfile, @body.to_sexp]
36
- end
37
-
38
- def implementation
39
- myco = ToplevelConstant.new @line, :Myco
40
- type = ScopedConstant.new @line, myco, :FileToplevel
41
- types = ArrayAssembly.new @line, [type]
42
- decl = DeclareObject.new @line, types, @body
43
- decl.scope_type = DeclareFileScope
44
- decl
45
- end
46
-
47
- def bytecode g
48
- pos(g)
49
-
50
- implementation.bytecode g
51
- end
52
- end
53
-
54
- end
@@ -1,86 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def meme loc, name, decorations, arguments, body
6
- DeclareMeme.new loc.line, name, decorations, arguments, body
7
- end
8
- end
9
-
10
- class DeclareMemeBody < Iter
11
- attr_accessor :name
12
-
13
- def bytecode(g)
14
- pos(g)
15
-
16
- g.state.scope.nest_scope self
17
-
18
- meth = new_generator g, @name, @arguments
19
-
20
- meth.push_state self
21
- meth.state.push_super self
22
- meth.definition_line @line
23
-
24
- meth.state.push_name @name
25
-
26
- @arguments.bytecode meth
27
- @body.bytecode meth
28
-
29
- meth.state.pop_name
30
-
31
- meth.local_count = local_count
32
- meth.local_names = local_names
33
- meth.splat_index = @arguments.splat_index
34
-
35
- meth.ret
36
- meth.close
37
- meth.pop_state
38
-
39
- g.push_scope
40
- g.send :for_method_definition, 0
41
- g.add_scope
42
-
43
- # Create the BlockEnvironment from the meth Generator
44
- g.create_block meth
45
- end
46
- end
47
-
48
- class DeclareMeme < Node
49
- attr_accessor :name, :decorations, :arguments, :body
50
-
51
- def initialize line, name, decorations, arguments, body
52
- @line = line
53
- @name = name.value
54
- @decorations = decorations || ArrayAssembly.new(line, [])
55
- @arguments = arguments || Parameters.new(line, [], nil, true, nil, nil, nil, nil)
56
- @body = body || NilLiteral.new(line)
57
- end
58
-
59
- def to_sexp
60
- [:meme, @name, @decorations.to_sexp, @arguments.to_sexp, @body.to_sexp]
61
- end
62
-
63
- def body_implementation
64
- meme_body = DeclareMemeBody.new(@line, @arguments, @body)
65
- meme_body.name = @name
66
- meme_body
67
- end
68
-
69
- def bytecode(g)
70
- pos(g)
71
-
72
- ##
73
- # module = scope.for_method_definition
74
- # module.send :declare_meme, @name, @decorations,
75
- # BlockEnvironment(body_implementation)
76
- #
77
- g.push_scope
78
- g.send :for_method_definition, 0
79
- g.push_literal @name
80
- @decorations.bytecode g
81
- body_implementation.bytecode(g)
82
- g.send :declare_meme, 3
83
- end
84
- end
85
-
86
- end
@@ -1,77 +0,0 @@
1
-
2
- require_relative 'myco_module_scope'
3
-
4
-
5
- module CodeTools::AST
6
-
7
- module BuilderMethods
8
- def declobj loc, types, body
9
- DeclareObject.new loc.line, types, body
10
- end
11
- end
12
-
13
- class DeclareObjectScope < MycoModuleScope
14
- def body_bytecode g
15
- g.push_scope
16
- g.send :set_myco_component, 0
17
- g.pop
18
-
19
- @body.bytecode g
20
- end
21
- end
22
-
23
- class DeclareObject < Node
24
- attr_accessor :types, :body
25
- attr_accessor :create
26
-
27
- attr_accessor :scope_type
28
-
29
- def initialize line, types, body
30
- @line = line
31
- @types = types
32
- @body = body
33
-
34
- @create = true
35
- @scope_type = DeclareObjectScope
36
- end
37
-
38
- def to_sexp
39
- [:declobj, @types.to_sexp, @body.to_sexp]
40
- end
41
-
42
- def scope_implementation
43
- @scope_type.new @line, @body
44
- end
45
-
46
- def bytecode g
47
- pos(g)
48
-
49
- # ::Myco::Component.new types, parent, filename
50
- g.push_cpath_top
51
- g.find_const :Myco
52
- g.find_const :Component
53
- @types.bytecode g
54
- g.push_scope; g.send :for_method_definition, 0
55
- g.push_scope; g.send :active_path, 0; g.meta_to_s
56
- g.push_int @line
57
- g.send :new, 4
58
-
59
- # The return value of Component.new at the top of the stack
60
- # will be consumed by @scope.bytecode, so save two copies of it.
61
- g.dup_top # One for sending :__last__= to
62
- g.dup_top # One for sending :instance to (or returning, if !@create)
63
-
64
- # Compile the inner scope,
65
- # leaving the last object in the scope at the top of the stack.
66
- scope_implementation.bytecode g
67
-
68
- # component.__last__ = (value left on stack from @scope.bytecode)
69
- g.send :__last__=, 1
70
- g.pop
71
-
72
- # return (@create ? component.instance : component)
73
- g.send :instance, 0 if @create
74
- end
75
- end
76
-
77
- end
@@ -1,37 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def declstr loc, types, string
6
- DeclareString.new loc.line, types, string
7
- end
8
- end
9
-
10
- class DeclareString < Node
11
- attr_accessor :types, :string
12
-
13
- def initialize line, types, string
14
- @line = line
15
- @types = types
16
- @string = string
17
- end
18
-
19
- def to_sexp
20
- [:declstr, @types.to_sexp, @string.to_sexp]
21
- end
22
-
23
- def implementation
24
- blk = NilLiteral.new @line
25
- obj = DeclareObject.new @line, @types, blk
26
- args = ArgumentAssembly.new @string.line, [@string]
27
- InvokeMethod.new @string.line, obj, :from_string, args
28
- end
29
-
30
- def bytecode g
31
- pos(g)
32
-
33
- implementation.bytecode g
34
- end
35
- end
36
-
37
- end
@@ -1,48 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def invoke loc, receiver, name, arguments, *rest
6
- Invoke.new loc.line, receiver, name, arguments, *rest
7
- end
8
- end
9
-
10
- class Invoke < Node
11
- attr_accessor :receiver, :name, :arguments
12
-
13
- def initialize line, receiver, name, arguments, block_params=nil, block=nil
14
- @line = line
15
- @receiver = receiver
16
- @name = name
17
- @arguments = arguments
18
-
19
- if block
20
- # TODO: error if passing both block argument and block literal
21
- # Currently, this fails silently and ignores the block argument
22
- @arguments ||= ArgumentAssembly.new(line, [])
23
- @arguments.block = Iter.new(line, block_params, block)
24
- end
25
- end
26
-
27
- def bytecode g
28
- pos(g)
29
-
30
- implementation.bytecode(g)
31
- end
32
-
33
- def to_sexp
34
- implementation.to_sexp
35
- end
36
-
37
- def implementation
38
- if @receiver.nil? && @arguments.nil?
39
- LocalVariableAccessAmbiguous.new(@line, @name)
40
- else
41
- rcvr = @receiver || Self.new(@line)
42
- args = @arguments || ArgumentAssembly.new(line, [])
43
- InvokeMethod.new @line, rcvr, @name, args
44
- end
45
- end
46
- end
47
-
48
- end
@@ -1,28 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- class InvokeMethod < Node
5
- attr_accessor :line, :receiver, :name, :arguments
6
-
7
- def initialize line, receiver, name, arguments
8
- @line = line
9
- @receiver = receiver
10
- @name = name
11
- @arguments = arguments
12
- end
13
-
14
- def bytecode(g)
15
- @receiver.bytecode(g)
16
- @arguments.bytecode(g)
17
-
18
- pos(g)
19
-
20
- g.__send__(@arguments.send_op, @name, @arguments.send_count)
21
- end
22
-
23
- def to_sexp
24
- [:call, @receiver.to_sexp, @name, @arguments.to_sexp]
25
- end
26
- end
27
-
28
- end
@@ -1,34 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def lambig loc, name
6
- LocalVariableAccessAmbiguous.new loc.line, name
7
- end
8
- end
9
-
10
- class LocalVariableAccessAmbiguous < Node
11
- attr_accessor :name
12
-
13
- def initialize line, name
14
- @line = line
15
- @name = name
16
- end
17
-
18
- def bytecode g
19
- pos(g)
20
-
21
- local = g.state.scope.search_local @name
22
- return local.get_bytecode(g) if local
23
-
24
- rcvr = Self.new @line
25
- send = Send.new @line, rcvr, @name, true, true
26
- send.bytecode(g)
27
- end
28
-
29
- def to_sexp
30
- [:lambig, @name]
31
- end
32
- end
33
-
34
- end
@@ -1,156 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- # These builder methods are copied directly from rubinius-processor
5
- # TODO: remove and Myco-ize all dependencies on rubinius-processor and rubinius-ast
6
- module BuilderMethods
7
- def colon2 loc, outer, name
8
- if outer
9
- if outer.kind_of? ConstantAccess and
10
- outer.name == :Rubinius
11
- case name
12
- when :Type
13
- TypeConstant.new loc.line
14
- when :Mirror
15
- MirrorConstant.new loc.line
16
- else
17
- ScopedConstant.new loc.line, outer, name
18
- end
19
- else
20
- ScopedConstant.new loc.line, outer, name
21
- end
22
- else
23
- ConstantAccess.new loc.line, name
24
- end
25
- end
26
-
27
- def colon3 loc, name
28
- ToplevelConstant.new loc.line, name
29
- end
30
-
31
- def const loc, name
32
- ConstantAccess.new loc.line, name
33
- end
34
-
35
- def lit loc, sym
36
- SymbolLiteral.new loc.line, sym
37
- end
38
-
39
- def args loc, required, optional, splat, post, kwargs, kwrest, block
40
- Parameters.new loc.line, required, optional, splat, post, kwargs, kwrest, block
41
- end
42
-
43
- def self loc
44
- Self.new loc.line
45
- end
46
-
47
- def block loc, array
48
- Block.new loc.line, array
49
- end
50
-
51
- def str loc, str
52
- StringLiteral.new loc.line, str
53
- end
54
-
55
- def splat loc, expr
56
- SplatValue.new loc.line, expr
57
- end
58
-
59
- def block_pass loc, arguments, body
60
- BlockPass19.new loc.line, arguments, body
61
- end
62
-
63
- def evstr loc, value
64
- if value
65
- ToString.new loc.line, value
66
- else
67
- StringLiteral.new loc.line, ""
68
- end
69
- end
70
-
71
- def dsym loc, str, array
72
- DynamicSymbol.new loc.line, str, array
73
- end
74
-
75
- def dstr loc, str, array
76
- DynamicString.new loc.line, str, array
77
- end
78
-
79
- def true loc
80
- TrueLiteral.new loc.line
81
- end
82
-
83
- def false loc
84
- FalseLiteral.new loc.line
85
- end
86
-
87
- def return loc, value
88
- Return.new loc.line, value
89
- end
90
-
91
- def lasgn loc, name, value
92
- LocalVariableAssignment.new loc.line, name, value
93
- end
94
-
95
- def hash loc, array
96
- HashLiteral.new loc.line, array
97
- end
98
-
99
- def cdecl loc, expr, value
100
- ConstantAssignment.new loc.line, expr, value
101
- end
102
-
103
- def op_cdecl loc, var, value, op
104
- op_value = case op
105
- when :and
106
- And.new loc.line, var, value
107
- when :or
108
- Or.new loc.line, var, value
109
- else
110
- args = ArrayLiteral.new loc.line, [value]
111
- SendWithArguments.new loc.line, var, op, args
112
- end
113
- ConstantAssignment.new loc.line, var, op_value
114
- end
115
- end
116
-
117
- # These builder methods process the null and void literals
118
- module BuilderMethods
119
- def null loc
120
- NullLiteral.new loc.line
121
- end
122
-
123
- def void loc
124
- VoidLiteral.new loc.line
125
- end
126
- end
127
-
128
- class NullLiteral < NilLiteral
129
- def to_sexp
130
- [:null]
131
- end
132
- end
133
-
134
- # Replace NilLiteral with NullLiteral and let original NilLiteral "disappear"
135
- NilLiteral = NullLiteral
136
-
137
- class ::CodeTools::Generator
138
- def push_void
139
- push_cpath_top
140
- find_const :Myco
141
- find_const :Void
142
- end
143
- end
144
-
145
- class VoidLiteral < Node
146
- def bytecode(g)
147
- pos(g)
148
- g.push_void
149
- end
150
-
151
- def to_sexp
152
- [:void]
153
- end
154
- end
155
-
156
- end
@@ -1,82 +0,0 @@
1
-
2
- module CodeTools::AST
3
-
4
- module BuilderMethods
5
- def quest loc, receiver, questable
6
- Quest.new loc.line, receiver, questable
7
- end
8
- end
9
-
10
- class Quest < Node
11
- attr_accessor :receiver
12
- attr_accessor :questable
13
-
14
- def initialize line, receiver, questable
15
- @line = line
16
- @receiver = receiver
17
- @questable = questable
18
-
19
- @void_literal = VoidLiteral.new @line
20
-
21
- @questable.receiver = FakeReceiver.new @line
22
- end
23
-
24
- def bytecode g
25
- pos(g)
26
-
27
- ##
28
- # unless @receiver.respond_to?(@questable.name).false?
29
- # execute_statement @questable
30
- # else
31
- # return void
32
- # end
33
-
34
- else_label = g.new_label
35
- end_label = g.new_label
36
-
37
- @receiver.bytecode g
38
- g.dup_top # dup the receiver to save it for later
39
- g.push_literal @questable.name
40
- g.send :respond_to?, 1
41
- g.send :false?, 0
42
- g.goto_if_true else_label
43
-
44
- # The duped receiver is still at the top of the stack,
45
- # and @questable.receiver has been set to an instance of FakeReceiver
46
- # to let the true receiver pass through instead.
47
- @questable.bytecode g
48
- g.goto end_label
49
-
50
- else_label.set!
51
- g.pop # pop the duped receiver - it won't be used after all
52
- g.push_cpath_top
53
- g.find_const :Myco
54
- g.find_const :Void
55
-
56
- end_label.set!
57
- end
58
-
59
- def to_sexp
60
- [:quest, @receiver.to_sexp, @questable.to_sexp]
61
- end
62
-
63
- class FakeReceiver < Node
64
- def initialize line
65
- @line = line
66
- end
67
-
68
- def bytecode g
69
- pos(g)
70
- # Do nothing here - this would normally be ill-advised,
71
- # because Nodes are expected to push an item onto the stack,
72
- # but here we are intentionally not doing so because
73
- # the real receiver should already at the top of the stack
74
- end
75
-
76
- def to_sexp
77
- [:qrcvr]
78
- end
79
- end
80
- end
81
-
82
- end
@@ -1,21 +0,0 @@
1
-
2
- require_relative "ast/constant_access"
3
- require_relative "ast/constant_define"
4
- require_relative "ast/constant_reopen"
5
- require_relative "ast/declare_category"
6
- require_relative "ast/declare_decorator"
7
- require_relative "ast/declare_file"
8
- require_relative "ast/declare_meme"
9
- require_relative "ast/declare_object"
10
- require_relative "ast/declare_string"
11
- require_relative "ast/invoke"
12
- require_relative "ast/local_variable_access_ambiguous"
13
- require_relative "ast/invoke_method"
14
- require_relative "ast/array_assembly"
15
- require_relative "ast/argument_assembly"
16
- require_relative "ast/quest"
17
- require_relative "ast/branch_operator"
18
-
19
- require_relative "ast/misc"
20
-
21
- Myco.eval_file 'ast/ToRuby.my'