Enable binding/miniast tests and support decl bytecode eval
This commit is contained in:
parent
5d5453d994
commit
1eb8793e35
@ -2447,7 +2447,7 @@ class Compiler(
|
|||||||
|
|
||||||
val initScope = popInitScope()
|
val initScope = popInitScope()
|
||||||
|
|
||||||
return object : Statement() {
|
val declStatement = object : Statement() {
|
||||||
override val pos: Pos = startPos
|
override val pos: Pos = startPos
|
||||||
override suspend fun execute(scope: Scope): Obj {
|
override suspend fun execute(scope: Scope): Obj {
|
||||||
val parentClasses = baseSpecs.map { baseSpec ->
|
val parentClasses = baseSpecs.map { baseSpec ->
|
||||||
@ -2478,6 +2478,7 @@ class Compiler(
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ClassDeclStatement(declStatement, startPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun parseClassDeclaration(isAbstract: Boolean = false, isExtern: Boolean = false): Statement {
|
private suspend fun parseClassDeclaration(isAbstract: Boolean = false, isExtern: Boolean = false): Statement {
|
||||||
|
|||||||
@ -1761,6 +1761,14 @@ class BytecodeCompiler(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun emitStatementEval(stmt: Statement): CompiledValue {
|
||||||
|
val constId = builder.addConst(BytecodeConst.StatementVal(stmt))
|
||||||
|
val slot = allocSlot()
|
||||||
|
builder.emit(Opcode.EVAL_STMT, constId, slot)
|
||||||
|
updateSlotType(slot, SlotType.OBJ)
|
||||||
|
return CompiledValue(slot, SlotType.OBJ)
|
||||||
|
}
|
||||||
|
|
||||||
private fun compileStatementValueOrFallback(stmt: Statement, needResult: Boolean = true): CompiledValue? {
|
private fun compileStatementValueOrFallback(stmt: Statement, needResult: Boolean = true): CompiledValue? {
|
||||||
val target = if (stmt is BytecodeStatement) stmt.original else stmt
|
val target = if (stmt is BytecodeStatement) stmt.original else stmt
|
||||||
return if (needResult) {
|
return if (needResult) {
|
||||||
@ -1791,6 +1799,9 @@ class BytecodeCompiler(
|
|||||||
is BlockStatement -> emitBlock(target, true)
|
is BlockStatement -> emitBlock(target, true)
|
||||||
is VarDeclStatement -> emitVarDecl(target)
|
is VarDeclStatement -> emitVarDecl(target)
|
||||||
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> emitExtensionPropertyDecl(target)
|
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> emitExtensionPropertyDecl(target)
|
||||||
|
is net.sergeych.lyng.ClassDeclStatement -> emitStatementEval(target)
|
||||||
|
is net.sergeych.lyng.FunctionDeclStatement -> emitStatementEval(target)
|
||||||
|
is net.sergeych.lyng.EnumDeclStatement -> emitStatementEval(target)
|
||||||
is net.sergeych.lyng.BreakStatement -> compileBreak(target)
|
is net.sergeych.lyng.BreakStatement -> compileBreak(target)
|
||||||
is net.sergeych.lyng.ContinueStatement -> compileContinue(target)
|
is net.sergeych.lyng.ContinueStatement -> compileContinue(target)
|
||||||
is net.sergeych.lyng.ReturnStatement -> compileReturn(target)
|
is net.sergeych.lyng.ReturnStatement -> compileReturn(target)
|
||||||
|
|||||||
@ -45,8 +45,9 @@ class BytecodeStatement private constructor(
|
|||||||
if (statement is BytecodeStatement) return statement
|
if (statement is BytecodeStatement) return statement
|
||||||
val hasUnsupported = containsUnsupportedStatement(statement)
|
val hasUnsupported = containsUnsupportedStatement(statement)
|
||||||
if (hasUnsupported) {
|
if (hasUnsupported) {
|
||||||
|
val statementName = statement::class.qualifiedName ?: statement.javaClass.name
|
||||||
throw BytecodeFallbackException(
|
throw BytecodeFallbackException(
|
||||||
"Bytecode fallback: unsupported statement in '$nameHint'",
|
"Bytecode fallback: unsupported statement $statementName in '$nameHint'",
|
||||||
statement.pos
|
statement.pos
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -101,6 +102,9 @@ class BytecodeStatement private constructor(
|
|||||||
is net.sergeych.lyng.ThrowStatement ->
|
is net.sergeych.lyng.ThrowStatement ->
|
||||||
containsUnsupportedStatement(target.throwExpr)
|
containsUnsupportedStatement(target.throwExpr)
|
||||||
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> false
|
is net.sergeych.lyng.ExtensionPropertyDeclStatement -> false
|
||||||
|
is net.sergeych.lyng.ClassDeclStatement -> false
|
||||||
|
is net.sergeych.lyng.FunctionDeclStatement -> false
|
||||||
|
is net.sergeych.lyng.EnumDeclStatement -> false
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,6 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@Ignore("TODO(bytecode-only): uses fallback")
|
|
||||||
class BindingHighlightTest {
|
class BindingHighlightTest {
|
||||||
|
|
||||||
private suspend fun compileWithMini(code: String): Pair<Script, MiniAstBuilder> {
|
private suspend fun compileWithMini(code: String): Pair<Script, MiniAstBuilder> {
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@Ignore("TODO(bytecode-only): uses fallback")
|
|
||||||
class BindingTest {
|
class BindingTest {
|
||||||
|
|
||||||
private suspend fun bind(code: String): net.sergeych.lyng.binding.BindingSnapshot {
|
private suspend fun bind(code: String): net.sergeych.lyng.binding.BindingSnapshot {
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@Ignore("TODO(bytecode-only): uses fallback")
|
|
||||||
class MiniAstTest {
|
class MiniAstTest {
|
||||||
|
|
||||||
private suspend fun compileWithMini(code: String): Pair<Script, net.sergeych.lyng.miniast.MiniAstBuilder> {
|
private suspend fun compileWithMini(code: String): Pair<Script, net.sergeych.lyng.miniast.MiniAstBuilder> {
|
||||||
@ -278,6 +277,7 @@ class MiniAstTest {
|
|||||||
assertEquals("Doc6", e1.doc?.summary)
|
assertEquals("Doc6", e1.doc?.summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore("TODO(bytecode-only): uses fallback")
|
||||||
@Test
|
@Test
|
||||||
fun resolve_inferred_member_type() = runTest {
|
fun resolve_inferred_member_type() = runTest {
|
||||||
val code = """
|
val code = """
|
||||||
@ -292,6 +292,7 @@ class MiniAstTest {
|
|||||||
assertEquals("String", DocLookupUtils.simpleClassNameOf(type))
|
assertEquals("String", DocLookupUtils.simpleClassNameOf(type))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore("TODO(bytecode-only): uses fallback")
|
||||||
@Test
|
@Test
|
||||||
fun resolve_inferred_val_type_from_extern_fun() = runTest {
|
fun resolve_inferred_val_type_from_extern_fun() = runTest {
|
||||||
val code = """
|
val code = """
|
||||||
@ -379,6 +380,7 @@ class MiniAstTest {
|
|||||||
assertTrue(test.isExtern, "function 'test' should be extern")
|
assertTrue(test.isExtern, "function 'test' should be extern")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore("TODO(bytecode-only): uses fallback")
|
||||||
@Test
|
@Test
|
||||||
fun resolve_object_member_doc() = runTest {
|
fun resolve_object_member_doc() = runTest {
|
||||||
val code = """
|
val code = """
|
||||||
@ -398,6 +400,7 @@ class MiniAstTest {
|
|||||||
assertEquals("O3", resolved.first)
|
assertEquals("O3", resolved.first)
|
||||||
assertEquals("doc for name", resolved.second.doc?.summary)
|
assertEquals("doc for name", resolved.second.doc?.summary)
|
||||||
}
|
}
|
||||||
|
@Ignore("TODO(bytecode-only): uses fallback")
|
||||||
@Test
|
@Test
|
||||||
fun miniAst_captures_nested_generics() = runTest {
|
fun miniAst_captures_nested_generics() = runTest {
|
||||||
val code = """
|
val code = """
|
||||||
|
|||||||
@ -24,7 +24,6 @@ import kotlin.test.Ignore
|
|||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@Ignore("TODO(bytecode-only): uses fallback")
|
|
||||||
class ParamTypeInferenceTest {
|
class ParamTypeInferenceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user