package fr.celticinfo.lox /** * The LoxClass class represents a class in the Lox language. */ class LoxClass(private val name: String, private val superClass: LoxClass?, private val methods: Map) : LoxCallable { override fun call(interpreter: Interpreter, arguments: List): Any? { val instance = LoxInstance(this) val initializer = findMethod("init") initializer?.bind(instance)?.call(interpreter, arguments) return instance } fun findMethod(name: String): LoxFunction? { if (methods.containsKey(name)) { return methods[name] } if (superClass != null) { return superClass.findMethod(name) } return null } override fun arity() = findMethod("init")?.arity() ?: 0 override fun toString() = name }