fancy 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -86
- data/bin/fdoc +2 -22
- data/bin/fspec +8 -3
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/array.rb +19 -0
- data/boot/fancy_ext/class.rb +2 -4
- data/boot/fancy_ext/module.rb +2 -0
- data/boot/fancy_ext/object.rb +0 -17
- data/boot/rbx-compiler/compiler/ast/method_def.rb +0 -4
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +0 -7
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/fancy_parser.c +1 -0
- data/doc/api/fancy.css +10 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -9
- data/doc/api/octocat.png +0 -0
- data/doc/features.md +1 -2
- data/examples/actors.fy +1 -2
- data/examples/armstrong_numbers.fy +7 -3
- data/examples/blocks.fy +3 -3
- data/examples/distributing_proxy.fy +31 -0
- data/examples/future_sends.fy +15 -0
- data/examples/person.fy +1 -2
- data/lib/argv.fy +1 -7
- data/lib/array.fy +7 -11
- data/lib/block.fy +15 -0
- data/lib/boot.fy +4 -3
- data/lib/class.fy +354 -10
- data/lib/compiler.fy +1 -1
- data/lib/compiler/ast/assign.fy +4 -8
- data/lib/compiler/ast/async_send.fy +1 -2
- data/lib/compiler/ast/block.fy +5 -0
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +1 -2
- data/lib/compiler/ast/future_send.fy +1 -2
- data/lib/compiler/ast/identifier.fy +34 -17
- data/lib/compiler/ast/literals.fy +31 -19
- data/lib/compiler/ast/match.fy +5 -4
- data/lib/compiler/ast/message_send.fy +3 -5
- data/lib/compiler/ast/method_def.fy +0 -3
- data/lib/compiler/ast/range.fy +2 -4
- data/lib/compiler/ast/return.fy +2 -4
- data/lib/compiler/ast/script.fy +2 -4
- data/lib/compiler/ast/singleton_method_def.fy +0 -3
- data/lib/compiler/ast/string_interpolation.fy +2 -2
- data/lib/compiler/ast/super.fy +2 -4
- data/lib/compiler/ast/try_catch.fy +13 -9
- data/lib/compiler/ast/tuple_literal.fy +1 -2
- data/lib/compiler/compiler.fy +2 -2
- data/lib/compiler/stages.fy +3 -6
- data/lib/contracts.fy +89 -57
- data/lib/dynamic_slot_object.fy +21 -3
- data/lib/enumerable.fy +140 -4
- data/lib/enumerator.fy +1 -1
- data/lib/eval.fy +23 -9
- data/lib/exception.fy +16 -0
- data/lib/false_class.fy +36 -5
- data/lib/fancy_spec.fy +64 -34
- data/lib/fdoc.fy +85 -24
- data/lib/file.fy +19 -0
- data/lib/future.fy +4 -46
- data/lib/hash.fy +113 -0
- data/lib/integer.fy +25 -6
- data/lib/iteration.fy +3 -3
- data/lib/main.fy +5 -0
- data/lib/matchers.fy +79 -0
- data/lib/nil_class.fy +8 -0
- data/lib/object.fy +109 -18
- data/lib/option_parser.fy +118 -0
- data/lib/package/dependency.fy +4 -8
- data/lib/package/dependency_installer.fy +1 -1
- data/lib/package/handler.fy +6 -0
- data/lib/package/installer.fy +43 -16
- data/lib/package/list.fy +1 -2
- data/lib/package/specification.fy +5 -5
- data/lib/package/uninstaller.fy +9 -2
- data/lib/parser.fy +1 -3
- data/lib/parser/ext/ext.c +1 -0
- data/lib/parser/ext/lexer.lex +5 -0
- data/lib/parser/methods.fy +48 -46
- data/lib/proxies.fy +151 -0
- data/lib/rbx.fy +1 -0
- data/lib/rbx/actor.fy +16 -18
- data/lib/rbx/array.fy +18 -3
- data/lib/rbx/block.fy +1 -7
- data/lib/rbx/class.fy +54 -9
- data/lib/rbx/code_loader.fy +2 -5
- data/lib/rbx/compiled_method.fy +31 -0
- data/lib/rbx/debugger.fy +66 -0
- data/lib/rbx/directory.fy +8 -3
- data/lib/rbx/documentation.fy +1 -1
- data/lib/rbx/file.fy +22 -0
- data/lib/rbx/integer.fy +1 -1
- data/lib/rbx/match_data.fy +2 -1
- data/lib/rbx/method.fy +26 -0
- data/lib/rbx/object.fy +8 -3
- data/lib/rbx/regexp.fy +6 -3
- data/lib/rbx/string.fy +9 -1
- data/lib/rbx/stringio.fy +12 -0
- data/lib/rbx/symbol.fy +4 -0
- data/lib/stack.fy +1 -1
- data/lib/string.fy +34 -0
- data/lib/stringio.fy +1 -1
- data/lib/symbol.fy +6 -2
- data/lib/system.fy +15 -1
- data/lib/tuple.fy +5 -2
- data/lib/version.fy +1 -1
- data/ruby_lib/fdoc +2 -22
- data/tests/array.fy +3 -17
- data/tests/class.fy +312 -10
- data/tests/contracts.fy +51 -0
- data/tests/distributing_proxy.fy +28 -0
- data/tests/enumerable.fy +104 -1
- data/tests/exception.fy +35 -0
- data/tests/fixnum.fy +1 -1
- data/tests/hash.fy +81 -1
- data/tests/integer.fy +9 -0
- data/tests/matchers.fy +18 -0
- data/tests/method.fy +8 -14
- data/tests/object.fy +76 -2
- data/tests/option_parser.fy +80 -0
- data/tests/string.fy +21 -0
- data/tests/stringio.fy +1 -1
- data/tests/tuple.fy +1 -1
- metadata +21 -44
- data/examples/arithmetic.fy +0 -7
- data/examples/array.fy +0 -50
- data/examples/boolean.fy +0 -24
- data/examples/class.fy +0 -68
- data/examples/constant_access.fy +0 -15
- data/examples/default_args.fy +0 -20
- data/examples/define_methods.fy +0 -15
- data/examples/dynamic_output.fy +0 -15
- data/examples/empty_catch.fy +0 -4
- data/examples/exception.fy +0 -9
- data/examples/files.fy +0 -23
- data/examples/finally.fy +0 -5
- data/examples/future.fy +0 -30
- data/examples/future_composition.fy +0 -20
- data/examples/futures.fy +0 -9
- data/examples/game_of_life.fy +0 -148
- data/examples/html_generator.fy +0 -84
- data/examples/implicit_return.fy +0 -3
- data/examples/matchers.fy +0 -6
- data/examples/nested_try.fy +0 -9
- data/examples/numbers.fy +0 -12
- data/examples/rbx/and_or.fy +0 -7
- data/examples/rbx/blocks.fy +0 -22
- data/examples/rbx/classes.fy +0 -32
- data/examples/rbx/hello.fy +0 -8
- data/examples/rbx/include.fy +0 -12
- data/examples/rbx/inherit.fy +0 -11
- data/examples/rbx/methods.fy +0 -15
- data/examples/rbx/nested_classes.fy +0 -9
- data/examples/rbx/require.fy +0 -3
- data/examples/rbx/strings.fy +0 -5
- data/examples/require.fy +0 -7
- data/examples/return.fy +0 -13
- data/examples/singleton_methods.fy +0 -21
- data/examples/threads.fy +0 -18
- data/examples/tuple.fy +0 -8
- data/examples/webserver/webserver.fy +0 -15
- data/lib/proxy.fy +0 -86
- data/lib/thread_pool.fy +0 -102
data/examples/rbx/and_or.fy
DELETED
data/examples/rbx/blocks.fy
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
2 times: |i| {
|
2
|
-
i println
|
3
|
-
}
|
4
|
-
|
5
|
-
1 upto: 4 do: |i| {
|
6
|
-
i println
|
7
|
-
}
|
8
|
-
|
9
|
-
x = 0
|
10
|
-
while: { x < 4 } do: {
|
11
|
-
"in while_true, with x = " ++ x println
|
12
|
-
x = x + 1
|
13
|
-
}
|
14
|
-
|
15
|
-
b = |x, y| {
|
16
|
-
"x is: " ++ (x inspect) println
|
17
|
-
"y is: " ++ (y inspect) println
|
18
|
-
x + y println
|
19
|
-
}
|
20
|
-
|
21
|
-
b call: [1,2]
|
22
|
-
|
data/examples/rbx/classes.fy
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class Person {
|
2
|
-
@@a_classvar = "foo"
|
3
|
-
def initialize: name {
|
4
|
-
@name = name
|
5
|
-
}
|
6
|
-
|
7
|
-
def to_s {
|
8
|
-
"Person with name: " ++ @name
|
9
|
-
}
|
10
|
-
|
11
|
-
def Person class_var {
|
12
|
-
@@a_classvar
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
p = Person new: "Christopher"
|
17
|
-
p println
|
18
|
-
Person class_var println
|
19
|
-
|
20
|
-
class PersonWithAge : Person {
|
21
|
-
def initialize: name age: age {
|
22
|
-
@name = name
|
23
|
-
@age = age
|
24
|
-
}
|
25
|
-
|
26
|
-
def to_s {
|
27
|
-
super to_s ++ " and age: " ++ @age
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
p2 = PersonWithAge new: "Christopher" age: 23
|
32
|
-
p2 println
|
data/examples/rbx/hello.fy
DELETED
data/examples/rbx/include.fy
DELETED
data/examples/rbx/inherit.fy
DELETED
data/examples/rbx/methods.fy
DELETED
data/examples/rbx/require.fy
DELETED
data/examples/rbx/strings.fy
DELETED
data/examples/require.fy
DELETED
data/examples/return.fy
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
def foo: block {
|
2
|
-
1 upto: 10 do: |i| {
|
3
|
-
val = block call: [i]
|
4
|
-
if: (block call: [i]) then: {
|
5
|
-
return i # non-local return from "foo:"
|
6
|
-
}
|
7
|
-
}
|
8
|
-
return "yay"
|
9
|
-
}
|
10
|
-
|
11
|
-
foo: |x| { x == 6 } . println
|
12
|
-
foo: |x| { x == 0 } . println
|
13
|
-
foo: |x| { return_local true } . println # local return
|
@@ -1,21 +0,0 @@
|
|
1
|
-
def self singleton_method {
|
2
|
-
"in singleton_method" println
|
3
|
-
}
|
4
|
-
|
5
|
-
self singleton_method
|
6
|
-
|
7
|
-
arr = [1,2,3]
|
8
|
-
|
9
|
-
def arr foobar {
|
10
|
-
self each: |x| {
|
11
|
-
"foobar: " ++ x println
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
arr foobar
|
16
|
-
|
17
|
-
def Array empty! {
|
18
|
-
[]
|
19
|
-
}
|
20
|
-
|
21
|
-
Array empty! inspect println
|
data/examples/threads.fy
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# threads.fy
|
2
|
-
# Example of threads in fancy
|
3
|
-
|
4
|
-
threads = []
|
5
|
-
10 times: |i| {
|
6
|
-
t = Thread new: {
|
7
|
-
"Running Thread #" ++ i println
|
8
|
-
i times: {
|
9
|
-
"." print
|
10
|
-
Thread sleep: 1.5 # sleep 1,5 sec
|
11
|
-
}
|
12
|
-
}
|
13
|
-
threads << t
|
14
|
-
}
|
15
|
-
|
16
|
-
"Waiting for all Threads to end..." print
|
17
|
-
threads each: 'join
|
18
|
-
|
data/examples/tuple.fy
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# webserver.fy
|
2
|
-
# Example of a simple webserver written in fancy, using Ruby socket library
|
3
|
-
|
4
|
-
host, port = "127.0.0.1", 3000
|
5
|
-
webserver = TCPServer new: host port: port
|
6
|
-
"Webserver running at: #{host}:#{port}" println
|
7
|
-
|
8
|
-
loop: {
|
9
|
-
session = webserver accept
|
10
|
-
Thread new: {
|
11
|
-
session print: "HTTP/1.1 200/OK\r\nContent-type:text/html\r\n\r\n"
|
12
|
-
session print: $ File read: "examples/webserver/index.html"
|
13
|
-
session close
|
14
|
-
}
|
15
|
-
}
|
data/lib/proxy.fy
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
class ProxyReceiver : Fancy BasicObject {
|
2
|
-
"""
|
3
|
-
A ProxyReceiver is an object which proxies all message sends to it to 2 other objects.
|
4
|
-
It will send each message first to its @proxy instance variable and then to the @obj instance variable.
|
5
|
-
"""
|
6
|
-
|
7
|
-
def initialize: @proxy for: @obj {
|
8
|
-
"""
|
9
|
-
@proxy Proxy receiver for @obj.
|
10
|
-
@obj Original receiver object.
|
11
|
-
|
12
|
-
Initializes a new ProxyReceiver with @proxy for @obj.
|
13
|
-
"""
|
14
|
-
|
15
|
-
self
|
16
|
-
}
|
17
|
-
|
18
|
-
def unknown_message: msg with_params: params {
|
19
|
-
"""
|
20
|
-
@msg Incoming message name.
|
21
|
-
@params Paremeters of incoming message send.
|
22
|
-
|
23
|
-
Forwards all incoming messages to @self to @@proxy and then @@obj.
|
24
|
-
"""
|
25
|
-
|
26
|
-
@proxy receive_message: msg with_params: params
|
27
|
-
@obj receive_message: msg with_params: params
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
Proxy = ProxyReceiver
|
32
|
-
|
33
|
-
class RespondsToProxy : Fancy BasicObject {
|
34
|
-
"""
|
35
|
-
A RespondsToProxy is a Proxy that forwards any message sent to it to it's @target instance variable
|
36
|
-
only if it responds to that message. Any messages that @target doesn't respond to simply won't be sent
|
37
|
-
and @nil will be returned.
|
38
|
-
"""
|
39
|
-
|
40
|
-
def initialize: @target {
|
41
|
-
"""
|
42
|
-
@target Target receiver object.
|
43
|
-
|
44
|
-
Initializes a new RespondsToProxy for @target.
|
45
|
-
"""
|
46
|
-
|
47
|
-
self
|
48
|
-
}
|
49
|
-
|
50
|
-
def unknown_message: msg with_params: params {
|
51
|
-
"""
|
52
|
-
@msg Incoming message name.
|
53
|
-
@params Paremeters of incoming message send.
|
54
|
-
|
55
|
-
Forwards all incoming message to @self to @@target
|
56
|
-
only if @@target responds to them.
|
57
|
-
"""
|
58
|
-
|
59
|
-
if: (@target responds_to?: msg) then: {
|
60
|
-
@target receive_message: msg with_params: params
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
class ActorProxy : Fancy BasicObject {
|
66
|
-
"""
|
67
|
-
A ActorProxy is a Proxy that forwards any message sent to it to it's
|
68
|
-
@target instance variable as a future send by default.
|
69
|
-
If explicitly sent an async message, it will forward the async send
|
70
|
-
to @target, returning nil instead of a @FutureSend@, as expected.
|
71
|
-
"""
|
72
|
-
|
73
|
-
def initialize: @target
|
74
|
-
|
75
|
-
def send_future: m with_params: p {
|
76
|
-
@target send_future: m with_params: p
|
77
|
-
}
|
78
|
-
|
79
|
-
def send_async: m with_params: p {
|
80
|
-
@target send_async: m with_params: p
|
81
|
-
}
|
82
|
-
|
83
|
-
def unknown_message: m with_params: p {
|
84
|
-
@target send_future: m with_params: p
|
85
|
-
}
|
86
|
-
}
|
data/lib/thread_pool.fy
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
# This ThreadPool class is adapted from the Ruby code at:
|
2
|
-
# https://github.com/fizx/thread_pool/
|
3
|
-
|
4
|
-
class ThreadPool {
|
5
|
-
class Executor {
|
6
|
-
read_slot: 'active
|
7
|
-
|
8
|
-
def initialize: queue mutex: mutex {
|
9
|
-
@thread = Thread new: {
|
10
|
-
loop: {
|
11
|
-
mutex synchronize() { @tuple = queue shift() }
|
12
|
-
if: @tuple then: {
|
13
|
-
args, block = @tuple
|
14
|
-
@active = true
|
15
|
-
val = nil
|
16
|
-
try {
|
17
|
-
val = block call: args
|
18
|
-
} catch Exception => e {
|
19
|
-
e message println
|
20
|
-
e backtrace() join: "\n" . println
|
21
|
-
}
|
22
|
-
block complete: true
|
23
|
-
block completed_value: val
|
24
|
-
} else: {
|
25
|
-
@active = false
|
26
|
-
Thread sleep: 0.1
|
27
|
-
}
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
def close {
|
33
|
-
@thread exit
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
read_write_slot: 'queue_limit
|
38
|
-
|
39
|
-
# Initialize with number of threads to run
|
40
|
-
def initialize: @count limit: @queue_limit (0) {
|
41
|
-
@mutex = Mutex new()
|
42
|
-
@executors = []
|
43
|
-
@queue = []
|
44
|
-
@count times: { @executors << (Executor new: @queue mutex: @mutex) }
|
45
|
-
}
|
46
|
-
|
47
|
-
# Runs the block at some time in the near future
|
48
|
-
def execute: block with_args: args ([]) {
|
49
|
-
init_completable: block
|
50
|
-
|
51
|
-
if: (@queue_limit > 0) then: {
|
52
|
-
{ Thread sleep: 0.1 } until: { @queue size < @queue_limit }
|
53
|
-
}
|
54
|
-
|
55
|
-
@mutex synchronize() {
|
56
|
-
@queue << [args, block]
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
# Runs the block at some time in the near future, and blocks until complete
|
61
|
-
def execute_synchronous: block with_args: args ([]) {
|
62
|
-
execute: block with_args: args
|
63
|
-
{ Thread sleep: 0.1 } until: { block complete? }
|
64
|
-
block completed_value
|
65
|
-
}
|
66
|
-
|
67
|
-
# Size of the task queue
|
68
|
-
def waiting {
|
69
|
-
@queue size
|
70
|
-
}
|
71
|
-
|
72
|
-
# Size of the thread pool
|
73
|
-
def size {
|
74
|
-
@count
|
75
|
-
}
|
76
|
-
|
77
|
-
# Kills all threads
|
78
|
-
def close {
|
79
|
-
@executors each: @{ close }
|
80
|
-
}
|
81
|
-
|
82
|
-
# Sleeps and blocks until the task queue is finished executing
|
83
|
-
def join {
|
84
|
-
{ Thread sleep: 0.1 } until: { { @queue empty? } && { @executors all?: @{ active not } } }
|
85
|
-
}
|
86
|
-
|
87
|
-
class Completable {
|
88
|
-
read_write_slot: 'completed_value
|
89
|
-
def complete: @complete {
|
90
|
-
}
|
91
|
-
|
92
|
-
def complete? {
|
93
|
-
@complete not not
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
def init_completable: block {
|
98
|
-
block extend(Completable)
|
99
|
-
block complete: false
|
100
|
-
}
|
101
|
-
protected: 'init_completable:
|
102
|
-
}
|