Fixed argumentless constructors being treated as variables.
This commit is contained in:
parent
d7549d421c
commit
2aff7a7743
3 changed files with 56 additions and 67 deletions
|
|
@ -14,8 +14,6 @@ import Data.Map (Map)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import Data.Maybe (fromJust, fromMaybe)
|
import Data.Maybe (fromJust, fromMaybe)
|
||||||
import Data.Tuple.Extra (dupe, first, second)
|
import Data.Tuple.Extra (dupe, first, second)
|
||||||
import Debug.Trace (trace)
|
|
||||||
import qualified Grammar.Abs as GA
|
|
||||||
import Grammar.ErrM (Err)
|
import Grammar.ErrM (Err)
|
||||||
import Monomorphizer.MonomorphizerIr as MIR
|
import Monomorphizer.MonomorphizerIr as MIR
|
||||||
import qualified TypeChecker.TypeCheckerIr as TIR
|
import qualified TypeChecker.TypeCheckerIr as TIR
|
||||||
|
|
@ -376,7 +374,7 @@ emitECased t e cases = do
|
||||||
emit $ SetVariable (fst x) (ExtractValue (CustomType (coerce consId)) (VIdent casted Ptr) i)
|
emit $ SetVariable (fst x) (ExtractValue (CustomType (coerce consId)) (VIdent casted Ptr) i)
|
||||||
PLit (l, t) -> undefined
|
PLit (l, t) -> undefined
|
||||||
PInj id ps -> undefined
|
PInj id ps -> undefined
|
||||||
PCatch -> undefined
|
PCatch -> pure()
|
||||||
PEnum id -> undefined
|
PEnum id -> undefined
|
||||||
--case c of
|
--case c of
|
||||||
-- CIdent x -> do
|
-- CIdent x -> do
|
||||||
|
|
@ -513,7 +511,13 @@ exprToValue = \case
|
||||||
(MIR.LChar i) -> VChar i
|
(MIR.LChar i) -> VChar i
|
||||||
(MIR.EVar name, t) -> do
|
(MIR.EVar name, t) -> do
|
||||||
funcs <- gets functions
|
funcs <- gets functions
|
||||||
case Map.lookup (name, t) funcs of
|
cons <- gets constructors
|
||||||
|
let res = Map.lookup (name, t) funcs
|
||||||
|
<|>
|
||||||
|
(\c -> FunctionInfo { numArgs = numArgsCI c
|
||||||
|
, arguments = argumentsCI c} )
|
||||||
|
<$> Map.lookup name cons
|
||||||
|
case res of
|
||||||
Just fi -> do
|
Just fi -> do
|
||||||
if numArgs fi == 0
|
if numArgs fi == 0
|
||||||
then do
|
then do
|
||||||
|
|
|
||||||
29
src/Main.hs
29
src/Main.hs
|
|
@ -7,27 +7,18 @@ import Data.Bool (bool)
|
||||||
import Data.List.Extra (isSuffixOf)
|
import Data.List.Extra (isSuffixOf)
|
||||||
import Data.Maybe (fromJust, isNothing)
|
import Data.Maybe (fromJust, isNothing)
|
||||||
import GHC.IO.Handle.Text (hPutStrLn)
|
import GHC.IO.Handle.Text (hPutStrLn)
|
||||||
import System.Console.GetOpt (
|
import System.Console.GetOpt (ArgDescr (NoArg, ReqArg),
|
||||||
ArgDescr (NoArg, ReqArg),
|
|
||||||
ArgOrder (RequireOrder),
|
ArgOrder (RequireOrder),
|
||||||
OptDescr (Option),
|
OptDescr (Option), getOpt,
|
||||||
getOpt,
|
usageInfo)
|
||||||
usageInfo,
|
import System.Directory (createDirectory, doesPathExist,
|
||||||
)
|
|
||||||
import System.Directory (
|
|
||||||
createDirectory,
|
|
||||||
doesPathExist,
|
|
||||||
getDirectoryContents,
|
getDirectoryContents,
|
||||||
removeDirectoryRecursive,
|
removeDirectoryRecursive,
|
||||||
setCurrentDirectory,
|
setCurrentDirectory)
|
||||||
)
|
|
||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
||||||
import System.Exit (
|
import System.Exit (ExitCode (ExitFailure),
|
||||||
ExitCode (ExitFailure),
|
exitFailure, exitSuccess,
|
||||||
exitFailure,
|
exitWith)
|
||||||
exitSuccess,
|
|
||||||
exitWith,
|
|
||||||
)
|
|
||||||
import System.IO (stderr)
|
import System.IO (stderr)
|
||||||
|
|
||||||
import Codegen.Codegen (generateCode)
|
import Codegen.Codegen (generateCode)
|
||||||
|
|
@ -111,8 +102,8 @@ main' opts s = do
|
||||||
bool (printToErr $ printTree typechecked) (printToErr $ show typechecked) opts.debug
|
bool (printToErr $ printTree typechecked) (printToErr $ show typechecked) opts.debug
|
||||||
|
|
||||||
printToErr "\n-- Lambda Lifter --"
|
printToErr "\n-- Lambda Lifter --"
|
||||||
let lifted = lambdaLift typechecked
|
--let lifted = lambdaLift typechecked
|
||||||
printToErr $ printTree lifted
|
--printToErr $ printTree lifted
|
||||||
|
|
||||||
-- printToErr "\n-- Lambda Lifter --"
|
-- printToErr "\n-- Lambda Lifter --"
|
||||||
-- let lifted = lambdaLift typechecked
|
-- let lifted = lambdaLift typechecked
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,20 @@
|
||||||
data Maybe () where {
|
data List () where {
|
||||||
Nothing : Maybe ()
|
Nil : List ()
|
||||||
Just : Int -> Maybe ()
|
Cons : Int -> List () -> List ()
|
||||||
};
|
};
|
||||||
|
|
||||||
-- fmap : (Int -> Int) -> Maybe () -> Maybe () ;
|
main = case Nil of {
|
||||||
-- fmap f ma = case ma of {
|
Nil => 0 ;
|
||||||
-- Nothing => Nothing ;
|
Cons a _ => a ;
|
||||||
-- Just a => Just (f a) ;
|
|
||||||
-- };
|
|
||||||
|
|
||||||
main = case (Just 10) of {
|
|
||||||
Just a => a ;
|
|
||||||
Nothing => 1 ;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
-- pure : Int -> Maybe () ;
|
-- length : List () -> Int ;
|
||||||
-- pure x = Just x ;
|
-- length xs = case xs of {
|
||||||
--
|
-- Nil => 0;
|
||||||
-- return = pure;
|
-- Cons _ xs => 1 + length xs ;
|
||||||
--
|
|
||||||
-- bind : Maybe () -> (Int -> Maybe ()) -> Maybe () ;
|
|
||||||
-- bind ma f = case ma of {
|
|
||||||
-- Nothing => Nothing ;
|
|
||||||
-- Just a => f a ;
|
|
||||||
-- };
|
-- };
|
||||||
|
|
||||||
|
--sum xs = case xs of {
|
||||||
|
-- Nil => 0 ;
|
||||||
|
-- Cons a xs => a + main xs ;
|
||||||
|
--};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue