Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cache-repl #102

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/scala/satify/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package satify

import satify.Architecture.MVU
import satify.Main.model
import satify.view.ComponentUtils.createLabelledTextArea
import satify.dsl.Reflection.startRepl
import satify.view.Constants.windowSize
import satify.view.GUI.*
import satify.view.Reactions.*

import java.util.concurrent.Executors
import scala.swing.event.{ButtonClicked, SelectionChanged}
import scala.swing.{Component, Dimension, FileChooser, MainFrame, Swing}
import scala.swing.event.ButtonClicked
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()"))
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package satify.features

import io.cucumber.scala.{EN, ScalaDsl}
import org.scalatest.matchers.should.Matchers.*
import satify.dsl.Reflection.reflect
import satify.model.cnf.CNF
import satify.model.expression.Expression
import satify.update.converters.{Converter, ConverterType}

object TseitinTransformationSteps extends ScalaDsl with EN:
Expand Down
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