Commit Graph

53 Commits

Author SHA1 Message Date
Edwin Brady
1acbf1b67e Add Show for Either 2020-05-17 14:51:27 +01:00
Edwin Brady
79d52c5207 Switch to List Char for the lexer
Surprisingly, this doesn't affect performance - it shows up as about the
same in the profile. But more importantly, it ports more directly to
Idris 2, which can't guarantee that 'strTail' doesn't allocate at
runtime, so using a List Char here is much more efficient.

This probably points to the need for better string primitives. Later...
2020-05-16 16:30:51 +01:00
Edwin Brady
560449e087 Check bounds on substring
Fixes #379
2020-05-16 13:50:37 +01:00
Edwin Brady
21507e64f3 Some Racket CG fixes
libc needs a version number, and we need to make sure we're not
generating FFI definitions more than once
2020-05-15 12:43:31 +01:00
Edwin Brady
9a0608b01f Add idris_crash function
Because sometimes all you can do is give up (e.g. failing to allocate
memory for some crucial thing).
2020-05-13 12:05:00 +01:00
Edwin Brady
1b36dd99b1 Move putChar, getChar etc primitives to C
Back ends can still shortcut these and use their own primitives, but
doing things this way gives consistent behaviour between the simple IO
primitives and file IO, and allow us to use stdin/stdout consistently
(e.g. to flush stdout).
This also fixes the behaviour of 'replWith' to be consistent with the
Idris 1 version.
2020-05-13 11:09:05 +01:00
Edwin Brady
38e43f2c17 Move file management to C support library
This removes the need for some external primitives, and allows the
details to be shared between all the backends (plus we don't have to do
things a certain way just because Scheme chooses to)
2020-05-12 22:35:14 +01:00
Edwin Brady
e7d0b33e64 Do another round of inlining, and io_bind
A big cost in IO heavy programs is io_bind, and we can often inline it
away and turn it into just sequencing operations. Things have to be
lined up right to do that though - ideally, case inlining and the
newtype optimisation will know just a little bit more to be able to do
it automatically, but for now, the inliner treats io_bind as a special
case.

Also do another round of inlining, since lots more things can become
inlinable (io_bind especially, becoming fully applied to the %World)
after the first pass.
2020-05-12 11:33:29 +01:00
Edwin Brady
7adb4d3342 Move buffer API to C
It's slightly different wrt to file reading and writing, and now
requires the created buffer to be explicitly freed (since unlike Idris 1
the run time can't be told to manage C values) but this makes the buffer
code more portable by not requiring it to run via scheme.
Performance appears more or less the same as before.
2020-05-11 18:10:08 +01:00
Edwin Brady
b617cae888 Add transformation rules for top level methods
This can be quite effective at removing runtime overhead when just using
an overloaded method directly. It is, however, still quite limited (only
works on top level interfaces, so no inlining of parents, e.g. like X a
=> X (List a), and sometimes generating the transform rules fails for
reasons I haven't worked out yet).

This is experimental, I might change the way this works at any point,
but it's a nice improvement for now.
2020-05-10 20:51:20 +01:00
Edwin Brady
d0a9f9e9a6 Move takeBefore/takeUntil to Data.Stream
They're not total, so shouldn't be exported from the Prelude - they are
kept there for range syntax though.
2020-04-27 15:25:25 +01:00
Edwin Brady
c95c4c6c0c
Merge branch 'master' into prelude-inline-doc 2020-04-27 13:38:29 +01:00
Edwin Brady
3d8d07621d Some inlining changes
Flags can now be set on implementations too, where the flags get passed
to each of the methods in the implementation. We might want something a
bit more fine grained than this later. Also some small changes to the
way inlining lets is done in the compiler.
2020-04-23 20:01:20 +01:00
Kamil Shakirov
5b58bf2cc1 Add missing export 2020-04-22 11:21:12 +06:00
Kamiλ Shakirov
0c7b553e23
Oops 2020-04-22 08:48:38 +06:00
Kamil Shakirov
35994b81e9 Port prelude's inline API documentation from Idris 1 2020-04-22 01:40:40 +06:00
Edwin Brady
1734841275 Add a lambda lifter
It's not actually used as part of any compilation pipeline yet, and I've
only tested it by eyeballing the output, but it'll be useful soon, and
it's good for it to be available to any new back ends that might need
it. It will need some optimisation.
2020-04-19 22:57:10 +01:00
Edwin Brady
69a7640a6e Allow flagging types as externally defined
e.g. in a C file. This means we don't accidentally treat things as
empty, since previously we just defined these as empty types, but that
broke coverage checking. Fixes #240
2020-04-10 11:45:52 +01:00
Edwin Brady
211fc359ca Erase %World for the purpose of newtypes
We never inspect it, so it carries no information - it just needs to be
there as a token to make sure that IO operations run at the right time.
So, IORes can be a newtype now and therefore optimised away.
2020-04-09 00:20:37 +01:00
Guillaume Allais
c5903c45e1 [ cosmetic ] various whitespace issues 2020-04-02 17:31:15 +01:00
Edwin Brady
b0e55b53eb A bit more library support 2020-03-30 13:06:59 +01:00
Kamil Shakirov
c8c0c5fb49 Add getChar, putChar and putCharLn to prelude 2020-03-05 14:55:20 +06:00
Edwin Brady
14e9872f07 Don't show MN names in hole contexts
This prevents display of shadowed names from case blocks/where clauses
that are now unusable. It does mean that constraint arguments aren't
displayed, unless given an explicit name - this may not be good, since
we might want to know which constraints are in scope, so it may yet need
a little tweaking.
2020-02-15 22:33:13 +00:00
Edwin Brady
c84e2b5cb7 void's argument is certainly irrelevant!
Since it's the empty type...
2020-01-23 17:45:19 +00:00
Edwin Brady
af9e920d74 Merge branch 'linearity-clean' of https://github.com/ohad/Idris2 into ohad-linearity-clean 2020-01-19 16:56:13 +00:00
Ohad Kammar
9a591b83ac Add linearity annotations in the prelude 2020-01-09 13:05:05 +00:00
Alex Gryzlov
1652a6be7d Merge remote-tracking branch 'upstream/master' into misc-fixes 2019-11-25 19:18:09 +03:00
Edwin Brady
2e9eabff71 Merge branch 'master' of github.com:edwinb/Idris2 2019-11-19 14:07:55 +00:00
Alex Gryzlov
f0ca75b537 add some lib fuctions from Idris1 2019-11-12 15:58:21 +03:00
Edwin Brady
ca3ea38cde Make sure Force is erased for termination checker
But only for 'Lazy', not for 'Inf'. This is necessary to build the size
change graphs correctly.
2019-11-11 19:35:23 +00:00
Michael Morgan
e6121e0935 Remove trailing whitespace from Idris sources.
This is the result of running the command:

$ find . -name '*.idr' -type f -exec sed -i -E 's/\s+$//' {} +

I confirmed before running it that this would not affect any markdown
formatting in documentation comments.
2019-10-25 14:24:25 -07:00
Edwin Brady
1a6c314d15
Merge pull request #119 from timsueberkrueb/add-missing-exports
Add some missing public exports
2019-10-19 13:53:23 +01:00
Edwin Brady
a162425384 Add curry/uncurry to Prelude 2019-10-13 12:12:49 +01:00
Tim Süberkrüb
7e72f9d2f4 Add some missing public exports 2019-10-08 21:16:41 +02:00
Edwin Brady
c6039e4fe5 Support callbacks in foreign calls to C
Currently Chez backend only
2019-09-29 17:25:26 +01:00
Edwin Brady
68b0d64879 Add parameterised pointer type
For at least a bit of safety in foreign APIs. AnyPtr has the old Ptr
behaviour.
2019-09-04 10:25:45 +01:00
Edwin Brady
bb246a072a Experimenting with a new FFI
Functions can be declared as %foreign with a list of calling
conventions, which a backend will work through until it finds one it can
understand. Currently implemented only in Chez backend. If this works
out, I'll implement it for Racket too, and remove the old primitive
functions.

There's a bit more boiler plate here than before, but it has the benefit
of being more extensible and portable between different back ends.

Some examples, pending proper documentation:

%foreign "C:puts,libc" "scheme:display"
putline : String -> PrimIO ()

%foreign "C:exp, libm.so.6, math.h"
fexp : Double -> Double

%foreign "C:initscr, ncurses_glue.so, ncurses.h"
prim_initscr : PrimIO ()
2019-09-02 17:10:48 +01:00
Christian Rasmussen
14db785ebe Fixes #88: integerToNat hangs for negative integers 2019-08-20 18:26:13 +02:00
Edwin Brady
0b692e4379 Pack/unpack should be public export
They're likely to be useful when manipulating strings in proofs.
2019-08-01 11:18:04 +01:00
Edwin Brady
4860d2b751 Add Range interface to prelude
This is part of what we used to have in Enum but I think it's better to
separate the two. Added implementations for Nat, and anything in
Integral/Ord/Neg, so that we get range syntax (at least when its
implemeted) for the most useful cases.
2019-07-11 23:38:25 +02:00
Edwin Brady
a422294f36 Pass auto implicits through interfaces
This allows 'traverse' to work now (it was treating them as normal
implicits, so building the wrong form of application)
2019-07-10 17:23:33 +02:00
Edwin Brady
2bb496f74b Chapter 11 examples now working 2019-07-08 23:46:20 +02:00
Edwin Brady
7c34fa1db4 Change equality elaboration
Elaborate via either === (homogeneous equality) or ~=~ (heterogeneous
equality) both of which are synonyms for Equal. This is to get the Idris
1 behaviour that equality is homogeneous by default to reduce the need
for type annotations, but heterogeneous if that doesn't work.
2019-07-05 11:26:45 +01:00
Edwin Brady
e526badfe2 Delay case elaboration
This helps a few things because it delays elaboration of the block until
as much as possible is known about its type.

Also added a few libraries.
2019-07-02 16:53:41 +01:00
Edwin Brady
00514887c4 More base libraries
This has shown up a problem with 'case' which is hard to fix - since it
works by generating a function with the appropriate type, it's hard to
ensure that let bindings computational behaviour is propagated while
maintaining appropriate dependencies between arguments and keeping the
let so that it only evaluates once. So, I've disabled the computational
behaviour of 'let' inside case blocks. I hope this isn't a big
inconvenience (there are workarounds if it's ever needed, anyway).
2019-06-30 23:54:50 +01:00
Edwin Brady
f37da6c5b7 Start adding tests for TypeDD book
Also detailing any changes needed to the code. Added primitives for
Doubles, and repl/replWith to get Chapter 2 code to work.
2019-06-30 15:50:58 +01:00
Edwin Brady
bf64f843aa A bit more totality checking polish
Need to check for 'assert_total' in getRefs, and get Inf and Lazy the
right way around!
2019-06-25 12:57:49 +01:00
Edwin Brady
0a15c2cda1 Pay attention to visibility of names
Name lookup and search should ignore names which aren't visible (that
is, private names in another namespace)
2019-06-24 00:57:22 +01:00
Edwin Brady
c3a4360ee9 Add missing ipkg 2019-06-19 18:50:46 +01:00
Edwin Brady
02c2358093 Add missing Makefile 2019-06-19 18:49:53 +01:00