mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
feat: Reduce binary size with more compact exhaustiveness error reporting (#1112)
This commit is contained in:
parent
eb1e060f54
commit
0c6eae63c8
@ -34,6 +34,12 @@ typedef char CChar;
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#define UNHANDLED(file, line) \
|
||||
do { \
|
||||
printf("Unhandled case in 'match' expression at %s:%d\n", file, line); \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
// Array
|
||||
typedef struct {
|
||||
size_t len;
|
||||
|
11
src/Emit.hs
11
src/Emit.hs
@ -20,6 +20,7 @@ import Info
|
||||
import qualified Map
|
||||
import qualified Meta
|
||||
import Obj
|
||||
import Path (takeFileName)
|
||||
import Project
|
||||
import Scoring
|
||||
import qualified Set
|
||||
@ -445,16 +446,8 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
|
||||
let Just t = ty
|
||||
in appendToSrc (addIndent indent ++ tyToCLambdaFix t ++ " " ++ retVar ++ ";\n")
|
||||
zipWithM_ (emitCase exprVar) (True : repeat False) (pairwise rest)
|
||||
appendToSrc (addIndent indent ++ "else {\n")
|
||||
appendToSrc (addIndent indent ++ " // This will not be needed with static exhaustiveness checking in 'match' expressions:\n")
|
||||
appendToSrc (addIndent indent ++ " fprintf(stderr, \"Unhandled case in 'match' expression at " ++ quoteBackslashes (prettyInfo info) ++ "\\n\");\n")
|
||||
appendToSrc (addIndent indent ++ " exit(1);\n")
|
||||
appendToSrc (addIndent indent ++ "}\n")
|
||||
appendToSrc (addIndent indent ++ "else UNHANDLED(\"" ++ takeFileName (infoFile info) ++ "\", " ++ show (infoLine info) ++ ");\n")
|
||||
pure retVar
|
||||
where
|
||||
quoteBackslashes [] = []
|
||||
quoteBackslashes ('\\' : r) = "\\\\" ++ quoteBackslashes r
|
||||
quoteBackslashes (x : r) = x : quoteBackslashes r
|
||||
XObj (Match _) _ _ : _ ->
|
||||
error "Fell through match."
|
||||
-- While
|
||||
|
Loading…
Reference in New Issue
Block a user