Skip to content

Commit

Permalink
Lua syntax: Use TypedSyntax.VId for Label
Browse files Browse the repository at this point in the history
  • Loading branch information
minoki committed Sep 8, 2024
1 parent bf552f8 commit c8fb6c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/codegen-lua.sml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ struct
[L.CallStat (L.VarExp (L.PredefinedId "_id"), vector [e])]

datatype cont_type =
GOTO of {label: L.Id, params: (L.Id option) list}
GOTO of {label: TypedSyntax.VId, params: (L.Id option) list}
| RETURN
type Env = {continuations: cont_type C.CVarMap.map}

Expand Down Expand Up @@ -244,7 +244,7 @@ struct
| NONE => raise CodeGenError "undefined continuation"

fun doLabel cname =
L.UserDefinedId (TypedSyntax.MkVId ("cont", C.CVar.toInt cname))
TypedSyntax.MkVId ("cont", C.CVar.toInt cname)

fun doValue ctx (C.Var vid) =
(case VIdToLua (ctx, vid) of
Expand Down Expand Up @@ -2950,11 +2950,11 @@ struct
in
if C.containsApp thenCont then
let
val thenLabel = L.UserDefinedId (genSymWithName (ctx, "then"))
val thenLabel = genSymWithName (ctx, "then")
in
if containsNestedBlock elseCont then
let
val elseLabel = L.UserDefinedId (genSymWithName (ctx, "else"))
val elseLabel = genSymWithName (ctx, "else")
in
L.IfStat
( doValue ctx cond
Expand Down
10 changes: 5 additions & 5 deletions src/lua-syntax.sml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ structure LuaSyntax :>
sig
datatype TableKey = IntKey of int | StringKey of string
datatype Id = PredefinedId of string | UserDefinedId of TypedSyntax.VId
type Label = Id
type Label = TypedSyntax.VId
structure IdSet: ORD_SET where type Key.ord_key = Id
structure IdMap: ORD_MAP where type Key.ord_key = Id
datatype VarAttr = CONST | LATE_INIT | MUTABLE
Expand Down Expand Up @@ -76,7 +76,7 @@ end =
struct
datatype TableKey = IntKey of int | StringKey of string
datatype Id = PredefinedId of string | UserDefinedId of TypedSyntax.VId
type Label = Id
type Label = TypedSyntax.VId
structure IdKey =
struct
type ord_key = Id
Expand Down Expand Up @@ -580,7 +580,7 @@ struct
labelMap (* TypedSyntax.VIdMap.inDomain (labelMap, label) should be true *)
and createLabelMapForBlock (unavailableLabels, labelMap, block) =
let
fun go (L.LabelStat label, acc) = declareId (label, acc)
fun go (L.LabelStat label, acc) = declare (label, acc)
| go (_, acc) = acc
val (unavailableLabels, labelMap) =
(Vector.foldl go (unavailableLabels, labelMap) block)
Expand Down Expand Up @@ -1017,14 +1017,14 @@ struct
doStat
( rest
, Indent :: Fragment "goto "
:: idToFragment labelMap label @ LineTerminator :: acc
:: vidToFragment labelMap label @ LineTerminator :: acc
)
| doStat (LuaSyntax.LabelStat label :: rest, acc) =
doStat
( rest
, Indent :: Fragment "::"
::
idToFragment labelMap label
vidToFragment labelMap label
@ Fragment "::" :: LineTerminator :: acc
)
and doBlock stats =
Expand Down

0 comments on commit c8fb6c3

Please sign in to comment.