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
@@ -38,7 +38,7 @@ BytecodeHelpers < BasicObject {
38
38
  g.push_subject; g.push_idx; g.send(:chr_at, 1)
39
39
 
40
40
  push_new_hash:
41
- g.push_cpath_top; g.find_const(:"Hash"); g.send(:new, 0)
41
+ g.push_cpath_top; g.find_const(:Hash); g.send(:new, 0)
42
42
 
43
43
  # Set the memo ivar to a new hash if it doesn't already exist
44
44
  memo_or_eq_new_hash: |name| {
@@ -54,7 +54,7 @@ BytecodeHelpers < BasicObject {
54
54
 
55
55
  # Copy the top two values into the memo ivar for |name| at the current idx.
56
56
  copy_result_to_memo: |name| {
57
- g.dup
57
+ g.dup_top
58
58
  g.push_captures
59
59
  g.make_array(2) # [result_idx, result_captures]
60
60
 
@@ -74,7 +74,7 @@ BytecodeHelpers < BasicObject {
74
74
  g.push_memo_for(name)
75
75
  g.push_idx
76
76
  g.send(:"[]", 1)
77
- g.dup # dup the result to retain after goto test
77
+ g.dup_top # dup the result to retain after goto test
78
78
  g.goto_if_nil(skip_label)
79
79
 
80
80
  # Shift result_idx onto the stack and swap with array
@@ -82,7 +82,7 @@
82
82
  memo_exists_label.__send__(:set!)
83
83
  )}
84
84
  declare_meme(:copy_result_to_memo, [], nil, ::Myco.cscope.dup) { |name| (
85
- self.g.dup
85
+ self.g.dup_top
86
86
  self.g.push_captures
87
87
  self.g.make_array(2)
88
88
  self.g.push_memo_for(name)
@@ -103,7 +103,7 @@
103
103
  :[],
104
104
  1
105
105
  )
106
- self.g.dup
106
+ self.g.dup_top
107
107
  self.g.goto_if_nil(skip_label)
108
108
  self.g.shift_array
109
109
  self.g.swap
@@ -49,42 +49,42 @@ BytecodeInstructions < BasicObject {
49
49
 
50
50
  NegativePredicate << { bytecode: |m|
51
51
  m.neg_predicate(
52
- Proc.new { inner.bytecode(m) }
52
+ &{ inner.bytecode(m) }
53
53
  inner.bytecode_can_capture
54
54
  )
55
55
  }
56
56
  PositivePredicate << { bytecode: |m|
57
57
  m.pos_predicate(
58
- Proc.new { inner.bytecode(m) }
58
+ &{ inner.bytecode(m) }
59
59
  inner.bytecode_can_capture
60
60
  )
61
61
  }
62
62
  OneOrMore << { bytecode: |m|
63
63
  m.many(
64
- Proc.new { inner.bytecode(m); inlaid.?call }
64
+ &{ inner.bytecode(m); inlaid.?call }
65
65
  inner.bytecode_can_capture
66
66
  )
67
67
  }
68
68
  ZeroOrOne << {
69
69
  bytecode: |m| {
70
70
  m.choice(
71
- Proc.new { inner.bytecode(m) }
72
- Proc.new { }
71
+ &{ inner.bytecode(m) }
72
+ &{ }
73
73
  inner.bytecode_can_capture
74
74
  )
75
75
  }
76
76
  }
77
77
  ZeroOrMore << { bytecode: |m|
78
78
  m.kleene(
79
- Proc.new { inner.bytecode(m); inlaid.?call }
79
+ &{ inner.bytecode(m); inlaid.?call }
80
80
  inner.bytecode_can_capture
81
81
  )
82
82
  }
83
83
  OrderedChoice << {
84
84
  bytecode: |m| {
85
85
  m.choice(
86
- Proc.new { first.bytecode(m) }
87
- Proc.new { second.bytecode(m) }
86
+ &{ first.bytecode(m) }
87
+ &{ second.bytecode(m) }
88
88
  first.bytecode_can_capture
89
89
  )
90
90
  }
@@ -96,7 +96,7 @@ BytecodeInstructions < BasicObject {
96
96
  NamedCapture << {
97
97
  bytecode: |m| {
98
98
  (inner.is_a?(OneOrMore) || inner.is_a?(ZeroOrMore)) &? (
99
- inner.inlaid = Proc.new { m.capture(:m_split, captargs) }
99
+ inner.inlaid = &{ m.capture(:m_split, captargs) }
100
100
  m.capture(:m_start)
101
101
  inner.bytecode(m)
102
102
  m.capture(:m_end, captargs)
@@ -17,35 +17,35 @@
17
17
  m.set(codes.map(&:chr).join)
18
18
  )})}
19
19
  ::Myco.find_constant(:NegativePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.neg_predicate(
20
- ::Myco.find_constant(:Proc).new { || (self.inner.bytecode(m))},
20
+ ::Proc.new { || (self.inner.bytecode(m))},
21
21
  self.inner.bytecode_can_capture
22
22
  ))})}
23
23
  ::Myco.find_constant(:PositivePredicate).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.pos_predicate(
24
- ::Myco.find_constant(:Proc).new { || (self.inner.bytecode(m))},
24
+ ::Proc.new { || (self.inner.bytecode(m))},
25
25
  self.inner.bytecode_can_capture
26
26
  ))})}
27
27
  ::Myco.find_constant(:OneOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.many(
28
- ::Myco.find_constant(:Proc).new { || (
28
+ ::Proc.new { || (
29
29
  self.inner.bytecode(m)
30
30
  (self.inlaid.respond_to?(:call).false? ? ::Myco::Void : self.inlaid.call)
31
31
  )},
32
32
  self.inner.bytecode_can_capture
33
33
  ))})}
34
34
  ::Myco.find_constant(:ZeroOrOne).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.choice(
35
- ::Myco.find_constant(:Proc).new { || (self.inner.bytecode(m))},
36
- ::Myco.find_constant(:Proc).new { || nil},
35
+ ::Proc.new { || (self.inner.bytecode(m))},
36
+ ::Proc.new { || nil},
37
37
  self.inner.bytecode_can_capture
38
38
  ))})}
39
39
  ::Myco.find_constant(:ZeroOrMore).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.kleene(
40
- ::Myco.find_constant(:Proc).new { || (
40
+ ::Proc.new { || (
41
41
  self.inner.bytecode(m)
42
42
  (self.inlaid.respond_to?(:call).false? ? ::Myco::Void : self.inlaid.call)
43
43
  )},
44
44
  self.inner.bytecode_can_capture
45
45
  ))})}
46
46
  ::Myco.find_constant(:OrderedChoice).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (m.choice(
47
- ::Myco.find_constant(:Proc).new { || (self.first.bytecode(m))},
48
- ::Myco.find_constant(:Proc).new { || (self.second.bytecode(m))},
47
+ ::Proc.new { || (self.first.bytecode(m))},
48
+ ::Proc.new { || (self.second.bytecode(m))},
49
49
  self.first.bytecode_can_capture
50
50
  ))})}
51
51
  ::Myco.find_constant(:Concatenation).component_eval {(declare_meme(:bytecode, [], nil, ::Myco.cscope.dup) { |m| (
@@ -61,7 +61,7 @@
61
61
  )}) {(
62
62
  self.inner.__send__(
63
63
  :inlaid=,
64
- ::Myco.find_constant(:Proc).new { || (m.capture(
64
+ ::Proc.new { || (m.capture(
65
65
  :m_split,
66
66
  self.captargs
67
67
  ))}
@@ -53,7 +53,7 @@ BytecodeParser < BasicObject {
53
53
 
54
54
  save_prototype: |filename| {
55
55
  code = compile_code(:__script__, :"(snippet)") |g| {
56
- g.push_cpath_top; g.find_const(:"Class")
56
+ g.push_cpath_top; g.find_const(:Class)
57
57
  g.create_block(compile_generator(:__block__, :"(snippet)") |g| {
58
58
  prototype.instance_methods.each |name| {
59
59
  code = prototype.instance_method(name).executable
@@ -120,7 +120,7 @@ BytecodeParser < BasicObject {
120
120
  self.error_col = pos.last
121
121
  self.error_string = \
122
122
  "Unexpected character near line: "error_row", column: "error_col".\n" \
123
- string.each_line.to_a[error_row]"" \
123
+ string.each_line.to_a[error_row - 1]"" \
124
124
  (' ' * [(error_col - 1), 0].max)"^"
125
125
  }
126
126
  self.result
@@ -205,7 +205,10 @@
205
205
  :error_string=,
206
206
  "Unexpected character near line: #{self.error_row}, column: #{self.error_col}.\n#{string.each_line.to_a.__send__(
207
207
  :[],
208
- self.error_row
208
+ self.error_row.__send__(
209
+ :-,
210
+ 1
211
+ )
209
212
  )}#{" ".__send__(
210
213
  :*,
211
214
  [
@@ -13,8 +13,7 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
13
13
  bytecode_can_capture: true
14
14
  }
15
15
 
16
- var rule_table: Hash.new
17
- var rule_table: Hash.new
16
+ var rule_table: ::Ruby::Hash.new
18
17
 
19
18
  # Force evaluation of the rule tree in a way that
20
19
  # doesn't get stuck in an infinite recursion.
@@ -37,7 +36,7 @@ Grammar < BasicObject, Patterns::ShorthandMethods {
37
36
  token: Decorator {
38
37
  apply: |meme| {
39
38
  orig_meme = meme.dup
40
- meme.body = Proc.new { orig_meme.result.token(:"t_"meme.name"") }
39
+ meme.body = &{ orig_meme.result.token(:"t_"meme.name"") }
41
40
  }
42
41
  [transforms]
43
42
  cache: true
@@ -22,8 +22,7 @@
22
22
  declare_meme(:bytecode_can_capture, [], nil, ::Myco.cscope.dup) { |*| (true)}
23
23
  )}}
24
24
  .tap { |__c__| __c__.__name__ = :RuleReference }
25
- declare_meme(:rule_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Hash).new)}
26
- declare_meme(:rule_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Hash).new)}
25
+ declare_meme(:rule_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Ruby::Hash.new)}
27
26
  declare_meme(:construct_all_rules, [], nil, ::Myco.cscope.dup) { |*| (
28
27
  self.rules.root.construct_rule
29
28
  seen_keys = []
@@ -49,7 +48,7 @@
49
48
  orig_meme = meme.dup
50
49
  meme.__send__(
51
50
  :body=,
52
- ::Myco.find_constant(:Proc).new { || (orig_meme.result.token(:"t_#{meme.name}"))}
51
+ ::Proc.new { || (orig_meme.result.token(:"t_#{meme.name}"))}
53
52
  )
54
53
  )}
55
54
  __category__(:transforms).component_eval {(declare_meme(:cache, [], nil, ::Myco.cscope.dup) { |*| (true)})}
@@ -23,7 +23,7 @@ Machine < BasicObject, Instructions {
23
23
  var subject: []
24
24
 
25
25
  # The sequence of instructions to execute for each rule name
26
- var sequence_table: Hash.new
26
+ var sequence_table: ::Ruby::Hash.new
27
27
 
28
28
 
29
29
  # Execute the root rule instruction sequence over the given subject
@@ -11,7 +11,7 @@
11
11
  declare_meme(:stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
12
12
  declare_meme(:captures, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
13
13
  declare_meme(:subject, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
14
- declare_meme(:sequence_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Hash).new)}
14
+ declare_meme(:sequence_table, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Ruby::Hash.new)}
15
15
  declare_meme(:execute, [], nil, ::Myco.cscope.dup) { |*| (self.loop { || (::Myco.branch_op(:"??", ::Myco.branch_op(:"|?", self.ip) {self.handle_fail}) {::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.ip.__send__(
16
16
  :==,
17
17
  true
@@ -40,7 +40,7 @@ Processor < BasicObject {
40
40
 
41
41
  # Given a string, return a map of indices of newline positions to line numbers
42
42
  memoize line_map_for: |string| {
43
- idx_hash = ::Hash.new
43
+ idx_hash = ::Ruby::Hash.new
44
44
  idx_hash[0] = 0
45
45
  count = 0
46
46
  idx = 0
@@ -56,13 +56,13 @@ Processor < BasicObject {
56
56
  # Given an index and string, return the row (line) and column numbers
57
57
  position_of: |idx, string| {
58
58
  nl_idx = string.rindex("\n", idx) || 0
59
- row = line_map_for(string).fetch(nl_idx) + 1
59
+ row = line_map_for(string).fetch(nl_idx) + 2
60
60
  col = idx - nl_idx
61
61
  [row, col]
62
62
  }
63
63
 
64
64
  # Push or pop a layer to/from the capture stack
65
- push_layer: capt_stack.push(::Hash.new)
65
+ push_layer: capt_stack.push(::Ruby::Hash.new)
66
66
  pop_layer: capt_stack.pop
67
67
 
68
68
  setup:
@@ -70,7 +70,7 @@ Processor < BasicObject {
70
70
 
71
71
  final_captures:
72
72
  pop_layer
73
- .select |k,v| { k.is_a?(::Symbol) }
73
+ .select |k,v| { k.is_a?(Symbol) }
74
74
  .map |k,v| { [k,v.last] }
75
75
  .to_h
76
76
 
@@ -185,7 +185,7 @@ Processor < BasicObject {
185
185
  # Try to find a group of "anonymous" captures by index first
186
186
  value = []
187
187
  captures.each |k,v| {
188
- (k.is_a?(::Fixnum) && k<=idx && k>start_idx) && (
188
+ (k.is_a?(Fixnum) && k<=idx && k>start_idx) && (
189
189
  loc = v.first
190
190
  (loc.first>=start_idx) && (
191
191
  value.push(v.last)
@@ -48,7 +48,7 @@
48
48
  declare_meme(:ridx_stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
49
49
  declare_meme(:capt_stack, [[:var, []]], nil, ::Myco.cscope.dup) { |*| ([])}
50
50
  declare_meme(:line_map_for, [[:memoize, []]], nil, ::Myco.cscope.dup) { |string| (
51
- idx_hash = ::Hash.new
51
+ idx_hash = ::Ruby::Hash.new
52
52
  idx_hash.__send__(
53
53
  :[]=,
54
54
  0,
@@ -84,7 +84,7 @@
84
84
  )) {0}
85
85
  row = self.line_map_for(string).fetch(nl_idx).__send__(
86
86
  :+,
87
- 1
87
+ 2
88
88
  )
89
89
  col = idx.__send__(
90
90
  :-,
@@ -95,12 +95,12 @@
95
95
  col
96
96
  ]
97
97
  )}
98
- declare_meme(:push_layer, [], nil, ::Myco.cscope.dup) { |*| (self.capt_stack.push(::Hash.new))}
98
+ declare_meme(:push_layer, [], nil, ::Myco.cscope.dup) { |*| (self.capt_stack.push(::Ruby::Hash.new))}
99
99
  declare_meme(:pop_layer, [], nil, ::Myco.cscope.dup) { |*| (self.capt_stack.pop)}
100
100
  declare_meme(:setup, [], nil, ::Myco.cscope.dup) { |*| (self.push_layer)}
101
101
  declare_meme(:final_captures, [], nil, ::Myco.cscope.dup) { |*| (self.pop_layer.select { |k, v| (k.__send__(
102
102
  :is_a?,
103
- ::Symbol
103
+ ::Myco.find_constant(:Symbol)
104
104
  ))}.map { |k, v| ([
105
105
  k,
106
106
  v.last
@@ -254,7 +254,7 @@
254
254
  value = []
255
255
  captures.each { |k, v| (::Myco.branch_op(:"&&", ::Myco.branch_op(:"&&", ::Myco.branch_op(:"&&", k.__send__(
256
256
  :is_a?,
257
- ::Fixnum
257
+ ::Myco.find_constant(:Fixnum)
258
258
  )) {k.__send__(
259
259
  :<=,
260
260
  idx
data/lib/myco/command.my CHANGED
@@ -8,7 +8,7 @@ BasicCommand {
8
8
 
9
9
  run: |*argv| {
10
10
  files = options_parse(*argv)
11
- files && files.uniq.each |file| { Myco.eval_file(file, [::Dir.pwd]) }
11
+ files && files.uniq.each |file| { Myco.eval_file(file, [Dir.pwd]) }
12
12
  }
13
13
 
14
14
  [options]
@@ -10,7 +10,7 @@
10
10
  files = self.options_parse(*argv)
11
11
  ::Myco.branch_op(:"&&", files) {files.uniq.each { |file| (::Myco.find_constant(:Myco).eval_file(
12
12
  file,
13
- [::Dir.pwd]
13
+ [::Myco.find_constant(:Dir).pwd]
14
14
  ))}}
15
15
  )}
16
16
  __category__(:options).component_eval {(
@@ -16,6 +16,8 @@
16
16
  cache: true # Enable caching of the value to act as storage
17
17
  }
18
18
 
19
+ # TODO: add const decorator to make all of these decorators 'thunks'
20
+
19
21
  # The 'var' decorator creates an instance variable getter and setter:
20
22
  var: Decorator {
21
23
  [transforms]
@@ -28,8 +30,8 @@
28
30
  cache: true
29
31
  }
30
32
 
31
- # The 'sclass' decorator makes the component's singleton class the target
32
- sclass: Decorator {
33
+ # The 'static' decorator makes the component's singleton class the target
34
+ static: Decorator {
33
35
  [transforms]
34
36
  target: |meme| meme.target.singleton_class
35
37
  }
@@ -39,7 +41,7 @@
39
41
  apply: |meme| {
40
42
  orig_meme = meme.target.memes[meme.name]
41
43
  wrap_meme = meme.dup
42
- meme.body = Proc.new |*a,&b| {
44
+ meme.body = &|*a,&b| {
43
45
  wrap_meme.result_for(self,*a,&b)
44
46
  orig_meme.result_for(self,*a,&b)
45
47
  }
@@ -51,7 +53,7 @@
51
53
  apply: |meme| {
52
54
  orig_meme = meme.target.memes[meme.name]
53
55
  wrap_meme = meme.dup
54
- meme.body = Proc.new |*a,&b| {
56
+ meme.body = &|*a,&b| {
55
57
  result = \
56
58
  orig_meme.result_for(self,*a,&b)
57
59
  wrap_meme.result_for(self,*a,&b)
@@ -65,7 +67,7 @@
65
67
  apply: |meme| {
66
68
  orig_meme = meme.target.memes[meme.name]
67
69
  wrap_meme = meme.dup
68
- meme.body = Proc.new |*a,&b| {
70
+ meme.body = &|*a,&b| {
69
71
  new_a = \
70
72
  wrap_meme.result_for(self,*a)
71
73
  orig_meme.result_for(self,*new_a,&b)
@@ -78,7 +80,7 @@
78
80
  apply: |meme| {
79
81
  orig_meme = meme.target.memes[meme.name]
80
82
  wrap_meme = meme.dup
81
- meme.body = Proc.new |*a,&b| {
83
+ meme.body = &|*a,&b| {
82
84
  result = \
83
85
  orig_meme.result_for(self,*a,&b)
84
86
  wrap_meme.result_for(self,result)
@@ -90,7 +92,7 @@
90
92
  setter: Decorator {
91
93
  apply: |meme| {
92
94
  wrap_meme = meme.dup
93
- meme.setter = Proc.new |orig_value| {
95
+ meme.setter = &|orig_value| {
94
96
  wrap_meme.result_for(self,orig_value)
95
97
  }
96
98
  }
@@ -100,7 +102,7 @@
100
102
  getter: Decorator {
101
103
  apply: |meme| {
102
104
  wrap_meme = meme.dup
103
- meme.getter = Proc.new |orig_value| {
105
+ meme.getter = &|orig_value| {
104
106
  wrap_meme.result_for(self,orig_value)
105
107
  }
106
108
  }
@@ -15,7 +15,7 @@
15
15
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(__category__(:transforms).component_eval {(declare_meme(:var, [], nil, ::Myco.cscope.dup) { |*| (true)})})}}.instance)}
16
16
  declare_meme(:memoize, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
17
17
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(__category__(:transforms).component_eval {(declare_meme(:cache, [], nil, ::Myco.cscope.dup) { |*| (true)})})}}.instance)}
18
- declare_meme(:sclass, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
18
+ declare_meme(:static, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
19
19
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(__category__(:transforms).component_eval {(declare_meme(:target, [], nil, ::Myco.cscope.dup) { |meme| (meme.target.singleton_class)})})}}.instance)}
20
20
  declare_meme(:before, [], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
21
21
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
@@ -26,7 +26,7 @@
26
26
  wrap_meme = meme.dup
27
27
  meme.__send__(
28
28
  :body=,
29
- ::Myco.find_constant(:Proc).new { |*a, &b| (
29
+ ::Proc.new { |*a, &b| (
30
30
  wrap_meme.result_for(
31
31
  self,
32
32
  *a,
@@ -49,7 +49,7 @@
49
49
  wrap_meme = meme.dup
50
50
  meme.__send__(
51
51
  :body=,
52
- ::Myco.find_constant(:Proc).new { |*a, &b| (
52
+ ::Proc.new { |*a, &b| (
53
53
  result = orig_meme.result_for(
54
54
  self,
55
55
  *a,
@@ -73,7 +73,7 @@
73
73
  wrap_meme = meme.dup
74
74
  meme.__send__(
75
75
  :body=,
76
- ::Myco.find_constant(:Proc).new { |*a, &b| (
76
+ ::Proc.new { |*a, &b| (
77
77
  new_a = wrap_meme.result_for(
78
78
  self,
79
79
  *a
@@ -95,7 +95,7 @@
95
95
  wrap_meme = meme.dup
96
96
  meme.__send__(
97
97
  :body=,
98
- ::Myco.find_constant(:Proc).new { |*a, &b| (
98
+ ::Proc.new { |*a, &b| (
99
99
  result = orig_meme.result_for(
100
100
  self,
101
101
  *a,
@@ -113,7 +113,7 @@
113
113
  wrap_meme = meme.dup
114
114
  meme.__send__(
115
115
  :setter=,
116
- ::Myco.find_constant(:Proc).new { |orig_value| (wrap_meme.result_for(
116
+ ::Proc.new { |orig_value| (wrap_meme.result_for(
117
117
  self,
118
118
  orig_value
119
119
  ))}
@@ -124,7 +124,7 @@
124
124
  wrap_meme = meme.dup
125
125
  meme.__send__(
126
126
  :getter=,
127
- ::Myco.find_constant(:Proc).new { |orig_value| (wrap_meme.result_for(
127
+ ::Proc.new { |orig_value| (wrap_meme.result_for(
128
128
  self,
129
129
  orig_value
130
130
  ))}
@@ -3,20 +3,51 @@
3
3
  # Basic conditional handling
4
4
  if: |cond, &blk| cond && blk.call
5
5
  unless: |cond, &blk| cond || blk.call
6
- switch: |input,comparator=:"=="|
6
+ case: |input, *rest| {
7
+ # If there is a final strategy with no test value, use it as the else case
8
+ use_strategy = rest.size.odd? && rest.pop
9
+ # Iterate over the pairs of test_values and strategies,
10
+ # selecting the first matching pair's strategy as the one to use.
11
+ rest.each_slice(2).detect |test_value, strategy| {
12
+ (test_value == input) && (
13
+ use_strategy = strategy
14
+ true
15
+ )
16
+ }
17
+ # Call or return the selected strategy or error if none
18
+ use_strategy &? (use_strategy.?call(input) ?? use_strategy)
19
+ ?? raise("No match for case("input")")
20
+ }
21
+ cond: |*rest| {
22
+ # If there is a final strategy with no test value, use it as the else case
23
+ use_strategy = rest.size.odd? && rest.pop
24
+ # Iterate over the pairs of test_values and strategies,
25
+ # selecting the first matching pair's strategy as the one to use.
26
+ rest.each_slice(2).detect |test_value, strategy| {
27
+ (test_value.?call ?? test_value) && (
28
+ use_strategy = strategy
29
+ true
30
+ )
31
+ }
32
+ # Call or return the selected strategy or error if none
33
+ use_strategy &? (use_strategy.?call ?? use_strategy)
34
+ ?? raise("No match for cond")
35
+ }
36
+
37
+ switch: |input,comparator=:"=="| # TODO: remove deprecated switch
7
38
  Switch.new(input:input, comparator:comparator)
8
39
 
9
40
  # TODO: alias more efficiently
10
- # alias(::Kernel, :raise) raise
11
- # alias(::Kernel, :loop) loop
12
- raise: |*args| ::Kernel.instance_method(:raise).bind(self).call(*args)
13
- loop: |&block| ::Kernel.instance_method(:loop).bind(self).call(&block)
14
- break: raise(::StopIteration)
41
+ # alias(::Ruby::Kernel, :raise) raise
42
+ # alias(::Ruby::Kernel, :loop) loop
43
+ raise: |*args| ::Ruby::Kernel.instance_method(:raise).bind(self).call(*args)
44
+ loop: |&block| ::Ruby::Kernel.instance_method(:loop).bind(self).call(&block)
45
+ break: raise(::Ruby::StopIteration)
15
46
 
16
47
  puts: |*args| STDOUT.puts(*args)
17
48
  p: |*args| STDOUT.puts(args.map |a| { a.inspect }.join(', '))
18
49
 
19
- ruby_require: |arg| Object.send(:require, arg)
50
+ ruby_require: |arg| ::Ruby.send(:require, arg)
20
51
  }
21
52
 
22
53
  # Because ::Myco::Instance is a ::BasicObject, we must shadow ::BasicObject here
@@ -8,16 +8,35 @@
8
8
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
9
9
  declare_meme(:if, [], nil, ::Myco.cscope.dup) { |cond, &blk| (::Myco.branch_op(:"&&", cond) {blk.call})}
10
10
  declare_meme(:unless, [], nil, ::Myco.cscope.dup) { |cond, &blk| (::Myco.branch_op(:"||", cond) {blk.call})}
11
+ declare_meme(:case, [], nil, ::Myco.cscope.dup) { |input, *rest| (
12
+ use_strategy = ::Myco.branch_op(:"&&", rest.size.__send__(:odd?)) {rest.pop}
13
+ rest.each_slice(2).detect { |test_value, strategy| (::Myco.branch_op(:"&&", test_value.__send__(
14
+ :==,
15
+ input
16
+ )) {(
17
+ use_strategy = strategy
18
+ true
19
+ )})}
20
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", use_strategy) {::Myco.branch_op(:"??", (use_strategy.respond_to?(:call).false? ? ::Myco::Void : use_strategy.call(input))) {use_strategy}}) {self.raise("No match for case(#{input})")}
21
+ )}
22
+ declare_meme(:cond, [], nil, ::Myco.cscope.dup) { |*rest| (
23
+ use_strategy = ::Myco.branch_op(:"&&", rest.size.__send__(:odd?)) {rest.pop}
24
+ rest.each_slice(2).detect { |test_value, strategy| (::Myco.branch_op(:"&&", ::Myco.branch_op(:"??", (test_value.respond_to?(:call).false? ? ::Myco::Void : test_value.call)) {test_value}) {(
25
+ use_strategy = strategy
26
+ true
27
+ )})}
28
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", use_strategy) {::Myco.branch_op(:"??", (use_strategy.respond_to?(:call).false? ? ::Myco::Void : use_strategy.call)) {use_strategy}}) {self.raise("No match for cond")}
29
+ )}
11
30
  declare_meme(:switch, [], nil, ::Myco.cscope.dup) { |input, comparator=:==| (::Myco.find_constant(:Switch).new({
12
31
  :input => input,
13
32
  :comparator => comparator
14
33
  }))}
15
- declare_meme(:raise, [], nil, ::Myco.cscope.dup) { |*args| (::Kernel.instance_method(:raise).bind(self).call(*args))}
16
- declare_meme(:loop, [], nil, ::Myco.cscope.dup) { |&block| (::Kernel.instance_method(:loop).bind(self).call(&block))}
17
- declare_meme(:break, [], nil, ::Myco.cscope.dup) { |*| (self.raise(::StopIteration))}
34
+ declare_meme(:raise, [], nil, ::Myco.cscope.dup) { |*args| (::Ruby::Kernel.instance_method(:raise).bind(self).call(*args))}
35
+ declare_meme(:loop, [], nil, ::Myco.cscope.dup) { |&block| (::Ruby::Kernel.instance_method(:loop).bind(self).call(&block))}
36
+ declare_meme(:break, [], nil, ::Myco.cscope.dup) { |*| (self.raise(::Ruby::StopIteration))}
18
37
  declare_meme(:puts, [], nil, ::Myco.cscope.dup) { |*args| (::Myco.find_constant(:STDOUT).puts(*args))}
19
38
  declare_meme(:p, [], nil, ::Myco.cscope.dup) { |*args| (::Myco.find_constant(:STDOUT).puts(args.map { |a| (a.inspect)}.join(", ")))}
20
- declare_meme(:ruby_require, [], nil, ::Myco.cscope.dup) { |arg| (::Myco.find_constant(:Object).send(
39
+ declare_meme(:ruby_require, [], nil, ::Myco.cscope.dup) { |arg| (::Ruby.send(
21
40
  :require,
22
41
  arg
23
42
  ))}
@@ -7,7 +7,7 @@ BasicCommand < Object {
7
7
  options_parse: |*argv| {
8
8
  command = argv.first && self.commands.memes[argv.first.to_sym]
9
9
  command
10
- &? (command.result.run(*argv.slice(::Range.new(1, -1))); null)
10
+ &? (command.result.run(*argv.slice(Range.new(1, -1))); null)
11
11
  ?? options_parser.parse(argv)
12
12
  }
13
13
 
@@ -11,7 +11,7 @@
11
11
  argv.first.to_sym
12
12
  )}
13
13
  ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", command) {(
14
- command.result.run(*argv.slice(::Range.new(
14
+ command.result.run(*argv.slice(::Myco.find_constant(:Range).new(
15
15
  1,
16
16
  -1
17
17
  )))
data/lib/myco/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Myco
3
- MYCO_VERSION = '0.1.6'
3
+ MYCO_VERSION = '0.1.7'
4
4
 
5
5
  MYCO_REQUIRED_GEMS = [
6
6
  ['rubinius-toolset', '~> 2.3'],
data/lib/myco.rb CHANGED
@@ -11,6 +11,9 @@ require_relative 'myco/backtrace'
11
11
  require_relative 'myco/bootstrap'
12
12
 
13
13
 
14
+ # TODO: remove this hack after 0.1.7 gem release
15
+ ::Ruby = ::Object
16
+
14
17
  # Detect whether a second pass is necessary (when no bytecode is available)
15
18
  # TODO: recursively check mtime for all rbc files as well,
16
19
  # to be sure that core implementation files don't need to be recompiled.