fancy 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
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,7 +0,0 @@
1
- true and: nil . inspect println
2
- nil and: true . inspect println
3
- true and: true . inspect println
4
-
5
- nil or: nil . inspect println
6
- nil or: true . inspect println
7
- true or: nil . inspect println
@@ -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
-
@@ -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
@@ -1,8 +0,0 @@
1
- "Hello from Fancy, " + "Rubinius!!" println
2
- 44 + 323.2323 println
3
-
4
- def foo: x {
5
- x + x println
6
- }
7
-
8
- foo: 10
@@ -1,12 +0,0 @@
1
- class Hello {
2
- def hello {
3
- "Hello " ++ @name println
4
- }
5
- }
6
-
7
- class World {
8
- include: Hello
9
- def initialize { @name = "World" }
10
- }
11
-
12
- World new hello
@@ -1,11 +0,0 @@
1
- class Hello {
2
- def hello {
3
- "Hello " ++ (self name) . println
4
- }
5
- }
6
-
7
- class World : Hello {
8
- def name { "World" }
9
- }
10
-
11
- World new hello
@@ -1,15 +0,0 @@
1
- # A simple example of one method calling another in self.
2
- def hello {
3
- "Hello " ++ (self world)
4
- }
5
-
6
- def world { "World" }
7
-
8
-
9
- self hello println
10
-
11
- def hello_to: obj {
12
- "Hello, " ++ obj println
13
- }
14
-
15
- hello_to: "World!"
@@ -1,9 +0,0 @@
1
- class Outer {
2
- class Inner {
3
- def foo: bar {
4
- "foo got: " ++ bar println
5
- }
6
- }
7
- }
8
-
9
- Outer::Inner new foo: "yay!"
@@ -1,3 +0,0 @@
1
- require: "hello.fy"
2
-
3
- "Now executing from require.fy!" println
@@ -1,5 +0,0 @@
1
- "foo bar baz" split: " " . each: |x| {
2
- x println
3
- }
4
-
5
- "hello \t world" println
@@ -1,7 +0,0 @@
1
- # require.fy
2
- # Examples of fancy code reusing and evaluation facilities
3
-
4
- require: "arithmetic.fy"
5
-
6
- "in require.fnc!" println
7
- ARGV println # prints any given command-line arguments as an array
@@ -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
@@ -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
-
@@ -1,8 +0,0 @@
1
- # tuple.fy
2
-
3
- tuple = (1,2,3)
4
- tuple size println
5
-
6
- (1,"foo",'bar) [0] inspect println
7
-
8
- (1, "foo", 'bar) == (1, "foo", 'bar) println
@@ -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
- }
@@ -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
- }
@@ -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
- }