-
Notifications
You must be signed in to change notification settings - Fork 259
[ new ] IO buffering, and loops #2367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
da96a88
[ new ] IO conditionals & loops
gallais a8be231
[ new ] stdin, stdout, stderr, buffering, etc.
gallais 1bf539e
[ fix ] and test for the new IO primitives
gallais a885335
[ fix ] compilation
gallais 1cf6f2c
[ fix ] more import fixing
gallais 513f564
[ done (?) ] with compilation fixes
gallais cd7200f
[ test ] add test to runner
gallais 1138237
[ doc ] explain the loop
gallais e200afc
[ compat ] add deprecated stub
gallais 9ae32c5
[ fix ] my silly mistake
gallais 4f4bbe0
[ doc ] list re-exports in CHANGELOG
gallais 48dfa71
Merge branch 'master' into io-extras
gallais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- IO handles: simple bindings to Haskell types and functions | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --cubical-compatible --guardedness #-} | ||
|
|
||
| module IO.Handle where | ||
|
|
||
| open import Level using (Level) | ||
| open import Data.Unit.Polymorphic.Base using (⊤) | ||
| open import IO.Base using (IO; lift; lift′) | ||
|
|
||
| private variable a : Level | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Re-exporting types and constructors | ||
|
|
||
| open import IO.Primitive.Handle as Prim public | ||
| using ( BufferMode | ||
| ; noBuffering | ||
| ; lineBuffering | ||
| ; blockBuffering | ||
| ; Handle | ||
| ; stdin | ||
| ; stdout | ||
| ; stderr | ||
| ) | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Wrapping functions | ||
|
|
||
| hSetBuffering : Handle → BufferMode → IO {a} ⊤ | ||
| hSetBuffering hdl bm = lift′ (Prim.hSetBuffering hdl bm) | ||
|
|
||
| hGetBuffering : Handle → IO BufferMode | ||
| hGetBuffering hdl = lift (Prim.hGetBuffering hdl) | ||
|
|
||
| hFlush : Handle → IO {a} ⊤ | ||
| hFlush hdl = lift′ (Prim.hFlush hdl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Primitive IO handles: simple bindings to Haskell types and functions | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| -- NOTE: the contents of this module should be accessed via `IO`. | ||
|
|
||
| {-# OPTIONS --cubical-compatible #-} | ||
|
|
||
| module IO.Primitive.Handle where | ||
|
|
||
| open import Data.Maybe.Base using (Maybe) | ||
| open import Data.Nat.Base using (ℕ) | ||
|
|
||
| data BufferMode : Set where | ||
| noBuffering lineBuffering : BufferMode | ||
| blockBuffering : Maybe ℕ → BufferMode | ||
| {-# FOREIGN GHC import System.IO #-} | ||
| {-# FOREIGN GHC | ||
| data AgdaBufferMode | ||
| = AgdaNoBuffering | ||
| | AgdaLineBuffering | ||
| | AgdaBlockBuffering (Maybe Integer) | ||
| toBufferMode :: AgdaBufferMode -> BufferMode | ||
| toBufferMode x = case x of | ||
| AgdaNoBuffering -> NoBuffering | ||
| AgdaLineBuffering -> LineBuffering | ||
| AgdaBlockBuffering mi -> BlockBuffering (fromIntegral <$> mi) | ||
| fromBufferMode :: BufferMode -> AgdaBufferMode | ||
| fromBufferMode x = case x of | ||
| NoBuffering -> AgdaNoBuffering | ||
| LineBuffering -> AgdaLineBuffering | ||
| BlockBuffering mi -> AgdaBlockBuffering (fromIntegral <$> mi) | ||
| #-} | ||
|
|
||
| {-# COMPILE GHC BufferMode = data AgdaBufferMode | ||
| ( AgdaNoBuffering | ||
| | AgdaLineBuffering | ||
| | AgdaBlockBuffering | ||
| ) | ||
| #-} | ||
|
|
||
| open import Data.Unit.Base using (⊤) | ||
| open import IO.Primitive.Core using (IO) | ||
|
|
||
| postulate | ||
| Handle : Set | ||
| stdin stdout stderr : Handle | ||
| hSetBuffering : Handle → BufferMode → IO ⊤ | ||
| hGetBuffering : Handle → IO BufferMode | ||
| hFlush : Handle → IO ⊤ | ||
|
|
||
| {-# FOREIGN GHC import System.IO #-} | ||
| {-# COMPILE GHC Handle = type Handle #-} | ||
| {-# COMPILE GHC stdin = stdin #-} | ||
| {-# COMPILE GHC stdout = stdout #-} | ||
| {-# COMPILE GHC stderr = stderr #-} | ||
| {-# COMPILE GHC hSetBuffering = \ h -> hSetBuffering h . toBufferMode #-} | ||
| {-# COMPILE GHC hGetBuffering = fmap fromBufferMode . hGetBuffering #-} | ||
| {-# COMPILE GHC hFlush = hFlush #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.