This commit is contained in:
msyds committed 2026-07-11 01:50:46 -06:00
1 parent b630cddb83
commit 475f0a7f68
4 files changed
+117 -83

No files matched your search

+6 -6
View File
@@ -1,9 +1,9 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultilineStrings #-}
{-# LANGUAGE OverloadedLists #-}
{-# OPTIONS_GHC -Wno-incomplete-patterns #-}
module Gyehoek.CPS.Lower
(
@@ -31,7 +31,7 @@ import qualified Data.Vector.Strict as V
import Data.IntMap.Strict (IntMap)
import Data.String.Interpolate
import Gyehoek.Wasm qualified as Wasm
import Gyehoek.Wasm (i32)
import Gyehoek.Wasm (i32, ins, sxp)
data Env = MkEnv { vars :: Vector Name }
@@ -57,10 +57,10 @@ lowerVal :: Env -> Val -> Wasm.Expr
lowerVal g (ValLit l) =
case l of
LitInt n -> [i|i32.const #{n}|]
LitInt n -> [ ins "i32.const" [sxp n] ]
_ -> _
lowerVal g (ValVar x) = [i|local.get #{l}|]
lowerVal g (ValVar x) = [ ins "local.get" [sxp l] ]
where
l = V.elemIndex x g.vars ^?! _Just
@@ -81,8 +81,8 @@ lowerBinOp
lowerBinOp op g x y r e =
lowerVal g x
<> lowerVal g y
<> op
<> [i|local.set #{n}|]
<> [ ins op [] ]
<> [ ins "local.set" [sxp n] ]
<> lower' g' e
where
g' = g & #vars <>~ [r]