further Arguments optimizations

This commit is contained in:
Sergey Chernov 2025-06-11 09:12:07 +04:00
parent c0eba1ecf0
commit 382532e0e1
3 changed files with 4 additions and 8 deletions

View File

@ -74,7 +74,7 @@ data class ArgsDeclaration(val params: List<Item>, val endTokenType: Token.Type)
fun processEllipsis(index: Int, toFromIndex: Int) {
val a = params[index]
val l = if (index > toFromIndex) ObjList()
else ObjList(fromArgs.values.subList(index, toFromIndex + 1).toMutableList())
else ObjList(fromArgs.list.subList(index, toFromIndex + 1).toMutableList())
assign(a, l)
}

View File

@ -28,12 +28,8 @@ suspend fun Collection<ParsedArgument>.toArguments(context: Context): Arguments
data class Arguments(val list: List<Obj>) : List<Obj> by list {
data class Info(val value: Obj, val pos: Pos)
val values = list
fun firstAndOnly(): Obj {
if (list.size != 1) throw IllegalArgumentException("Expected one argument, got ${list.size}")
fun firstAndOnly(pos: Pos = Pos.UNKNOWN): Obj {
if (list.size != 1) throw ScriptError(pos, "expected one argument, got ${list.size}")
return list.first()
}

View File

@ -379,7 +379,7 @@ class Compiler(
val context = closure!!.copy(pos, args)
if (argsDeclaration == null) {
// no args: automatic var 'it'
val l = args.values
val l = args.list
val itValue: Obj = when (l.size) {
// no args: it == void
0 -> ObjVoid