v1.1.0-beta1: mini function declarations and working properties
This commit is contained in:
1 parent
17b4904ae3
commit
8300c2a3ab
5 files changed
+39
-7
No files matched your search
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
group = "net.sergeych"
|
||||
version = "1.0.10-SNAPSHOT"
|
||||
version = "1.1.0-beta1"
|
||||
|
||||
// Removed legacy buildscript classpath declarations; plugins are applied via the plugins DSL below
|
||||
|
||||
|
||||
@@ -2433,7 +2433,20 @@ class Compiler(
|
||||
val fnStatements = if (isExtern)
|
||||
statement { raiseError("extern function not provided: $name") }
|
||||
else
|
||||
withLocalNames(paramNames) { parseBlock() }
|
||||
withLocalNames(paramNames) {
|
||||
val next = cc.peekNextNonWhitespace()
|
||||
if (next.type == Token.Type.ASSIGN) {
|
||||
cc.skipWsTokens()
|
||||
cc.next() // consume '='
|
||||
val expr = parseExpression() ?: throw ScriptError(cc.current().pos, "Expected function body expression")
|
||||
// Shorthand function returns the expression value
|
||||
statement(expr.pos) { scope ->
|
||||
expr.execute(scope)
|
||||
}
|
||||
} else {
|
||||
parseBlock()
|
||||
}
|
||||
}
|
||||
// Capture and pop the local declarations count for this function
|
||||
val fnLocalDecls = localDeclCountStack.removeLastOrNull() ?: 0
|
||||
|
||||
|
||||
@@ -3697,7 +3697,7 @@ class ScriptTest {
|
||||
}
|
||||
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
fun testMinimumOptimization() = runTest {
|
||||
for (i in 1..200) {
|
||||
bm {
|
||||
@@ -4518,4 +4518,18 @@ class ScriptTest {
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFunMiniDeclaration() = runTest {
|
||||
eval("""
|
||||
class T(x) {
|
||||
fun method() = x + 1
|
||||
}
|
||||
fun median(a,b) = (a+b)/2
|
||||
|
||||
assertEquals(11, T(10).method())
|
||||
assertEquals(2, median(1,3))
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user