mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
implement support for setting indexed values
This commit is contained in:
@ -177,7 +177,7 @@ class EvaluationVisitor(root: Scope, val stack: CallStack) : FunctionLevelVisito
|
||||
return previousValue
|
||||
}
|
||||
|
||||
override fun visitSetAssignment(node: SetAssignment): Any {
|
||||
override fun visitSymbolSetAssignment(node: SymbolSetAssignment): Any {
|
||||
val value = node.value.visit(this)
|
||||
currentScope.set(node.symbol.id, value)
|
||||
return value
|
||||
@ -399,6 +399,24 @@ class EvaluationVisitor(root: Scope, val stack: CallStack) : FunctionLevelVisito
|
||||
throw RuntimeException("Failed to index '${value}' by '${index}': Unsupported types used.")
|
||||
}
|
||||
|
||||
override fun visitIndexedSetAssignment(node: IndexedSetAssignment): Any {
|
||||
val value = node.value.visit(this)
|
||||
val index = node.index.visit(this)
|
||||
val target = node.target.visit(this)
|
||||
if (target is MutableList<*> && index is Number) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(target as MutableList<Any?>)[index.toInt()] = value
|
||||
return None
|
||||
}
|
||||
|
||||
if (target is Array<*> && index is Number) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(target as MutableList<Any?>)[index.toInt()] = value
|
||||
return None
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
override fun visitNoneLiteral(node: NoneLiteral): Any = None
|
||||
|
||||
override fun visitContinue(node: Continue): Any = ContinueMarker
|
||||
|
Reference in New Issue
Block a user