This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
{-# LANGUAGE PartialTypeSignatures #-}
|
{-# LANGUAGE PartialTypeSignatures #-}
|
||||||
{-# OPTIONS_GHC -Wno-orphans -Wno-unused-matches -Wno-missing-signatures #-}
|
{-# OPTIONS_GHC -Wno-orphans -Wno-unused-matches -Wno-missing-signatures #-}
|
||||||
{- HLINT ignore "Avoid lambda using `infix`" -}
|
{- HLINT ignore "Avoid lambda using `infix`" -}
|
||||||
module Gyehoek.ANF
|
module Gyehoek.ANF.Syntax
|
||||||
(toANF, lower)
|
(toANF, lower)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -21,8 +21,8 @@ import Data.Generics.Labels
|
|||||||
import Data.Vector.Strict (Vector)
|
import Data.Vector.Strict (Vector)
|
||||||
import Data.Function (fix)
|
import Data.Function (fix)
|
||||||
import Effectful.Writer.Static.Local
|
import Effectful.Writer.Static.Local
|
||||||
import Gyehoek.Syntax qualified as Lam
|
import Gyehoek.Scheme.Syntax qualified as Lam
|
||||||
import Gyehoek.Syntax (Name, Prim(..), Lit(..))
|
import Gyehoek.Scheme.Syntax (Name, Prim(..), Lit(..))
|
||||||
import Gyehoek.GenSym
|
import Gyehoek.GenSym
|
||||||
import Control.Monad.Cont
|
import Control.Monad.Cont
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
@@ -185,7 +185,12 @@ expr2 =
|
|||||||
(PrimCons
|
(PrimCons
|
||||||
(Lam.ExpLit (LitInt 2))
|
(Lam.ExpLit (LitInt 2))
|
||||||
(Lam.ExpLit (LitInt 3)))))
|
(Lam.ExpLit (LitInt 3)))))
|
||||||
, Lam.ExpPrim (PrimWrite (Lam.ExpLit (LitInt 4)))
|
, Lam.ExpPrim
|
||||||
|
(PrimWrite
|
||||||
|
(Lam.ExpPrim
|
||||||
|
(PrimMul
|
||||||
|
(Lam.ExpLit (LitInt 5))
|
||||||
|
(Lam.ExpLit (LitInt 4)))))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -364,9 +369,14 @@ lowerPrim r p e k =
|
|||||||
telescope (lowerVal <$> p) \case
|
telescope (lowerVal <$> p) \case
|
||||||
(preview binaryPrim -> Just (bop,a,b)) -> do
|
(preview binaryPrim -> Just (bop,a,b)) -> do
|
||||||
r1 <- gensym
|
r1 <- gensym
|
||||||
|
r2 <- gensym
|
||||||
Emit [ QBE.BinaryOp (r1 QBE.:= QBE.Long) bop a b
|
Emit [ QBE.BinaryOp (r1 QBE.:= QBE.Long) bop a b
|
||||||
, QBE.BinaryOp (lowerName r QBE.:= QBE.Long) QBE.And
|
, QBE.BinaryOp (r2 QBE.:= QBE.Long) QBE.And
|
||||||
(QBE.ValTemporary r1) (QBE.ValConst (QBE.CInt 0b10))
|
(QBE.ValTemporary r1)
|
||||||
|
(QBE.ValConst (QBE.CInt 0xffff_ffff_ffff_fffd))
|
||||||
|
, QBE.BinaryOp (lowerName r QBE.:= QBE.Long) QBE.Or
|
||||||
|
(QBE.ValTemporary r2)
|
||||||
|
(QBE.ValConst (QBE.CInt 0b10))
|
||||||
]
|
]
|
||||||
<$> lower' e k
|
<$> lower' e k
|
||||||
PrimCons x y -> lowerCons r x y e k
|
PrimCons x y -> lowerCons r x y e k
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
{-# LANGUAGE PartialTypeSignatures #-}
|
{-# LANGUAGE PartialTypeSignatures #-}
|
||||||
module Gyehoek.Syntax where
|
module Gyehoek.Scheme.Syntax where
|
||||||
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.List (List)
|
import Data.List (List)
|
||||||
@@ -1 +0,0 @@
|
|||||||
module Gyehoek.Scratch where
|
|
||||||
@@ -6,7 +6,7 @@ module Main
|
|||||||
(main)
|
(main)
|
||||||
where
|
where
|
||||||
|
|
||||||
import qualified Gyehoek.ANF as ANF
|
import qualified Gyehoek.ANF.Syntax as ANF
|
||||||
import Gyehoek.QBE (render)
|
import Gyehoek.QBE (render)
|
||||||
import qualified Data.Text.IO as TIO
|
import qualified Data.Text.IO as TIO
|
||||||
import Prelude hiding ((.),id)
|
import Prelude hiding ((.),id)
|
||||||
|
|||||||
@@ -13,29 +13,34 @@ build-type: Simple
|
|||||||
-- extra-doc-files: CHANGELOG.md
|
-- extra-doc-files: CHANGELOG.md
|
||||||
-- extra-source-files:
|
-- extra-source-files:
|
||||||
|
|
||||||
|
common ghcstuffs-dev
|
||||||
|
ghc-options:
|
||||||
|
-Wno-unused-matches -Wno-missing-signatures -Wno-typed-holes
|
||||||
|
|
||||||
common ghcstuffs
|
common ghcstuffs
|
||||||
ghc-options:
|
ghc-options:
|
||||||
-Wall -fdefer-type-errors -fno-show-valid-hole-fits
|
-Wall -fdefer-type-errors -fno-show-valid-hole-fits
|
||||||
-fdefer-out-of-scope-variables -Wno-typed-holes
|
-fdefer-out-of-scope-variables -fplugin=Effectful.Plugin
|
||||||
-fplugin=Effectful.Plugin
|
|
||||||
|
|
||||||
other-extensions:
|
other-extensions:
|
||||||
BlockArguments
|
BlockArguments
|
||||||
|
DeriveGeneric
|
||||||
|
OverloadedStrings
|
||||||
PartialTypeSignatures
|
PartialTypeSignatures
|
||||||
|
PatternSynonyms
|
||||||
|
|
||||||
executable gyehoek
|
executable gyehoek
|
||||||
import: ghcstuffs
|
import: ghcstuffs, ghcstuffs-dev
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
|
|
||||||
-- cabal-fmt: expand app -Main
|
-- cabal-fmt: expand app -Main
|
||||||
other-modules:
|
other-modules:
|
||||||
Gyehoek.ANF
|
Gyehoek.ANF.Syntax
|
||||||
Gyehoek.Sexp
|
|
||||||
Gyehoek.GenSym
|
Gyehoek.GenSym
|
||||||
Gyehoek.QBE
|
Gyehoek.QBE
|
||||||
Gyehoek.QBE.Parse
|
Gyehoek.QBE.Parse
|
||||||
Gyehoek.Scratch
|
Gyehoek.Scheme.Syntax
|
||||||
Gyehoek.Syntax
|
Gyehoek.Sexp
|
||||||
|
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends:
|
build-depends:
|
||||||
@@ -43,18 +48,19 @@ executable gyehoek
|
|||||||
, effectful
|
, effectful
|
||||||
, effectful-core
|
, effectful-core
|
||||||
, effectful-plugin
|
, effectful-plugin
|
||||||
|
, generic-lens
|
||||||
|
, invertible-grammar
|
||||||
, lens
|
, lens
|
||||||
, megaparsec
|
, megaparsec
|
||||||
, mtl
|
, mtl
|
||||||
|
, optparse-applicative
|
||||||
, prettyprinter
|
, prettyprinter
|
||||||
, qbe
|
, qbe
|
||||||
, recursion-schemes
|
, recursion-schemes
|
||||||
|
, sexp-grammar
|
||||||
, template-haskell
|
, template-haskell
|
||||||
, text
|
, text
|
||||||
, vector
|
, vector
|
||||||
, generic-lens
|
|
||||||
, sexp-grammar
|
|
||||||
, invertible-grammar
|
|
||||||
|
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
default-language: GHC2024
|
default-language: GHC2024
|
||||||
|
|||||||
BIN
play/a.out
BIN
play/a.out
Binary file not shown.
11
play/t.ssa
11
play/t.ssa
@@ -3,10 +3,13 @@ export
|
|||||||
function w $main () {
|
function w $main () {
|
||||||
@start
|
@start
|
||||||
%x0 =l call $GC_malloc (l 16)
|
%x0 =l call $GC_malloc (l 16)
|
||||||
%.3 =l add %x0, 8
|
%.4 =l add %x0, 8
|
||||||
storel 10, %x0
|
storel 10, %x0
|
||||||
storel 14, %.3
|
storel 14, %.4
|
||||||
%x1 =l call $scm_write (l %x0)
|
%x1 =l call $scm_write (l %x0)
|
||||||
%x2 =l call $scm_write (l 18)
|
%.5 =l mul 22, 18
|
||||||
ret %x2
|
%.6 =l and %.5, 18446744073709551613
|
||||||
|
%x2 =l or %.6, 2
|
||||||
|
%x3 =l call $scm_write (l %x2)
|
||||||
|
ret %x3
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
SCM scm_write (SCM x) {
|
SCM scm_write (SCM x) {
|
||||||
if (SCM_IMP (x)) {
|
if (SCM_IMP (x)) {
|
||||||
printf ("#<immediate %ld>\n", SCM_UNPACK (x));
|
printf ("#<immediate %ld>\n", SCM_UNPACK (x) >> 2);
|
||||||
} else {
|
} else {
|
||||||
printf ("#<heap object %ld>\n", SCM_UNPACK(x));
|
printf ("#<heap object %ld>\n", SCM_UNPACK(x));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user