-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
782 additions
and
538 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
module Kroha where | ||
module Kroha (kroha) where | ||
|
||
import Control.Monad.Zip (mzip) | ||
import Data.Bifunctor (first) | ||
import Data.Tree (Tree (..)) | ||
import Data.Foldable (toList) | ||
import Data.HashMap (fromList, lookup) | ||
|
||
import Kroha.Ast (NodeId, Program, genId, pzip, pzip3) | ||
import Kroha.Backends.Common (runBackend, typeConfig) | ||
import Kroha.Backends.Nasm (nasm) | ||
import Kroha.Errors (Result, showErrors) | ||
import Kroha.Instructions (instructions) | ||
import Kroha.Parser (parse) | ||
import Kroha.Ast (FrameElement (Instructions), selectorProg) | ||
import Kroha.Scope (linkProgram, linksTree) | ||
import Kroha.Types (resolve, typeCastsTree, TypeConfig(..)) | ||
import Kroha.Scope (linkProgram) | ||
import Kroha.Stack (stack) | ||
import Kroha.Instructions (instructions) | ||
import Kroha.Backends.Common (runBackend, Backend(typeConfig)) | ||
import Kroha.Backends.Nasm (nasm) | ||
import Kroha.Types (resolve, typeCastsTree) | ||
|
||
|
||
compile :: Program NodeId -> Result String | ||
compile program = do | ||
scopes <- linkProgram program | ||
let tc = typeConfig nasm | ||
casts <- typeCastsTree tc scopes | ||
types <- resolve tc (pzip program casts) | ||
let stackRanges = stack tc program | ||
let prepared = instructions (pzip3 stackRanges (fmap snd scopes) program) | ||
return (runBackend nasm prepared) | ||
|
||
kroha :: String -> String -> Either String String | ||
kroha name src = | ||
case parse name src of | ||
Left err -> Left err | ||
Right parsed -> first (showErrors (`Data.HashMap.lookup` rangeTable)) $ compile prog | ||
where prog = genId parsed | ||
rangeTable = fromList $ toList $ pzip prog parsed | ||
|
||
|
||
kroha :: String -> Either String String | ||
kroha src = first show compile | ||
where compile = do | ||
program <- parse src | ||
scopes <- linkProgram program | ||
let programTree = Node (Instructions []) (selectorProg (const $ Instructions []) id program) | ||
let tc = (typeConfig nasm) | ||
casts <- (typeCastsTree tc $ mzip (linksTree program) scopes) | ||
types <- resolve tc casts | ||
let stackRanges = stack tc program | ||
let prepared = instructions stackRanges scopes program | ||
return (runBackend nasm prepared) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.