atomy 0.1.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +13 -0
  3. data/LICENSE.md +201 -0
  4. data/bin/atomy +16 -133
  5. data/kernel/array.ay +6 -0
  6. data/kernel/atomy.ay +18 -0
  7. data/kernel/condition.ay +171 -271
  8. data/kernel/control-flow.ay +197 -192
  9. data/kernel/core.ay +120 -0
  10. data/kernel/data.ay +83 -39
  11. data/kernel/define.ay +84 -93
  12. data/kernel/doc.ay +282 -449
  13. data/kernel/dynamic.ay +25 -29
  14. data/kernel/file.ay +9 -0
  15. data/kernel/grammar.ay +267 -0
  16. data/kernel/hash.ay +17 -0
  17. data/kernel/interpolation.ay +59 -0
  18. data/kernel/io.ay +70 -244
  19. data/kernel/let-macro.ay +24 -0
  20. data/kernel/let-pattern.ay +24 -0
  21. data/kernel/loop.ay +80 -0
  22. data/kernel/mutation.ay +53 -0
  23. data/kernel/particles.ay +176 -39
  24. data/kernel/patterns.ay +527 -191
  25. data/kernel/pretty.ay +311 -277
  26. data/kernel/quotes.ay +29 -0
  27. data/kernel/range.ay +4 -0
  28. data/kernel/regexp.ay +23 -0
  29. data/kernel/repl.ay +83 -109
  30. data/kernel/stack-local.ay +21 -0
  31. data/lib/atomy.rb +37 -0
  32. data/lib/atomy/bootstrap.rb +256 -0
  33. data/lib/atomy/code/assign.rb +64 -0
  34. data/lib/atomy/code/block.rb +98 -0
  35. data/lib/atomy/code/class_variable.rb +17 -0
  36. data/lib/atomy/code/constant.rb +21 -0
  37. data/lib/atomy/code/define.rb +242 -0
  38. data/lib/atomy/code/define_function.rb +51 -0
  39. data/lib/atomy/code/define_method.rb +20 -0
  40. data/lib/atomy/code/false.rb +9 -0
  41. data/lib/atomy/code/instance_variable.rb +15 -0
  42. data/lib/atomy/code/integer.rb +13 -0
  43. data/lib/atomy/code/list.rb +17 -0
  44. data/lib/atomy/code/nil.rb +9 -0
  45. data/lib/atomy/code/pattern.rb +23 -0
  46. data/lib/atomy/code/pattern/and.rb +61 -0
  47. data/lib/atomy/code/pattern/quasi_quote.rb +185 -0
  48. data/lib/atomy/code/pattern/splat.rb +29 -0
  49. data/lib/atomy/code/pattern/wildcard.rb +37 -0
  50. data/lib/atomy/code/quasi_quote.rb +118 -0
  51. data/lib/atomy/code/quote.rb +13 -0
  52. data/lib/atomy/code/self.rb +9 -0
  53. data/lib/atomy/code/send.rb +110 -0
  54. data/lib/atomy/code/sequence.rb +23 -0
  55. data/lib/atomy/code/string_literal.rb +53 -0
  56. data/lib/atomy/code/symbol.rb +13 -0
  57. data/lib/atomy/code/true.rb +9 -0
  58. data/lib/atomy/code/undefined.rb +9 -0
  59. data/lib/atomy/code/variable.rb +17 -0
  60. data/lib/atomy/codeloader.rb +218 -0
  61. data/lib/atomy/compiler.rb +57 -0
  62. data/lib/atomy/errors.rb +54 -0
  63. data/lib/atomy/grammar.rb +2278 -0
  64. data/lib/atomy/locals.rb +75 -0
  65. data/lib/atomy/message_structure.rb +277 -0
  66. data/lib/atomy/method.rb +343 -0
  67. data/lib/atomy/module.rb +144 -0
  68. data/lib/atomy/node/constructable.rb +169 -0
  69. data/lib/atomy/node/equality.rb +113 -0
  70. data/lib/atomy/node/meta.rb +206 -0
  71. data/lib/atomy/node/pretty.rb +108 -0
  72. data/lib/atomy/parser.rb +21 -0
  73. data/lib/atomy/pattern.rb +26 -0
  74. data/lib/atomy/pattern/and.rb +59 -0
  75. data/lib/atomy/pattern/attribute.rb +16 -0
  76. data/lib/atomy/pattern/class_variable.rb +15 -0
  77. data/lib/atomy/pattern/equality.rb +42 -0
  78. data/lib/atomy/pattern/instance_variable.rb +15 -0
  79. data/lib/atomy/pattern/kind_of.rb +20 -0
  80. data/lib/atomy/pattern/or.rb +48 -0
  81. data/lib/atomy/pattern/quasi_quote.rb +164 -0
  82. data/lib/atomy/pattern/splat.rb +15 -0
  83. data/lib/atomy/pattern/wildcard.rb +18 -0
  84. data/lib/atomy/rubygems.rb +48 -0
  85. data/lib/atomy/version.rb +3 -0
  86. metadata +169 -134
  87. data/COPYING +0 -30
  88. data/README.md +0 -1
  89. data/kernel/block.ay +0 -30
  90. data/kernel/boot.ay +0 -10
  91. data/kernel/comparison.ay +0 -61
  92. data/kernel/concurrency.ay +0 -84
  93. data/kernel/cosmetics.ay +0 -3
  94. data/kernel/data-delta.ay +0 -105
  95. data/kernel/documentation.ay +0 -135
  96. data/kernel/errors.ay +0 -6
  97. data/kernel/format.ay +0 -13
  98. data/kernel/format/data.ay +0 -89
  99. data/kernel/format/formatter.ay +0 -345
  100. data/kernel/format/parser.ay +0 -13
  101. data/kernel/hashes.ay +0 -39
  102. data/kernel/namespaces.ay +0 -63
  103. data/kernel/node.ay +0 -48
  104. data/kernel/operators.ay +0 -28
  105. data/kernel/precision.ay +0 -148
  106. data/kernel/therie.ay +0 -204
  107. data/lib/ast/binary_send.rb +0 -44
  108. data/lib/ast/block.rb +0 -268
  109. data/lib/ast/constant.rb +0 -88
  110. data/lib/ast/internal/assign.rb +0 -19
  111. data/lib/ast/internal/block_pass.rb +0 -21
  112. data/lib/ast/internal/catch.rb +0 -247
  113. data/lib/ast/internal/class.rb +0 -30
  114. data/lib/ast/internal/class_variable.rb +0 -23
  115. data/lib/ast/internal/define.rb +0 -174
  116. data/lib/ast/internal/ensure.rb +0 -135
  117. data/lib/ast/internal/file.rb +0 -14
  118. data/lib/ast/internal/global_variable.rb +0 -20
  119. data/lib/ast/internal/if_then_else.rb +0 -24
  120. data/lib/ast/internal/instance_variable.rb +0 -17
  121. data/lib/ast/internal/let_macro.rb +0 -35
  122. data/lib/ast/internal/macro_quote.rb +0 -23
  123. data/lib/ast/internal/match.rb +0 -53
  124. data/lib/ast/internal/module.rb +0 -30
  125. data/lib/ast/internal/pattern.rb +0 -17
  126. data/lib/ast/internal/return.rb +0 -29
  127. data/lib/ast/internal/set.rb +0 -19
  128. data/lib/ast/internal/singleton_class.rb +0 -18
  129. data/lib/ast/internal/splat.rb +0 -14
  130. data/lib/ast/internal/when.rb +0 -24
  131. data/lib/ast/list.rb +0 -25
  132. data/lib/ast/macro.rb +0 -37
  133. data/lib/ast/node.rb +0 -599
  134. data/lib/ast/operator.rb +0 -21
  135. data/lib/ast/particle.rb +0 -13
  136. data/lib/ast/primitive.rb +0 -20
  137. data/lib/ast/quasi_quote.rb +0 -20
  138. data/lib/ast/quote.rb +0 -13
  139. data/lib/ast/send.rb +0 -104
  140. data/lib/ast/splice.rb +0 -32
  141. data/lib/ast/string.rb +0 -23
  142. data/lib/ast/unary.rb +0 -44
  143. data/lib/ast/unquote.rb +0 -45
  144. data/lib/ast/variable.rb +0 -64
  145. data/lib/atomy.kpeg.rb +0 -3995
  146. data/lib/code_loader.rb +0 -137
  147. data/lib/compiler/compiler.rb +0 -155
  148. data/lib/compiler/stages.rb +0 -81
  149. data/lib/formatter.kpeg.rb +0 -1394
  150. data/lib/macros.rb +0 -317
  151. data/lib/method.rb +0 -261
  152. data/lib/namespace.rb +0 -236
  153. data/lib/parser.rb +0 -28
  154. data/lib/patterns.rb +0 -276
  155. data/lib/patterns/any.rb +0 -21
  156. data/lib/patterns/attribute.rb +0 -59
  157. data/lib/patterns/block_pass.rb +0 -54
  158. data/lib/patterns/constant.rb +0 -33
  159. data/lib/patterns/default.rb +0 -44
  160. data/lib/patterns/head_tail.rb +0 -63
  161. data/lib/patterns/list.rb +0 -77
  162. data/lib/patterns/match.rb +0 -45
  163. data/lib/patterns/named.rb +0 -55
  164. data/lib/patterns/named_class.rb +0 -46
  165. data/lib/patterns/named_global.rb +0 -46
  166. data/lib/patterns/named_instance.rb +0 -46
  167. data/lib/patterns/particle.rb +0 -29
  168. data/lib/patterns/quasi_quote.rb +0 -184
  169. data/lib/patterns/quote.rb +0 -33
  170. data/lib/patterns/singleton_class.rb +0 -31
  171. data/lib/patterns/splat.rb +0 -57
  172. data/lib/util.rb +0 -37
data/lib/patterns/any.rb DELETED
@@ -1,21 +0,0 @@
1
- module Atomy::Patterns
2
- class Any < Pattern
3
- def construct(g)
4
- get(g)
5
- g.send :new, 0
6
- end
7
-
8
- def ==(b)
9
- b.kind_of?(Any)
10
- end
11
-
12
- def target(g)
13
- g.push_const :Object
14
- end
15
-
16
- def matches?(g)
17
- g.pop
18
- g.push_true
19
- end
20
- end
21
- end
@@ -1,59 +0,0 @@
1
- module Atomy::Patterns
2
- class Attribute < Pattern
3
- attr_reader :receiver, :name, :arguments
4
-
5
- def initialize(r, n, as = [])
6
- @receiver = r
7
- @name = n
8
- @arguments = as
9
- end
10
-
11
- def construct(g)
12
- get(g)
13
- @receiver.construct(g, nil)
14
- g.push_literal @name
15
- @arguments.each do |a|
16
- a.construct(g)
17
- end
18
- g.make_array @arguments.size
19
- g.send :new, 3
20
- end
21
-
22
- def ==(b)
23
- b.kind_of?(Attribute) and \
24
- @receiver == b.receiver and \
25
- @name == b.name and \
26
- @arguments == b.arguments
27
- end
28
-
29
- def target(g)
30
- # this should be pretty rare, but seems sensible
31
- @receiver.construct(g)
32
- end
33
-
34
- def matches?(g)
35
- g.pop
36
- g.push_true
37
- end
38
-
39
- def deconstruct(g, locals = {})
40
- @receiver.compile(g)
41
- g.swap
42
- @arguments.each do |a|
43
- a.compile(g)
44
- g.swap
45
- end
46
- g.send((@name + "=").to_sym, 1 + @arguments.size)
47
- g.pop
48
- end
49
-
50
- def local_names
51
- []
52
- end
53
-
54
- def bindings
55
- 1
56
- end
57
- end
58
- end
59
-
@@ -1,54 +0,0 @@
1
- module Atomy::Patterns
2
- class BlockPass < Pattern
3
- attr_reader :pattern
4
-
5
- def initialize(p)
6
- @pattern = p
7
- end
8
-
9
- def construct(g)
10
- get(g)
11
- @pattern.construct(g)
12
- g.send :new, 1
13
- end
14
-
15
- def ==(b)
16
- b.kind_of?(BlockPass) and \
17
- @pattern == b.pattern
18
- end
19
-
20
- def target(g)
21
- g.push_const :Object
22
- end
23
-
24
- def matches?(g)
25
- g.pop
26
- g.push_true
27
- end
28
-
29
- def deconstruct(g, locals = {})
30
- nil_block = g.new_label
31
- done = g.new_label
32
-
33
- g.dup
34
- g.is_nil
35
- g.git nil_block
36
-
37
- g.push_cpath_top
38
- g.find_const :Proc
39
- g.swap
40
- g.send :__from_block__, 1
41
- @pattern.deconstruct(g, locals)
42
- g.goto done
43
-
44
- nil_block.set!
45
- g.pop
46
-
47
- done.set!
48
- end
49
-
50
- def local_names
51
- @pattern.local_names
52
- end
53
- end
54
- end
@@ -1,33 +0,0 @@
1
- module Atomy::Patterns
2
- class Constant < Pattern
3
- attr_reader :constant, :ancestors
4
-
5
- def initialize(constant, ancestors = nil)
6
- @constant = constant
7
- @ancestors = ancestors
8
- end
9
-
10
- def construct(g)
11
- get(g)
12
- @constant.construct(g)
13
- @constant.bytecode(g)
14
- g.send :ancestors, 0
15
- g.send :new, 2
16
- end
17
-
18
- def ==(b)
19
- b.kind_of?(Constant) and \
20
- @constant == b.constant
21
- end
22
-
23
- def target(g)
24
- @constant.bytecode(g)
25
- end
26
-
27
- def matches?(g)
28
- target(g)
29
- g.swap
30
- g.kind_of
31
- end
32
- end
33
- end
@@ -1,44 +0,0 @@
1
- module Atomy::Patterns
2
- class Default < Pattern
3
- attr_reader :pattern, :default
4
-
5
- def initialize(p, d)
6
- @pattern = p
7
- @default = d
8
- end
9
-
10
- def construct(g)
11
- get(g)
12
- @pattern.construct(g)
13
- @default.construct(g, nil)
14
- g.send :new, 2
15
- end
16
-
17
- def ==(b)
18
- b.kind_of?(Default) and \
19
- @pattern == b.pattern and \
20
- @default == b.default
21
- end
22
-
23
- def target(g)
24
- @pattern.target(g)
25
- end
26
-
27
- def matches?(g)
28
- @pattern.matches?(g)
29
- end
30
-
31
- def deconstruct(g, locals = {})
32
- @pattern.deconstruct(g, locals)
33
- end
34
-
35
- def local_names
36
- @pattern.local_names
37
- end
38
-
39
- def bindings
40
- @pattern.bindings
41
- end
42
- end
43
- end
44
-
@@ -1,63 +0,0 @@
1
- module Atomy::Patterns
2
- class HeadTail < Pattern
3
- attr_reader :head, :tail
4
-
5
- def initialize(head, tail)
6
- @head = head
7
- @tail = tail
8
- end
9
-
10
- def construct(g)
11
- get(g)
12
- @head.construct(g)
13
- @tail.construct(g)
14
- g.send :new, 2
15
- end
16
-
17
- def ==(b)
18
- b.kind_of?(HeadTail) and \
19
- @head == b.head and \
20
- @tail == b.tail
21
- end
22
-
23
- def target(g)
24
- g.push_const :Array
25
- end
26
-
27
- def matches?(g)
28
- mismatch = g.new_label
29
- matched = g.new_label
30
-
31
- g.dup
32
- g.send :empty?, 0
33
- g.git mismatch
34
-
35
- g.shift_array
36
- @head.matches?(g)
37
- g.gif mismatch
38
-
39
- @tail.matches?(g)
40
- g.goto matched
41
-
42
- mismatch.set!
43
- g.pop
44
- g.push_false
45
-
46
- matched.set!
47
- end
48
-
49
- def deconstruct(g, locals = {})
50
- g.shift_array
51
- @head.deconstruct(g, locals)
52
- @tail.deconstruct(g, locals)
53
- end
54
-
55
- def local_names
56
- @head.local_names + @tail.local_names
57
- end
58
-
59
- def bindings
60
- @head.bindings + @tail.bindings
61
- end
62
- end
63
- end
data/lib/patterns/list.rb DELETED
@@ -1,77 +0,0 @@
1
- module Atomy::Patterns
2
- class List < Pattern
3
- attr_reader :patterns
4
-
5
- def initialize(ps)
6
- @patterns = ps
7
- end
8
-
9
- def construct(g)
10
- get(g)
11
- @patterns.each do |p|
12
- p.construct(g)
13
- end
14
- g.make_array @patterns.size
15
- g.send :new, 1
16
- end
17
-
18
- def ==(b)
19
- b.kind_of?(List) and \
20
- @patterns == b.patterns
21
- end
22
-
23
- def target(g)
24
- g.push_const :Array
25
- end
26
-
27
- def matches?(g)
28
- matched = g.new_label
29
- mismatch = g.new_label
30
-
31
- g.dup
32
- g.push_cpath_top
33
- g.find_const :Array
34
- g.swap
35
- g.kind_of
36
- g.gif mismatch
37
-
38
- g.dup
39
- g.send :size, 0
40
- g.push @patterns.size
41
- g.send :==, 1
42
- g.gif mismatch
43
-
44
- @patterns.each do |p|
45
- g.shift_array
46
- p.matches?(g)
47
- g.gif mismatch
48
- end
49
- g.pop
50
-
51
- g.push_true
52
- g.goto matched
53
-
54
- mismatch.set!
55
- g.pop
56
- g.push_false
57
-
58
- matched.set!
59
- end
60
-
61
- def deconstruct(g, locals = {})
62
- @patterns.each do |p|
63
- g.shift_array
64
- p.deconstruct(g, locals)
65
- end
66
- g.pop
67
- end
68
-
69
- def local_names
70
- @patterns.collect { |p| p.local_names }.flatten
71
- end
72
-
73
- def bindings
74
- @patterns.reduce(0) { |a, p| p.bindings + a }
75
- end
76
- end
77
- end
@@ -1,45 +0,0 @@
1
- module Atomy::Patterns
2
- class Match < Pattern
3
- attr_reader :value
4
-
5
- def initialize(x)
6
- @value = x
7
- end
8
-
9
- def construct(g)
10
- get(g)
11
- g.push_literal @value
12
- g.send :new, 1
13
- end
14
-
15
- def ==(b)
16
- b.kind_of?(Match) and \
17
- @value == b.value
18
- end
19
-
20
- def target(g)
21
- case @value
22
- when :true
23
- g.push_const :TrueClass
24
- when :false
25
- g.push_const :FalseClass
26
- when :nil
27
- g.push_const :NilClass
28
- when :self
29
- g.push_self
30
- else
31
- g.push_const @value.class.name.to_sym
32
- end
33
- end
34
-
35
- def matches?(g)
36
- case @value
37
- when :true, :false, :self, :nil, Integer
38
- g.push @value
39
- else
40
- g.push_literal @value
41
- end
42
- g.send :==, 1
43
- end
44
- end
45
- end
@@ -1,55 +0,0 @@
1
- module Atomy::Patterns
2
- class Named < Pattern
3
- attr_reader :name, :pattern
4
-
5
- def initialize(n, p)
6
- @name = n
7
- @pattern = p
8
- end
9
-
10
- def construct(g)
11
- get(g)
12
- g.push_literal @name
13
- @pattern.construct(g)
14
- g.send :new, 2
15
- end
16
-
17
- def ==(b)
18
- b.kind_of?(Named) and \
19
- @name == b.name and \
20
- @pattern == b.pattern
21
- end
22
-
23
- def target(g)
24
- @pattern.target(g)
25
- end
26
-
27
- def matches?(g)
28
- @pattern.matches?(g)
29
- end
30
-
31
- def deconstruct(g, locals = {})
32
- if locals[@name]
33
- local = locals[@name]
34
- else
35
- local = Atomy.assign_local(g, @name)
36
- end
37
-
38
- if @pattern.bindings > 0
39
- g.dup
40
- @pattern.deconstruct(g, locals)
41
- end
42
-
43
- local.set_bytecode(g)
44
- g.pop
45
- end
46
-
47
- def local_names
48
- [@name] + @pattern.local_names
49
- end
50
-
51
- def bindings
52
- 1 + @pattern.bindings
53
- end
54
- end
55
- end