added cabal build system
This commit is contained in:
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Revision history for zorth
|
||||||
|
|
||||||
|
## 0.0.6.9 -- YYYY-mm-dd
|
||||||
|
|
||||||
|
* First version. Released on an unsuspecting world.
|
||||||
9
Main.hs
9
Main.hs
@@ -1,9 +0,0 @@
|
|||||||
module Main where
|
|
||||||
|
|
||||||
import Parser
|
|
||||||
import Compiler
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
contents <- getContents
|
|
||||||
compileZorth $ parseZorth contents
|
|
||||||
@@ -3,6 +3,7 @@ module Compiler where
|
|||||||
import Parser
|
import Parser
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import Control.Monad (void)
|
import Control.Monad (void)
|
||||||
|
import System.Process
|
||||||
import System.IO
|
import System.IO
|
||||||
|
|
||||||
handleSymbol :: Handle -> ZorthExpr -> IO ()
|
handleSymbol :: Handle -> ZorthExpr -> IO ()
|
||||||
@@ -87,8 +88,8 @@ forthPrelude h = do
|
|||||||
\ ret\n\
|
\ ret\n\
|
||||||
\_start:\n"
|
\_start:\n"
|
||||||
|
|
||||||
compileZorth :: ZorthAST -> IO ()
|
compileZorth :: Handle -> ZorthAST -> IO ()
|
||||||
compileZorth [] = return ()
|
compileZorth h [] = return ()
|
||||||
compileZorth xs = do
|
compileZorth h xs = do
|
||||||
forthPrelude stdout
|
forthPrelude h
|
||||||
foldr ((>>) . handleSymbol stdout) (return ()) xs
|
foldr ((>>) . handleSymbol h) (return ()) xs
|
||||||
14
app/Main.hs
Normal file
14
app/Main.hs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module Main where
|
||||||
|
|
||||||
|
import Parser
|
||||||
|
import Compiler
|
||||||
|
import System.Process
|
||||||
|
import System.IO
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
contents <- getContents
|
||||||
|
withFile "out.asm" WriteMode (\f -> compileZorth f $ parseZorth contents)
|
||||||
|
readProcess "nasm" ["-f", "elf64", "out.asm", "-o", "out.o"] ""
|
||||||
|
readProcess "ld" ["out.o", "-o", "a.out"] ""
|
||||||
|
return ()
|
||||||
@@ -75,4 +75,7 @@ word = neWord <|> return ""
|
|||||||
neWord = do
|
neWord = do
|
||||||
x <- sat (\x -> x /= '\n' && x /= ' ')
|
x <- sat (\x -> x /= '\n' && x /= ' ')
|
||||||
xs <- word
|
xs <- word
|
||||||
return $ x:xs
|
return $ x:xs
|
||||||
|
|
||||||
|
manyTill :: Parser a -> Parser b -> Parser [a]
|
||||||
|
manyTill p q = (q >> return []) <++ do { x <- p; xs <- manyTill p q; return $ x:xs }
|
||||||
@@ -9,7 +9,7 @@ type ZorthAST = [ZorthExpr]
|
|||||||
|
|
||||||
data ZorthExpr = ZorthASTInteger Int
|
data ZorthExpr = ZorthASTInteger Int
|
||||||
| ZorthASTWord String
|
| ZorthASTWord String
|
||||||
| ZorthASTWordDecl [ZorthExpr]
|
| ZorthASTWordDecl (String,ZorthAST)
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
word1 :: Parser String
|
word1 :: Parser String
|
||||||
@@ -48,8 +48,18 @@ pZorthWord = do
|
|||||||
skipNonsenseSymbols
|
skipNonsenseSymbols
|
||||||
ZorthASTWord <$> word1
|
ZorthASTWord <$> word1
|
||||||
|
|
||||||
|
pZorthWordDecl :: Parser ZorthExpr
|
||||||
|
pZorthWordDecl = do
|
||||||
|
ZorthASTWord ":" <- pZorthWord
|
||||||
|
ZorthASTWord name <- pZorthWord
|
||||||
|
xs <- manyTill pZorthExpr (do { ZorthASTWord ";" <- pZorthWord; return () })
|
||||||
|
return $ ZorthASTWordDecl (name,xs)
|
||||||
|
|
||||||
|
pZorthExpr :: Parser ZorthExpr
|
||||||
|
pZorthExpr = pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||||
|
|
||||||
pZorth :: Parser ZorthAST
|
pZorth :: Parser ZorthAST
|
||||||
pZorth = some (pZorthInteger <++ pZorthWord)
|
pZorth = some pZorthExpr
|
||||||
|
|
||||||
parseZorth :: String -> ZorthAST
|
parseZorth :: String -> ZorthAST
|
||||||
parseZorth = fst . head . runParser pZorth
|
parseZorth = fst . head . runParser pZorth
|
||||||
2
build.sh
Normal file → Executable file
2
build.sh
Normal file → Executable file
@@ -1 +1 @@
|
|||||||
ghc Main.hs -o zorth && ./zorth > out.asm && nasm -f elf64 out.asm -o out.o && ld out.o -o a.out && ./a.out
|
cabal build && dist-newstyle/build/x86_64-linux/ghc-9.6.7/zorth-0.0.6.9/x/zorth/build/zorth/zorth && ./a.out
|
||||||
20
zorth.cabal
Normal file
20
zorth.cabal
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
cabal-version: 3.0
|
||||||
|
name: zorth
|
||||||
|
version: 0.0.6.9
|
||||||
|
license: BSD-3-Clause
|
||||||
|
license-file: LICENSE
|
||||||
|
author: bunny
|
||||||
|
maintainer: bunnyanonn@proton.me
|
||||||
|
category: Development
|
||||||
|
build-type: Simple
|
||||||
|
extra-doc-files: CHANGELOG.md
|
||||||
|
common warnings
|
||||||
|
ghc-options: -Wall
|
||||||
|
|
||||||
|
executable zorth
|
||||||
|
import: warnings
|
||||||
|
main-is: Main.hs
|
||||||
|
build-depends: base ^>=4.18.3.0,
|
||||||
|
process ^>=1.6.26.1
|
||||||
|
hs-source-dirs: app
|
||||||
|
default-language: Haskell2010
|
||||||
Reference in New Issue
Block a user