myco 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/myco/bootstrap/add_method.rb +38 -0
  3. data/lib/myco/bootstrap/component.rb +43 -21
  4. data/lib/myco/bootstrap/find_constant.rb +73 -25
  5. data/lib/myco/bootstrap/instance.rb +96 -25
  6. data/lib/myco/bootstrap/meme.rb +18 -12
  7. data/lib/myco/bootstrap/tuple.rb +13 -0
  8. data/lib/myco/bootstrap/undefined.rb +9 -0
  9. data/lib/myco/bootstrap/void.rb +5 -4
  10. data/lib/myco/bootstrap.my +24 -13
  11. data/lib/myco/bootstrap.my.rb +41 -4
  12. data/lib/myco/bootstrap.rb +4 -0
  13. data/lib/myco/code_loader.rb +11 -9
  14. data/lib/myco/code_tools/AST/Block.my.rb +2 -2
  15. data/lib/myco/code_tools/AST/ConstantAccess.my.rb +4 -4
  16. data/lib/myco/code_tools/AST/ConstantAssignment.my.rb +4 -4
  17. data/lib/myco/code_tools/AST/Invoke.my +1 -1
  18. data/lib/myco/code_tools/AST/Invoke.my.rb +1 -1
  19. data/lib/myco/code_tools/AST/Node.my +2 -4
  20. data/lib/myco/code_tools/AST/Node.my.rb +3 -3
  21. data/lib/myco/code_tools/AST/PipeOperator.my.rb +1 -1
  22. data/lib/myco/code_tools/AST/ToRuby.my.rb +8 -8
  23. data/lib/myco/code_tools/AST/misc.my.rb +1 -1
  24. data/lib/myco/code_tools/Parser.my +8 -15
  25. data/lib/myco/code_tools/Parser.my.rb +8 -14
  26. data/lib/myco/code_tools/parser/MycoBuilder.my +3 -4
  27. data/lib/myco/code_tools/parser/MycoBuilder.my.rb +5 -6
  28. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my +8 -4
  29. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeHelpers.my.rb +5 -5
  30. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my +2 -2
  31. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeInstructions.my.rb +12 -12
  32. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my +54 -44
  33. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/BytecodeParser.my.rb +69 -83
  34. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my +18 -8
  35. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Grammar.my.rb +24 -10
  36. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Machine.my.rb +1 -1
  37. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my +1 -1
  38. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Parser.my.rb +1 -2
  39. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my +1 -1
  40. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Patterns.my.rb +1 -1
  41. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my +3 -3
  42. data/lib/myco/code_tools/parser/pegleromyces/lib/pegleromyces/Processor.my.rb +5 -6
  43. data/lib/myco/code_tools/parser/pegleromyces/spec/BasicSpec.my +35 -0
  44. data/lib/myco/code_tools/parser/pegleromyces/spec/BasicSpec.my.rb +35 -0
  45. data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my +10 -0
  46. data/lib/myco/code_tools/parser/pegleromyces/spec/Builder.test.my.rb +9 -0
  47. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my +10 -0
  48. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeInstructions.test.my.rb +9 -0
  49. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeParser.test.my +81 -0
  50. data/lib/myco/code_tools/parser/pegleromyces/spec/BytecodeParser.test.my.rb +209 -0
  51. data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my +229 -0
  52. data/lib/myco/code_tools/parser/pegleromyces/spec/Constructions.test.my.rb +663 -0
  53. data/lib/myco/code_tools/parser/pegleromyces/spec/Grammar.test.my +10 -0
  54. data/lib/myco/code_tools/parser/pegleromyces/spec/Grammar.test.my.rb +9 -0
  55. data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my +10 -0
  56. data/lib/myco/code_tools/parser/pegleromyces/spec/Instructions.test.my.rb +9 -0
  57. data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my +13 -0
  58. data/lib/myco/code_tools/parser/pegleromyces/spec/Machine.test.my.rb +20 -0
  59. data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my +54 -0
  60. data/lib/myco/code_tools/parser/pegleromyces/spec/Parser.test.my.rb +215 -0
  61. data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my +156 -0
  62. data/lib/myco/code_tools/parser/pegleromyces/spec/Patterns.test.my.rb +334 -0
  63. data/lib/myco/code_tools/parser/pegleromyces/spec/Processor.test.my +10 -0
  64. data/lib/myco/code_tools/parser/pegleromyces/spec/Processor.test.my.rb +9 -0
  65. data/lib/myco/code_tools/parser/pegleromyces/spec/run.my +20 -0
  66. data/lib/myco/code_tools/parser/pegleromyces/spec/run.my.rb +16 -0
  67. data/lib/myco/core/BasicDecorators.my +19 -11
  68. data/lib/myco/core/BasicDecorators.my.rb +24 -20
  69. data/lib/myco/core/BasicObject.my +12 -7
  70. data/lib/myco/core/BasicObject.my.rb +50 -44
  71. data/lib/myco/core/Category.my +12 -2
  72. data/lib/myco/core/Category.my.rb +15 -7
  73. data/lib/myco/core/Decorator.my +1 -1
  74. data/lib/myco/core/Decorator.my.rb +8 -10
  75. data/lib/myco/core/FileToplevel.my +3 -3
  76. data/lib/myco/core/FileToplevel.my.rb +4 -6
  77. data/lib/myco/core/Object.my +7 -10
  78. data/lib/myco/core/Object.my.rb +11 -17
  79. data/lib/myco/core/Ruby.my +6 -0
  80. data/lib/myco/core/Ruby.my.rb +16 -0
  81. data/lib/myco/core/Switch.my +1 -1
  82. data/lib/myco/core/Switch.my.rb +1 -1
  83. data/lib/myco/core.my +4 -0
  84. data/lib/myco/core.my.rb +7 -0
  85. data/lib/myco/dev/call_sites.rb +39 -0
  86. data/lib/myco/dev/counter.rb +26 -0
  87. data/lib/myco/dev.rb +3 -0
  88. data/lib/myco/eval.rb +1 -1
  89. data/lib/myco/tools/BasicCommand.my.rb +1 -1
  90. data/lib/myco/version.rb +1 -1
  91. data/lib/myco.rb +2 -3
  92. metadata +53 -20
  93. data/lib/myco/bootstrap/evaluator.rb +0 -58
@@ -1,46 +1,52 @@
1
1
 
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(
4
- ::Myco::BasicObject = ::Myco::Component.new([
5
- ::Myco::EmptyObject,
6
- ::Myco::BasicDecorators
7
- ], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
8
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(
9
- declare_meme(:if, [], nil, ::Myco.cscope.dup) { |cond, &blk| (::Myco.branch_op(:"&&", cond) {blk.call})}
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
- )}
30
- declare_meme(:switch, [], nil, ::Myco.cscope.dup) { |input, comparator=:==| (::Myco.find_constant(:Switch).new({
31
- :input => input,
32
- :comparator => comparator
33
- }))}
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))}
37
- declare_meme(:puts, [], nil, ::Myco.cscope.dup) { |*args| (::Myco.find_constant(:STDOUT).puts(*args))}
38
- declare_meme(:p, [], nil, ::Myco.cscope.dup) { |*args| (::Myco.find_constant(:STDOUT).puts(args.map { |a| (a.inspect)}.join(", ")))}
39
- declare_meme(:ruby_require, [], nil, ::Myco.cscope.dup) { |arg| (::Ruby.send(
40
- :require,
41
- arg
42
- ))}
43
- )}}
44
- .tap { |__c__| __c__.__name__ = :BasicObject }
45
- ::Myco::Instance::BasicObject = (::Myco::BasicObject)
46
- )}}.instance
3
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::BasicObject.component_eval {(
4
+ declare_meme(:if, [], nil, ::Myco.cscope.dup) { |cond, &blk| (::Myco.branch_op(:"&&", cond) {blk.call})}
5
+ declare_meme(:unless, [], nil, ::Myco.cscope.dup) { |cond, &blk| (::Myco.branch_op(:"||", cond) {blk.call})}
6
+ declare_meme(:case, [], nil, ::Myco.cscope.dup) { |input, *rest| (
7
+ use_strategy = ::Myco.branch_op(:"&&", rest.size.__send__(:odd?)) {rest.pop}
8
+ rest.each_slice(2).detect { |test_value, strategy| (::Myco.branch_op(:"&&", test_value.__send__(
9
+ :==,
10
+ input
11
+ )) {(
12
+ use_strategy = strategy
13
+ true
14
+ )})}
15
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", use_strategy) {::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(use_strategy, :call).false? ? ::Myco::Void : use_strategy.call(input))) {use_strategy}}) {self.raise("No match for case(#{input})")}
16
+ )}
17
+ declare_meme(:cond, [], nil, ::Myco.cscope.dup) { |*rest| (
18
+ use_strategy = ::Myco.branch_op(:"&&", rest.size.__send__(:odd?)) {rest.pop}
19
+ rest.each_slice(2).detect { |test_value, strategy| (::Myco.branch_op(:"&&", ::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(test_value, :call).false? ? ::Myco::Void : test_value.call)) {test_value}) {(
20
+ use_strategy = strategy
21
+ true
22
+ )})}
23
+ ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", use_strategy) {::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(use_strategy, :call).false? ? ::Myco::Void : use_strategy.call)) {use_strategy}}) {self.raise("No match for cond")}
24
+ )}
25
+ declare_meme(:switch, [], nil, ::Myco.cscope.dup) { |input, comparator=:==| (::Myco.find_constant(:Switch).new({
26
+ :input => input,
27
+ :comparator => comparator
28
+ }))}
29
+ declare_meme(:raise, [], nil, ::Myco.cscope.dup) { |*args| (::Object.__send__(
30
+ :raise,
31
+ *args
32
+ ))}
33
+ declare_meme(:loop, [], nil, ::Myco.cscope.dup) { |&block| (::Object.__send__(
34
+ :loop,
35
+ &block
36
+ ))}
37
+ declare_meme(:break, [], nil, ::Myco.cscope.dup) { |*| (self.raise(::Object::StopIteration))}
38
+ declare_meme(:send, [], nil, ::Myco.cscope.dup) { |*args, &block| (self.__send__(
39
+ *args,
40
+ &block
41
+ ))}
42
+ declare_meme(:kind_of?, [], nil, ::Myco.cscope.dup) { |mod| (self.__kind_of__(mod))}
43
+ declare_meme(:is_a?, [], nil, ::Myco.cscope.dup) { |mod| (self.__kind_of__(mod))}
44
+ declare_meme(:class, [], nil, ::Myco.cscope.dup) { |*| (self.__class__)}
45
+ declare_meme(:dup, [], nil, ::Myco.cscope.dup) { |*| (self.__dup__)}
46
+ declare_meme(:puts, [], nil, ::Myco.cscope.dup) { |*args| (::Myco.find_constant(:STDOUT).puts(*args))}
47
+ declare_meme(:p, [], nil, ::Myco.cscope.dup) { |*args| (::Myco.find_constant(:STDOUT).puts(args.map { |a| (a.inspect)}.join(", ")))}
48
+ declare_meme(:ruby_require, [], nil, ::Myco.cscope.dup) { |arg| (::Object.send(
49
+ :require,
50
+ arg
51
+ ))}
52
+ )})}}.instance
@@ -1,5 +1,15 @@
1
1
 
2
- ::Myco::Category < ::Myco::EmptyObject {
2
+ ::Myco::Category << {
3
3
  # Forward unknown methods to parent
4
- method_missing: |sym, *a, &b| parent.send(sym, *a, &b)
4
+ method_missing: |sym, *a, &b| parent.__send__(sym, *a, &b)
5
+
6
+ # TODO: make DRY with respect to BasicObject.my (or remove these methods entirely...)
7
+ send: |*args, &block| __send__(*args, &block)
8
+
9
+ kind_of?: |mod| __kind_of__(mod)
10
+ is_a?: |mod| __kind_of__(mod)
11
+
12
+ class: __class__ # TODO: consider removing
13
+
14
+ dup: __dup__ # TODO: remove
5
15
  }
@@ -1,9 +1,17 @@
1
1
 
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Category = ::Myco::Component.new([::Myco::EmptyObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:method_missing, [], nil, ::Myco.cscope.dup) { |sym, *a, &b| (self.parent.send(
5
- sym,
6
- *a,
7
- &b
8
- ))})}}
9
- .tap { |__c__| __c__.__name__ = :Category })}}.instance
3
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Category.component_eval {(
4
+ declare_meme(:method_missing, [], nil, ::Myco.cscope.dup) { |sym, *a, &b| (self.parent.__send__(
5
+ sym,
6
+ *a,
7
+ &b
8
+ ))}
9
+ declare_meme(:send, [], nil, ::Myco.cscope.dup) { |*args, &block| (self.__send__(
10
+ *args,
11
+ &block
12
+ ))}
13
+ declare_meme(:kind_of?, [], nil, ::Myco.cscope.dup) { |mod| (self.__kind_of__(mod))}
14
+ declare_meme(:is_a?, [], nil, ::Myco.cscope.dup) { |mod| (self.__kind_of__(mod))}
15
+ declare_meme(:class, [], nil, ::Myco.cscope.dup) { |*| (self.__class__)}
16
+ declare_meme(:dup, [], nil, ::Myco.cscope.dup) { |*| (self.__dup__)}
17
+ )})}}.instance
@@ -1,5 +1,5 @@
1
1
 
2
- ::Myco::Decorator < ::Myco::BasicObject {
2
+ ::Myco::Decorator << {
3
3
  # Implement the apply meme to mutate the incoming meme in more custom ways.
4
4
  # This is run after transforms.apply has already mutated the meme.
5
5
  apply: |meme, *args| { }
@@ -1,33 +1,31 @@
1
1
 
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Decorator = ::Myco::Component.new([::Myco::BasicObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(
3
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Decorator.component_eval {(
5
4
  declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme, *args| nil}
6
5
  __category__(:transforms).component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme, *args| (
7
- (self.respond_to?(:target).false? ? ::Myco::Void : self.target(meme)).tap { |x| (meme.__send__(
6
+ (Rubinius::Type.object_respond_to?(self, :target).false? ? ::Myco::Void : self.target(meme)).tap { |x| (meme.__send__(
8
7
  :target=,
9
8
  x
10
9
  ))}
11
- (self.respond_to?(:name).false? ? ::Myco::Void : self.name(meme)).tap { |x| (meme.__send__(
10
+ (Rubinius::Type.object_respond_to?(self, :name).false? ? ::Myco::Void : self.name(meme)).tap { |x| (meme.__send__(
12
11
  :name=,
13
12
  x
14
13
  ))}
15
- (self.respond_to?(:body).false? ? ::Myco::Void : self.body(meme)).tap { |x| (meme.__send__(
14
+ (Rubinius::Type.object_respond_to?(self, :body).false? ? ::Myco::Void : self.body(meme)).tap { |x| (meme.__send__(
16
15
  :body=,
17
16
  x
18
17
  ))}
19
- (self.respond_to?(:cache).false? ? ::Myco::Void : self.cache(meme)).tap { |x| (meme.__send__(
18
+ (Rubinius::Type.object_respond_to?(self, :cache).false? ? ::Myco::Void : self.cache(meme)).tap { |x| (meme.__send__(
20
19
  :cache=,
21
20
  x
22
21
  ))}
23
- (self.respond_to?(:var).false? ? ::Myco::Void : self.var(meme)).tap { |x| (meme.__send__(
22
+ (Rubinius::Type.object_respond_to?(self, :var).false? ? ::Myco::Void : self.var(meme)).tap { |x| (meme.__send__(
24
23
  :var=,
25
24
  x
26
25
  ))}
27
- (self.respond_to?(:expose).false? ? ::Myco::Void : self.expose(meme)).tap { |x| (meme.__send__(
26
+ (Rubinius::Type.object_respond_to?(self, :expose).false? ? ::Myco::Void : self.expose(meme)).tap { |x| (meme.__send__(
28
27
  :expose=,
29
28
  x
30
29
  ))}
31
30
  )})}
32
- )}}
33
- .tap { |__c__| __c__.__name__ = :Decorator })}}.instance
31
+ )})}}.instance
@@ -1,5 +1,5 @@
1
1
 
2
- ::Myco::FileToplevel < ::Myco::Object {
2
+ ::Myco::FileToplevel << {
3
3
  # TODO: don't use instance_variable_get
4
4
  dirname: component.instance_variable_get("@dirname")
5
5
  basename: component.instance_variable_get("@basename")
@@ -9,7 +9,7 @@
9
9
 
10
10
  # Run the code in the given file, ignoring the return value but
11
11
  # importing the constants defined therein into the current namespace.
12
- var import: Decorator {
12
+ const import: Decorator {
13
13
  apply: |meme| {
14
14
  load_paths = [meme.target.instance.dirname]
15
15
  scope = meme.target.constant_scope
@@ -25,7 +25,7 @@
25
25
  }
26
26
  # Force an import to assign to a constant in the current namespace
27
27
  # instead of being included into the current namespace.
28
- var as: Decorator {
28
+ const as: Decorator {
29
29
  apply: |meme, given| meme.metadata[:as] = given
30
30
  }
31
31
  }
@@ -1,12 +1,11 @@
1
1
 
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::FileToplevel = ::Myco::Component.new([::Myco::Object], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
- .tap { |__c__| __c__.__last__ = __c__.component_eval {(
3
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::FileToplevel.component_eval {(
5
4
  declare_meme(:dirname, [], nil, ::Myco.cscope.dup) { |*| (self.component.instance_variable_get("@dirname"))}
6
5
  declare_meme(:basename, [], nil, ::Myco.cscope.dup) { |*| (self.component.instance_variable_get("@basename"))}
7
6
  declare_meme(:filename, [], nil, ::Myco.cscope.dup) { |*| (self.component.instance_variable_get("@filename"))}
8
7
  __category__(:decorators).component_eval {(
9
- declare_meme(:import, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
8
+ declare_meme(:import, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
10
9
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (
11
10
  load_paths = [meme.target.instance.dirname]
12
11
  scope = meme.target.constant_scope
@@ -25,12 +24,11 @@
25
24
  component
26
25
  )}) {meme.target.include(component)}
27
26
  )})}}.instance)}
28
- declare_meme(:as, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
27
+ declare_meme(:as, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
29
28
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme, given| (meme.metadata.__send__(
30
29
  :[]=,
31
30
  :as,
32
31
  given
33
32
  ))})}}.instance)}
34
33
  )}
35
- )}}
36
- .tap { |__c__| __c__.__name__ = :FileToplevel })}}.instance
34
+ )})}}.instance
@@ -3,22 +3,19 @@
3
3
  # Send the named signal to all handlers for this object
4
4
  __signal__: |name, *args, &block| {
5
5
  component.ancestors.reverse.each |other| {
6
- other.is_a?(Component) && (
7
- inst = (component == other) &? self ?? other.instance
8
- inst.?decorators.?on.?signal_handlers(name).each |meme| {
9
- meme.result_for(self, *args, &block)
10
- }
11
- )
6
+ other.?__signal_handlers__(name).each |meme| {
7
+ meme.result_for(self, *args, &block)
8
+ }
12
9
  }
13
10
  }
14
11
 
12
+ static storage __signal_handlers__: []
13
+
15
14
  [decorators]
16
15
 
17
16
  # Register a named signal handler
18
- var on: Decorator {
19
- storage signal_handlers: Array.new
20
-
21
- apply: |meme| signal_handlers(meme.name).push(meme)
17
+ const on: Decorator {
18
+ apply: |meme| meme.target.__signal_handlers__(meme.name).push(meme)
22
19
 
23
20
  [transforms]
24
21
  expose: false
@@ -2,24 +2,18 @@
2
2
  ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
3
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Object = ::Myco::Component.new([::Myco::BasicObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
4
4
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
5
- declare_meme(:__signal__, [], nil, ::Myco.cscope.dup) { |name, *args, &block| (self.component.ancestors.reverse.each { |other| (::Myco.branch_op(:"&&", other.__send__(
6
- :is_a?,
7
- ::Myco.find_constant(:Component)
8
- )) {(
9
- inst = ::Myco.branch_op(:"??", ::Myco.branch_op(:"&?", self.component.__send__(
10
- :==,
11
- other
12
- )) {self}) {other.instance}
13
- (((inst.respond_to?(:decorators).false? ? ::Myco::Void : inst.decorators).respond_to?(:on).false? ? ::Myco::Void : (inst.respond_to?(:decorators).false? ? ::Myco::Void : inst.decorators).on).respond_to?(:signal_handlers).false? ? ::Myco::Void : ((inst.respond_to?(:decorators).false? ? ::Myco::Void : inst.decorators).respond_to?(:on).false? ? ::Myco::Void : (inst.respond_to?(:decorators).false? ? ::Myco::Void : inst.decorators).on).signal_handlers(name)).each { |meme| (meme.result_for(
14
- self,
15
- *args,
16
- &block
17
- ))}
18
- )})})}
19
- __category__(:decorators).component_eval {(declare_meme(:on, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
5
+ declare_meme(:__signal__, [], nil, ::Myco.cscope.dup) { |name, *args, &block| (self.component.ancestors.reverse.each { |other| ((Rubinius::Type.object_respond_to?(other, :__signal_handlers__).false? ? ::Myco::Void : other.__signal_handlers__(name)).each { |meme| (meme.result_for(
6
+ self,
7
+ *args,
8
+ &block
9
+ ))})})}
10
+ declare_meme(:__signal_handlers__, [
11
+ [:storage, []],
12
+ [:static, []]
13
+ ], nil, ::Myco.cscope.dup) { |*| ([])}
14
+ __category__(:decorators).component_eval {(declare_meme(:on, [[:const, []]], nil, ::Myco.cscope.dup) { |*| (::Myco::Component.new([::Myco.find_constant(:Decorator)], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
20
15
  .tap { |__c__| __c__.__last__ = __c__.component_eval {(
21
- declare_meme(:signal_handlers, [[:storage, []]], nil, ::Myco.cscope.dup) { |*| (::Myco.find_constant(:Array).new)}
22
- declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (self.signal_handlers(meme.name).push(meme))}
16
+ declare_meme(:apply, [], nil, ::Myco.cscope.dup) { |meme| (meme.target.__signal_handlers__(meme.name).push(meme))}
23
17
  __category__(:transforms).component_eval {(declare_meme(:expose, [], nil, ::Myco.cscope.dup) { |*| (false)})}
24
18
  )}}.instance)})}
25
19
  )}}
@@ -0,0 +1,6 @@
1
+
2
+ ::Myco::Ruby < ::Ruby::Object, ::Myco::BasicObject {
3
+ static eval: |*a,&b| Kernel.eval(*a, &b)
4
+
5
+ Eval < ::Myco::EmptyObject { from_string: |string| Ruby.eval(string) }
6
+ }
@@ -0,0 +1,16 @@
1
+
2
+ ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(::Myco::Ruby = ::Myco::Component.new([
4
+ ::Object::Object,
5
+ ::Myco::BasicObject
6
+ ], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
7
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
8
+ declare_meme(:eval, [[:static, []]], nil, ::Myco.cscope.dup) { |*a, &b| (::Myco.find_constant(:Kernel).eval(
9
+ *a,
10
+ &b
11
+ ))}
12
+ ::Myco.cscope.for_method_definition::Eval = ::Myco::Component.new([::Myco::EmptyObject], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
13
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(declare_meme(:from_string, [], nil, ::Myco.cscope.dup) { |string| (::Myco.find_constant(:Ruby).eval(string))})}}
14
+ .tap { |__c__| __c__.__name__ = :Eval }
15
+ )}}
16
+ .tap { |__c__| __c__.__name__ = :Ruby })}}.instance
@@ -6,7 +6,7 @@
6
6
  var comparator: :"=="
7
7
 
8
8
  when: |expected, &blk| {
9
- matched || (input.send(comparator, expected) &&
9
+ matched || (input.__send__(comparator, expected) &&
10
10
  ((matched() = true) && (output() = blk.call(input))))
11
11
  self
12
12
  }
@@ -7,7 +7,7 @@
7
7
  declare_meme(:matched, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (false)}
8
8
  declare_meme(:comparator, [[:var, []]], nil, ::Myco.cscope.dup) { |*| (:==)}
9
9
  declare_meme(:when, [], nil, ::Myco.cscope.dup) { |expected, &blk| (
10
- ::Myco.branch_op(:"||", self.matched) {::Myco.branch_op(:"&&", self.input.send(
10
+ ::Myco.branch_op(:"||", self.matched) {::Myco.branch_op(:"&&", self.input.__send__(
11
11
  self.comparator,
12
12
  expected
13
13
  )) {::Myco.branch_op(:"&&", self.__send__(
data/lib/myco/core.my ADDED
@@ -0,0 +1,4 @@
1
+
2
+ import "core/Object.my"
3
+ import "core/Switch.my"
4
+ import "core/Ruby.my"
@@ -0,0 +1,7 @@
1
+
2
+ ::Myco::Component.new([::Myco::FileToplevel], ::Myco.cscope.for_method_definition, __FILE__, __LINE__)
3
+ .tap { |__c__| __c__.__last__ = __c__.component_eval {(
4
+ declare_meme(:"core/Object.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
5
+ declare_meme(:"core/Switch.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
6
+ declare_meme(:"core/Ruby.my", [[:import, []]], nil, ::Myco.cscope.dup) { |*| nil}
7
+ )}}.instance
@@ -0,0 +1,39 @@
1
+
2
+ module Myco
3
+ module DEV
4
+ class CallSites
5
+ class << self
6
+
7
+ def report(*modules)
8
+ list = []
9
+ if modules.empty?
10
+ ObjectSpace.each_object(Module) { |mod| analyze_module(mod, list) }
11
+ else
12
+ modules.each { |mod| analyze_module(mod, list) }
13
+ end
14
+ list.uniq.sort
15
+ end
16
+
17
+ def report!(*args, count: 2000)
18
+ list = report(*args)
19
+ list = list[-count..-1] if list.size > count
20
+ list.each { |item| p item }
21
+ end
22
+
23
+ def analyze_module(mod, list)
24
+ mod.method_table.each_entry do |name, executable, _|
25
+ if executable.respond_to?(:call_sites)
26
+ executable.call_sites.each do |cache|
27
+ called = "#{cache.stored_module}##{cache.method.name}" rescue "#{cache.name}"
28
+ caller = "#{mod}##{name}"
29
+ location = "#{executable.active_path}:#{executable.line_from_ip(0)}"
30
+
31
+ list.push [cache.hits, "#{called} in #{caller} near #{location}"]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+
2
+ module Myco
3
+ module DEV
4
+ class Counter
5
+ class << self
6
+ def coll
7
+ @coll ||= begin
8
+ at_exit { print! }
9
+ Hash.new(0)
10
+ end
11
+ end
12
+
13
+ def count(*items)
14
+ coll[items] += 1
15
+ end
16
+
17
+ def print!
18
+ STDOUT.puts "#{self} report:"
19
+ coll.to_a.sort_by { |x| x.last }.each do |key,val|
20
+ STDOUT.puts " #{val} : #{key.inspect}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/myco/dev.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require_relative 'dev/counter'
3
+ require_relative 'dev/call_sites'
data/lib/myco/eval.rb CHANGED
@@ -10,7 +10,7 @@ module Myco
10
10
  end
11
11
 
12
12
  # TODO: deprecate with proper import set of functions
13
- def self.eval_file path, load_paths=nil, get_last=true, scope=nil
13
+ def self.eval_file path, load_paths=nil, get_last=true, scope=Rubinius::ConstantScope.new(::Myco, nil)
14
14
  load_paths ||= [File.dirname(Rubinius::VM.backtrace(1).first.file)]
15
15
  file_toplevel = CodeLoader.load(path, load_paths, cscope:scope, call_depth:1)
16
16
  get_last ? file_toplevel.component.__last__ : file_toplevel.component
@@ -42,7 +42,7 @@
42
42
  )
43
43
  args = [
44
44
  name,
45
- ::Myco.branch_op(:"??", (self.respond_to?(:argument).false? ? ::Myco::Void : self.argument)) {nil},
45
+ ::Myco.branch_op(:"??", (Rubinius::Type.object_respond_to?(self, :argument).false? ? ::Myco::Void : self.argument)) {nil},
46
46
  self.long_form,
47
47
  self.description
48
48
  ]
data/lib/myco/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Myco
3
- MYCO_VERSION = '0.1.7'
3
+ MYCO_VERSION = '0.1.8'
4
4
 
5
5
  MYCO_REQUIRED_GEMS = [
6
6
  ['rubinius-toolset', '~> 2.3'],
data/lib/myco.rb CHANGED
@@ -3,6 +3,7 @@ require_relative 'myco/version'
3
3
  Myco.activate_required_gems
4
4
 
5
5
  Myco::SingletonClass = Myco.singleton_class
6
+ require_relative 'myco/dev'
6
7
 
7
8
  require_relative 'myco/code_loader'
8
9
  require_relative 'myco/eval'
@@ -11,9 +12,6 @@ require_relative 'myco/backtrace'
11
12
  require_relative 'myco/bootstrap'
12
13
 
13
14
 
14
- # TODO: remove this hack after 0.1.7 gem release
15
- ::Ruby = ::Object
16
-
17
15
  # Detect whether a second pass is necessary (when no bytecode is available)
18
16
  # TODO: recursively check mtime for all rbc files as well,
19
17
  # to be sure that core implementation files don't need to be recompiled.
@@ -33,6 +31,7 @@ stages.each do |toolset_name|
33
31
  # TODO: be more clever here communicating the load path for bootstrapping
34
32
  Myco::CoreLoadPath = File.expand_path('myco', File.dirname(__FILE__))
35
33
  Myco.eval_file 'myco/bootstrap.my'
34
+ Myco.eval_file 'myco/core.my'
36
35
  end
37
36
 
38
37
  require "rubinius/compiler"