+ pat <- expr ==> expr >>= \ pat -> return [coerce HVal x, coerce HVal y, ...]
+ bindings: [x,y,...]
+
+ expr (of IO type) ==> expr >>= \ v -> return [v]
+ [NB: result not printed] bindings: [it]
+
+
+ expr (of non-IO type,
+ result showable) ==> let v = expr in print v >> return [v]
+ bindings: [it]
+
+ expr (of non-IO type,
+ result not showable) ==> error
+
+\begin{code}
+hscStmt dflags hst hit pcs0 icontext stmt just_expr
+ = do { maybe_stmt <- hscParseStmt dflags stmt
+ ; case maybe_stmt of
+ Nothing -> return (pcs0, Nothing)
+ Just parsed_stmt -> do {
+
+ let { notExprStmt (ExprStmt _ _ _) = False;
+ notExprStmt _ = True
+ };
+
+ if (just_expr && notExprStmt parsed_stmt)
+ then do hPutStrLn stderr ("not an expression: `" ++ stmt ++ "'")
+ return (pcs0, Nothing)
+ else do {
+
+ -- Rename it
+ (pcs1, print_unqual, maybe_renamed_stmt)
+ <- renameStmt dflags hit hst pcs0
+ iNTERACTIVE icontext parsed_stmt
+
+ ; case maybe_renamed_stmt of
+ Nothing -> return (pcs0, Nothing)
+ Just (bound_names, rn_stmt) -> do {
+
+ -- Typecheck it
+ maybe_tc_return <-
+ if just_expr
+ then case rn_stmt of { (ExprStmt e _ _, decls) ->
+ typecheckExpr dflags pcs1 hst (ic_type_env icontext)
+ print_unqual iNTERACTIVE (e,decls) }
+ else typecheckStmt dflags pcs1 hst (ic_type_env icontext)
+ print_unqual iNTERACTIVE bound_names rn_stmt
+
+ ; case maybe_tc_return of
+ Nothing -> return (pcs0, Nothing)
+ Just (pcs2, tc_expr, bound_ids, ty) -> do {
+
+ -- Desugar it
+ ds_expr <- deSugarExpr dflags pcs2 hst iNTERACTIVE print_unqual tc_expr
+
+ -- Simplify it
+ ; simpl_expr <- simplifyExpr dflags pcs2 hst ds_expr
+
+ -- Tidy it (temporary, until coreSat does cloning)
+ ; tidy_expr <- tidyCoreExpr simpl_expr
+
+ -- Prepare for codegen
+ ; prepd_expr <- corePrepExpr dflags tidy_expr
+
+ -- Convert to BCOs
+ ; bcos <- coreExprToBCOs dflags prepd_expr
+
+ ; let
+ -- Make all the bound ids "global" ids, now that
+ -- they're notionally top-level bindings. This is
+ -- important: otherwise when we come to compile an expression
+ -- using these ids later, the byte code generator will consider
+ -- the occurrences to be free rather than global.
+ global_bound_ids = map globaliseId bound_ids;
+ globaliseId id = setGlobalIdDetails id VanillaGlobal
+
+ ; return (pcs2, Just (global_bound_ids, ty, bcos))
+
+ }}}}}
+
+hscParseStmt :: DynFlags -> String -> IO (Maybe RdrNameStmt)
+hscParseStmt dflags str
+ = do -------------------------- Parser ----------------
+ showPass dflags "Parser"
+ _scc_ "Parser" do
+
+ buf <- stringToStringBuffer str
+
+ let glaexts | dopt Opt_GlasgowExts dflags = 1#
+ | otherwise = 0#
+
+ case parseStmt buf PState{ bol = 0#, atbol = 1#,
+ context = [], glasgow_exts = glaexts,
+ loc = mkSrcLoc SLIT("<interactive>") 1 } of {
+
+ PFailed err -> do { hPutStrLn stderr (showSDoc err);
+-- Not yet implemented in <4.11 freeStringBuffer buf;
+ return Nothing };
+
+ -- no stmt: the line consisted of just space or comments
+ POk _ Nothing -> return Nothing;
+
+ POk _ (Just rdr_stmt) -> do {
+
+ --ToDo: can't free the string buffer until we've finished this
+ -- compilation sweep and all the identifiers have gone away.
+ --freeStringBuffer buf;
+ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr rdr_stmt);
+ return (Just rdr_stmt)
+ }}
+#endif