Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ lazy val root = (project in file(".")).
// Dependencies
libraryDependencies ++= Seq(
scalaParserCombinators,
cats,
scalaTest % Test,
scalaCheck % Test
),
Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1"
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.13.4"
lazy val scalaParserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.5"
lazy val cats = "org.typelevel" %% "cats" % "0.9.0"
}
6 changes: 6 additions & 0 deletions src/main/scala/edu/colorado/plv/cuanto/jsy/imp/Parser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package edu.colorado.plv.cuanto.jsy.imp

import edu.colorado.plv.cuanto.jsy.common.UnitOpParser
import edu.colorado.plv.cuanto.jsy.{mutation, numerical}

object Parser extends UnitOpParser with mutation.ParserLike with numerical.ParserWithBindingLike
21 changes: 21 additions & 0 deletions src/main/scala/edu/colorado/plv/cuanto/jsy/imp/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.colorado.plv.cuanto.jsy

import edu.colorado.plv.cuanto.jsy.binding.Mode

package imp {

/** Mode `var`. Mutable variables.
*
* @group Abstract Syntax Nodes
*/
case object MVar extends Mode

}

/** The Imp subset of JavaScripty.
*
* Mixes [[numerical]] and [[mutation]].
*
* @author Bor-Yuh Evan Chang
*/
package object imp
21 changes: 11 additions & 10 deletions src/main/scala/edu/colorado/plv/cuanto/jsy/mutation/Parser.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package edu.colorado.plv.cuanto.jsy.mutation
package edu.colorado.plv.cuanto.jsy
package mutation

import edu.colorado.plv.cuanto.jsy.common.{JsyParserLike, OpParserLike, UnitOpParser}
import edu.colorado.plv.cuanto.jsy.common.{JsyParserLike, OpParserLike}

trait ParserLike extends OpParserLike with JsyParserLike
trait ParserLike extends OpParserLike with JsyParserLike {
abstract override def opAtom: Parser[Expr] =
positioned("null" ^^^ Null) |
super.opAtom

/**
* @author Bor-Yuh Evan Chang
*/
object Parser extends UnitOpParser with ParserLike {
override val bop = ???
override def expr = ???
override def start = ???
lazy val mutationBop: OpPrecedence = List(
List("=" -> Assign)
)
}

41 changes: 41 additions & 0 deletions src/main/scala/edu/colorado/plv/cuanto/jsy/mutation/mem/Mem.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.colorado.plv.cuanto.jsy
package mutation.mem

import cats.data.State

/** Address.
*
* @group Intermediate AST Nodes
*/
case class A private (a: Int) extends Val

/** Memory.
*
* Memory is a mapping from addresses to values. It enforces the invariant that
* addresses are allocated in this module.
*
* @tparam V The value type stored in this memory
* @author Bor-Yuh Evan Chang
*/
class Mem[V] private (map: Map[A, V], nextAddr: Int) {
def apply(key: A): V = map(key)
def get(key: A): Option[V] = map.get(key)
def +(kv: (A, V)): Mem[V] = new Mem[V](map + kv, nextAddr)
def contains(key: A): Boolean = map.contains(key)
override def toString: String = map.toString

private def alloc(v: V): (Mem[V], A) = {
val fresha = A(nextAddr)
(new Mem[V](map + (fresha -> v), nextAddr + 1), fresha)
}
}

object Mem {
def empty[V]: Mem[V] = new Mem[V](Map.empty, 1)

/** Get a fresh address. */
def alloc[V](v: V): State[Mem[V], A] = State.get flatMap { m =>
val (mp, a) = m.alloc(v)
State.set(mp) map { _ => a }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ package mutation {
/** @group Intermediate AST Nodes */
case object Deref extends Uop

/** Address.
*
* @group Intermediate AST Nodes
*/
case class A private (a: Int) extends Val

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ package object string {
/** The string concatenation operator is syntactically overloaded as
* [[edu.colorado.plv.cuanto.jsy.arithmetic.Plus]].
*/
val Concat: Bop = arithmetic.Plus
val Concat = arithmetic.Plus

}
35 changes: 35 additions & 0 deletions src/test/scala/edu/colorado/plv/cuanto/jsy/imp/ImpParserSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.colorado.plv.cuanto.jsy
package imp

import edu.colorado.plv.cuanto.CuantoSpec
import edu.colorado.plv.cuanto.jsy.arithmetic.N
import edu.colorado.plv.cuanto.jsy.binding._
import edu.colorado.plv.cuanto.jsy.boolean._
import edu.colorado.plv.cuanto.jsy.common.ParserBehaviors
import edu.colorado.plv.cuanto.jsy.mutation.Assign

/**
* @author Bor-Yuh Evan Chang
*/
class ImpParserSpec extends CuantoSpec with ParserBehaviors {

override lazy val positives = Table(
"concrete" -> "abstract",
"""{ let x = 3
| var y = true
| if (y) { x = 4 } else { x = 5 }
|}
""".stripMargin
-> Bind(MVar, Var("x"), N(3),
Bind(MVar, Var("y"), B(true),
If(Var("y"),
Binary(Assign, Var("x"), N(4)),
Binary(Assign, Var("x"), N(4))
)
)
)

)

"jsy.imp.Parser" should behave like parser(Parser.parse)
}

This file was deleted.