fancy 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. data/README.md +38 -86
  2. data/bin/fdoc +2 -22
  3. data/bin/fspec +8 -3
  4. data/bin/ifancy +1 -1
  5. data/boot/fancy_ext.rb +1 -0
  6. data/boot/fancy_ext/array.rb +19 -0
  7. data/boot/fancy_ext/class.rb +2 -4
  8. data/boot/fancy_ext/module.rb +2 -0
  9. data/boot/fancy_ext/object.rb +0 -17
  10. data/boot/rbx-compiler/compiler/ast/method_def.rb +0 -4
  11. data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +0 -7
  12. data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
  13. data/boot/rbx-compiler/parser/fancy_parser.c +1 -0
  14. data/doc/api/fancy.css +10 -1
  15. data/doc/api/fancy.jsonp +1 -1
  16. data/doc/api/fdoc.js +22 -9
  17. data/doc/api/octocat.png +0 -0
  18. data/doc/features.md +1 -2
  19. data/examples/actors.fy +1 -2
  20. data/examples/armstrong_numbers.fy +7 -3
  21. data/examples/blocks.fy +3 -3
  22. data/examples/distributing_proxy.fy +31 -0
  23. data/examples/future_sends.fy +15 -0
  24. data/examples/person.fy +1 -2
  25. data/lib/argv.fy +1 -7
  26. data/lib/array.fy +7 -11
  27. data/lib/block.fy +15 -0
  28. data/lib/boot.fy +4 -3
  29. data/lib/class.fy +354 -10
  30. data/lib/compiler.fy +1 -1
  31. data/lib/compiler/ast/assign.fy +4 -8
  32. data/lib/compiler/ast/async_send.fy +1 -2
  33. data/lib/compiler/ast/block.fy +5 -0
  34. data/lib/compiler/ast/class_def.fy +2 -1
  35. data/lib/compiler/ast/expression_list.fy +1 -2
  36. data/lib/compiler/ast/future_send.fy +1 -2
  37. data/lib/compiler/ast/identifier.fy +34 -17
  38. data/lib/compiler/ast/literals.fy +31 -19
  39. data/lib/compiler/ast/match.fy +5 -4
  40. data/lib/compiler/ast/message_send.fy +3 -5
  41. data/lib/compiler/ast/method_def.fy +0 -3
  42. data/lib/compiler/ast/range.fy +2 -4
  43. data/lib/compiler/ast/return.fy +2 -4
  44. data/lib/compiler/ast/script.fy +2 -4
  45. data/lib/compiler/ast/singleton_method_def.fy +0 -3
  46. data/lib/compiler/ast/string_interpolation.fy +2 -2
  47. data/lib/compiler/ast/super.fy +2 -4
  48. data/lib/compiler/ast/try_catch.fy +13 -9
  49. data/lib/compiler/ast/tuple_literal.fy +1 -2
  50. data/lib/compiler/compiler.fy +2 -2
  51. data/lib/compiler/stages.fy +3 -6
  52. data/lib/contracts.fy +89 -57
  53. data/lib/dynamic_slot_object.fy +21 -3
  54. data/lib/enumerable.fy +140 -4
  55. data/lib/enumerator.fy +1 -1
  56. data/lib/eval.fy +23 -9
  57. data/lib/exception.fy +16 -0
  58. data/lib/false_class.fy +36 -5
  59. data/lib/fancy_spec.fy +64 -34
  60. data/lib/fdoc.fy +85 -24
  61. data/lib/file.fy +19 -0
  62. data/lib/future.fy +4 -46
  63. data/lib/hash.fy +113 -0
  64. data/lib/integer.fy +25 -6
  65. data/lib/iteration.fy +3 -3
  66. data/lib/main.fy +5 -0
  67. data/lib/matchers.fy +79 -0
  68. data/lib/nil_class.fy +8 -0
  69. data/lib/object.fy +109 -18
  70. data/lib/option_parser.fy +118 -0
  71. data/lib/package/dependency.fy +4 -8
  72. data/lib/package/dependency_installer.fy +1 -1
  73. data/lib/package/handler.fy +6 -0
  74. data/lib/package/installer.fy +43 -16
  75. data/lib/package/list.fy +1 -2
  76. data/lib/package/specification.fy +5 -5
  77. data/lib/package/uninstaller.fy +9 -2
  78. data/lib/parser.fy +1 -3
  79. data/lib/parser/ext/ext.c +1 -0
  80. data/lib/parser/ext/lexer.lex +5 -0
  81. data/lib/parser/methods.fy +48 -46
  82. data/lib/proxies.fy +151 -0
  83. data/lib/rbx.fy +1 -0
  84. data/lib/rbx/actor.fy +16 -18
  85. data/lib/rbx/array.fy +18 -3
  86. data/lib/rbx/block.fy +1 -7
  87. data/lib/rbx/class.fy +54 -9
  88. data/lib/rbx/code_loader.fy +2 -5
  89. data/lib/rbx/compiled_method.fy +31 -0
  90. data/lib/rbx/debugger.fy +66 -0
  91. data/lib/rbx/directory.fy +8 -3
  92. data/lib/rbx/documentation.fy +1 -1
  93. data/lib/rbx/file.fy +22 -0
  94. data/lib/rbx/integer.fy +1 -1
  95. data/lib/rbx/match_data.fy +2 -1
  96. data/lib/rbx/method.fy +26 -0
  97. data/lib/rbx/object.fy +8 -3
  98. data/lib/rbx/regexp.fy +6 -3
  99. data/lib/rbx/string.fy +9 -1
  100. data/lib/rbx/stringio.fy +12 -0
  101. data/lib/rbx/symbol.fy +4 -0
  102. data/lib/stack.fy +1 -1
  103. data/lib/string.fy +34 -0
  104. data/lib/stringio.fy +1 -1
  105. data/lib/symbol.fy +6 -2
  106. data/lib/system.fy +15 -1
  107. data/lib/tuple.fy +5 -2
  108. data/lib/version.fy +1 -1
  109. data/ruby_lib/fdoc +2 -22
  110. data/tests/array.fy +3 -17
  111. data/tests/class.fy +312 -10
  112. data/tests/contracts.fy +51 -0
  113. data/tests/distributing_proxy.fy +28 -0
  114. data/tests/enumerable.fy +104 -1
  115. data/tests/exception.fy +35 -0
  116. data/tests/fixnum.fy +1 -1
  117. data/tests/hash.fy +81 -1
  118. data/tests/integer.fy +9 -0
  119. data/tests/matchers.fy +18 -0
  120. data/tests/method.fy +8 -14
  121. data/tests/object.fy +76 -2
  122. data/tests/option_parser.fy +80 -0
  123. data/tests/string.fy +21 -0
  124. data/tests/stringio.fy +1 -1
  125. data/tests/tuple.fy +1 -1
  126. metadata +21 -44
  127. data/examples/arithmetic.fy +0 -7
  128. data/examples/array.fy +0 -50
  129. data/examples/boolean.fy +0 -24
  130. data/examples/class.fy +0 -68
  131. data/examples/constant_access.fy +0 -15
  132. data/examples/default_args.fy +0 -20
  133. data/examples/define_methods.fy +0 -15
  134. data/examples/dynamic_output.fy +0 -15
  135. data/examples/empty_catch.fy +0 -4
  136. data/examples/exception.fy +0 -9
  137. data/examples/files.fy +0 -23
  138. data/examples/finally.fy +0 -5
  139. data/examples/future.fy +0 -30
  140. data/examples/future_composition.fy +0 -20
  141. data/examples/futures.fy +0 -9
  142. data/examples/game_of_life.fy +0 -148
  143. data/examples/html_generator.fy +0 -84
  144. data/examples/implicit_return.fy +0 -3
  145. data/examples/matchers.fy +0 -6
  146. data/examples/nested_try.fy +0 -9
  147. data/examples/numbers.fy +0 -12
  148. data/examples/rbx/and_or.fy +0 -7
  149. data/examples/rbx/blocks.fy +0 -22
  150. data/examples/rbx/classes.fy +0 -32
  151. data/examples/rbx/hello.fy +0 -8
  152. data/examples/rbx/include.fy +0 -12
  153. data/examples/rbx/inherit.fy +0 -11
  154. data/examples/rbx/methods.fy +0 -15
  155. data/examples/rbx/nested_classes.fy +0 -9
  156. data/examples/rbx/require.fy +0 -3
  157. data/examples/rbx/strings.fy +0 -5
  158. data/examples/require.fy +0 -7
  159. data/examples/return.fy +0 -13
  160. data/examples/singleton_methods.fy +0 -21
  161. data/examples/threads.fy +0 -18
  162. data/examples/tuple.fy +0 -8
  163. data/examples/webserver/webserver.fy +0 -15
  164. data/lib/proxy.fy +0 -86
  165. data/lib/thread_pool.fy +0 -102
@@ -1,15 +0,0 @@
1
- class Foo {
2
- class Bar {
3
- def self name { 'bar }
4
- }
5
- }
6
-
7
- Foo Bar name println
8
-
9
- class Foo Baz { }
10
-
11
- Foo Baz == Foo::Baz println
12
-
13
- def Foo Baz name { 'baz }
14
-
15
- Foo Baz name println
@@ -1,20 +0,0 @@
1
- # default_args.fy
2
- # Example of fancy's default arguments
3
-
4
- def arg1: arg1 ("default_arg1") arg2: arg2 ("default_arg2") arg3: arg3 ("default_arg3") {
5
- "arguments are: " println
6
- arg1 println
7
- arg2 println
8
- arg3 println
9
- }
10
-
11
- arg1: "hello" arg2: "world" arg3: "how are you?"
12
-
13
- Console newline
14
- arg1: "hello" arg2: "world"
15
-
16
- Console newline
17
- arg1: "hello"
18
-
19
- Console newline
20
- arg1
@@ -1,15 +0,0 @@
1
- arr = [1,2,3]
2
- arr define_singleton_method: "foo" with: {
3
- "in foo!" println
4
- self inspect println
5
- }
6
-
7
- arr receive_message: 'foo
8
-
9
- arr undefine_singleton_method: "foo"
10
-
11
- try {
12
- arr receive_message: 'foo
13
- } catch NoMethodError => e {
14
- e println
15
- }
@@ -1,15 +0,0 @@
1
- # *stdout* refers to STDOUT
2
- File open: "/tmp/foo.txt" modes: ['write] with: |f| {
3
- let: '*stdout* be: f in: {
4
- # *stdout* refers to f
5
- # "foo" will be written to /tmp/foo.txt
6
- # and not STDOUT
7
- "foo" println
8
- }
9
- }
10
- File open: "/tmp/foo.txt" modes: ['read] with: |f| {
11
- let: '*stdin* be: f in: {
12
- *stdin* readln println # => prints "foo" to *stdout*
13
- }
14
- }
15
- # *stdout* refers to STDOUT
@@ -1,4 +0,0 @@
1
- try {
2
- "Empty catch" println
3
- } catch StdError => e {
4
- }
@@ -1,9 +0,0 @@
1
- try {
2
- "Hola" println
3
- StdError new: "Hello" . raise!
4
- "Hi" println
5
- } catch StdError => e {
6
- e println
7
- } finally {
8
- "Adios" println
9
- }
@@ -1,23 +0,0 @@
1
- # files.fy
2
- # File handling examples
3
-
4
- {
5
- Directory create: "tmp/"
6
- } unless: $ Directory exists?: "tmp/"
7
-
8
- File open: "tmp/Hello-World.txt" modes: ['write] with: |f| {
9
- f writeln: "Hello, world"
10
- }
11
-
12
- File delete: "tmp/Hello-World.txt"
13
-
14
- arr = [1,2,3,4]
15
- File open: "tmp/Array-Test.txt" modes: ['write] with: |f| {
16
- arr each: |x| {
17
- f writeln: x
18
- }
19
- }
20
-
21
- File delete: "tmp/Array-Test.txt"
22
-
23
- Directory delete: "tmp/"
@@ -1,5 +0,0 @@
1
- try {
2
- "Hello" println
3
- } finally {
4
- "World" println
5
- }
@@ -1,30 +0,0 @@
1
- def foo {
2
- Thread sleep: 3
3
- "FOO"
4
- }
5
-
6
- def + other {
7
- Thread sleep: 1.5
8
- "PLUS"
9
- }
10
-
11
- def baz: num {
12
- Thread sleep: (num * 0.5)
13
- "BAZ"
14
- }
15
-
16
- "Start" println
17
-
18
- f = self @ foo
19
- f println # print future object
20
- ?f println # access and print the future's value
21
-
22
- f = self @ + 10
23
- f println
24
- ?f println
25
-
26
- f = self @ baz: 10
27
- f println
28
- ?f println
29
-
30
- "End" println
@@ -1,20 +0,0 @@
1
- # example of composing futures:
2
-
3
- def do_large_computation: x {
4
- x upto: (x ** x)
5
- }
6
-
7
- # FutureSend#&& takes a Block (or a Callable - something that implements 'call:)
8
- # and creates a new FutureSend that executes the given Block with the value of the first FutureSend
9
- # when it has finished its computation. This makes pipelining tasks easy.
10
-
11
- f = self @ do_large_computation: 5 && @{select: 'even?} && @{inspect println}
12
- "computing .. " println
13
- f value
14
-
15
- #the above is the same as:
16
- # f = self @ do_large_computation: 5
17
- # f = f when_done: @{select: 'even?}
18
- # f = f when_done: @{inspect println}
19
- # "computing .. " println
20
- # f value
@@ -1,9 +0,0 @@
1
- fs = []
2
- 100 times: |i| {
3
- f = { Thread sleep: 0.5; i println } @ call
4
- fs << f
5
- }
6
-
7
- "Waiting" println
8
- fs each: 'value
9
- "Done" println
@@ -1,148 +0,0 @@
1
- # game_of_life.fy
2
- # Conway's Game of Life in Fancy :)
3
-
4
- class World {
5
- read_write_slots: ['matrix]
6
-
7
- def World with_height: height and_width: width {
8
- World new: [height, width]
9
- }
10
-
11
- def initialize {
12
- # the offsets are the positions to check for neighbors relative to
13
- # each position (e.g. [-1,-1] points to the upper left neighbor of
14
- # each cell)
15
- @offsets = [[-1, -1], [-1, 0], [-1, 1],
16
- [0, -1], [0, 1],
17
- [1, -1], [1, 0], [1, 1]]
18
- }
19
-
20
- def initialize: size {
21
- "Initialize a World with a given size ([height, width])."
22
-
23
- self initialize
24
- height = size[0]
25
- width = size[1]
26
- @last_alive = []
27
- @matrix = Array new: height
28
- height times: |i| {
29
- @matrix at: i put: (Array new: width with: 0)
30
- }
31
- }
32
-
33
- def [index] {
34
- "Return the row for a given index."
35
- @matrix[index]
36
- }
37
-
38
- def simulate: amount_generations {
39
- "Simulate the World for a given amount of iterations (generations)."
40
-
41
- display: 0
42
- amount_generations times: |i| {
43
- Thread sleep: 0.5 # sleep 500 ms
44
- self simulate
45
- display: (i + 1)
46
- }
47
- }
48
-
49
- def display {
50
- "Display the World (print on Screen)."
51
-
52
- @matrix each: |row| {
53
- row each: |entry| {
54
- if: (entry == 0) then: {
55
- " " print
56
- } else: {
57
- ". " print
58
- }
59
- }
60
- "" println
61
- }
62
- }
63
-
64
- def display: iteration {
65
- "Display the World (print on Screen) with the current iteration count."
66
-
67
- Console clear
68
- "Generation: " ++ iteration println
69
- self display
70
- }
71
-
72
- def was_alive?: pos {
73
- "Indicates, if a cell ([row,column]) was alive in the last generation."
74
-
75
- @last_alive[pos[0]] if_true: |row| {
76
- row[pos[1]] == 1
77
- }
78
- }
79
-
80
- def live: pos {
81
- "Sets the given cell ([row,column]) alive."
82
- (@matrix[pos[0]]) at: (pos[1]) put: 1
83
- }
84
-
85
- def die: pos {
86
- "Sets the given cell ([row,column]) dead."
87
- (@matrix[pos[0]]) at: (pos[1]) put: 0
88
- }
89
-
90
- def simulate {
91
- "Simulates the world one iteration."
92
-
93
- @last_alive = @matrix map: |row| { row select_with_index: |c| { c == 1 } }
94
- @matrix each_with_index: |row i| {
95
- row each_with_index: |column j| {
96
- # check amount of neighbors
97
- n_neighbors = neighbors_of: [i, j]
98
- if: (was_alive?: [i,j]) then: {
99
- if: ({n_neighbors <= 1} || {n_neighbors >= 4}) then: {
100
- die: [i,j]
101
- } else: {
102
- live: [i,j]
103
- }
104
- } else: {
105
- if: (n_neighbors == 3) then: {
106
- live: [i,j]
107
- }
108
- }
109
- }
110
- }
111
- }
112
-
113
- def neighbors_of: pos {
114
- row = pos[0]
115
- column = pos[1]
116
-
117
- neighbors = @offsets map: |o| {
118
- @matrix[row + (o[0])] if_true: |r| {
119
- r[column + (o[1])]
120
- }
121
- }
122
- neighbors select: |x| { x != 0 } . size
123
- }
124
- }
125
-
126
- X = 1
127
- PULSAR = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
128
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
129
- [0, 0, 0, 0, X, X, X, 0, 0, 0, X, X, X, 0, 0, 0],
130
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
131
- [0, 0, X, 0, 0, 0, 0, X, 0, X, 0, 0, 0, 0, X, 0],
132
- [0, 0, X, 0, 0, 0, 0, X, 0, X, 0, 0, 0, 0, X, 0],
133
- [0, 0, X, 0, 0, 0, 0, X, 0, X, 0, 0, 0, 0, X, 0],
134
- [0, 0, 0, 0, X, X, X, 0, 0, 0, X, X, X, 0, 0, 0],
135
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
136
- [0, 0, 0, 0, X, X, X, 0, 0, 0, X, X, X, 0, 0, 0],
137
- [0, 0, X, 0, 0, 0, 0, X, 0, X, 0, 0, 0, 0, X, 0],
138
- [0, 0, X, 0, 0, 0, 0, X, 0, X, 0, 0, 0, 0, X, 0],
139
- [0, 0, X, 0, 0, 0, 0, X, 0, X, 0, 0, 0, 0, X, 0],
140
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
141
- [0, 0, 0, 0, X, X, X, 0, 0, 0, X, X, X, 0, 0, 0],
142
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
143
- ]
144
-
145
- w = World new
146
- w matrix: PULSAR
147
-
148
- w simulate: 20
@@ -1,84 +0,0 @@
1
- # html_generator.fy
2
- # Simple HTML generator written in fancy
3
-
4
- class String {
5
- def but_last {
6
- # same as: self from: 0 to: -2
7
- # and: self from: 0 to: (self size - 2)
8
- self[[0,-2]]
9
- }
10
- }
11
-
12
- class HTML {
13
- def initialize {
14
- @buf = ""
15
- }
16
-
17
- def initialize: block {
18
- initialize
19
- block call_with_receiver: self
20
- self
21
- }
22
-
23
- def open_tag: name attrs: attrs (<[]>) {
24
- @buf << "<" << (name but_last)
25
- unless: (attrs empty?) do: {
26
- @buf << " "
27
- attrs each: |k v| {
28
- @buf << k << "=" << (v inspect)
29
- } in_between: {
30
- @buf << " "
31
- }
32
- }
33
- @buf << ">"
34
- }
35
-
36
- def close_tag: name {
37
- @buf << "</" << (name but_last) << ">"
38
- }
39
-
40
- def html_block: tag body: body attrs: attrs (<[]>) {
41
- open_tag: tag attrs: attrs
42
- match body first {
43
- case Block -> @buf << (body first call)
44
- case _ -> @buf << (body first)
45
- }
46
- close_tag: tag
47
- }
48
-
49
- def unknown_message: m with_params: p {
50
- match m to_s {
51
- case /with:$/ ->
52
- tag = m to_s substitute: /with:$/ with: ""
53
- html_block: tag body: (p rest) attrs: (p first)
54
- case _ ->
55
- html_block: (m to_s) body: p
56
- }
57
- nil
58
- }
59
-
60
- def to_s {
61
- @buf
62
- }
63
- }
64
-
65
- # lets generate some simple HTML output :)
66
- HTML new: |h| {
67
- html: {
68
- body: <['id => "body id" ]> with: {
69
- div: {
70
- "hello, world!"
71
- }
72
- div: {
73
- p: {
74
- "OKIDOKI"
75
- }
76
- }
77
- div: {
78
- h3: {
79
- "oh no!"
80
- }
81
- }
82
- }
83
- }
84
- } . println
@@ -1,3 +0,0 @@
1
- # Methods implicitly return the last expression.
2
- def hello { "Hello!" }
3
- self hello println
@@ -1,6 +0,0 @@
1
- # matchers.fy
2
-
3
- match "foobarbaz" {
4
- case /foo([a-z]+)baz/ -> |matcher|
5
- matcher[1] println # => bar
6
- }
@@ -1,9 +0,0 @@
1
- try {
2
- try {
3
- StdError new: "Propagated exception" . raise!
4
- } catch String => not_matched {
5
- "Should not enter here" println
6
- }
7
- } catch Object => anything {
8
- anything println
9
- }
@@ -1,12 +0,0 @@
1
- # numbers.fy
2
- # Examples of fancy's number objects
3
-
4
- -10 abs println # prints: 10
5
- 10 abs println # prints: 10
6
- 0 abs println # prints: 0
7
-
8
- "" println
9
-
10
- -10 negate println # prints: 10
11
- 10 negate println # prints: -10
12
- 0 negate println # prints: 0