Skip to content

Commit

Permalink
Merge pull request #102 from Mala1180/feature/cache-repl
Browse files Browse the repository at this point in the history
Feature/cache-repl
  • Loading branch information
Mala1180 authored Sep 17, 2023
2 parents 7dd7f1a + f898424 commit e168900
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/satify/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package satify

import satify.Architecture.MVU
import satify.Main.model
import satify.dsl.Reflection.startRepl
import satify.view.Constants.windowSize
import satify.view.GUI.*
import satify.view.Reactions.*
Expand All @@ -12,6 +13,7 @@ import scala.swing.{Dimension, FileChooser, MainFrame, Swing}

/** Entry point of the application. */
object Main extends App with MVU:
startRepl()
new MainFrame:
title = "Satify SAT Solver"

Expand Down
24 changes: 16 additions & 8 deletions src/main/scala/satify/dsl/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package satify.dsl
import satify.model.expression.Expression
import satify.model.expression.Expression.Symbol

import java.util.concurrent.Executors

object Reflection:

private val excludedWords = getDSLKeywords.mkString("|")
Expand All @@ -19,17 +21,16 @@ object Reflection:
* @param input the input to process
* @return the processed input
*/
def processInput(input: String): String =
// TODO: link these operators to the ones in the DSL
// regExp to match all words that are not operators
input
.replaceAll(regexPattern, "\"$1\"")
.replaceAll("\n", " ")

/** Reflects the input to the REPL returning an Expression
def processInput(input: String): String = input
.replaceAll(regexPattern, "\"$1\"")
.replaceAll("\n", " ")

/** Reflects the input to the REPL returning an Expression.
* If the REPL is not started yet, waits until it is started.
* @param input the input to evaluate
* @return the [[Expression]]
* @throws IllegalArgumentException if the input is malformed
* @see [[startRepl]]
*/
def reflect(input: String): Expression =
if input.matches(regexPattern) then Symbol(input)
Expand All @@ -44,3 +45,10 @@ object Reflection:
println(code)
try dotty.tools.repl.ScriptEngine().eval(imports + code).asInstanceOf[Expression]
catch case e: Exception => throw new IllegalArgumentException(e.getMessage)

/** Starts the REPL in a separate thread
* When the REPL is started, the a promise is completed permitting to call [[reflect]] method.
*/
def startRepl(): Unit = Executors
.newSingleThreadExecutor()
.execute(() => dotty.tools.repl.ScriptEngine().eval("println()"))
1 change: 0 additions & 1 deletion src/test/scala/satify/update/ConvertUpdateTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.scalatest.matchers.should.Matchers
import satify.model.State
import satify.update.Message.*
import satify.update.Update.update
import satify.view.GUI.inputTextArea

class ConvertUpdateTest extends AnyFlatSpec with Matchers:

Expand Down

0 comments on commit e168900

Please sign in to comment.