myco 0.1.0.dev → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -7
  2. data/LICENSE +1 -1
  3. data/README.md +79 -0
  4. data/lib/myco/backtrace.rb +1 -1
  5. data/lib/myco/bootstrap/component.rb +78 -39
  6. data/lib/myco/bootstrap/find_constant.rb +12 -1
  7. data/lib/myco/bootstrap/instance.rb +5 -12
  8. data/lib/myco/bootstrap/meme.rb +176 -28
  9. data/lib/myco/bootstrap.my +8 -7
  10. data/lib/myco/code_loader.rb +332 -0
  11. data/lib/myco/command/inoculate.my +83 -0
  12. data/lib/myco/command.my +26 -26
  13. data/lib/myco/core/BasicDecorators.my +62 -0
  14. data/lib/myco/core/BasicObject.my +12 -34
  15. data/lib/myco/core/Decorator.my +1 -0
  16. data/lib/myco/core/FileToplevel.my +0 -3
  17. data/lib/myco/core/Myco.my +4 -0
  18. data/lib/myco/core/Object.my +6 -4
  19. data/lib/myco/eval.rb +17 -18
  20. data/lib/myco/misc.rb +16 -0
  21. data/lib/myco/parser/ast/argument_assembly.rb +76 -0
  22. data/lib/myco/parser/ast/array_assembly.rb +57 -0
  23. data/lib/myco/parser/ast/branch_operator.rb +73 -0
  24. data/lib/myco/parser/ast/constant_access.rb +4 -18
  25. data/lib/myco/parser/ast/constant_define.rb +3 -3
  26. data/lib/myco/parser/ast/constant_reopen.rb +12 -13
  27. data/lib/myco/parser/ast/declare_category.rb +8 -6
  28. data/lib/myco/parser/ast/declare_decorator.rb +4 -4
  29. data/lib/myco/parser/ast/declare_file.rb +4 -4
  30. data/lib/myco/parser/ast/declare_meme.rb +53 -11
  31. data/lib/myco/parser/ast/declare_object.rb +9 -7
  32. data/lib/myco/parser/ast/declare_string.rb +5 -5
  33. data/lib/myco/parser/ast/invoke.rb +18 -36
  34. data/lib/myco/parser/ast/invoke_method.rb +28 -0
  35. data/lib/myco/parser/ast/local_variable_access_ambiguous.rb +9 -13
  36. data/lib/myco/parser/ast/misc.rb +128 -33
  37. data/lib/myco/parser/ast/myco_module_scope.rb +26 -0
  38. data/lib/myco/parser/ast/quest.rb +3 -3
  39. data/lib/myco/parser/ast/to_ruby/array_assembly.rb +15 -0
  40. data/lib/myco/parser/ast/to_ruby/block.rb +14 -0
  41. data/lib/myco/parser/ast/to_ruby/block_pass.rb +6 -0
  42. data/lib/myco/parser/ast/to_ruby/branch_operator.rb +9 -0
  43. data/lib/myco/parser/ast/to_ruby/constant_access.rb +10 -0
  44. data/lib/myco/parser/ast/to_ruby/constant_assignment.rb +6 -0
  45. data/lib/myco/parser/ast/to_ruby/constant_define.rb +9 -0
  46. data/lib/myco/parser/ast/to_ruby/constant_reopen.rb +6 -0
  47. data/lib/myco/parser/ast/to_ruby/declare_category.rb +7 -0
  48. data/lib/myco/parser/ast/to_ruby/declare_decorator.rb +6 -0
  49. data/lib/myco/parser/ast/to_ruby/declare_file.rb +6 -0
  50. data/lib/myco/parser/ast/to_ruby/declare_meme.rb +16 -0
  51. data/lib/myco/parser/ast/to_ruby/declare_object.rb +8 -0
  52. data/lib/myco/parser/ast/to_ruby/declare_string.rb +6 -0
  53. data/lib/myco/parser/ast/to_ruby/dynamic_string.rb +14 -0
  54. data/lib/myco/parser/ast/to_ruby/dynamic_symbol.rb +7 -0
  55. data/lib/myco/parser/ast/to_ruby/eval_expression.rb +6 -0
  56. data/lib/myco/parser/ast/to_ruby/false_literal.rb +6 -0
  57. data/lib/myco/parser/ast/to_ruby/hash_literal.rb +16 -0
  58. data/lib/myco/parser/ast/to_ruby/invoke.rb +6 -0
  59. data/lib/myco/parser/ast/to_ruby/invoke_method.rb +35 -0
  60. data/lib/myco/parser/ast/to_ruby/iter.rb +10 -0
  61. data/lib/myco/parser/ast/to_ruby/local_variable_access_ambiguous.rb +16 -0
  62. data/lib/myco/parser/ast/to_ruby/local_variable_assignment.rb +8 -0
  63. data/lib/myco/parser/ast/to_ruby/myco_module_scope.rb +8 -0
  64. data/lib/myco/parser/ast/to_ruby/null_literal.rb +6 -0
  65. data/lib/myco/parser/ast/to_ruby/parameters.rb +60 -0
  66. data/lib/myco/parser/ast/to_ruby/quest.rb +13 -0
  67. data/lib/myco/parser/ast/to_ruby/return.rb +7 -0
  68. data/lib/myco/parser/ast/to_ruby/scoped_constant.rb +11 -0
  69. data/lib/myco/parser/ast/to_ruby/self.rb +6 -0
  70. data/lib/myco/parser/ast/to_ruby/splat_value.rb +33 -0
  71. data/lib/myco/parser/ast/to_ruby/string_literal.rb +6 -0
  72. data/lib/myco/parser/ast/to_ruby/symbol_literal.rb +6 -0
  73. data/lib/myco/parser/ast/to_ruby/toplevel_constant.rb +11 -0
  74. data/lib/myco/parser/ast/to_ruby/true_literal.rb +6 -0
  75. data/lib/myco/parser/ast/to_ruby/void_literal.rb +6 -0
  76. data/lib/myco/parser/ast/to_ruby.rb +138 -0
  77. data/lib/myco/parser/ast.rb +6 -0
  78. data/lib/myco/parser/peg_parser.rb +361 -181
  79. data/lib/myco/parser.rb +27 -11
  80. data/lib/myco/tools/BasicCommand.my +42 -0
  81. data/lib/myco/tools/Generator.my +18 -0
  82. data/lib/myco/toolset.rb +0 -3
  83. data/lib/myco/version.rb +1 -4
  84. data/lib/myco.rb +2 -0
  85. metadata +230 -160
  86. data/lib/myco/parser/builder.output +0 -3995
  87. data/lib/myco/parser/builder.racc +0 -585
  88. data/lib/myco/parser/builder.rb +0 -1592
  89. data/lib/myco/parser/lexer.rb +0 -2306
  90. data/lib/myco/parser/lexer.rl +0 -393
  91. data/lib/myco/parser/lexer_char_classes.rl +0 -56
  92. data/lib/myco/parser/lexer_common.rb +0 -95
  93. data/lib/myco/parser/lexer_skeleton.rl +0 -154
  94. data/lib/myco/parser/peg_parser.kpeg +0 -759
  95. data/lib/myco/tools/OptionParser.my +0 -38
@@ -0,0 +1,6 @@
1
+
2
+ class CodeTools::AST::Self
3
+ def to_ruby g
4
+ g.add("self")
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+
2
+ class CodeTools::AST::SplatValue
3
+ def to_ruby g
4
+ if @value.is_a?(self.class)
5
+ @value.to_ruby(g)
6
+ else
7
+ g.add("*")
8
+ @value.to_ruby(g)
9
+ end
10
+ end
11
+ end
12
+
13
+ module CodeTools::AST
14
+ class CollectSplat
15
+ def to_ruby g
16
+ # TODO
17
+ end
18
+ end
19
+ end
20
+
21
+ module CodeTools::AST
22
+ class ConcatArgs
23
+ def to_ruby g
24
+ # TODO
25
+ end
26
+ end
27
+ end
28
+
29
+ class CodeTools::AST::PushArgs
30
+ def to_ruby g
31
+ # TODO
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class CodeTools::AST::StringLiteral
3
+ def to_ruby g
4
+ g.add(@string.inspect)
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class CodeTools::AST::SymbolLiteral
3
+ def to_ruby g
4
+ g.add(@value.inspect)
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+
2
+ class CodeTools::AST::ToplevelConstant
3
+ def to_ruby g
4
+ g.add("::#{@name}")
5
+ end
6
+
7
+ def to_ruby_assign g, value
8
+ to_ruby(g)
9
+ g.add(" = "); g.add(value)
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class CodeTools::AST::TrueLiteral
3
+ def to_ruby g
4
+ g.add("true")
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class CodeTools::AST::VoidLiteral
3
+ def to_ruby g
4
+ g.add("::Myco::Void")
5
+ end
6
+ end
@@ -0,0 +1,138 @@
1
+
2
+ module CodeTools::AST
3
+ class ToRuby
4
+ def initialize
5
+ @lines = []
6
+ @indents = [""]
7
+
8
+ @var_scopes = []
9
+ end
10
+
11
+ # The currently held string of generated ruby code
12
+ def to_s
13
+ @lines.join("\n")
14
+ end
15
+
16
+ # Start a new line, optionally adding a string
17
+ # or an object that responds to :to_ruby
18
+ def line string=""
19
+ if string.is_a?(String)
20
+ @lines.push(@indents.last + string)
21
+ else
22
+ line
23
+ string.to_ruby(self)
24
+ end
25
+ end
26
+
27
+ # Add to the current line a string
28
+ # or an object that responds to :to_ruby
29
+ def add string
30
+ if string.is_a?(String)
31
+ (@lines.last || @lines[0]="").concat(string)
32
+ else
33
+ string.to_ruby(self)
34
+ end
35
+ end
36
+
37
+ ##
38
+ # Stack of indent levels (as strings to be prefixed)
39
+ #
40
+ def push_indent amount=2
41
+ @indents.push(@indents.last + " "*2)
42
+ end
43
+
44
+ def pop_indent
45
+ @indents.pop
46
+ end
47
+
48
+ ##
49
+ # Stack of every AST node in hierarchy that can hold local variables
50
+ #
51
+ def var_scope
52
+ @var_scopes.last
53
+ end
54
+
55
+ def with_nested_var_scope node
56
+ @var_scopes.push(node)
57
+ yield
58
+ ensure
59
+ @var_scopes.pop
60
+ end
61
+
62
+ def var_scope_has_local? name
63
+ @var_scopes.reverse.each { |scope|
64
+ return true if scope.variables.has_key?(name)
65
+ }
66
+ return false
67
+ end
68
+
69
+ def var_scope_declare_local name
70
+ var_scope.variables[name] = true
71
+ end
72
+
73
+ def var_scope_declare_locals names
74
+ names.each { |name| var_scope_declare_local(name) }
75
+ end
76
+
77
+ ##
78
+ # Helper methods
79
+
80
+ # TODO: make comprehensive
81
+ # Return false if the given indent might be problematic in generated Ruby
82
+ def easy_ident? sym
83
+ str = sym.to_s
84
+ return false if !(str=~/^[a-z_][A-Za-z_]*$/)
85
+ return false if %i(
86
+ if unless and or def do class module end break begin rescue ensure
87
+ ).include?(sym)
88
+ return true
89
+ end
90
+ end
91
+
92
+ class Node
93
+ def to_ruby_code
94
+ g = ToRuby.new
95
+ to_ruby(g)
96
+ g.to_s
97
+ end
98
+ end
99
+ end
100
+
101
+
102
+ require_relative "to_ruby/self"
103
+ require_relative "to_ruby/null_literal"
104
+ require_relative "to_ruby/void_literal"
105
+ require_relative "to_ruby/true_literal"
106
+ require_relative "to_ruby/false_literal"
107
+ require_relative "to_ruby/string_literal"
108
+ require_relative "to_ruby/symbol_literal"
109
+ require_relative "to_ruby/hash_literal"
110
+ require_relative "to_ruby/dynamic_string"
111
+ require_relative "to_ruby/dynamic_symbol"
112
+ require_relative "to_ruby/scoped_constant"
113
+ require_relative "to_ruby/toplevel_constant"
114
+ require_relative "to_ruby/constant_access"
115
+ require_relative "to_ruby/constant_assignment"
116
+ require_relative "to_ruby/constant_define"
117
+ require_relative "to_ruby/constant_reopen"
118
+ require_relative "to_ruby/myco_module_scope"
119
+ require_relative "to_ruby/declare_file"
120
+ require_relative "to_ruby/declare_object"
121
+ require_relative "to_ruby/declare_string"
122
+ require_relative "to_ruby/declare_category"
123
+ require_relative "to_ruby/declare_meme"
124
+ require_relative "to_ruby/declare_decorator"
125
+ require_relative "to_ruby/parameters"
126
+ require_relative "to_ruby/block"
127
+ require_relative "to_ruby/invoke"
128
+ require_relative "to_ruby/invoke_method"
129
+ require_relative "to_ruby/local_variable_assignment"
130
+ require_relative "to_ruby/local_variable_access_ambiguous"
131
+ require_relative "to_ruby/splat_value"
132
+ require_relative "to_ruby/block_pass"
133
+ require_relative "to_ruby/iter"
134
+ require_relative "to_ruby/quest"
135
+ require_relative "to_ruby/branch_operator"
136
+ require_relative "to_ruby/return"
137
+ require_relative "to_ruby/array_assembly"
138
+ require_relative "to_ruby/eval_expression"
@@ -10,6 +10,12 @@ require_relative "ast/declare_object"
10
10
  require_relative "ast/declare_string"
11
11
  require_relative "ast/invoke"
12
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"
13
16
  require_relative "ast/quest"
17
+ require_relative "ast/branch_operator"
14
18
 
15
19
  require_relative "ast/misc"
20
+
21
+ require_relative "ast/to_ruby"