Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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 runsol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ if [[ -n "$create_arguments_sig" ]] && [[ -n "$create_raw_args" ]]; then
fi

# Execute compilation pipeline
echo "Compiling to core..."
echo "Compiling to hull..."
if ! cabal run sol-core -- -f "$file"; then
echo "Error: sol-core compilation failed"
exit 1
fi

mkdir -p build
if ls ./output*.core 1> /dev/null 2>&1; then
mv ./output*.core build/
if ls ./output*.hull 1> /dev/null 2>&1; then
mv ./output*.hull build/
fi

echo "Generating Yul..."
yule_args=("$core" -o "$yulfile")
yule_args=("$hull" -o "$yulfile")
if [[ "$create" == "false" ]]; then
yule_args+=(--nodeploy)
fi
Expand Down
10 changes: 5 additions & 5 deletions sol-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ library

-- cabal-fmt: expand src
exposed-modules:
Solcore.Backend.EmitHull
Solcore.Backend.Specialise
Solcore.Desugarer.FieldAccess
Solcore.Desugarer.IfDesugarer
Solcore.Desugarer.IndirectCall
Solcore.Desugarer.MatchCompiler
Solcore.Desugarer.ReplaceWildcard
Solcore.Desugarer.Specialise
Solcore.Desugarer.EmitCore
Solcore.Desugarer.ContractDispatch
Solcore.Desugarer.ReplaceFunTypeArgs
Solcore.Desugarer.UniqueTypeGen
Expand Down Expand Up @@ -98,9 +98,9 @@ library
Solcore.Pipeline.Options
Solcore.Pipeline.SolcorePipeline
Solcore.Primitives.Primitives
Language.Core
Language.Core.Parser
Language.Core.Types
Language.Hull
Language.Hull.Parser
Language.Hull.Types
Language.Yul
Language.Yul.Parser
Language.Yul.QuasiQuote
Expand Down
15 changes: 7 additions & 8 deletions src/Language/Core.hs → src/Language/Hull.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

{-# OPTIONS_GHC -Wincomplete-patterns #-}
{-# LANGUAGE InstanceSigs #-}
module Language.Core
module Language.Hull
( Expr(..), Stmt(..), Arg(..), Alt(..), pattern ConAlt, Pat(..), Con(..), Contract(..), Object(..), Body
, module Language.Core.Types
, module Language.Hull.Types
, pattern SAV
, Name
) where

import Common.Pretty
import Language.Core.Types
import Language.Hull.Types
import Language.Yul


Expand Down Expand Up @@ -64,8 +63,8 @@ data Con = CInl | CInr | CInK Int deriving Show

data Contract = Contract { ccName :: Name, ccStmts :: [Stmt] }

newtype Core = Core [Stmt]
instance Show Core where show = render . ppr
newtype Hull = Hull [Stmt]
instance Show Hull where show = render . ppr
instance Show Contract where show = render . ppr


Expand Down Expand Up @@ -150,8 +149,8 @@ instance Pretty Con where
instance Pretty Arg where
ppr (TArg n t) = text n <+> text ":" <+> ppr t

instance Pretty Core where
ppr (Core stmts) = vcat (map ppr stmts)
instance Pretty Hull where
ppr (Hull stmts) = vcat (map ppr stmts)

pprBody :: Body -> Doc
pprBody stmts = braces $ nest 2 (vcat (map ppr stmts))
Expand Down
92 changes: 46 additions & 46 deletions src/Language/Core/Parser.hs → src/Language/Hull/Parser.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Language.Core.Parser where
import Language.Core
module Language.Hull.Parser where
import Language.Hull
( Object(..),
Body,
Alt(..),
Expand All @@ -17,7 +17,7 @@ import Language.Yul.Parser(yulBlock)


parseObject :: String -> String -> Object
parseObject filename = runMyParser filename coreObject
parseObject filename = runMyParser filename hullObject

-- Note: this module repeats some definitions from YulParser.Name
-- This is intentional as we may want to make different syntax choices
Expand Down Expand Up @@ -68,19 +68,19 @@ pKeyword w = try $ lexeme (string w <* notFollowedBy identChar)

pPrimaryType :: Parser Type
pPrimaryType = choice
[ try $ TNamed <$> identifier <*> braces coreType
[ try $ TNamed <$> identifier <*> braces hullType
, TWord <$ pKeyword "word"
, TBool <$ pKeyword "bool"
, TUnit <$ pKeyword "unit"
, TSumN <$> ( pKeyword "sum" *> parens (commaSep coreType))
, parens coreType
, TSumN <$> ( pKeyword "sum" *> parens (commaSep hullType))
, parens hullType
]

coreType :: Parser Type
coreType = makeExprParser pPrimaryType coreTypeTable
hullType :: Parser Type
hullType = makeExprParser pPrimaryType hullTypeTable

coreTypeTable :: [[Operator Parser Type]]
coreTypeTable = [[InfixR (TPair <$ symbol "*")]
hullTypeTable :: [[Operator Parser Type]]
hullTypeTable = [[InfixR (TPair <$ symbol "*")]
,[InfixR (TSum <$ symbol "+")]]

pPrimaryExpr :: Parser Expr
Expand All @@ -89,24 +89,24 @@ pPrimaryExpr = choice
, EBool True <$ pKeyword "true"
, EBool False <$ pKeyword "false"
, pTuple
, try (ECall <$> identifier <*> parens (commaSep coreExpr))
, try (ECall <$> identifier <*> parens (commaSep hullExpr))
, EVar <$> (identifier <* notFollowedBy (symbol "("))
, parens coreExpr
, parens hullExpr
]

pTuple :: Parser Expr
pTuple = go <$> parens (commaSep coreExpr) where
pTuple = go <$> parens (commaSep hullExpr) where
go [] = EUnit
go [e] = e
go [e1, e2] = EPair e1 e2
go (e:es) = EPair e (go es)


coreExpr :: Parser Expr
coreExpr = choice
[ pKeyword "inl" *> (EInl <$> angles coreType <*> pPrimaryExpr)
, pKeyword "inr" *> (EInr <$> angles coreType <*> pPrimaryExpr)
, pKeyword "in" *> (EInK <$> parens int <*> coreType <*> pPrimaryExpr)
hullExpr :: Parser Expr
hullExpr = choice
[ pKeyword "inl" *> (EInl <$> angles hullType <*> pPrimaryExpr)
, pKeyword "inr" *> (EInr <$> angles hullType <*> pPrimaryExpr)
, pKeyword "in" *> (EInK <$> parens int <*> hullType <*> pPrimaryExpr)
, pKeyword "fst" *> (EFst <$> pPrimaryExpr)
, pKeyword "snd" *> (ESnd <$> pPrimaryExpr)
, condExpr
Expand All @@ -115,40 +115,40 @@ coreExpr = choice

condExpr = do
pKeyword "if"
t <- angles coreType
e1 <- coreExpr
t <- angles hullType
e1 <- hullExpr
pKeyword "then"
e2 <- coreExpr
e2 <- hullExpr
pKeyword "else"
e3 <- coreExpr
e3 <- hullExpr
pure (ECond t e1 e2 e3)

coreStmt :: Parser Stmt
coreStmt = choice
[ SAlloc <$> (pKeyword "let" *> identifier) <*> (symbol ":" *> coreType)
, SReturn <$> (pKeyword "return" *> coreExpr)
, SBlock <$> braces(many coreStmt)
, SMatch <$> (pKeyword "match" *> angles coreType) <*> (coreExpr <* pKeyword "with") <*> braces(many coreAlt)
-- , SMatch <$> (pKeyword "match" *> coreExpr <* pKeyword "with") <*> (symbol "{" *> many coreAlt <* symbol "}")
, SFunction <$> (pKeyword "function" *> identifier) <*> (parens (commaSep coreArg)) <*> (symbol "->" *> coreType)
<*> coreBody
hullStmt :: Parser Stmt
hullStmt = choice
[ SAlloc <$> (pKeyword "let" *> identifier) <*> (symbol ":" *> hullType)
, SReturn <$> (pKeyword "return" *> hullExpr)
, SBlock <$> braces(many hullStmt)
, SMatch <$> (pKeyword "match" *> angles hullType) <*> (hullExpr <* pKeyword "with") <*> braces(many hullAlt)
-- , SMatch <$> (pKeyword "match" *> hullExpr <* pKeyword "with") <*> (symbol "{" *> many hullAlt <* symbol "}")
, SFunction <$> (pKeyword "function" *> identifier) <*> (parens (commaSep hullArg)) <*> (symbol "->" *> hullType)
<*> hullBody
, SAssembly <$> (pKeyword "assembly" *> yulBlock)
, SRevert <$> (pKeyword "revert" *> stringLiteral)
, try (SAssign <$> (coreExpr <* symbol ":=") <*> coreExpr)
, SExpr <$> coreExpr
, try (SAssign <$> (hullExpr <* symbol ":=") <*> hullExpr)
, SExpr <$> hullExpr
]

coreBody :: Parser Body
coreBody = braces(many coreStmt)
hullBody :: Parser Body
hullBody = braces(many hullStmt)

coreArg :: Parser Arg
coreArg = TArg <$> identifier <*> (symbol ":" *> coreType)
hullArg :: Parser Arg
hullArg = TArg <$> identifier <*> (symbol ":" *> hullType)

coreAlt :: Parser Alt
coreAlt = Alt <$> corePat <*> identifier <* symbol "=>" <*> coreBody
hullAlt :: Parser Alt
hullAlt = Alt <$> hullPat <*> identifier <* symbol "=>" <*> hullBody

corePat :: Parser Pat
corePat = choice
hullPat :: Parser Pat
hullPat = choice
[ PIntLit <$> integer
, PCon CInl <$ pKeyword "inl"
, PCon CInr <$ pKeyword "inr"
Expand All @@ -157,9 +157,9 @@ corePat = choice
, PWildcard <$ pKeyword "_"
]

coreObject :: Parser Object
coreObject = sc *> (Object <$> (pKeyword "object" *> identifier <* symbol "{")
<*> coreCode <*> many coreObject) <* symbol "}"
hullObject :: Parser Object
hullObject = sc *> (Object <$> (pKeyword "object" *> identifier <* symbol "{")
<*> hullCode <*> many hullObject) <* symbol "}"

coreCode :: Parser Body
coreCode = sc *> (Object <$> pKeyword "code" *> coreBody)
hullCode :: Parser Body
hullCode = sc *> (Object <$> pKeyword "code" *> hullBody)
2 changes: 1 addition & 1 deletion src/Language/Core/Types.hs → src/Language/Hull/Types.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Language.Core.Types where
module Language.Hull.Types where

data Type
= TWord
Expand Down
Loading