fancy 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. data/README.md +14 -14
  2. data/Rakefile +16 -4
  3. data/bin/fancy +3 -0
  4. data/bin/fspec +20 -0
  5. data/bin/fyi +27 -11
  6. data/bin/ifancy +1 -1
  7. data/boot/fancy_ext.rb +1 -0
  8. data/boot/fancy_ext/block_env.rb +1 -9
  9. data/boot/fancy_ext/delegator.rb +64 -0
  10. data/boot/fancy_ext/object.rb +4 -0
  11. data/boot/fancy_ext/thread.rb +4 -0
  12. data/boot/load.rb +5 -1
  13. data/boot/rbx-compiler/compiler/ast.rb +0 -1
  14. data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
  15. data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
  16. data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
  17. data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
  18. data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
  19. data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
  20. data/boot/rbx-compiler/parser/lexer.lex +5 -11
  21. data/boot/rbx-compiler/parser/parser.rb +16 -5
  22. data/boot/rbx-compiler/parser/parser.y +39 -24
  23. data/doc/api/fancy.css +1 -1
  24. data/doc/api/fancy.jsonp +1 -1
  25. data/doc/api/fdoc.js +22 -4
  26. data/doc/api/index.html +5 -6
  27. data/doc/api/jquery-ui.min.js +401 -0
  28. data/doc/api/jquery.tools.min.js +192 -0
  29. data/doc/api/themeswitchertool.js +250 -0
  30. data/doc/features.md +17 -0
  31. data/examples/actor_bunnies.fy +32 -0
  32. data/examples/actors.fy +26 -0
  33. data/examples/actors_primitive.fy +27 -0
  34. data/examples/actors_ring.fy +37 -0
  35. data/examples/armstrong_numbers.fy +1 -1
  36. data/examples/array.fy +7 -9
  37. data/examples/async_send.fy +1 -2
  38. data/examples/blocks.fy +4 -4
  39. data/examples/call_with_receiver.fy +1 -1
  40. data/examples/class.fy +1 -1
  41. data/examples/default_args.fy +4 -1
  42. data/examples/define_methods.fy +2 -2
  43. data/examples/echo.fy +1 -1
  44. data/examples/factorial.fy +1 -1
  45. data/examples/future_composition.fy +2 -2
  46. data/examples/futures.fy +0 -5
  47. data/examples/game_of_life.fy +1 -1
  48. data/examples/person.fy +1 -1
  49. data/lib/argv.fy +7 -2
  50. data/lib/array.fy +109 -42
  51. data/lib/block.fy +39 -14
  52. data/lib/boot.fy +2 -0
  53. data/lib/class.fy +2 -0
  54. data/lib/compiler/ast.fy +2 -1
  55. data/lib/compiler/ast/assign.fy +2 -3
  56. data/lib/compiler/ast/async_send.fy +1 -15
  57. data/lib/compiler/ast/class_def.fy +2 -1
  58. data/lib/compiler/ast/expression_list.fy +4 -5
  59. data/lib/compiler/ast/future_send.fy +1 -10
  60. data/lib/compiler/ast/goto.fy +46 -0
  61. data/lib/compiler/ast/identifier.fy +9 -7
  62. data/lib/compiler/ast/literals.fy +8 -1
  63. data/lib/compiler/ast/match.fy +14 -4
  64. data/lib/compiler/ast/message_send.fy +34 -6
  65. data/lib/compiler/ast/method_def.fy +6 -6
  66. data/lib/compiler/ast/node.fy +3 -3
  67. data/lib/compiler/ast/range.fy +1 -0
  68. data/lib/compiler/ast/script.fy +0 -2
  69. data/lib/compiler/ast/singleton_method_def.fy +2 -4
  70. data/lib/compiler/ast/string_interpolation.fy +17 -0
  71. data/lib/compiler/ast/super.fy +5 -4
  72. data/lib/compiler/ast/try_catch.fy +8 -6
  73. data/lib/compiler/ast/tuple_literal.fy +3 -2
  74. data/lib/compiler/command.fy +0 -1
  75. data/lib/compiler/compiler.fy +1 -5
  76. data/lib/compiler/stages.fy +6 -14
  77. data/lib/documentation.fy +57 -46
  78. data/lib/enumerable.fy +257 -23
  79. data/lib/enumerator.fy +122 -15
  80. data/lib/false_class.fy +10 -1
  81. data/lib/fancy_spec.fy +263 -61
  82. data/lib/fdoc.fy +11 -25
  83. data/lib/fiber.fy +11 -0
  84. data/lib/file.fy +8 -11
  85. data/lib/future.fy +84 -5
  86. data/lib/hash.fy +65 -14
  87. data/lib/integer.fy +35 -0
  88. data/lib/iteration.fy +54 -29
  89. data/lib/message.fy +6 -0
  90. data/lib/method.fy +0 -16
  91. data/lib/nil_class.fy +58 -8
  92. data/lib/number.fy +49 -22
  93. data/lib/object.fy +371 -65
  94. data/lib/package.fy +24 -1
  95. data/lib/package/installer.fy +5 -9
  96. data/lib/package/specification.fy +2 -2
  97. data/lib/parser/ext/lexer.lex +15 -11
  98. data/lib/parser/ext/parser.y +70 -23
  99. data/lib/parser/methods.fy +33 -14
  100. data/lib/proxy.fy +33 -3
  101. data/lib/range.fy +28 -0
  102. data/lib/rbx.fy +3 -1
  103. data/lib/rbx/actor.fy +53 -0
  104. data/lib/rbx/alpha.fy +31 -0
  105. data/lib/rbx/array.fy +21 -12
  106. data/lib/rbx/bignum.fy +6 -2
  107. data/lib/rbx/block.fy +23 -26
  108. data/lib/rbx/class.fy +54 -2
  109. data/lib/rbx/code_loader.fy +8 -4
  110. data/lib/rbx/date.fy +9 -0
  111. data/lib/rbx/directory.fy +18 -0
  112. data/lib/rbx/environment_variables.fy +1 -0
  113. data/lib/rbx/exception.fy +9 -2
  114. data/lib/rbx/fiber.fy +22 -4
  115. data/lib/rbx/file.fy +5 -5
  116. data/lib/rbx/fixnum.fy +5 -0
  117. data/lib/rbx/float.fy +11 -3
  118. data/lib/rbx/hash.fy +31 -16
  119. data/lib/rbx/integer.fy +1 -0
  120. data/lib/rbx/io.fy +17 -7
  121. data/lib/rbx/match_data.fy +15 -4
  122. data/lib/rbx/method.fy +40 -7
  123. data/lib/rbx/name_error.fy +4 -0
  124. data/lib/rbx/object.fy +92 -24
  125. data/lib/rbx/range.fy +20 -6
  126. data/lib/rbx/regexp.fy +11 -3
  127. data/lib/rbx/string.fy +51 -1
  128. data/lib/rbx/stringio.fy +17 -0
  129. data/lib/rbx/symbol.fy +15 -1
  130. data/lib/rbx/system.fy +20 -2
  131. data/lib/rbx/tcp_server.fy +4 -1
  132. data/lib/rbx/tcp_socket.fy +11 -0
  133. data/lib/rbx/time.fy +6 -0
  134. data/lib/rbx/tuple.fy +14 -5
  135. data/lib/set.fy +144 -29
  136. data/lib/stack.fy +42 -11
  137. data/lib/string.fy +118 -8
  138. data/lib/struct.fy +13 -3
  139. data/lib/symbol.fy +21 -2
  140. data/lib/thread_pool.fy +2 -1
  141. data/lib/true_class.fy +45 -7
  142. data/lib/tuple.fy +27 -9
  143. data/lib/version.fy +2 -2
  144. data/ruby_lib/fancy +43 -0
  145. data/ruby_lib/fdoc +23 -0
  146. data/ruby_lib/fspec +3 -0
  147. data/ruby_lib/fyi +3 -0
  148. data/ruby_lib/ifancy +3 -0
  149. data/tests/argv.fy +5 -9
  150. data/tests/array.fy +323 -196
  151. data/tests/assignment.fy +29 -29
  152. data/tests/block.fy +72 -59
  153. data/tests/class.fy +227 -138
  154. data/tests/control_flow.fy +83 -51
  155. data/tests/documentation.fy +8 -8
  156. data/tests/enumerable.fy +8 -0
  157. data/tests/enumerator.fy +47 -29
  158. data/tests/exception.fy +49 -32
  159. data/tests/file.fy +28 -28
  160. data/tests/fixnum.fy +170 -0
  161. data/tests/future.fy +24 -7
  162. data/tests/hash.fy +55 -38
  163. data/tests/method.fy +50 -43
  164. data/tests/nil_class.fy +37 -37
  165. data/tests/object.fy +152 -70
  166. data/tests/pattern_matching.fy +67 -31
  167. data/tests/range.fy +6 -6
  168. data/tests/set.fy +101 -4
  169. data/tests/stack.fy +14 -5
  170. data/tests/string.fy +115 -61
  171. data/tests/stringio.fy +18 -0
  172. data/tests/struct.fy +27 -0
  173. data/tests/symbol.fy +19 -6
  174. data/tests/true_class.fy +34 -34
  175. data/tests/tuple.fy +30 -12
  176. metadata +103 -81
  177. data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
  178. data/examples/actor.fy +0 -37
  179. data/examples/curl_async.fy +0 -37
  180. data/lib/compiler/ast/require.fy +0 -15
  181. data/tests/number.fy +0 -135
  182. data/tests/parsing/sexp.fy +0 -50
@@ -1,20 +0,0 @@
1
- class Fancy
2
- class AST
3
-
4
- class Require < Node
5
- def initialize(line, string)
6
- super(line)
7
- @string = string
8
- end
9
-
10
- def bytecode(g)
11
- Rubinius::AST::Self.new(1).bytecode(g)
12
- @string.bytecode(g)
13
- pos(g)
14
- g.allow_private
15
- g.send :fancy_require, 1, false
16
- end
17
- end
18
-
19
- end
20
- end
@@ -1,37 +0,0 @@
1
- require("actor")
2
- class Actor {
3
- alias_method: '! for_ruby: '<<
4
- }
5
-
6
- # Execute with Rubinius: rbx ex1.rb
7
-
8
- def error_loop: block{
9
- try {
10
- loop: block
11
- } catch Exception => ex {
12
- ex message println
13
- ex backtrace join: "\n"
14
- }
15
- }
16
-
17
- pong = nil
18
- ping = Actor spawn() {
19
- error_loop: {
20
- count = Actor receive()
21
- "." print
22
- { return count println } if: (count > 1000)
23
- pong ! (count + 1)
24
- }
25
- }
26
- pong = Actor.spawn() {
27
- error_loop: {
28
- count = Actor receive()
29
- "-" print
30
- { return count println } if: (count > 1000)
31
- ping ! (count + 1)
32
- }
33
- }
34
- ping ! 1
35
-
36
- # Let the actors process while the main thread sleeps...
37
- Thread sleep: 1
@@ -1,37 +0,0 @@
1
- def async curl: url {
2
- out = System pipe: "curl #{url}"
3
- return out read # return string of html
4
- }
5
-
6
- def async curl_urls: urls {
7
- results = []
8
- urls each: |url| {
9
- # await means it will suspend the current context until the curl: has finished
10
- # and will resume with the line below
11
- data = await curl: url
12
- results << data
13
- }
14
- return results
15
- }
16
-
17
- URLS = ["http://www.backtype.com", "http://www.fancy-lang.org", "http://tech.backtype.com"]
18
-
19
- # usage (runs it asynchronously and returns a future that will hold the data when its done)
20
- f = curl_urls: URLS
21
-
22
- # do something else...
23
- # then after some time access the data:
24
-
25
- f value each: |html| {
26
- html println
27
- }
28
-
29
- # or hook it up with something to do when its done:
30
- curl_urls: URLS && |data| {
31
- data each: |html| {
32
- html println
33
- }
34
- }
35
-
36
- # shorter version of above:
37
- curl_urls: URLS && @{each: 'println}
@@ -1,15 +0,0 @@
1
- class Fancy AST {
2
- class Require : Node {
3
- def initialize: @line file: @string {
4
- }
5
-
6
- def bytecode: g {
7
- pos(g)
8
- ms = MessageSend new: @line \
9
- message: (Identifier from: "require:" line: @line) \
10
- to: (Identifier from: "Fancy::CodeLoader" line: @line) \
11
- args: (MessageArgs new: @line args: [@string])
12
- ms bytecode: g
13
- }
14
- }
15
- }
@@ -1,135 +0,0 @@
1
- FancySpec describe: Number with: {
2
- it: "should add two numbers correctly" for: '+ when: {
3
- n1 = 20
4
- n2 = 22
5
- n1 + n2 should == 42
6
- }
7
-
8
- it: "should subtract two numbers correctly" for: '- when: {
9
- n1 = 20
10
- n2 = 22
11
- n1 - n2 should == -2
12
- }
13
-
14
- it: "should multiply two numbers correctly" for: '* when: {
15
- n1 = 20
16
- n2 = 22
17
- n1 * n2 should == 440
18
- }
19
-
20
- it: "should divide two numbers correctly" for: '/ when: {
21
- n1 = 20
22
- n2 = 10
23
- n1 / n2 should == 2
24
- }
25
-
26
- it: "should raise an exception when dividing by zero" when: {
27
- { 10 / 0 } should raise: ZeroDivisionError
28
- }
29
-
30
- it: "should calculate the correct modulo value" for: 'modulo: when: {
31
- 9 % 4 should == 1
32
- 10 modulo: 2 . should == 0
33
- }
34
-
35
- it: "should do proper integer division" for: 'div: when: {
36
- 50 div: 10 . should == 5
37
- 55 div: 10 . should == 5
38
- 5 div: 10 . should == 0
39
- ((55 div: 10) * 10) + (55 modulo: 10) should == 55
40
- }
41
-
42
- it: "should be the negation" for: 'negate when: {
43
- 42 negate should == -42
44
- }
45
-
46
- it: "should be odd" for: 'odd? when: {
47
- 1 odd? should == true
48
- 1 even? should == false
49
- }
50
-
51
- it: "should be even" for: 'even? when: {
52
- 2 odd? should == false
53
- 2 even? should == true
54
- }
55
-
56
- it: "should return an array from 0 upto 10" for: 'upto: when: {
57
- 0 upto: 10 . should == [0,1,2,3,4,5,6,7,8,9,10]
58
- }
59
-
60
- it: "should iterate from 1 upto 10" for: 'upto:do: when: {
61
- sum = 0
62
- 1 upto: 10 do: |n| { sum = sum + n }
63
- sum should == 55
64
- }
65
-
66
- it: "should return an array from 10 downto 0" for: 'downto: when: {
67
- 10 downto: 0 . should == [10,9,8,7,6,5,4,3,2,1,0]
68
- }
69
-
70
- it: "should iterate from 10 downto 1" for: 'downto:do: when: {
71
- sum = 0
72
- 10 downto: 1 do: |n| { sum = sum + n }
73
- sum should == 55
74
- }
75
-
76
- it: "should calculate the given power of itself" for: '** when: {
77
- 2 ** 3 should == 8
78
- 2 ** 0 should == 1
79
- 2 ** 1 should == 2
80
- 0 upto: 10 do: |i| {
81
- i ** 0 should == 1
82
- i ** 1 should == i
83
- i ** 2 should == (i squared)
84
- }
85
- }
86
-
87
- it: "should be the square of self" for: 'squared when: {
88
- 5 squared should == 25
89
- 10 squared should == 100
90
- 20 upto: 50 do: |i| {
91
- i squared should == (i * i)
92
- }
93
- }
94
-
95
- it: "should be the double value of self" for: 'doubled when: {
96
- 5 doubled should == 10
97
- 10 doubled should == 20
98
- 20 upto: 50 do: |i| {
99
- i doubled should == (i + i)
100
- }
101
- }
102
-
103
- it: "should be the same when using underscores within the literal" when: {
104
- 50000 should == 50_000
105
- 100_000 should == 100000
106
- 100_000 should == 100_000
107
- 100_000 should == 100000.0
108
- 100_000.0 should == 100000
109
- 100_999.999 should == 100999.999
110
- }
111
-
112
- it: "should evaluate octal literals correctly" when: {
113
- 0o00 should == 0
114
- 0o01 should == 1
115
- 0o07 should == 7
116
- 0o10 should == 8
117
- 0o70 should == 56
118
- }
119
-
120
- it: "should evaluate binary literals correctly" when: {
121
- 0b00 should == 0
122
- 0b01 should == 1
123
- 0b10 should == 2
124
- 0b11 should == 3
125
- 0b100 should == 4
126
- }
127
-
128
- it: "should evaluate hexadecimal literals correctly" when: {
129
- 0x00 should == 0
130
- 0x01 should == 1
131
- 0x0A should == 10
132
- 0xA0 should == 160
133
- 0xFF should == 255
134
- }
135
- }
@@ -1,50 +0,0 @@
1
- FancySpec describe: "S-Expression" for: String with: {
2
- it: "should be correct for assignment" for: 'to_sexp when: {
3
- "x = 3" to_sexp should == ['exp_list, [['assign, ['ident, 'x], ['int_lit, 3]]]]
4
- "foobar = nil" to_sexp should == ['exp_list, [['assign, ['ident, 'foobar], ['ident, 'nil]]]]
5
- }
6
-
7
- it: "should be correct for symbol literals" for: 'to_sexp when: {
8
- "'foo" to_sexp should == ['exp_list, [['symbol_lit, 'foo]]]
9
- }
10
-
11
- it: "should be correct for string literals" for: 'to_sexp when: {
12
- # "\"foo\"" to_sexp should == ['exp_list, [['string_lit, "foo"]]
13
- }
14
-
15
- it: "should be correct for integer literals" for: 'to_sexp when: {
16
- "3" to_sexp should == ['exp_list, [['int_lit, 3]]]
17
- "-3" to_sexp should == ['exp_list, [['int_lit, -3]]]
18
- "0" to_sexp should == ['exp_list, [['int_lit, 0]]]
19
- }
20
-
21
- it: "should be correct for double literals" for: 'to_sexp when: {
22
- "3.5" to_sexp should == ['exp_list, [['double_lit, 3.5]]]
23
- "-3.5" to_sexp should == ['exp_list, [['double_lit, -3.5]]]
24
- "0.0" to_sexp should == ['exp_list, [['double_lit, 0.0]]]
25
- }
26
-
27
- it: "should be correct for array literals" for: 'to_sexp when: {
28
- "[1,2,3]" to_sexp should == ['exp_list, [['array_lit, [['int_lit, 1], ['int_lit, 2], ['int_lit, 3]]]]]
29
-
30
- "[[1,2],[3,4]]" to_sexp should == .
31
- ['exp_list, [['array_lit, [['array_lit, [['int_lit, 1], ['int_lit, 2]]],
32
- ['array_lit, [['int_lit, 3], ['int_lit, 4]]]]]]]
33
-
34
- "[]" to_sexp should == ['exp_list, [['array_lit, []]]]
35
- }
36
-
37
- it: "should be able to parse multiple expressions in one string" for: 'to_sexp when: {
38
- "x = 1; y = 2" to_sexp should == ['exp_list, [['assign, ['ident, 'x], ['int_lit, 1]],
39
- ['assign, ['ident, 'y], ['int_lit, 2]]]]
40
- }
41
-
42
- it: "should parse an RubyArgsLiteral correctly" for: 'to_sexp when: {
43
- "obj foo: ~[1,2]" to_sexp should == .
44
- ['exp_list, [['message_send, ['ident, 'obj],
45
- ['ident, 'foo:],
46
- [['rb_args_lit, ['array_lit,
47
- [['int_lit, 1],
48
- ['int_lit, 2]]]]]]]]
49
- }
50
- }