Interpreting mathematical expressions at runtime is a standard task in scientific software engineering. There are different approaches to this problem from creating an embedded domain-specific language (eDSL) with its own parser and interpreter specifically for that task, to using a full-fledged embedded compiler. This article is dedicated to a middle-ground solution implemented in the KMath library, which uses the Kotlin object builder DSL and its own algebraic abstractions to generate an AST for mathematical operations. This AST is then compiled just-in-time to generate JVM bytecode. A similar approach is tested on other Kotlin platforms, where its performance is compared across a variety of supported platforms.
翻译:运行时解析数学表达式是科学软件工程的一项标准任务。 解决这个问题有各种不同的方法, 从创建嵌入的域名语言(eDSL), 专门为此项任务创建其自己的分析员和翻译员, 到使用完整的内嵌编译员。 此文章致力于在 KMath 库中实施的中层解决方案, 该库使用 Kotlin 对象构建器 DSL 及其自己的代数抽象学来生成用于数学操作的 AST 。 此 AST 将及时编译, 以生成 JVM 字节码 。 在其他 Kotlin 平台上测试类似的方法, 其性能在各种支持的平台上进行比较 。