fancy 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -14
- data/Rakefile +16 -4
- data/bin/fancy +3 -0
- data/bin/fspec +20 -0
- data/bin/fyi +27 -11
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/block_env.rb +1 -9
- data/boot/fancy_ext/delegator.rb +64 -0
- data/boot/fancy_ext/object.rb +4 -0
- data/boot/fancy_ext/thread.rb +4 -0
- data/boot/load.rb +5 -1
- data/boot/rbx-compiler/compiler/ast.rb +0 -1
- data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
- data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/lexer.lex +5 -11
- data/boot/rbx-compiler/parser/parser.rb +16 -5
- data/boot/rbx-compiler/parser/parser.y +39 -24
- data/doc/api/fancy.css +1 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -4
- data/doc/api/index.html +5 -6
- data/doc/api/jquery-ui.min.js +401 -0
- data/doc/api/jquery.tools.min.js +192 -0
- data/doc/api/themeswitchertool.js +250 -0
- data/doc/features.md +17 -0
- data/examples/actor_bunnies.fy +32 -0
- data/examples/actors.fy +26 -0
- data/examples/actors_primitive.fy +27 -0
- data/examples/actors_ring.fy +37 -0
- data/examples/armstrong_numbers.fy +1 -1
- data/examples/array.fy +7 -9
- data/examples/async_send.fy +1 -2
- data/examples/blocks.fy +4 -4
- data/examples/call_with_receiver.fy +1 -1
- data/examples/class.fy +1 -1
- data/examples/default_args.fy +4 -1
- data/examples/define_methods.fy +2 -2
- data/examples/echo.fy +1 -1
- data/examples/factorial.fy +1 -1
- data/examples/future_composition.fy +2 -2
- data/examples/futures.fy +0 -5
- data/examples/game_of_life.fy +1 -1
- data/examples/person.fy +1 -1
- data/lib/argv.fy +7 -2
- data/lib/array.fy +109 -42
- data/lib/block.fy +39 -14
- data/lib/boot.fy +2 -0
- data/lib/class.fy +2 -0
- data/lib/compiler/ast.fy +2 -1
- data/lib/compiler/ast/assign.fy +2 -3
- data/lib/compiler/ast/async_send.fy +1 -15
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +4 -5
- data/lib/compiler/ast/future_send.fy +1 -10
- data/lib/compiler/ast/goto.fy +46 -0
- data/lib/compiler/ast/identifier.fy +9 -7
- data/lib/compiler/ast/literals.fy +8 -1
- data/lib/compiler/ast/match.fy +14 -4
- data/lib/compiler/ast/message_send.fy +34 -6
- data/lib/compiler/ast/method_def.fy +6 -6
- data/lib/compiler/ast/node.fy +3 -3
- data/lib/compiler/ast/range.fy +1 -0
- data/lib/compiler/ast/script.fy +0 -2
- data/lib/compiler/ast/singleton_method_def.fy +2 -4
- data/lib/compiler/ast/string_interpolation.fy +17 -0
- data/lib/compiler/ast/super.fy +5 -4
- data/lib/compiler/ast/try_catch.fy +8 -6
- data/lib/compiler/ast/tuple_literal.fy +3 -2
- data/lib/compiler/command.fy +0 -1
- data/lib/compiler/compiler.fy +1 -5
- data/lib/compiler/stages.fy +6 -14
- data/lib/documentation.fy +57 -46
- data/lib/enumerable.fy +257 -23
- data/lib/enumerator.fy +122 -15
- data/lib/false_class.fy +10 -1
- data/lib/fancy_spec.fy +263 -61
- data/lib/fdoc.fy +11 -25
- data/lib/fiber.fy +11 -0
- data/lib/file.fy +8 -11
- data/lib/future.fy +84 -5
- data/lib/hash.fy +65 -14
- data/lib/integer.fy +35 -0
- data/lib/iteration.fy +54 -29
- data/lib/message.fy +6 -0
- data/lib/method.fy +0 -16
- data/lib/nil_class.fy +58 -8
- data/lib/number.fy +49 -22
- data/lib/object.fy +371 -65
- data/lib/package.fy +24 -1
- data/lib/package/installer.fy +5 -9
- data/lib/package/specification.fy +2 -2
- data/lib/parser/ext/lexer.lex +15 -11
- data/lib/parser/ext/parser.y +70 -23
- data/lib/parser/methods.fy +33 -14
- data/lib/proxy.fy +33 -3
- data/lib/range.fy +28 -0
- data/lib/rbx.fy +3 -1
- data/lib/rbx/actor.fy +53 -0
- data/lib/rbx/alpha.fy +31 -0
- data/lib/rbx/array.fy +21 -12
- data/lib/rbx/bignum.fy +6 -2
- data/lib/rbx/block.fy +23 -26
- data/lib/rbx/class.fy +54 -2
- data/lib/rbx/code_loader.fy +8 -4
- data/lib/rbx/date.fy +9 -0
- data/lib/rbx/directory.fy +18 -0
- data/lib/rbx/environment_variables.fy +1 -0
- data/lib/rbx/exception.fy +9 -2
- data/lib/rbx/fiber.fy +22 -4
- data/lib/rbx/file.fy +5 -5
- data/lib/rbx/fixnum.fy +5 -0
- data/lib/rbx/float.fy +11 -3
- data/lib/rbx/hash.fy +31 -16
- data/lib/rbx/integer.fy +1 -0
- data/lib/rbx/io.fy +17 -7
- data/lib/rbx/match_data.fy +15 -4
- data/lib/rbx/method.fy +40 -7
- data/lib/rbx/name_error.fy +4 -0
- data/lib/rbx/object.fy +92 -24
- data/lib/rbx/range.fy +20 -6
- data/lib/rbx/regexp.fy +11 -3
- data/lib/rbx/string.fy +51 -1
- data/lib/rbx/stringio.fy +17 -0
- data/lib/rbx/symbol.fy +15 -1
- data/lib/rbx/system.fy +20 -2
- data/lib/rbx/tcp_server.fy +4 -1
- data/lib/rbx/tcp_socket.fy +11 -0
- data/lib/rbx/time.fy +6 -0
- data/lib/rbx/tuple.fy +14 -5
- data/lib/set.fy +144 -29
- data/lib/stack.fy +42 -11
- data/lib/string.fy +118 -8
- data/lib/struct.fy +13 -3
- data/lib/symbol.fy +21 -2
- data/lib/thread_pool.fy +2 -1
- data/lib/true_class.fy +45 -7
- data/lib/tuple.fy +27 -9
- data/lib/version.fy +2 -2
- data/ruby_lib/fancy +43 -0
- data/ruby_lib/fdoc +23 -0
- data/ruby_lib/fspec +3 -0
- data/ruby_lib/fyi +3 -0
- data/ruby_lib/ifancy +3 -0
- data/tests/argv.fy +5 -9
- data/tests/array.fy +323 -196
- data/tests/assignment.fy +29 -29
- data/tests/block.fy +72 -59
- data/tests/class.fy +227 -138
- data/tests/control_flow.fy +83 -51
- data/tests/documentation.fy +8 -8
- data/tests/enumerable.fy +8 -0
- data/tests/enumerator.fy +47 -29
- data/tests/exception.fy +49 -32
- data/tests/file.fy +28 -28
- data/tests/fixnum.fy +170 -0
- data/tests/future.fy +24 -7
- data/tests/hash.fy +55 -38
- data/tests/method.fy +50 -43
- data/tests/nil_class.fy +37 -37
- data/tests/object.fy +152 -70
- data/tests/pattern_matching.fy +67 -31
- data/tests/range.fy +6 -6
- data/tests/set.fy +101 -4
- data/tests/stack.fy +14 -5
- data/tests/string.fy +115 -61
- data/tests/stringio.fy +18 -0
- data/tests/struct.fy +27 -0
- data/tests/symbol.fy +19 -6
- data/tests/true_class.fy +34 -34
- data/tests/tuple.fy +30 -12
- metadata +103 -81
- data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
- data/examples/actor.fy +0 -37
- data/examples/curl_async.fy +0 -37
- data/lib/compiler/ast/require.fy +0 -15
- data/tests/number.fy +0 -135
- 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
|
data/examples/actor.fy
DELETED
@@ -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
|
data/examples/curl_async.fy
DELETED
@@ -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}
|
data/lib/compiler/ast/require.fy
DELETED
@@ -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
|
-
}
|
data/tests/number.fy
DELETED
@@ -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
|
-
}
|
data/tests/parsing/sexp.fy
DELETED
@@ -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
|
-
}
|