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 Text.Printf (printf)
|
||||
import Control.Monad (void)
|
||||
import System.Process
|
||||
import System.IO
|
||||
|
||||
handleSymbol :: Handle -> ZorthExpr -> IO ()
|
||||
@@ -87,8 +88,8 @@ forthPrelude h = do
|
||||
\ ret\n\
|
||||
\_start:\n"
|
||||
|
||||
compileZorth :: ZorthAST -> IO ()
|
||||
compileZorth [] = return ()
|
||||
compileZorth xs = do
|
||||
forthPrelude stdout
|
||||
foldr ((>>) . handleSymbol stdout) (return ()) xs
|
||||
compileZorth :: Handle -> ZorthAST -> IO ()
|
||||
compileZorth h [] = return ()
|
||||
compileZorth h xs = do
|
||||
forthPrelude h
|
||||
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
|
||||
x <- sat (\x -> x /= '\n' && x /= ' ')
|
||||
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
|
||||
| ZorthASTWord String
|
||||
| ZorthASTWordDecl [ZorthExpr]
|
||||
| ZorthASTWordDecl (String,ZorthAST)
|
||||
deriving Show
|
||||
|
||||
word1 :: Parser String
|
||||
@@ -48,8 +48,18 @@ pZorthWord = do
|
||||
skipNonsenseSymbols
|
||||
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 = some (pZorthInteger <++ pZorthWord)
|
||||
pZorth = some pZorthExpr
|
||||
|
||||
parseZorth :: String -> ZorthAST
|
||||
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