Skip to content

Commit d0a8a34

Browse files
committed
Use tupson library for JSON. Update scala and scalajs
1 parent 12464a1 commit d0a8a34

30 files changed

+145
-144
lines changed

build.sbt

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import org.scalajs.linker.interface.OutputPatterns
22

33
inThisBuild(
44
List(
5-
scalaVersion := "3.1.0",
5+
scalaVersion := "3.2.2",
66
evictionErrorLevel := Level.Warn,
77
publish / skip := true,
88
scalafmtSbt := true,
99
resolvers +=
1010
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
11+
resolvers += "jitpack" at "https://jitpack.io",
1112
organization := "dev.sacode",
1213
licenses := List("GPL-3.0" -> url("https://www.gnu.org/licenses/gpl-3.0.html")),
1314
scmInfo := Some(
@@ -31,19 +32,20 @@ lazy val core = (project in file("core"))
3132
.settings(
3233
name := "FlowRun",
3334
libraryDependencies ++= Seq(
34-
// TODO ("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0").cross(CrossVersion.for3Use2_13),
35+
("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0").cross(CrossVersion.for3Use2_13),
3536
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0-M1",
3637
"com.lihaoyi" %%% "scalatags" % "0.11.0",
37-
"com.lihaoyi" %%% "pprint" % "0.7.1",
3838
"com.outr" %%% "reactify" % "4.0.6",
39-
"org.getshaka" %%% "native-converter" % "0.5.2",
40-
"com.lihaoyi" %%% "utest" % "0.7.10" % Test
39+
"ba.sake" %%% "tupson" % "0.5.1",
40+
"com.lihaoyi" %%% "utest" % "0.7.10" % Test,
41+
"com.lihaoyi" %%% "pprint" % "0.7.1" % Test
4142
),
4243
scalacOptions ++= Seq(
4344
"-Xmax-inlines",
4445
"64",
4546
"-Ysafe-init",
46-
"-deprecation"
47+
"-deprecation",
48+
"-Yretain-trees"
4749
),
4850
//scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
4951

core/src/main/scala/dev/sacode/flowrun/FlowRun.scala

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package dev.sacode.flowrun
22

3+
import java.time.Instant
4+
import java.time.Duration
5+
import java.time.temporal.TemporalUnit
6+
import java.time.temporal.ChronoUnit
37
import scala.concurrent.ExecutionContext.Implicits.global
48
import scala.scalajs.js
59
import scala.scalajs.js.annotation.*
610
import org.scalajs.dom
11+
712
import scalatags.JsDom.all.*
8-
import org.getshaka.nativeconverter.fromJson
913
import reactify.*
14+
import ba.sake.tupson.*
1015
import dev.sacode.flowrun.eval.Interpreter
1116
import dev.sacode.flowrun.ast.*
1217
import dev.sacode.flowrun.edit.FlowchartPresenter
@@ -19,10 +24,6 @@ import dev.sacode.flowrun.codegen.CodeGeneratorFactory
1924
import dev.sacode.flowrun.codegen.Language
2025
import dev.sacode.flowrun.toastify.*
2126
import dev.sacode.flowrun.eval.Interpreter.State
22-
import java.time.Instant
23-
import java.time.Duration
24-
import java.time.temporal.TemporalUnit
25-
import java.time.temporal.ChronoUnit
2627
import dev.sacode.flowrun.edit.CodeArea
2728

2829
@JSExportTopLevel("FlowRun")
@@ -41,7 +42,7 @@ class FlowRun(
4142
Option.when(mountElemText.nonEmpty)(mountElemText)
4243
}
4344
private val program = jsonSourceOpt match
44-
case Some(json) => json.fromJson[Program]
45+
case Some(json) => json.parseJson[Program]
4546
case None =>
4647
Program(
4748
AST.newId,
@@ -85,6 +86,8 @@ class FlowRun(
8586

8687
attachRunAndCopyListeners()
8788

89+
// fixed layout is when you force layout with a class
90+
// meaning not-changeable with checkboxes
8891
private val fixedLayout = flowRunElements.mountElem.classList.exists(_.startsWith("flowrun-layout"))
8992
if fixedLayout then flowRunElements.configWidget.querySelector(".flowrun-config-layout").remove()
9093
else updateLayout()
@@ -315,19 +318,15 @@ class FlowRun(
315318

316319
flowRunElements.showFunctionsCheckbox.checked = programModel.ast.config.showFunctions
317320
flowRunElements.showCodeCheckbox.checked = programModel.ast.config.showGenCode
321+
flowRunElements.showDebugVarsCheckbox.checked = programModel.ast.config.showDebugVars
318322

319323
if !fixedLayout then
320324
flowRunElements.showFunctionsCheckbox.oninput = _ => setLayout()
321325
flowRunElements.showCodeCheckbox.oninput = _ => setLayout()
322326

323-
/*
324-
flowRunElements.drawArea.addEventListener(
325-
"dblclick",
326-
(event: dom.MouseEvent) => {
327-
Toastify(ToastifyOptions("Please right click on arrow to add more nodes. (Long press on touchscreen)"))
328-
.showToast()
329-
}
330-
)*/
327+
flowRunElements.showDebugVarsCheckbox.oninput = _ => {
328+
flowRunElements.debugVariables.classList.remove("flowrun--hidden")
329+
}
331330
}
332331

333332
private def doOnChange(): Unit =
@@ -337,6 +336,17 @@ class FlowRun(
337336
private def doOnModelChange(): Unit =
338337
Option(changeCallback).foreach(cb => cb(this))
339338

339+
private def setLayout(): Unit = {
340+
val oldConfig = programModel.ast.config
341+
val newConfig = oldConfig.copy(
342+
showFunctions = flowRunElements.showFunctionsCheckbox.checked,
343+
showGenCode = flowRunElements.showCodeCheckbox.checked,
344+
showDebugVars = flowRunElements.showDebugVarsCheckbox.checked
345+
)
346+
programModel.setConfig(newConfig)
347+
updateLayout()
348+
}
349+
340350
private def updateLayout(): Unit = {
341351
val flowrunMount = flowRunElements.mountElem
342352
flowrunMount.classList.remove("flowrun-layout-f-d-o")
@@ -348,16 +358,6 @@ class FlowRun(
348358
if newLayout.nonEmpty then flowrunMount.classList.add(newLayout)
349359
}
350360

351-
private def setLayout(): Unit = {
352-
val oldConfig = programModel.ast.config
353-
val newConfig = oldConfig.copy(
354-
showFunctions = flowRunElements.showFunctionsCheckbox.checked,
355-
showGenCode = flowRunElements.showCodeCheckbox.checked
356-
)
357-
programModel.setConfig(newConfig)
358-
updateLayout()
359-
}
360-
361361
private def resolveLayout(showFunctions: Boolean, showCode: Boolean): String = {
362362
if showFunctions && showCode then ""
363363
else if showFunctions && !showCode then "flowrun-layout-f-d-o"

core/src/main/scala/dev/sacode/flowrun/FlowRunElements.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ class FlowRunElements(
4646
mountElem.querySelector(".flowrun-btn-fun-add-param").asInstanceOf[dom.html.Element]
4747
val deleteParamButton: dom.html.Element =
4848
mountElem.querySelector(".flowrun-btn-fun-delete-param").asInstanceOf[dom.html.Element]
49-
49+
5050
val showFunctionsCheckbox: dom.html.Input =
5151
mountElem.querySelector(".flowrun-cb-show-functions").asInstanceOf[dom.html.Input]
5252
val showCodeCheckbox: dom.html.Input =
5353
mountElem.querySelector(".flowrun-cb-show-gen-code").asInstanceOf[dom.html.Input]
54+
val showDebugVarsCheckbox: dom.html.Input =
55+
mountElem.querySelector(".flowrun-cb-show-debug-vars").asInstanceOf[dom.html.Input]
5456

5557
// general
5658
private val enterButton = mountElem.querySelector(".flowrun-btn-enter").asInstanceOf[dom.html.Element]

core/src/main/scala/dev/sacode/flowrun/ProgramModel.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ProgramModel(
1919
def setName(name: String): Unit =
2020
ast = ast.copy(name = name)
2121
flowrunChannel := FlowRun.Event.FunctionUpdated
22-
22+
2323
def setConfig(config: FlowRunConfig): Unit =
2424
ast = ast.copy(config = config)
2525
flowrunChannel := FlowRun.Event.ConfigChanged

core/src/main/scala/dev/sacode/flowrun/ast/expression.scala

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.sacode.flowrun.ast
22

3-
import org.getshaka.nativeconverter.NativeConverter
3+
import ba.sake.tupson.*
44
import dev.sacode.flowrun.parse.Token
55

66
/*
@@ -20,10 +20,9 @@ atom -> NUMBER | STRING | "true" | "false" | "null"
2020
*/
2121

2222
case class Expression(boolOrComparison: BoolOrComparison, boolOrComparisons: List[BoolOrComparison])
23-
derives NativeConverter
2423

2524
object Expression:
26-
enum Type derives NativeConverter:
25+
enum Type derives JsonRW:
2726
case Void
2827
case Integer
2928
case Real
@@ -35,27 +34,26 @@ object Expression:
3534
case class BoolOrComparison(
3635
boolAndComparison: BoolAndComparison,
3736
boolAndComparisons: List[BoolAndComparison]
38-
) derives NativeConverter
37+
)
3938

4039
case class BoolAndComparison(numComparison: NumComparison, numComparisons: List[NumComparisonOpt])
41-
derives NativeConverter
4240

43-
case class NumComparison(term: Term, terms: Option[TermOpt]) derives NativeConverter
44-
case class NumComparisonOpt(op: Token, numComparison: NumComparison) derives NativeConverter
41+
case class NumComparison(term: Term, terms: Option[TermOpt])
42+
case class NumComparisonOpt(op: Token, numComparison: NumComparison)
4543

46-
case class Term(factor: Factor, factors: List[FactorOpt]) derives NativeConverter
47-
case class TermOpt(op: Token, term: Term) derives NativeConverter
44+
case class Term(factor: Factor, factors: List[FactorOpt])
45+
case class TermOpt(op: Token, term: Term)
4846

49-
case class Factor(unary: Unary, unaries: List[UnaryOpt]) derives NativeConverter
50-
case class FactorOpt(op: Token, factor: Factor) derives NativeConverter
47+
case class Factor(unary: Unary, unaries: List[UnaryOpt])
48+
case class FactorOpt(op: Token, factor: Factor)
5149

52-
enum Unary derives NativeConverter:
50+
enum Unary:
5351
case Prefixed(op: Token, unary: Unary)
5452
case Simple(atom: Atom)
5553

56-
case class UnaryOpt(op: Token, unary: Unary) derives NativeConverter
54+
case class UnaryOpt(op: Token, unary: Unary)
5755

58-
enum Atom derives NativeConverter:
56+
enum Atom:
5957
case IntegerLit(value: Int)
6058
case RealLit(value: Double)
6159
case StringLit(value: String)

core/src/main/scala/dev/sacode/flowrun/ast/program.scala

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package dev.sacode.flowrun.ast
22

33
import java.util.UUID
4-
import org.getshaka.nativeconverter.NativeConverter
4+
import ba.sake.tupson.*
55

66
case class Function(
77
rawId: String,
88
name: String,
99
parameters: List[Function.Parameter] = List.empty,
1010
tpe: Expression.Type = Expression.Type.Void,
1111
statements: List[Statement] = List.empty
12-
) derives NativeConverter:
12+
) derives JsonRW:
1313

1414
val id = s"fun-$rawId"
1515

@@ -25,7 +25,7 @@ case class Function(
2525
s"$title$params: $tpe"
2626

2727
object Function:
28-
case class Parameter(id: String, name: String, tpe: Expression.Type):
28+
case class Parameter(id: String, name: String, tpe: Expression.Type) derives JsonRW:
2929
def pretty: String = s"$name: $tpe"
3030

3131
case class Program(
@@ -35,10 +35,11 @@ case class Program(
3535
main: Function,
3636
functions: List[Function] = List.empty,
3737
version: String = "0.1"
38-
) derives NativeConverter:
39-
def allFunctions:List[Function] =
38+
) derives JsonRW:
39+
40+
def allFunctions: List[Function] =
4041
functions.prepended(main)
41-
42+
4243
def hasInputs: Boolean = {
4344
val allStmts = allFunctions.flatMap(_.statements).flatMap {
4445
case Statement.Block(_, blockStats) =>
@@ -61,7 +62,8 @@ final case class FlowRunConfig(
6162
lang: String,
6263
showFunctions: Boolean,
6364
showGenCode: Boolean,
64-
) derives NativeConverter
65+
showDebugVars: Boolean = true
66+
) derives JsonRW
6567

6668
object FlowRunConfig:
67-
val default = FlowRunConfig("java", true, true)
69+
val default = FlowRunConfig("java", true, true)

0 commit comments

Comments
 (0)