diff --git a/hkmc2/jvm/src/test/scala/hkmc2/BbmlDiffMaker.scala b/hkmc2/jvm/src/test/scala/hkmc2/BbmlDiffMaker.scala index deea6994f..d2d322b4c 100644 --- a/hkmc2/jvm/src/test/scala/hkmc2/BbmlDiffMaker.scala +++ b/hkmc2/jvm/src/test/scala/hkmc2/BbmlDiffMaker.scala @@ -17,8 +17,10 @@ abstract class BbmlDiffMaker extends JSBackendDiffMaker: if isGlobal then typeCheck.disable.isGlobal = true typeCheck.disable.setCurrentValue(()) if file =/= bbPreludeFile then + curCtx = Elaborator.State.init importFile(bbPreludeFile, verbose = false) - + curCtx = curCtx.nest(N) + override def init(): Unit = if bbmlOpt.isSet then import syntax.* diff --git a/hkmc2/shared/src/main/scala/hkmc2/bbml/bbML.scala b/hkmc2/shared/src/main/scala/hkmc2/bbml/bbML.scala index 91e3881a1..14b7f0f9f 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/bbml/bbML.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/bbml/bbML.scala @@ -26,12 +26,7 @@ final case class BbCtx( env: HashMap[Uid[Symbol], GeneralType] ): def +=(p: Symbol -> GeneralType): Unit = env += p._1.uid -> p._2 - def get(sym: Symbol): Option[GeneralType] = - if BbCtx.builtinOps(sym.nme) then ctx.get(s"#${sym.nme}") match - case S(Ctx.SelElem(_, _, symOpt)) => symOpt.flatMap(getImpl(_)) - case _ => N - else getImpl(sym) - private def getImpl(sym: Symbol): Option[GeneralType] = env.get(sym.uid) orElse parent.dlof(_.getImpl(sym))(None) + def get(sym: Symbol): Option[GeneralType] = env.get(sym.uid) orElse parent.dlof(_.get(sym))(None) def getCls(name: Str): Option[TypeSymbol] = for elem <- ctx.get(name) @@ -443,6 +438,8 @@ class BBTyper(using elState: Elaborator.State, tl: TL): goStats(stats) case (clsDef: ClassDef) :: stats => goStats(stats) + case (modDef: ModuleDef) :: stats => + goStats(stats) case Import(sym, pth) :: stats => goStats(stats) // TODO: goStats(stats) diff --git a/hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala b/hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala index a69c4d0b5..eebdbd686 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala @@ -95,7 +95,7 @@ class JSBuilder(using Elaborator.State, Elaborator.Ctx) extends CodeBuilder: case Call(Value.Ref(l: BuiltinSymbol), args) => err(msg"Illeal arity for builtin symbol '${l.nme}'") case Call(s @ Select(_, id), lhs :: rhs :: Nil) => - Elaborator.ctx.Builtins.tryMapOp(id.name) match + Elaborator.ctx.Builtins.getBuiltinOp(id.name) match case S(jsOp) => val res = doc"${result(lhs)} ${jsOp} ${result(rhs)}" if needsParens(jsOp) then doc"(${res})" else res diff --git a/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala b/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala index 6d4967dec..40437d60e 100644 --- a/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala +++ b/hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala @@ -29,7 +29,10 @@ object Elaborator: ";" -> ",", "+." -> "+", "-." -> "-", - "*." -> "*") + "*." -> "*", + "/." -> "/") + private val builtinBinOps = aliasOps ++ (binaryOps.map: op => + op -> op).toMap val reservedNames = binaryOps.toSet ++ aliasOps.keySet + "NaN" + "Infinity" @@ -91,7 +94,7 @@ object Elaborator: val Num = assumeBuiltinCls("Num") val Str = assumeBuiltinCls("Str") val Predef = assumeBuiltinMod("Predef") - def tryMapOp(op: Str): Opt[Str] = aliasOps.get(op) + def getBuiltinOp(op: Str): Opt[Str] = if getBuiltin(op).isDefined then builtinBinOps.get(op) else N object Ctx: abstract class Elem: diff --git a/hkmc2/shared/src/test/mlscript/bbml/bbPrelude.mls b/hkmc2/shared/src/test/mlscript/bbml/bbPrelude.mls index d4916948c..193beb4ad 100644 --- a/hkmc2/shared/src/test/mlscript/bbml/bbPrelude.mls +++ b/hkmc2/shared/src/test/mlscript/bbml/bbPrelude.mls @@ -1,7 +1,15 @@ // :bbml + +class Any +class Nothing + class Alloc +class Bool +class Int +class Num + class CodeBase[T, C, S] class Region[T] class Ref[T, S](reg: Region[T], value: S) @@ -10,26 +18,28 @@ class Str(length: Int, concat: Str -> Str) class Error(msg: Str) +declare module Predef + fun run: [T] -> CodeBase[out T, out Nothing, out Any] -> T fun log: Str -> Any fun error: Nothing -fun (#+): (Int, Int) -> Int -fun (#-): (Int, Int) -> Int -fun (#*): (Int, Int) -> Int -fun (#/): (Int, Int) -> Num +fun (+): (Int, Int) -> Int +fun (-): (Int, Int) -> Int +fun (*): (Int, Int) -> Int +fun (/): (Int, Int) -> Num fun (+.): (Num, Num) -> Num fun (-.): (Num, Num) -> Num fun (*.): (Num, Num) -> Num fun (/.): (Num, Num) -> Num -fun (#<): (Int, Int) -> Bool -fun (#>): (Int, Int) -> Bool -fun (#<=): (Int, Int) -> Bool -fun (#>=): (Int, Int) -> Bool -fun (#==): [T] -> (T, T) -> Bool -fun (#!=): [T] -> (T, T) -> Bool +fun (<): (Int, Int) -> Bool +fun (>): (Int, Int) -> Bool +fun (<=): (Int, Int) -> Bool +fun (>=): (Int, Int) -> Bool +fun (==): [T] -> (T, T) -> Bool +fun (!=): [T] -> (T, T) -> Bool -fun (#&&): (Bool, Bool) -> Bool -fun (#||): (Bool, Bool) -> Bool +fun (&&): (Bool, Bool) -> Bool +fun (||): (Bool, Bool) -> Bool