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/README.md DELETED
@@ -1 +0,0 @@
1
- Atomo-like language on the Rubinius VM.
data/kernel/block.ay DELETED
@@ -1,30 +0,0 @@
1
- namespace(atomy)
2
-
3
- macro(x onto(&b)):
4
- names [ctx]:
5
- shadowed? = false
6
-
7
- blk = b through-quotes [n]:
8
- n match:
9
- `@~(v: Atomy::AST::Variable) -> do:
10
- shadowed? =! true
11
- `(~ctx instance-variable-get(#~("@" + v name)))
12
-
13
- 'self -> do:
14
- shadowed? =! true
15
- ctx
16
-
17
- Atomy::AST::Send ? @private ->
18
- n dup tap [p]:
19
- p receiver = 'self
20
-
21
- Atomy::AST::BinarySend ? @private ->
22
- n dup tap [p]:
23
- p lhs = 'self
24
-
25
- _ ->
26
- n
27
-
28
- if(shadowed?)
29
- then: `(do: ~ctx = self, ~blk block call-on-instance(~x))
30
- else: `(~b block call-on-instance(~x))
data/kernel/boot.ay DELETED
@@ -1,10 +0,0 @@
1
- macro(_LINE): line
2
- macro(_FILE): Atomy::AST::File new(line)
3
-
4
- macro(import(name)): `(require-atomy(~name, "load" to-sym))
5
-
6
- "operators define cosmetics data comparison dynamic control-flow namespaces
7
- patterns precision data-delta documentation particles hashes node block errors
8
- doc pretty format concurrency io condition therie repl" split each [k]:
9
- puts("loading " + k)
10
- import(File expand-path("../", _FILE) + "/" + k)
data/kernel/comparison.ay DELETED
@@ -1,61 +0,0 @@
1
- module(Atomy::AST):
2
- class(And < Node):
3
- children(#a, #b)
4
- generate
5
-
6
- bytecode(g) := do:
7
- pos(g)
8
- done = g new-label
9
- no = g new-label
10
-
11
- @a compile(g)
12
- g dup
13
- g gif(done)
14
-
15
- g pop
16
- @b compile(g)
17
-
18
- done set!
19
-
20
- class(Or < Node):
21
- children(#a, #b)
22
- generate
23
-
24
- bytecode(g) := do:
25
- pos(g)
26
- done = g new-label
27
-
28
- @a compile(g)
29
- g dup
30
- g git(done)
31
-
32
- g pop
33
- @b compile(g)
34
-
35
- done set!
36
-
37
- class(Negate < Node):
38
- children(#expression)
39
- generate
40
-
41
- bytecode(g) := do:
42
- pos(g)
43
- done = g new-label
44
- yes = g new-label
45
-
46
- @expression compile(g)
47
- g git(yes)
48
-
49
- g push-true
50
- g goto(done)
51
-
52
- yes set!
53
- g push-false
54
-
55
- done set!
56
-
57
- macro(a && b): Atomy::AST::And new(line, a, b)
58
- macro(a || b): Atomy::AST::Or new(line, a, b)
59
- macro(!a): Atomy::AST::Negate new(line, a)
60
- macro(a != b): `!(~a == ~b)
61
- macro(a !~ b): `!(~a =~ ~b)
@@ -1,84 +0,0 @@
1
- namespace(atomy)
2
-
3
- require("actor")
4
-
5
- title"Concurrency"
6
-
7
- doc"
8
- Get the current actor.
9
- " spec {
10
- => Actor
11
- } for:
12
- me := Actor current
13
-
14
-
15
- section("Sending & Receiving"):
16
- doc"
17
- Send message \code{v} to the actor.
18
- " spec {
19
- => Actor
20
- } for {
21
- Actor <- v := send(v)
22
- } examples:
23
- a = spawn: receive { 42 -> #ok } write
24
- a <- 42
25
-
26
- doc"
27
- Receive a message sent to the current actor that matches any of the \
28
- patterns listed in \hl{body}. Blocks until a matching message is \
29
- received. Non-matching messages are consumed and ignored.
30
- " spec {
31
- body contents all? [x]: x match { `(~_ -> ~_) -> true, _ -> false }
32
- => any
33
- } for {
34
- macro(receive(&body)):
35
- names [e]:
36
- bs = body contents collect [`(~pat -> ~exp)]:
37
- `(~e when('~pat to-pattern) [~pat]: ~exp)
38
-
39
- `(Actor receive [~e]: ~*bs)
40
- } examples:
41
- a = spawn: receive { 1 -> #got-1 } write
42
- a <- 0
43
- a <- 2
44
- a <- 1
45
-
46
- doc"
47
- Similar to \code{receive}, but with a timeout and an action to \
48
- perform if it times out.
49
- " spec {
50
- body contents all? [x]: x match { `(~_ -> ~_) -> true, _ -> false }
51
- timeout match: `(~_ -> ~_) -> true, _ -> false
52
- => any
53
- } for {
54
- macro(receive(&body) after(timeout)):
55
- names [e]:
56
- bs = body contents collect [`(~pat -> ~exp)]:
57
- `(~e when('~pat to-pattern) [~pat]: ~exp)
58
-
59
- bs << `(~e after(~(timeout lhs)): ~(timeout rhs))
60
-
61
- `(Actor receive [~e]: ~*bs)
62
- } examples:
63
- receive { 1 -> #ok } after(1 -> #too-slow)
64
-
65
-
66
- section("Spawning"):
67
- doc"
68
- Spawn a new actor, performing \code{action}.
69
- " spec {
70
- => Actor
71
- } for {
72
- spawn(&action) := Actor send(#spawn, &action)
73
- } examples:
74
- spawn: (2 + 2) write
75
-
76
- doc"
77
- Spawn a new actor, performing \code{action}, linked to the current \
78
- actor.
79
- " spec {
80
- => Actor
81
- } for {
82
- spawn-link(&action) := Actor send(#spawn-link, &action)
83
- } examples:
84
- spawn-link: (2 + 2) write
data/kernel/cosmetics.ay DELETED
@@ -1,3 +0,0 @@
1
- `($~(x: Atomy::AST::Block)) as-message(send) :=
2
- send receiver to-send dup tap [s]:
3
- s arguments += x contents
data/kernel/data-delta.ay DELETED
@@ -1,105 +0,0 @@
1
- namespace(atomy)
2
-
3
- macro(data(root, &children)):
4
- cs = children contents map [e]:
5
- e match:
6
- Atomy::AST::Send -> do:
7
- name =
8
- Atomy::AST::Constant new(0, e method-name)
9
-
10
- pat = name
11
-
12
- tmps = names(e arguments size) collect [t]:
13
- Atomy::AST::Unquote new(0, t)
14
-
15
- e arguments zip(tmps) [[a, t]]:
16
- pat =! `(~pat & with(~a, ~t))
17
-
18
- cons = `(~(name)(~*tmps))
19
-
20
- pat-def =
21
- `(~(Atomy::AST::QuasiQuote new(0, cons)) pattern :=
22
- ~(Atomy::AST::QuasiQuote new(0, pat)) pattern)
23
-
24
- define =
25
- `(export:
26
- class(~name < ~root):
27
- attr-accessor $:
28
- ~*(e arguments collect [a]:
29
- `#~(a receiver))
30
-
31
- initialize(~*(e arguments)) := nil
32
-
33
- ~pat-def)
34
-
35
- if(e block)
36
- then:
37
- `(do:
38
- ~define
39
-
40
- data(~name):
41
- ~*(e block contents))
42
- else:
43
- define
44
-
45
- Atomy::AST::Constant ->
46
- `(class(~e < ~root):)
47
-
48
- Atomy::AST::ScopedConstant ->
49
- `(class(~e < ~root):)
50
-
51
- Atomy::AST::ToplevelConstant ->
52
- `(class(~e < ~root):)
53
-
54
- _ -> raise("unknown module name: " + e to-s)
55
-
56
- `(do: class(~root):;, ~*cs, nil)
57
-
58
-
59
- macro(macro-quoter(n, &x)):
60
- `(evaluate-when(compile, load):
61
- Atomy::Macro::Environment quoter(#~n, &~x))
62
-
63
- macro-quoter(w) [c]: c split
64
-
65
- macro-quoter(r) [c, fs]:
66
- flags = 0
67
-
68
- when(fs include?("m")):
69
- flags |= Regexp::MULTILINE
70
-
71
- when(fs include?("i")):
72
- flags |= Regexp::IGNORECASE
73
-
74
- when(fs include?("x")):
75
- flags |= Regexp::EXTENDED
76
-
77
- when(fs include?("u")):
78
- flags |= Regexp::KCODE_UTF8
79
-
80
- `(Regexp new(~c, ~flags))
81
-
82
- macro-quoter(raw) [c]: c
83
-
84
- macro(_undefined):
85
- Atomy::AST::Undefined new(line)
86
-
87
- macro($(x: Primitive ? @value is-a?(::Integer) && @value > 0)):
88
- Atomy::AST::NthRef new(line, x value)
89
-
90
- export:
91
- module(Atomy::AST):
92
- class(Undefined < Node):
93
- generate
94
-
95
- bytecode(g) := do:
96
- pos(g)
97
- g push-undef
98
-
99
- pattern := Atomy::Patterns::Any new
100
-
101
- class(NthRef < Rubinius::AST::NthRef):
102
- include(NodeLike)
103
- extend(SentientNode)
104
- attributes(#which)
105
- generate
@@ -1,135 +0,0 @@
1
- namespace(atomy/documentation)
2
-
3
- in-namespace(atomy):
4
- symbols(pretty, show)
5
-
6
- for-macro:
7
- escape(x) :=
8
- x gsub(r"[\{\}\\]", raw"\\\0")
9
-
10
- indent(x, n = 1) :=
11
- x split("\n") collect [x] { (" " * n * 2) + x } join("\n")
12
-
13
- str-expr(e) :=
14
- escape $:
15
- e match:
16
- String -> e
17
- Atomy::AST::String -> e value
18
- _ -> e show
19
-
20
- to-thumb(x: Atomy::AST::Macro) :=
21
- indent(escape(x pattern show))
22
- to-thumb(`(~meth := ~_)) :=
23
- indent(escape(meth show))
24
- to-thumb(d: `(data(Object))) :=
25
- let(atomy/pretty/multiline? = true):
26
- indent(escape(d block body show))
27
- to-thumb(d: `(data(~r))) :=
28
- let(atomy/pretty/multiline? = true):
29
- indent(escape(`(~r ~(d block)) show))
30
- to-thumb(`(dynamic(~n, ~r))) :=
31
- indent(`^~n show + "\n> " + r show)
32
- to-thumb(`(class(~n))) :=
33
- indent(n show + "\n> Class")
34
- to-thumb(`(module(~n))) :=
35
- indent(n show + "\n> Module")
36
- to-thumb(x) := str-expr(x)
37
-
38
- to-spec([]) := ""
39
- to-spec(b) :=
40
- "\n" + indent $:
41
- b collect [e] {
42
- e match:
43
- `(=> ~x) ->
44
- "> " + str-expr(x)
45
-
46
- _ ->
47
- "| " + str-expr(e)
48
- } join("\n")
49
-
50
- to-examples(b) :=
51
- b collect [e] {
52
- " " + str-expr(e)
53
- } join("\n")
54
-
55
- export-to(atomy):
56
- -- TODO: shoudln't need to export this; not being resolved in #section
57
- macro(for-docs(&body)):
58
- `(when(^documentation):
59
- ^documentation << ~(body block-body))
60
-
61
- macro-quoter(doc) [c]:
62
- for-docs:
63
- c + "\n\n"
64
-
65
- c
66
-
67
- macro-quoter(title) [c]:
68
- for-docs:
69
- "\\title{" + escape(c) + "}\n\n"
70
-
71
- c
72
-
73
- macro(section(name, &body)):
74
- `(do:
75
- evaluate-when(compile):
76
- for-docs: "\\section{" + ~name + "}{\n\\style{Atomy}\n\n"
77
-
78
- res = ~(body caller)
79
-
80
- evaluate-when(compile):
81
- for-docs: "}"
82
-
83
- res)
84
-
85
- macro(docs spec(&s) for(&code)):
86
- for-docs:
87
- [ "\\define{"
88
- "\n" + to-thumb(code contents first)
89
- to-spec(s contents)
90
- "\n}{"
91
- docs contents
92
- "}\n\n"
93
- ] join
94
-
95
- code block-body
96
-
97
- macro(docs for(&code)):
98
- for-docs:
99
- [ "\\define{"
100
- "\n" + to-thumb(code contents first)
101
- "\n}{"
102
- docs contents
103
- "}\n\n"
104
- ] join
105
-
106
- code block-body
107
-
108
- macro(docs spec(&s) for(&code) examples(&es)):
109
- for-docs:
110
- [ "\\define{"
111
- "\n" + to-thumb(code contents first)
112
- to-spec(s contents)
113
- "\n}{"
114
- docs contents
115
- "\n \\examples{"
116
- "\n" + to-examples(es contents)
117
- "\n }"
118
- "\n}\n\n"
119
- ] join
120
-
121
- code block-body
122
-
123
- macro(docs for(&code) examples(&es)):
124
- for-docs:
125
- [ "\\define{"
126
- "\n" + to-thumb(code contents first)
127
- "\n}{"
128
- docs contents
129
- "\n \\examples{"
130
- "\n" + to-examples(es contents)
131
- "\n }"
132
- "\n}\n\n"
133
- ] join
134
-
135
- code block-body
data/kernel/errors.ay DELETED
@@ -1,6 +0,0 @@
1
- MethodFail message :=
2
- ("method '" + @method-name to-s + "' did not understand " +
3
- "its arguments (non-exhaustive patterns)")
4
-
5
- PatternMismatch message :=
6
- "irrefutable pattern failed for " + @pattern to-s