Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
0fc3a1a9
Commit
0fc3a1a9
authored
May 18, 2014
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some issues with :load, closes #140
parent
5b918068
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
36 deletions
+47
-36
Test.ipynb
notebooks/Test.ipynb
+8
-7
Evaluate.hs
src/IHaskell/Eval/Evaluate.hs
+39
-29
No files found.
notebooks/Test.ipynb
View file @
0fc3a1a9
...
@@ -36,20 +36,23 @@
...
@@ -36,20 +36,23 @@
"cell_type": "code",
"cell_type": "code",
"collapsed": false,
"collapsed": false,
"input": [
"input": [
"1+1"
":load a/Test.hs\n",
"test"
],
],
"language": "python",
"language": "python",
"metadata": {},
"metadata": {
"hidden": false
},
"outputs": [
"outputs": [
{
{
"metadata": {},
"metadata": {},
"output_type": "display_data",
"output_type": "display_data",
"text": [
"text": [
"
2
"
"
3
"
]
]
}
}
],
],
"prompt_number": 1
"prompt_number": 1
4
},
},
{
{
"cell_type": "code",
"cell_type": "code",
...
@@ -93,9 +96,7 @@
...
@@ -93,9 +96,7 @@
"parser"
"parser"
],
],
"language": "python",
"language": "python",
"metadata": {
"metadata": {},
"hidden": false
},
"outputs": [
"outputs": [
{
{
"javascript": [
"javascript": [
...
...
src/IHaskell/Eval/Evaluate.hs
View file @
0fc3a1a9
...
@@ -480,11 +480,8 @@ evalCommand _ (Directive LoadFile name) state = wrapExecution state $ do
...
@@ -480,11 +480,8 @@ evalCommand _ (Directive LoadFile name) state = wrapExecution state $ do
let
filename
=
if
endswith
".hs"
name
let
filename
=
if
endswith
".hs"
name
then
name
then
name
else
name
++
".hs"
else
name
++
".hs"
let
modName
=
replace
"/"
"."
$
contents
<-
readFile
$
fpFromString
filename
if
endswith
".hs"
name
modName
<-
intercalate
"."
<$>
getModuleName
contents
then
replace
".hs"
""
name
else
name
doLoadModule
filename
modName
doLoadModule
filename
modName
evalCommand
publish
(
Directive
ShellCmd
(
'!'
:
cmd
))
state
=
wrapExecution
state
$
liftIO
$
evalCommand
publish
(
Directive
ShellCmd
(
'!'
:
cmd
))
state
=
wrapExecution
state
$
liftIO
$
...
@@ -920,43 +917,56 @@ readChars handle delims nchars = do
...
@@ -920,43 +917,56 @@ readChars handle delims nchars = do
doLoadModule
::
String
->
String
->
Ghc
Display
doLoadModule
::
String
->
String
->
Ghc
Display
doLoadModule
name
modName
=
flip
gcatch
unload
$
do
doLoadModule
name
modName
=
do
-- Compile loaded modules.
flags
<-
getSessionDynFlags
let
objTarget
=
defaultObjectTarget
setSessionDynFlags
flags
{
hscTarget
=
objTarget
}
-- Remember which modules we've loaded before.
-- Remember which modules we've loaded before.
importedModules
<-
getContext
importedModules
<-
getContext
-- Create a new target
flip
gcatch
(
unload
importedModules
)
$
do
target
<-
guessTarget
name
Nothing
-- Compile loaded modules.
addTarget
target
flags
<-
getSessionDynFlags
result
<-
load
LoadAllTargets
let
objTarget
=
defaultObjectTarget
setSessionDynFlags
flags
{
hscTarget
=
objTarget
}
-- Reset the context, since loading things screws it up.
-- Clear old targets to be sure.
initializeItVariable
setTargets
[]
load
LoadAllTargets
-- Add imports
-- Load the new target.
importDecl
<-
parseImportDecl
$
"import "
++
modName
target
<-
guessTarget
name
Nothing
let
implicitImport
=
importDecl
{
ideclImplicit
=
True
}
addTarget
target
setContext
$
IIDecl
implicitImport
:
importedModule
s
result
<-
load
LoadAllTarget
s
-- Switch back to interpreted mode.
-- Reset the context, since loading things screws it up.
flags
<-
getSessionDynFlags
initializeItVariable
setSessionDynFlags
flags
{
hscTarget
=
HscInterpreted
}
case
result
of
-- Add imports
Succeeded
->
return
mempty
importDecl
<-
parseImportDecl
$
"import "
++
modName
Failed
->
return
$
displayError
$
"Failed to load module "
++
modName
let
implicitImport
=
importDecl
{
ideclImplicit
=
True
}
setContext
$
IIDecl
implicitImport
:
importedModules
-- Switch back to interpreted mode.
flags
<-
getSessionDynFlags
setSessionDynFlags
flags
{
hscTarget
=
HscInterpreted
}
case
result
of
Succeeded
->
return
mempty
Failed
->
return
$
displayError
$
"Failed to load module "
++
modName
where
where
unload
::
SomeException
->
Ghc
Display
unload
::
[
InteractiveImport
]
->
SomeException
->
Ghc
Display
unload
exception
=
do
unload
imported
exception
=
do
print
$
show
exception
-- Explicitly clear targets
-- Explicitly clear targets
setTargets
[]
setTargets
[]
load
LoadAllTargets
load
LoadAllTargets
-- Switch to interpreted mode!
flags
<-
getSessionDynFlags
setSessionDynFlags
flags
{
hscTarget
=
HscInterpreted
}
-- Return to old context, make sure we have `it`.
setContext
imported
initializeItVariable
initializeItVariable
return
$
displayError
$
"Failed to load module "
++
modName
++
": "
++
show
exception
return
$
displayError
$
"Failed to load module "
++
modName
++
": "
++
show
exception
keepingItVariable
::
Interpreter
a
->
Interpreter
a
keepingItVariable
::
Interpreter
a
->
Interpreter
a
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment