aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Sil/Compile.icl14
-rw-r--r--Sil/Parse.icl22
-rw-r--r--Sil/Syntax.dcl20
-rw-r--r--Sil/Syntax.icl4
-rw-r--r--Sil/Util/Printer.dcl2
5 files changed, 31 insertions, 31 deletions
diff --git a/Sil/Compile.icl b/Sil/Compile.icl
index abed973..b4854ba 100644
--- a/Sil/Compile.icl
+++ b/Sil/Compile.icl
@@ -186,16 +186,16 @@ where
Just i -> comment (toString st) *> gen app *>
tell ['ABC'.Update_a 0 $ i+1, 'ABC'.Pop_a 1]
_ -> liftT $ Error $ UndefinedName n
- gen (Application app) = comment "Application" *> gen app *> tell ['ABC'.Pop_a 1]
- gen (Return (Just app)) = comment "Return" *> gen app *> cleanup *> tell ['ABC'.Rtn]
- gen (Return Nothing) = comment "Return" *> cleanup *> tell ['ABC'.Rtn]
- gen (MachineStm s) = tell ['ABC'.Raw s]
- gen (If blocks else) =
+ gen (Application e) = comment "Application" *> gen e *> tell ['ABC'.Pop_a 1]
+ gen (Return (Just e)) = comment "Return" *> gen e *> cleanup *> tell ['ABC'.Rtn]
+ gen (Return Nothing) = comment "Return" *> cleanup *> tell ['ABC'.Rtn]
+ gen (MachineStm s) = tell ['ABC'.Raw s]
+ gen (If blocks else) =
fresh "ifend" >>= \end ->
mapM_ (genifblock end) blocks *>
genelse end else
where
- genifblock :: 'ABC'.Label (Application, CodeBlock) -> Gen ()
+ genifblock :: 'ABC'.Label (Expression, CodeBlock) -> Gen ()
genifblock end (cond, cb) =
fresh "ifelse" >>= \else ->
gen cond *>
@@ -209,7 +209,7 @@ where
genelse end Nothing = tell ['ABC'.Label end]
genelse end (Just cb) = gen cb *> tell ['ABC'.Label end]
-instance gen Application
+instance gen Expression
where
gen (Name n) =
gets stackoffset >>= \so ->
diff --git a/Sil/Parse.icl b/Sil/Parse.icl
index 2e21d08..2ee2bc1 100644
--- a/Sil/Parse.icl
+++ b/Sil/Parse.icl
@@ -139,17 +139,17 @@ initialisation =
statement :: Parser Token Statement
statement = declaration
- <|> liftM Application (application <* item TSemicolon)
+ <|> liftM Application (expression <* item TSemicolon)
<|> return
<|> if`
//<|> while
<|> machinecode
where
declaration :: Parser Token Statement
- declaration = liftM2 Declaration name (item TAssign *> application <* item TSemicolon)
+ declaration = liftM2 Declaration name (item TAssign *> expression <* item TSemicolon)
return :: Parser Token Statement
- return = liftM Return (item TReturn *> optional application <* item TSemicolon)
+ return = liftM Return (item TReturn *> optional expression <* item TSemicolon)
machinecode :: Parser Token Statement
machinecode = (\(TMachineCode s) -> MachineStm s) <$> satisfy isMachineCode
@@ -157,19 +157,19 @@ where
if` :: Parser Token Statement
if` = item TIf *>
- parenthised application >>= \cond ->
+ parenthised expression >>= \cond ->
braced codeblock >>= \iftrue ->
many elseif >>= \elseifs ->
optional (item TElse *> braced codeblock) >>= \iffalse ->
pure $ If [(cond,iftrue):elseifs] iffalse
where
elseif = list [TElse, TIf] *>
- parenthised application >>= \cond ->
+ parenthised expression >>= \cond ->
braced codeblock >>= \block ->
pure (cond, block)
-application :: Parser Token Application
-application
+expression :: Parser Token Expression
+expression
= rightAssoc (op TDoubleBar LogOr)
$ rightAssoc (op TDoubleAmpersand LogAnd)
$ rightAssoc (op TDoubleEquals Equals)
@@ -187,17 +187,17 @@ where
op :: Token Op2 -> Parser Token Op2
op token operator = item token *> pure operator
- rightAssoc :: (Parser Token Op2) (Parser Token Application) -> Parser Token Application
+ rightAssoc :: (Parser Token Op2) (Parser Token Expression) -> Parser Token Expression
rightAssoc opp appp = appp >>= \e1 -> optional (opp >>= \op -> rightAssoc opp appp >>= \e -> pure (op,e))
>>= pure o maybe e1 (\(op,e2) -> BuiltinApp2 e1 op e2)
- leftAssoc :: (Parser Token Op2) (Parser Token Application) -> Parser Token Application
+ leftAssoc :: (Parser Token Op2) (Parser Token Expression) -> Parser Token Expression
leftAssoc opp appp = appp >>= \e1 -> many (opp >>= \op -> appp >>= \e -> pure (op,e))
>>= foldM (\e (op,e2) -> pure $ BuiltinApp2 e op e2) e1
- noInfix :: Parser Token Application
+ noInfix :: Parser Token Expression
noInfix
- = liftM2 App name (item TParenOpen *> seplist TComma application <* item TParenClose)
+ = liftM2 App name (item TParenOpen *> seplist TComma expression <* item TParenClose)
<|> liftM (BuiltinApp Neg) (item TTilde *> noInfix)
<|> liftM Literal literal
<|> liftM Name name
diff --git a/Sil/Syntax.dcl b/Sil/Syntax.dcl
index b3ecdb7..58515fe 100644
--- a/Sil/Syntax.dcl
+++ b/Sil/Syntax.dcl
@@ -31,19 +31,19 @@ from Data.Maybe import :: Maybe
}
:: Statement
- = Declaration Name Application
- | Application Application
- | Return (Maybe Application)
- | If [(Application, CodeBlock)] (Maybe CodeBlock)
- | While Application CodeBlock
+ = Declaration Name Expression
+ | Application Expression
+ | Return (Maybe Expression)
+ | If [(Expression, CodeBlock)] (Maybe CodeBlock)
+ | While Expression CodeBlock
| MachineStm String
-:: Application
+:: Expression
= Name Name
| Literal Literal
- | App Name [Application]
- | BuiltinApp Op1 Application
- | BuiltinApp2 Application Op2 Application
+ | App Name [Expression]
+ | BuiltinApp Op1 Expression
+ | BuiltinApp2 Expression Op2 Expression
:: Op1
= Neg //* ~
@@ -72,7 +72,7 @@ from Data.Maybe import :: Maybe
instance toString Statement
instance toString Type
instance toString Arg
-instance toString Application
+instance toString Expression
instance toString Op1
instance toString Op2
instance toString Literal
diff --git a/Sil/Syntax.icl b/Sil/Syntax.icl
index ec7aafa..c812508 100644
--- a/Sil/Syntax.icl
+++ b/Sil/Syntax.icl
@@ -11,7 +11,7 @@ import Sil.Util.Printer
instance toString Statement
where
toString (Declaration n a) = n <+ " := " <+ a <+ ";"
- toString (Application app) = toString app <+ ";"
+ toString (Application e) = toString e <+ ";"
toString (Return Nothing) = "return;"
toString (Return (Just a)) = "return " <+ a <+ ";"
toString (If bs e) = "if ..."
@@ -26,7 +26,7 @@ where
instance toString Arg where toString arg = arg.arg_type <+ " " <+ arg.arg_name
-instance toString Application
+instance toString Expression
where
toString (Name n) = n
toString (Literal lit) = toString lit
diff --git a/Sil/Util/Printer.dcl b/Sil/Util/Printer.dcl
index 1d8fc5c..5535dc2 100644
--- a/Sil/Util/Printer.dcl
+++ b/Sil/Util/Printer.dcl
@@ -4,7 +4,7 @@ from StdOverloaded import class toString, class zero
from Sil.Parse import :: Token
from Sil.Syntax import :: Program, :: Function, :: CodeBlock,
- :: Initialisation, :: Statement, :: Type, :: Application, :: Literal
+ :: Initialisation, :: Statement
:: PrintState