Load built-in functions with reflection
This commit is contained in:
parent
0efae35391
commit
55668a05a6
6
pom.xml
6
pom.xml
|
@ -172,6 +172,12 @@
|
|||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.11</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package function
|
||||
|
||||
import kotlin.annotation.AnnotationRetention.RUNTIME
|
||||
import kotlin.annotation.AnnotationTarget.CLASS
|
||||
import kotlin.annotation.AnnotationTarget.FILE
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(CLASS, FILE)
|
||||
@Target(CLASS)
|
||||
annotation class FunctionNames(vararg val value: String)
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package sexpression
|
||||
|
||||
import kotlin.annotation.AnnotationRetention.RUNTIME
|
||||
import kotlin.annotation.AnnotationTarget.CLASS
|
||||
import kotlin.annotation.AnnotationTarget.FILE
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(CLASS, FILE)
|
||||
@Target(CLASS)
|
||||
annotation class DisplayName(val value: String)
|
||||
|
|
|
@ -3,106 +3,16 @@ package table
|
|||
import error.CriticalLispException
|
||||
import function.FunctionNames
|
||||
import function.LispFunction
|
||||
import function.builtin.APPLY
|
||||
import function.builtin.Eval
|
||||
import function.builtin.Exit
|
||||
import function.builtin.FUNCALL
|
||||
import function.builtin.FUSE
|
||||
import function.builtin.GENSYM
|
||||
import function.builtin.LOAD
|
||||
import function.builtin.PRINT
|
||||
import function.builtin.SET
|
||||
import function.builtin.SYMBOLS
|
||||
import function.builtin.SYMBOL_FUNCTION
|
||||
import function.builtin.cons.APPEND
|
||||
import function.builtin.cons.CONS
|
||||
import function.builtin.cons.FIRST
|
||||
import function.builtin.cons.LENGTH
|
||||
import function.builtin.cons.LIST
|
||||
import function.builtin.cons.REST
|
||||
import function.builtin.math.DIVIDE
|
||||
import function.builtin.math.MINUS
|
||||
import function.builtin.math.MODULO
|
||||
import function.builtin.math.MULTIPLY
|
||||
import function.builtin.math.PLUS
|
||||
import function.builtin.math.REMAINDER
|
||||
import function.builtin.predicate.ATOM
|
||||
import function.builtin.predicate.EQ
|
||||
import function.builtin.predicate.EQUAL
|
||||
import function.builtin.predicate.GENSYM_EQUAL
|
||||
import function.builtin.predicate.LISTP
|
||||
import function.builtin.predicate.NULL
|
||||
import function.builtin.predicate.NUMERIC_GREATER
|
||||
import function.builtin.predicate.NUMERIC_LESS
|
||||
import function.builtin.predicate.NumericEqual
|
||||
import function.builtin.special.AND
|
||||
import function.builtin.special.CASE
|
||||
import function.builtin.special.COND
|
||||
import function.builtin.special.DEFINE_SPECIAL
|
||||
import function.builtin.special.DEFMACRO
|
||||
import function.builtin.special.DEFUN
|
||||
import function.builtin.special.IF
|
||||
import function.builtin.special.LET
|
||||
import function.builtin.special.LET_STAR
|
||||
import function.builtin.special.Lambda
|
||||
import function.builtin.special.OR
|
||||
import function.builtin.special.PROGN
|
||||
import function.builtin.special.QUOTE
|
||||
import function.builtin.special.RECUR
|
||||
import function.builtin.special.SETQ
|
||||
import org.reflections.Reflections
|
||||
|
||||
object FunctionTable {
|
||||
|
||||
private val allBuiltIns = setOf(
|
||||
AND::class.java,
|
||||
APPEND::class.java,
|
||||
APPLY::class.java,
|
||||
ATOM::class.java,
|
||||
CASE::class.java,
|
||||
COND::class.java,
|
||||
CONS::class.java,
|
||||
DEFINE_SPECIAL::class.java,
|
||||
DEFMACRO::class.java,
|
||||
DEFUN::class.java,
|
||||
DIVIDE::class.java,
|
||||
EQ::class.java,
|
||||
EQUAL::class.java,
|
||||
NumericEqual::class.java,
|
||||
Eval::class.java,
|
||||
Exit::class.java,
|
||||
FIRST::class.java,
|
||||
FUNCALL::class.java,
|
||||
FUSE::class.java,
|
||||
GENSYM::class.java,
|
||||
GENSYM_EQUAL::class.java,
|
||||
NUMERIC_GREATER::class.java,
|
||||
IF::class.java,
|
||||
Lambda::class.java,
|
||||
LENGTH::class.java,
|
||||
NUMERIC_LESS::class.java,
|
||||
LET::class.java,
|
||||
LET_STAR::class.java,
|
||||
LIST::class.java,
|
||||
LISTP::class.java,
|
||||
LOAD::class.java,
|
||||
MINUS::class.java,
|
||||
MODULO::class.java,
|
||||
MULTIPLY::class.java,
|
||||
NULL::class.java,
|
||||
OR::class.java,
|
||||
PLUS::class.java,
|
||||
PRINT::class.java,
|
||||
PROGN::class.java,
|
||||
QUOTE::class.java,
|
||||
RECUR::class.java,
|
||||
REMAINDER::class.java,
|
||||
REST::class.java,
|
||||
SET::class.java,
|
||||
SETQ::class.java,
|
||||
SYMBOL_FUNCTION::class.java,
|
||||
SYMBOLS::class.java)
|
||||
|
||||
private val table = mutableMapOf<String, LispFunction>()
|
||||
private val reflections = Reflections("function")
|
||||
private val allBuiltIns =
|
||||
reflections.getTypesAnnotatedWith(FunctionNames::class.java)
|
||||
.filterIsInstance<Class<out LispFunction>>()
|
||||
.toSet()
|
||||
|
||||
init {
|
||||
initializeFunctionTable(allBuiltIns)
|
||||
|
|
Loading…
Reference in New Issue