-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial lambda implementation * Add ops on creation * New implementation * Functions are now tables, containing parameter signature, return type and inner function * function:getParameterTypes() * function:getReturnType() * Don't reset global variables on `@strict`, fixing issue with top level locals not working as upvalues since they'd be reset by the runtime. I don't think this would actually affect anyone since you shouldn't be able to use variables before they're assigned, but it's `@strict` only behavior anyway. * Fix missing parity change I'd already fixed this bug with functions that have return values but this was not fixed for functions without return values. Also added a test case for this. * More tests, enforce returns at compile time * Add tests to ensure variadic parameters, void parameters and implicit parameters aren't allowed * Fix lambdas potentially not returning at all codepaths like functions now are expected to do. Added a test for that. * Fix early returns I should stop prematurely optimizing this.. This is like the third or second time I've made this mistake lol * Fix highlighting Actually a really easy fix. Surprising * Fix merge regression
- Loading branch information
Showing
13 changed files
with
416 additions
and
130 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
data/expression2/tests/compiler/compiler/restrictions/fn_void_param.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## SHOULD_FAIL:COMPILE | ||
|
||
function test(X:void) {} |
4 changes: 4 additions & 0 deletions
4
data/expression2/tests/compiler/compiler/restrictions/lambda/implicit_param.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## SHOULD_FAIL:COMPILE | ||
|
||
# Implicit number fallback is not going to be allowed. | ||
const J = function(X) {} |
6 changes: 6 additions & 0 deletions
6
data/expression2/tests/compiler/compiler/restrictions/lambda/return_codepaths.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## SHOULD_FAIL:COMPILE | ||
|
||
const X = function() { | ||
if (1) { return "str" } | ||
# doesn't return string | ||
} |
6 changes: 6 additions & 0 deletions
6
data/expression2/tests/compiler/compiler/restrictions/lambda/return_type_mix.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## SHOULD_FAIL:COMPILE | ||
|
||
const X = function() { | ||
if (1) { return "str" } | ||
return 22 | ||
} |
4 changes: 4 additions & 0 deletions
4
data/expression2/tests/compiler/compiler/restrictions/lambda/variadic_param.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## SHOULD_FAIL:COMPILE | ||
|
||
const X = function(...A:array) {} | ||
const Y = function(...A:table) {} |
3 changes: 3 additions & 0 deletions
3
data/expression2/tests/compiler/compiler/restrictions/lambda/void_param.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## SHOULD_FAIL:COMPILE | ||
|
||
const X = function(X:void) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
## SHOULD_PASS:EXECUTE | ||
|
||
# Returns | ||
|
||
assert( (function() { return 55 })()[number] == 55 ) | ||
assert( (function() { return "str" })()[string] == "str" ) | ||
|
||
# Upvalues | ||
|
||
const Wrapper = function(V:number) { | ||
return function() { | ||
return V | ||
} | ||
} | ||
|
||
const F1 = Wrapper(55)[function] | ||
|
||
if (1) { | ||
if (2) { | ||
local V = 22 | ||
assert(F1()[number] == 55) | ||
} | ||
} | ||
|
||
assert(F1()[number] == 55) | ||
assert(F1()[number] == 55) | ||
|
||
const F2 = Wrapper(1238)[function] | ||
|
||
assert(F2()[number] == 1238) | ||
#local V = 21 | ||
assert(F2()[number] == 1238) | ||
|
||
const IsEven = function(N:number) { | ||
return N % 2 == 0 | ||
} | ||
|
||
const Not = function(N:number) { | ||
return !N | ||
} | ||
|
||
const IsOdd = function(N:number) { | ||
return Not(IsEven(N)[number])[number] | ||
} | ||
|
||
assert(IsOdd(1)[number] == 1) | ||
assert(IsOdd(2)[number] == 0) | ||
|
||
assert( ((function() { return function() { return 55 } })()[function])()[number] == 55 ) | ||
|
||
const Identity = function(N:number) { | ||
return N | ||
} | ||
|
||
assert(Identity(2)[number] == 2) | ||
assert(Identity(2193921)[number] == 2193921) | ||
|
||
local SayMessage = function() {} | ||
|
||
const SetMessage = function(Message:string) { | ||
SayMessage = function() { | ||
return Message | ||
} | ||
} | ||
|
||
SetMessage("There's a snake in my boot!") | ||
|
||
assert( SayMessage()[string] == "There's a snake in my boot!" ) | ||
assert( SayMessage()[string] == "There's a snake in my boot!" ) | ||
|
||
SetMessage("Reach for the sky!") | ||
|
||
assert( SayMessage()[string] == "Reach for the sky!" ) | ||
|
||
const EarlyReturn = function() { | ||
return | ||
} | ||
|
||
Ran = 0 | ||
|
||
function wrapper() { | ||
EarlyReturn() | ||
Ran = 1 | ||
} | ||
|
||
wrapper() | ||
assert(Ran) |
Oops, something went wrong.