Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev #20

Merged
merged 32 commits into from
Jan 14, 2024
Merged

dev #20

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ef31143
Rename lib file
guillaumeAbel Dec 21, 2023
289ffe2
Add AST
guillaumeAbel Jan 3, 2024
7bead12
Fix file location
guillaumeAbel Jan 3, 2024
4ce0c16
Add header
guillaumeAbel Jan 3, 2024
b6e2464
Add exports
guillaumeAbel Jan 3, 2024
924b829
Fix TypeValue
guillaumeAbel Jan 3, 2024
4287510
Fix norm + returnValue
guillaumeAbel Jan 3, 2024
e15385b
Fix
guillaumeAbel Jan 3, 2024
cac38e5
Fix type
guillaumeAbel Jan 3, 2024
2b5c4c3
Fix export
guillaumeAbel Jan 3, 2024
a3a0beb
Add current progress
guillaumeAbel Jan 7, 2024
a637ac3
Add awaiting tests
guillaumeAbel Jan 14, 2024
2cd8616
Add awaiting tests
guillaumeAbel Jan 14, 2024
9505160
Fix conflicts
guillaumeAbel Jan 14, 2024
d2d17aa
Add while
Saverio976 Jan 14, 2024
14f5dfd
Add while to bnf
Saverio976 Jan 14, 2024
63e6cd7
add some operations
TTENSHII Jan 14, 2024
a4b3a37
Fix documentation
Saverio976 Jan 14, 2024
4010983
Fix type char
Saverio976 Jan 14, 2024
9a21820
Merge pull request #19 from X-R-G-B/add-while
Saverio976 Jan 14, 2024
2f27dc8
Merge branch 'main' into dev
Saverio976 Jan 14, 2024
7ef7c25
add loop
TTENSHII Jan 14, 2024
38ea155
fix norm
TTENSHII Jan 14, 2024
a0f771e
Add type checker
guillaumeAbel Jan 14, 2024
0b84024
Add stdlib
Saverio976 Jan 14, 2024
ce1d910
Add typecheck
guillaumeAbel Jan 14, 2024
907e8c3
Add
guillaumeAbel Jan 14, 2024
6f9fa7e
Merge remote-tracking branch 'origin/step4TypeCheck' into dev
Saverio976 Jan 14, 2024
a93fdb0
Call typecheck
Saverio976 Jan 14, 2024
01a5070
add else
TTENSHII Jan 14, 2024
525d330
Merge pull request #21 from X-R-G-B/vm
Saverio976 Jan 14, 2024
0bb3f8f
fix norm
TTENSHII Jan 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions book.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[book]
title = "Koaky (Yet Another Programming Language)"
title = "Leviator (Yet Another Programming Language)"
authors = ["@Saverio976", "@TTENSHII", "@guillaumeAbel"]
description = "Documentation of Koaky"
description = "Documentation of Leviator"
src = "docs"

[build]
Expand All @@ -10,8 +10,8 @@ create-missing = false
use-default-preprocessors = true

[output.html]
git-repository-url = "https://github.com/X-R-G-B/koak"
edit-url-template = "https://github.com/X-R-G-B/koak/edit/main/{path}"
git-repository-url = "https://github.com/X-R-G-B/Leviator"
edit-url-template = "https://github.com/X-R-G-B/Leviator/edit/main/{path}"

[output.html.search]
enable = true
Expand Down
3 changes: 2 additions & 1 deletion docs/BNF.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parameter> ::= <identifier> ": " <type>
<type> ::= <upperLetter> <char2>
<instruction> ::= <instructionIns> ";\n"
<instructionIns> ::= <declaration> | <assignment> | <functionCall> | <return> | <condition>
<instructionIns> ::= <declaration> | <assignment> | <functionCall> | <return> | <condition> | <while>
<declaration> ::= "@" <type> " " <identifier> " = " <value>
<assignment> ::= <identifier> " = " <value>
<functionCall> ::= <identifier> "(" <varParamList>* ")"
Expand All @@ -39,6 +39,7 @@
<conditionIfElse> ::= <conditionIf> <conditionElse>
<conditionIf> ::= "if (" <value> ")\n{\n" <instruction>* "}\n"
<conditionElse> ::= "else\n{\n" <instruction>* "}\n"
<while> ::= "while (" <value> ")\n{\n" <instruction>* "}\n"

<character> ::= "'" <char1> "'"
<bool> ::= "True" | "False"
Expand Down
14 changes: 11 additions & 3 deletions lvtc/app/Args.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ data Args = Args {
action :: Action,
folderPath :: String,
outFile :: String,
verbose :: Bool
verbose :: Bool,
folders :: [String]
}

parseArgs' :: [String] -> Args -> Either Args String
Expand All @@ -42,6 +43,10 @@ parseArgs' ["-o"] _ =
Right "Missing argument for -o"
parseArgs' ("--verbose":xs) args =
parseArgs' xs (args {verbose = True})
parseArgs' ("--lib":x:xs) args =
parseArgs' xs (args {folders = x : folders args})
parseArgs' ("-l":x:xs) args =
parseArgs' xs (args {folders = x : folders args})
parseArgs' (('-':xs):_) _ =
Right ("Unknown option: " ++ xs)
parseArgs' (x:xs) args =
Expand All @@ -51,7 +56,8 @@ parseArgs :: [String] -> IO (Either Args String)
parseArgs args =
getCurrentDirectory >>= \path ->
return (parseArgs' args (Args {
action = Run, folderPath = path, outFile = "out.wasm", verbose = False
action = Run, folderPath = path, outFile = "out.wasm",
verbose = False, folders = []
}))

hLine1 :: String
Expand All @@ -77,9 +83,11 @@ hLine9 = part1 ++ part2
part2 = " source code recursively from FOLDER\n"
hLine10 :: String
hLine10 = "\t--verbose\n\t\tVerbose mode\n"
hLine11 :: String
hLine11 = "\t-l, --lib\n\t\tAdd folder to compiled Leviator source code\n"

printHelp :: IO ()
printHelp =
putStr hLine1 >> putStr hLine2 >> putStr hLine3 >> putStr hLine4
>> putStr hLine5 >> putStr hLine6 >> putStr hLine7 >> putStr hLine8
>> putStr hLine9 >> putStr hLine10
>> putStr hLine9 >> putStr hLine10 >> putStr hLine11
6 changes: 3 additions & 3 deletions lvtc/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import Run (run)
import Version (printVersion)

dispatchArgs :: Args -> IO ()
dispatchArgs (Args Run fPath oFile v) = run (Args Run fPath oFile v)
dispatchArgs (Args ShowHelp _ _ _) = printHelp
dispatchArgs (Args ShowVersion _ _ _) = printVersion
dispatchArgs (Args Run fPath oFile v fs) = run (Args Run fPath oFile v fs)
dispatchArgs (Args ShowHelp _ _ _ _) = printHelp
dispatchArgs (Args ShowVersion _ _ _ _) = printVersion

dispatchIfOk :: Either Args String -> IO ()
dispatchIfOk (Left args) = dispatchArgs args
Expand Down
18 changes: 13 additions & 5 deletions lvtc/app/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import WatLikeToWat (watsLikeToWat)
import Wasm (Wasm)
import WatToWasm (watToWasm)
import WriteWasm (writeWasm)
import TypeCheck (typeCheck)
import Args

import System.Directory (listDirectory)
Expand Down Expand Up @@ -67,6 +68,13 @@ listAllFiles v path =
p True = putStrLn ("Compiling Folder: " ++ show path)
p False = return ()

listsAllFiles :: Bool -> [FilePath] -> IO [FilePath]
listsAllFiles _ [] = return []
listsAllFiles v (f:fs) =
listAllFiles v f
>>= (\files -> listsAllFiles v fs
>>= (\others -> return (files ++ others)))

getAllFunc :: Bool -> [Expression] -> IO [FuncDeclaration]
getAllFunc _ [] = return []
getAllFunc v ((Expression.Function str):expressions) =
Expand All @@ -83,9 +91,9 @@ getAllFunc v (x : expressions) = p v >> getAllFunc v expressions
checkAst :: Bool -> IO [FuncDeclaration] -> IO [FuncDeclaration]
checkAst _ funcsIo =
funcsIo
>>= (\funcs -> case Just funcs of
Just f -> return f
Nothing -> fail "Invalid Code")
>>= (\funcs -> case typeCheck funcs of
True -> return funcs
False -> fail "Invalid Code")

transformToWatLike :: Bool -> IO [FuncDeclaration] -> IO [FuncDeclare]
transformToWatLike v funcsIo =
Expand Down Expand Up @@ -119,10 +127,10 @@ showDebug True wasm = print wasm
showDebug False _ = return ()

run :: Args -> IO ()
run (Args Run fPath oFile v) =
run (Args Run fPath oFile v fPaths) =
transformedWasm >>= \wasm -> (showDebug v wasm >> writeWasm wasm oFile)
where
expressions = listAllFiles v fPath >>= getFilesExpression v
expressions = listsAllFiles v (fPath:fPaths) >>= getFilesExpression v
funcs = expressions >>= getAllFunc v
transformedWatLike = transformToWatLike v (checkAst v funcs)
transformedWat = transformToWat v transformedWatLike
Expand Down
2 changes: 2 additions & 0 deletions lvtc/lvtc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ library
Parser
ParseUtil
ShuntingYard
TypeCheck
Wasm
WasmUtils
WatAST
Expand Down Expand Up @@ -82,6 +83,7 @@ test-suite lvtc-test
UTLexeme
UTParseLvt
UTShuntingYard
UTTypeCheck
UTWasm
UTWat
UTWatLike
Expand Down
16 changes: 11 additions & 5 deletions lvtc/src/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ module AST
( Type
, Value (..)
, Var
, Symbol
, FuncCall
, FuncPrototype
, FuncDeclaration
, Instruction (..)
, VarDeclaration
, VarAssignation
, Condition
, Symbol
, IsFuncExport
) where
, Export
, WhileBlock
) where

import Data.Int (Int32)

Expand Down Expand Up @@ -58,9 +59,9 @@ instance Eq Value where

type Var = (Symbol, Type)

type IsFuncExport = Bool
type Export = Bool

type FuncPrototype = (IsFuncExport, Symbol, [Var], Type)
type FuncPrototype = (Export, Symbol, [Var], Type)

type FuncDeclaration = (FuncPrototype, [Instruction])

Expand All @@ -77,12 +78,15 @@ type VarDeclaration = (Var, Value)

type VarAssignation = (Symbol, Value)

type WhileBlock = (Value, [Instruction])

data Instruction =
Function FuncCall
| Return Value
| Declaration VarDeclaration
| Assignation VarAssignation
| Cond Condition
| While WhileBlock

instance Show Instruction where
show (Function x) =
Expand All @@ -95,6 +99,8 @@ instance Show Instruction where
"Assignation[< " ++ show x ++ " >]"
show (Cond x) =
"Cond[< " ++ show x ++ " >]"
show (While x) =
"While[< " ++ show x ++ " >]"

instance Eq Instruction where
(==) (Function x) (Function y) = x == y
Expand Down
3 changes: 3 additions & 0 deletions lvtc/src/Lexeme.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Lexeme
replaceN :: Int -> String -> String
replaceN _ [] = []
replaceN 0 ('"':xs) = '"' : replaceN 1 xs
replaceN 1 ('\\':'0':xs) = '\0' : replaceN 1 xs
replaceN 1 ('\\':'n':xs) = '\n' : replaceN 1 xs
replaceN 1 ('\\':'t':xs) = '\t' : replaceN 1 xs
replaceN 1 ('\\':'v':xs) = '\v' : replaceN 1 xs
Expand Down Expand Up @@ -66,6 +67,8 @@ lexeme 0 ('i':'f':' ':xs) = lexeme 0 ('i':'f':xs)
lexeme 0 (' ':'i':'f':xs) = lexeme 0 ('i':'f':xs)
lexeme 0 ('e':'l':'s':'e':' ':xs) = lexeme 0 ('e':'l':'s':'e':xs)
lexeme 0 (' ':'e':'l':'s':'e':xs) = lexeme 0 ('e':'l':'s':'e':xs)
lexeme 0 ('w':'h':'i':'l':'e':' ':xs) = lexeme 0 ('w':'h':'i':'l':'e':xs)
lexeme 0 (' ':'w':'h':'i':'l':'e':xs) = lexeme 0 ('w':'h':'i':'l':'e':xs)
lexeme 0 ('\\':x:xs) = x : lexeme 0 xs
lexeme 1 ('\\':x:xs) = x : lexeme 1 xs
lexeme 0 (' ':' ':xs) = lexeme 0 (' ':xs)
Expand Down
17 changes: 14 additions & 3 deletions lvtc/src/ParseLvt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module ParseLvt
parseDeclaration,
parseAssignation,
parseCond,
parseWhile,
-- Function
parseFuncDeclaration
) where
Expand Down Expand Up @@ -94,8 +95,8 @@ parseOperatorOp =
Var
<$> (parseString "+" <|> parseString "-" <|> parseString "*"
<|> parseString "/" <|> parseString "{" <|> parseString "}"
<|> parseString "==" <|> parseString "!=" <|> parseString "<"
<|> parseString ">" <|> parseString "<=" <|> parseString ">=")
<|> parseString "==" <|> parseString "!=" <|> parseString "<="
<|> parseString ">=" <|> parseString "<" <|> parseString ">")

parseOperator' :: ShuntingYardState -> Parser ShuntingYardState
parseOperator' sys =
Expand Down Expand Up @@ -269,9 +270,19 @@ parseCond = Parser f
Nothing -> Nothing
Just (ifBlock, ys) -> runParser (parseCond' val ifBlock) ys

parseWhileComp :: Parser Value
parseWhileComp = parseString "while(" *> parseValue <* parseString ")"

parseWhileBlock :: Parser [Instruction]
parseWhileBlock = parseString "{" *> parseInstructions <* parseString "}"

parseWhile :: Parser Instruction
parseWhile = While <$> ((,) <$> parseWhileComp <*> parseWhileBlock)

parseInstruction :: Parser Instruction
parseInstruction =
(parseCond
<|> parseWhile
<|> parseReturn
<|> parseDeclaration
<|> parseAssignation
Expand Down Expand Up @@ -299,7 +310,7 @@ parseFuncVars =
<|> parseFuncVar)
<* parseChar ')'

parseFuncName :: Parser (IsFuncExport, Symbol)
parseFuncName :: Parser (Export, Symbol)
parseFuncName =
((\x -> (True, x)) <$> (parseString "export fn " *> parseVarName))
<|> ((\x -> (False, x)) <$> (parseString "fn " *> parseVarName))
Expand Down
Loading
Loading