Unify body handling.

Blocks, functions, and methods now have the same code for handling
their bodies.

This means that single-line methods work like single-line functions:
they return the result of their expression.
This commit is contained in:
Bob Nystrom
2014-04-03 07:48:19 -07:00
parent 55c2c6ffb0
commit da4cadf16b
34 changed files with 1165 additions and 1187 deletions
+17 -17
View File
@@ -1,21 +1,21 @@
class Foo {
method { return 0 }
method(a) { return a }
method(a, b) { return a + b }
method(a, b, c) { return a + b + c }
method(a, b, c, d) { return a + b + c + d }
method(a, b, c, d, e) { return a + b + c + d + e }
method(a, b, c, d, e, f) { return a + b + c + d + e + f }
method(a, b, c, d, e, f, g) { return a + b + c + d + e + f + g }
method(a, b, c, d, e, f, g, h) { return a + b + c + d + e + f + g + h }
method(a, b, c, d, e, f, g, h, i) { return a + b + c + d + e + f + g + h + i }
method(a, b, c, d, e, f, g, h, i, j) { return a + b + c + d + e + f + g + h + i + j }
method(a, b, c, d, e, f, g, h, i, j, k) { return a + b + c + d + e + f + g + h + i + j + k}
method(a, b, c, d, e, f, g, h, i, j, k, l) { return a + b + c + d + e + f + g + h + i + j + k + l}
method(a, b, c, d, e, f, g, h, i, j, k, l, m) { return a + b + c + d + e + f + g + h + i + j + k + l + m}
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n) { return a + b + c + d + e + f + g + h + i + j + k + l + m + n}
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) { return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o}
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) { return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p}
method { 0 }
method(a) { a }
method(a, b) { a + b }
method(a, b, c) { a + b + c }
method(a, b, c, d) { a + b + c + d }
method(a, b, c, d, e) { a + b + c + d + e }
method(a, b, c, d, e, f) { a + b + c + d + e + f }
method(a, b, c, d, e, f, g) { a + b + c + d + e + f + g }
method(a, b, c, d, e, f, g, h) { a + b + c + d + e + f + g + h }
method(a, b, c, d, e, f, g, h, i) { a + b + c + d + e + f + g + h + i }
method(a, b, c, d, e, f, g, h, i, j) { a + b + c + d + e + f + g + h + i + j }
method(a, b, c, d, e, f, g, h, i, j, k) { a + b + c + d + e + f + g + h + i + j + k}
method(a, b, c, d, e, f, g, h, i, j, k, l) { a + b + c + d + e + f + g + h + i + j + k + l}
method(a, b, c, d, e, f, g, h, i, j, k, l, m) { a + b + c + d + e + f + g + h + i + j + k + l + m}
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n) { a + b + c + d + e + f + g + h + i + j + k + l + m + n}
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) { a + b + c + d + e + f + g + h + i + j + k + l + m + n + o}
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) { a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p}
}
var foo = new Foo
+1000 -1000
View File
File diff suppressed because it is too large Load Diff
+15 -15
View File
@@ -1,20 +1,20 @@
class Foo {
+ other { return "infix + " + other }
- other { return "infix - " + other }
* other { return "infix * " + other }
/ other { return "infix / " + other }
% other { return "infix % " + other }
< other { return "infix < " + other }
> other { return "infix > " + other }
<= other { return "infix <= " + other }
>= other { return "infix >= " + other }
== other { return "infix == " + other }
!= other { return "infix != " + other }
& other { return "infix & " + other }
| other { return "infix | " + other }
+ other { "infix + " + other }
- other { "infix - " + other }
* other { "infix * " + other }
/ other { "infix / " + other }
% other { "infix % " + other }
< other { "infix < " + other }
> other { "infix > " + other }
<= other { "infix <= " + other }
>= other { "infix >= " + other }
== other { "infix == " + other }
!= other { "infix != " + other }
& other { "infix & " + other }
| other { "infix | " + other }
! { return "prefix !" }
- { return "prefix -" }
! { "prefix !" }
- { "prefix -" }
}
var foo = new Foo
+4 -4
View File
@@ -1,9 +1,9 @@
class Foo {
bar { return "on instance" }
static bar { return "on metaclass" }
bar { "on instance" }
static bar { "on metaclass" }
bar(arg) { return "on instance " + arg }
static bar(arg) { return "on metaclass " + arg }
bar(arg) { "on instance " + arg }
static bar(arg) { "on metaclass " + arg }
}
IO.print((new Foo).bar) // expect: on instance