Skip to content

Commit

Permalink
Use Idris Strings internally
Browse files Browse the repository at this point in the history
Instead of Python `StringUTF8`s
  • Loading branch information
madman-bob committed Aug 11, 2021
1 parent 64b7e7c commit d8886a3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Idris2Jupyter/Idris2Jupyter.idr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Idris2Jupyter.IPyKernel
export
doExecute : (idris2 : CommandLineInterface)
-> (ker : IPyKernelInstance)
=> (code : StringUTF8)
=> (code : String)
-> (silent : Bool)
-> (storeHistory : Bool)
-> (userExpressions : PythonDict)
Expand Down
6 changes: 3 additions & 3 deletions Idris2Jupyter/Idris2Jupyter/CommandLineInterface.idr
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ export
record CommandLineInterface where
constructor MkCommandLineInterface
process : Process
prompt : StringUTF8
prompt : String

export
start : HasIO io => (cli : StringUTF8) -> (prompt : StringUTF8) -> io (CommandLineInterface, StringUTF8)
start : HasIO io => (cli : String) -> (prompt : String) -> io (CommandLineInterface, String)
start cli prompt = do
process <- spawn cli
_ <- expect process prompt
preamble <- before process
pure (MkCommandLineInterface process prompt, preamble)

export
run : HasIO io => CommandLineInterface -> (cmd : StringUTF8) -> io StringUTF8
run : HasIO io => CommandLineInterface -> (cmd : String) -> io String
run (MkCommandLineInterface process prompt) cmd = do
_ <- sendLine process cmd
_ <- expect process prompt
Expand Down
14 changes: 7 additions & 7 deletions Idris2Jupyter/Idris2Jupyter/IPyKernel.idr
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ IPyKernelBase = primIO prim__IPyKernelBase
public export
record IPyKernel where
constructor MkIPyKernel
kernelName : StringUTF8
kernelVersion : StringUTF8
banner : StringUTF8
kernelName : String
kernelVersion : String
banner : String
languageInfo : LanguageInfo
doExecute : (ker : IPyKernelInstance)
=> (code : StringUTF8)
=> (code : String)
-> (silent : Bool)
-> (storeHistory : Bool)
-> (userExpressions : PythonDict)
-> (allowStdin : Bool)
-> IO PythonDict

wrapDoExecute : (doExecute : (ker : IPyKernelInstance)
=> (code : StringUTF8)
=> (code : String)
-> (silent : Bool)
-> (storeHistory : Bool)
-> (userExpressions : PythonDict)
Expand All @@ -56,7 +56,7 @@ wrapDoExecute : (doExecute : (ker : IPyKernelInstance)
-> (allowStdin : PythonBool)
-> PrimIO PythonDict
wrapDoExecute doExecute ker code silent storeHistory userExpressions allowStdin =
toPrimIO $ do doExecute @{ker} code !(isTruthy silent) !(isTruthy storeHistory) userExpressions !(isTruthy allowStdin)
toPrimIO $ do doExecute @{ker} (fromUTF8 code) !(isTruthy silent) !(isTruthy storeHistory) userExpressions !(isTruthy allowStdin)

export
toPyClass : HasIO io => IPyKernel -> io PythonClass
Expand All @@ -68,7 +68,7 @@ toPyClass (MkIPyKernel kernelName kernelVersion banner languageInfo doExecute) =
("language_info", languageInfo),
("do_execute", wrapDoExecute doExecute)
]
subclass kernelName [!IPyKernelBase] d
subclass (toUTF8 kernelName) [!IPyKernelBase] d

export
HasIO io => PythonType io IPyKernel where
Expand Down
4 changes: 2 additions & 2 deletions Idris2Jupyter/Idris2Jupyter/IPyKernelInstance.idr
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ ioPubSocket @{_} @{ker} = primIO $ prim__py_ioPubSocket ker
prim__py_sendResponse : IPyKernelInstance -> IPyKernelSocket -> StringUTF8 -> PythonDict -> PrimIO ()

export
sendResponse : HasIO io => IPyKernelInstance => IPyKernelSocket -> StringUTF8 -> PythonDict -> io ()
sendResponse @{_} @{ker} soc s d = primIO $ prim__py_sendResponse ker soc s d
sendResponse : HasIO io => IPyKernelInstance => IPyKernelSocket -> String -> PythonDict -> io ()
sendResponse @{_} @{ker} soc s d = primIO $ prim__py_sendResponse ker soc (toUTF8 s) d
16 changes: 8 additions & 8 deletions Idris2Jupyter/Idris2Jupyter/Pexpect.idr
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ data Process : Type where [external]
prim__py_spawn : StringUTF8 -> PrimIO Process

export
spawn : HasIO io => StringUTF8 -> io Process
spawn = primIO . prim__py_spawn
spawn : HasIO io => String -> io Process
spawn cmd = primIO $ prim__py_spawn $ toUTF8 cmd

%foreign "python: spawn.expect, pexpect"
prim__py_expect : Process -> StringUTF8 -> PrimIO Int

export
expect : HasIO io => Process -> StringUTF8 -> io Int
expect process re = primIO $ prim__py_expect process re
expect : HasIO io => Process -> String -> io Int
expect process re = primIO $ prim__py_expect process $ toUTF8 re

%foreign "python: attrgetter(\"before\"), operator"
prim__py_before : Process -> PrimIO StringUTF8

export
before : HasIO io => Process -> io StringUTF8
before = primIO . prim__py_before
before : HasIO io => Process -> io String
before process = map fromUTF8 $ primIO $ prim__py_before process

%foreign "python: spawn.sendline, pexpect"
prim__py_sendLine : Process -> StringUTF8 -> PrimIO Int

export
sendLine : HasIO io => Process -> StringUTF8 -> io Int
sendLine process line = primIO $ prim__py_sendLine process line
sendLine : HasIO io => Process -> String -> io Int
sendLine process line = primIO $ prim__py_sendLine process (toUTF8 line)

0 comments on commit d8886a3

Please sign in to comment.