Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
abd0f35
Basic implementation of new error-printer
Thizizmyname May 25, 2018
0a8274a
test for NonAssignableLHSError
Thizizmyname May 25, 2018
ddc9b0b
Elias TCError now takes Environment instead of Backtrace
Thizizmyname May 25, 2018
1bf6d72
Added Elias patch to include Environment into TCError
Thizizmyname May 25, 2018
8f4f265
Update output of tests
Thizizmyname May 25, 2018
3131c66
Updated Meta.hs for new way to print position
Thizizmyname May 29, 2018
3939c13
Printer accepts multi-line errors with no additional arguments
Thizizmyname May 29, 2018
f826e76
Optimized code-input as well as refactored for future function
Thizizmyname May 31, 2018
b08e8b5
Reverted back to not show ranges in error position
Thizizmyname Jun 14, 2018
ec8364a
Swapped Text.PrettyPrint to Data.Text.Prettyprint.Doc
Thizizmyname Jun 13, 2018
a1a3acb
Remade errorprinter to use rich text Doc instead of ANSI Console
Thizizmyname Jun 14, 2018
a63903d
Refactoring and modularization
Thizizmyname Jun 15, 2018
b793649
Reverted to use pretty-1.1.3.* instead of prettyprinter-1.2.1
Thizizmyname Jun 23, 2018
6303390
Added annotation for code blocks
Thizizmyname Jun 18, 2018
8987ed4
List visible methods/functions and added method suggestions
Thizizmyname Jun 22, 2018
be98118
Minor touchups
Thizizmyname Jun 23, 2018
48d95fd
Added functions for method-name analysis and refactorization
Thizizmyname Jun 23, 2018
5452465
stupid typo
Thizizmyname Jun 23, 2018
72dff6b
Working explainer with sub-par data structure
Thizizmyname Jun 12, 2018
c710af5
Added rudimentary fixed table
Thizizmyname Jun 23, 2018
b31315b
Ability to construct explanations of different error types
Thizizmyname Jun 23, 2018
64297e4
Re-added instance Show for Error
Thizizmyname Jun 23, 2018
cbbea76
Added TypeMismatchError and explanation
Thizizmyname Jul 24, 2018
959717f
Expose default function modules in visibleFunctions
Thizizmyname Jul 26, 2018
3d9d3ff
Test using external file and pager for explanations
Thizizmyname Jul 27, 2018
0d76dfe
Code cleanup
Thizizmyname Jul 27, 2018
f1473cc
Updated to latest 'development' branch
Thizizmyname Jul 27, 2018
390d593
Alternative codeviewer with new multiline renderer
Thizizmyname Nov 25, 2018
6c07c05
Added pretty rendering of warnings
Thizizmyname Nov 25, 2018
02874a5
Uses now pager for every explanation
Thizizmyname Nov 26, 2018
3905379
Added functionality for external explanations for specific errors and
Thizizmyname Nov 26, 2018
ddad6e8
Added graphical tests suite
Thizizmyname Nov 26, 2018
475b895
Moved auxiliary info to long suggest
Thizizmyname Mar 16, 2019
6f9b25b
Update from feedback
Thizizmyname Mar 27, 2019
ce3ee62
Merge branch 'development' into enhanced-errors
Thizizmyname Mar 27, 2019
53ef4a6
feedback resolved and workarounds to solve stupidity
Thizizmyname Jan 29, 2020
dbdfa01
Updated from upstream parapluu/encore
Thizizmyname Jan 29, 2020
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
7 changes: 7 additions & 0 deletions encore.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ executable encorec
, unordered-containers
, boxes
, filepath
, ansi-terminal
, pager
, bytestring
hs-source-dirs: src/back src/front src/ir src/opt src/parser src/types
ghc-options: -Werror -fmax-pmcheck-iterations=10000000
default-language: Haskell2010
Expand Down Expand Up @@ -82,9 +85,13 @@ executable encorec
, Optimizer.Optimizer
, Parser.Parser
, SystemUtils
, Typechecker.Backtrace
, Typechecker.Capturechecker
, Typechecker.Environment
, Typechecker.Errorprinter
, Typechecker.ExplainTable
, Typechecker.Prechecker
, Typechecker.Suggestable
, Typechecker.TypeError
, Typechecker.Typechecker
, Typechecker.Util
Expand Down
19 changes: 19 additions & 0 deletions modules/explanations/E0014.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Welcome to the Encore Compiler!
Here you will meet many wonderful methods and functions and whatnot!

To be able to compile an Encore program you will need to have a Main-class
with a main-method inside.
Lets try a simple "Hello World"!

For example:


```
active class Main

def main() : unit
println("hello world")
end

end
```
17 changes: 17 additions & 0 deletions modules/explanations/E0073.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
This error occurs when the compiler was unable to infer the concrete type of a
variable. It can occur for several cases, the most common of which is a
mismatch in the expected type that the compiler inferred for a variable's
initializing expression, and the actual type explicitly assigned to the
variable.

For example:

```
let x: int = "I am not a number!"
-- ~~~ ~~~~~~~~~~~~~~~~~~~~
-- | |
-- | initializing expression;
-- | compiler infers type `String.String`
-- |
-- type `int` assigned to variable `x`
```
48 changes: 42 additions & 6 deletions src/front/TopLevel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import System.Directory
import System.IO
import System.Exit
import System.Process
import qualified Data.ByteString.Lazy as B (readFile)
import System.Pager (sendToPager)
import System.Posix.Directory
import Data.List
import Data.List.Utils(split)
Expand All @@ -25,6 +27,7 @@ import qualified Data.Map.Strict as Map
import SystemUtils
import Language.Haskell.TH -- for Template Haskell hackery
import Text.Printf
import qualified Text.PrettyPrint.Annotated as Pretty
import qualified Text.PrettyPrint.Boxes as Box
import System.FilePath (splitPath, joinPath)
import Text.Megaparsec.Error(errorPos, parseErrorTextPretty)
Expand All @@ -41,6 +44,7 @@ import ModuleExpander
import Typechecker.Environment(buildLookupTable)
import Typechecker.Prechecker(precheckProgram)
import Typechecker.Typechecker(typecheckProgram, checkForMainClass)
import Typechecker.Errorprinter
import Typechecker.Capturechecker(capturecheckProgram)
import Optimizer.Optimizer
import CodeGen.Main
Expand Down Expand Up @@ -72,6 +76,7 @@ data Option =
| Verbose
| Literate
| NoGC
| Explain String
| Help
| Undefined String
| Malformed String
Expand Down Expand Up @@ -122,6 +127,8 @@ optionMappings =
"Compile and run the program, but do not produce executable file."),
(NoArg NoGC, "", "--no-gc", "",
"DEBUG: disable GC and use C-malloc for allocation."),
(Arg Explain, "-e", "--explain", "[error]",
"Display information for error code"),
(NoArg Help, "", "--help", "",
"Display this information.")
]
Expand Down Expand Up @@ -293,6 +300,9 @@ main =
checkForUndefined options
when (Help `elem` options)
(exit helpMessage)
case find isExplain options of
Just (Explain errCode) -> explainError errCode
Nothing -> return ()
when (null programs)
(abort ("No program specified! Aborting.\n\n" <>
usage <> "\n" <>
Expand Down Expand Up @@ -349,7 +359,7 @@ main =

unless (TypecheckOnly `elem` options) $
case checkForMainClass mainSource fullAst of
Just error -> abort $ show error
Just error -> errorAbort error
Nothing -> return ()

exeName <- compileProgram fullAst sourceName options
Expand All @@ -372,7 +382,7 @@ main =
(Right ast, warnings) -> return (ast, warnings)
(Left error, warnings) -> do
showWarnings warnings
abort $ show error
errorAbort error
showWarnings precheckingWarnings
return precheckedAST

Expand All @@ -387,7 +397,7 @@ main =
(Right (newEnv, ast), warnings) -> return (ast, warnings)
(Left error, warnings) -> do
showWarnings warnings
abort $ show error
errorAbort error
showWarnings typecheckingWarnings
return typecheckedAST

Expand All @@ -402,14 +412,14 @@ main =
(Right (newEnv, ast), warnings) -> return (ast, warnings)
(Left error, warnings) -> do
showWarnings warnings
abort $ show error
errorAbort error
showWarnings capturecheckingWarnings
return capturecheckedAST
usage = "Usage: encorec [flags] file"
verbose options str = when (Verbose `elem` options)
(putStrLn str)

showWarnings = mapM print

helpMessage =
"Welcome to the Encore compiler!\n" <>
usage <> "\n\n" <>
Expand All @@ -428,4 +438,30 @@ main =
optionBox = longBox Box.<+> shortBox Box.<+> descBox
flags = intercalate "\n" $
map ((" " ++) . strip) . lines $
Box.render optionBox
Box.render optionBox

errorAbort e = do
printf "*** Error during typechecking *** \n\n"
printError e
abort $ "Aborting due to previous error"

showWarnings = mapM printWarning . reverse


isExplain (Explain _) = True
isExplain _ = False

explainError errCode = do
isHash <- isExplanationHash errCode
case isHash of
False -> do
noExplanation errCode
exitSuccess
True -> do
let fnom = standardLibLocation ++ "/explanations/" ++ errCode ++ ".txt"
B.readFile fnom >>= sendToPager
exitSuccess

isExplanationHash :: String -> IO Bool
isExplanationHash str@('E':_:_:_:_:[]) = doesFileExist $ standardLibLocation ++ "/explanations/" ++ str ++ ".txt"
isExplanationHash _ = return False
15 changes: 14 additions & 1 deletion src/ir/AST/Meta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ instance Show Position where
-- TODO: If we ever want to print ranges, this should be updated
show = showSourcePos . startPos


newPos :: SourcePos -> Position
newPos = SingletonPos

Expand Down Expand Up @@ -54,14 +55,26 @@ showSourcePos pos =
let line = unPos (sourceLine pos)
col = unPos (sourceColumn pos)
file = sourceName pos
in printf "%s (line %d, column %d)" (show file) line col
in printf "%s (Line:%d, Column:%d)" (show file) line col

showPos :: Meta a -> String
showPos = showSourcePos . startPos . position

getPos :: Meta a -> Position
getPos = position

getPositions :: Position -> ((Int, Int), (Int, Int))
getPositions pos =
case pos of
SingletonPos start -> ((line start, column start), (line start, column start+1))
RangePos start end -> ((line start, column start), (line end, column end))
where
line p = fromIntegral $ unPos (sourceLine p)
column p = fromIntegral $ unPos (sourceColumn p)

getPositionFile :: Position -> String
getPositionFile = sourceName . startPos

setType :: Type -> Meta a -> Meta a
setType newType m = m {metaType = Just newType}

Expand Down
Loading