-
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
31 changed files
with
635 additions
and
497 deletions.
There are no files selected for viewing
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,36 +1,34 @@ | ||
module Kroha (kroha) where | ||
|
||
import Data.Bifunctor (first) | ||
import Data.Foldable (toList) | ||
import Data.HashMap (fromList, lookup) | ||
import Data.Bifunctor (first) | ||
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.Scope (linkProgram) | ||
import Kroha.Stack (stack) | ||
import Kroha.Types (resolve, typeCastsTree) | ||
import Kroha.Backends.Common (runBackend, typeConfig) | ||
import Kroha.Backends.Nasm (nasm) | ||
import Kroha.Errors (Result, showErrors) | ||
import Kroha.Instructions (instructions) | ||
import Kroha.Parser.Declarations (parseProgram) | ||
import Kroha.Scope (linkProgram) | ||
import Kroha.Stack (stack) | ||
import Kroha.Syntax.Declarations (NodeId, Program, genId, pzip, pzip3) | ||
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) | ||
_ <- 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 | ||
case parseProgram 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 | ||
|
||
|
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
Oops, something went wrong.