Skip to content

Commit 32ac934

Browse files
committed
Fixing errors caused by rebase
1 parent bbcfbd7 commit 32ac934

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

hkmc2/shared/src/main/scala/hkmc2/MLsCompiler.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,6 @@ class MLsCompiler(preludeFile: os.Path):
5252
var dbgParsing = false
5353

5454
def compileModule(file: os.Path): Unit =
55-
56-
val block = os.read(file)
57-
val fph = new FastParseHelpers(block)
58-
val origin = Origin(file.toString, 0, fph)
59-
60-
val lexer = new syntax.Lexer(origin, dbg = dbgParsing)
61-
val tokens = lexer.bracketedTokens
62-
63-
// if showParse.isSet || dbgParsing.isSet then
64-
// output(syntax.Lexer.printTokens(tokens))
65-
66-
val p = new syntax.Parser(origin, tokens, raise, dbg = dbgParsing):
67-
def doPrintDbg(msg: => Str): Unit =
68-
// if dbg then output(msg)
69-
if dbg then println(msg)
70-
val res = p.parseAll(p.block(allowNewlines = true))
7155
given Elaborator.State = new Elaborator.State
7256

7357
val preludeParse = ParserSetup(preludeFile, dbgParsing)

hkmc2/shared/src/main/scala/hkmc2/semantics/Elaborator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ extends Importer:
904904
ps
905905
case _ =>
906906
t.asParam.map: (isSpd, p, st) =>
907-
isSpd -> Param(FldFlags.fromTerm(t), fieldOrVarSym(ParamBind, p), st.map(term))
907+
isSpd -> Param(FldFlags.fromTerm(t), fieldOrVarSym(ParamBind, p), st.map(term(_)))
908908

909909
def params(t: Tree): Ctxl[(ParamList, Ctx)] = t match
910910
case Tup(ps) =>

hkmc2/shared/src/main/scala/hkmc2/semantics/Specialiser.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class Specialiser(val tl: TraceLogger, val ctx: Ctx)(using val raise: Raise, val
3737
term match
3838
case Blk(Nil, res) => collectDefs(res)
3939
case Blk((d: Declaration) :: stats, res) => collectDefs(Blk(stats, res)) ++ (d match
40-
case td@TermDefinition(_, Fun, sym, params, _, Some(body), _) =>
40+
case td@TermDefinition(_, Fun, sym, params, _, Some(body), _, _, _) =>
4141
val map = collectDefs(body) ++ collectDefs(Blk(stats, res))
4242
if params.flatMap(_.params).exists(_.flags.spec) then map + (td.sym -> td) else map
4343
case _ => d.subTerms.foldLeft(Map.empty[Symbol, TermDefinition])((acc, sub) => acc ++ collectDefs(sub)))
4444
case Blk((t: Term) :: stats, res) => collectDefs(t) ++ collectDefs(Blk(stats, res))
45-
case Blk(LetDecl(_) :: stats, res) => collectDefs(Blk(stats, res))
45+
case Blk(LetDecl(_, _) :: stats, res) => collectDefs(Blk(stats, res))
4646
case Blk(DefineVar(_, rhs) :: stats, res) => collectDefs(rhs) ++ collectDefs(Blk(stats, res))
4747
case _ => term.subTerms.foldLeft(Map.empty)((acc, sub) => acc ++ collectDefs(sub))
4848

@@ -59,14 +59,13 @@ class Specialiser(val tl: TraceLogger, val ctx: Ctx)(using val raise: Raise, val
5959
case s => (acc._1 :+ s, acc._2)
6060
collectApps(tree.res) match { case (res, ts) => (Blk(stats, res), types ::: ts) }
6161

62-
// TODO: Make specFns immutable so this can be nice and pure
6362
def collectApps(tree: Term)(using defs: Map[Symbol, TermDefinition], specFns: MutMap[Str, Ident]): Ctxl[(Term, Ls[SpApp])] =
6463
trace(s"Collecting term ${tree.showDbg}"):
6564
tree match
6665
case app@App(lhs, Tup(fields)) => lhs match
6766
case s@Sel(pre, nme) =>
6867
if s.sym.isDefined && defs.contains(s.sym.get) then
69-
val typs = defs(s.sym.get).params.flatMap(_.params).zip(fields.map(_.value).map {
68+
val typs = defs(s.sym.get).params.flatMap(_.params).zip(fields.filter(e => e.isInstanceOf[Fld]).map(_.asInstanceOf[Fld].term).map {
7069
case Lit(lit) => lit.asTree match
7170
case _: IntLit => "Int"
7271
case _: StrLit => "Str"
@@ -75,13 +74,13 @@ class Specialiser(val tl: TraceLogger, val ctx: Ctx)(using val raise: Raise, val
7574
}).filter(_._1.flags.spec)
7675
log(s"Specialising ${s.sym.get} with ${typs.map((s, t) => s.sym.nme + ": " + t)}.")
7776
val fId = s.sym.get.nme + typs.map(_._2).mkString("_", "_", "")
78-
val name = specFns.getOrElseUpdate(fId, Ident(fId + "_" + state.nextUid)) // not sure state is the way to do this
77+
val name = specFns.getOrElseUpdate(fId, Ident(fId + "_" + state.suid.nextUid))
7978
val specApp: App = app.copy(lhs = s.copy(nme = name)(s.sym))(app.tree, app.resSym)
8079
(specApp, SpApp(s.sym.get, typs.foldLeft(Map.empty)((acc, p) => acc + (p._1.sym -> p._2)), specApp) :: Nil)
8180
else
8281
(tree, Nil)
8382
// FIXME: Ref applications aren't implemented, nor do I know when they are used
84-
case Ref(sym) => if defs.contains(sym) then (tree, SpApp(TempSymbol(999, N, ""), Map.empty, app) :: Nil) else (tree, Nil)
83+
case Ref(sym) => if defs.contains(sym) then (tree, SpApp(TempSymbol(N, ""), Map.empty, app) :: Nil) else (tree, Nil)
8584
case _ => (tree, Nil)
8685
case b: Blk => collectApps(b)
8786
// FIXME: This won't work for nested applications in all cases

hkmc2/shared/src/main/scala/hkmc2/semantics/Term.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ object FldFlags:
359359
val empty: FldFlags = FldFlags(false, false, false, false)
360360

361361
def fromTerm(t: Tree): FldFlags = t match
362-
case Tree.Modified(Keyword.`mut`, _, b) => FldFlags(true, false, false).addFlags(b)
363-
case Tree.Modified(Keyword.`spec`, _, b) => FldFlags(false, true, false).addFlags(b)
362+
case Tree.Modified(Keyword.`mut`, _, b) => FldFlags(true, false, false, false).addFlags(b)
363+
case Tree.Modified(Keyword.`spec`, _, b) => FldFlags(false, true, false, false).addFlags(b)
364+
case Tree.Modified(Keyword.`module`, _, b) => FldFlags(false, false, false, true).addFlags(b)
364365
case _ => empty
365366

366367
sealed abstract class Elem:

hkmc2/shared/src/main/scala/hkmc2/syntax/Tree.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ enum Tree extends AutoLocated:
189189
case Spread(Keyword.`...`, _, S(und: Under)) => S(S(true), new Ident("_").withLocOf(und), N)
190190
case InfixApp(lhs: Ident, Keyword.`:`, rhs) => S(N, lhs, S(rhs))
191191
case TermDef(ImmutVal, inner, _) => inner.asParam
192-
case Modified(_, _, inner) => inner.param
192+
case Modified(_, _, inner) => inner.asParam
193193

194194
def isModuleModifier: Bool = this match
195195
case Tree.TypeDef(Mod, _, N, N) => true

0 commit comments

Comments
 (0)