Commit Graph

204 Commits

Author SHA1 Message Date
Edwin Brady
050abe663e
Merge pull request #1638 from stepancheg/idris2-time
Use C idris2_time for all C-based backends
2021-07-16 09:40:08 +01:00
Edwin Brady
69663735f4
Merge pull request #1680 from stepancheg/buffer-buffer
Remove Value_Buffer.len field
2021-07-16 09:22:48 +01:00
Edwin Brady
59387fc87b
Merge pull request #1679 from stepancheg/new-value
In RefC, allocate the exact size of value subtype
2021-07-16 09:22:10 +01:00
Edwin Brady
6143508f7b
Merge pull request #1659 from stepancheg/verify
IDRIS2_VERIFY macro
2021-07-16 09:01:31 +01:00
Edwin Brady
dad1804509 Fix for thread data in racket/gambit too 2021-07-15 15:12:50 +01:00
Edwin Brady
62586627d8 fix arity for blodwen-set-thread-data
This is an update of PR #540, thanks to @lodi
2021-07-15 15:02:43 +01:00
Stiopa Koltsov
f81c37ea3a Pass Buffer as char* when using C functions in RefC
To be able to use `C` functions for both Scheme and RefC: it was
not possible for `Buffer` before this PR.

As an example, `writeBufferData` and `readBufferData` functions are
removed: generic C backend implementations are used instead.
2021-07-13 23:04:36 +01:00
Stiopa Koltsov
d910677d74 IDRIS2_VERIFY macro
```
IDRIS2_VERIFY(cond, message_format, ...)
```

When condition is false, crash.

Used in native functions where correct error handling is hard or
not impossible.

For example, `malloc` rarely fails, but if it fails, better crash
with clear error message than spend time debugging null pointer
dereference.
2021-07-13 13:57:24 +01:00
Stiopa Koltsov
1617d95961 System.Errno.strerror
* add `strerror` function
* move `getErrno` to `System.Errno`
* use `strerror` in `Show FileError`
* on node there's no access to `strerror`, so `strerror` just converts the number to string
2021-07-13 10:34:04 +01:00
Stiopa Koltsov
d676ea6ab4 Expose malloc and free from System.FFI
* Move `malloc`/`free` from `Network.FFI` to `System.FFI`
* Might be useful by other code
2021-07-13 10:24:26 +01:00
Stiopa Koltsov
ed40b212b2 Make System.Signal async-signal-safe
It is not safe to call `malloc` or `pthread_mutex_lock` from signal
handler.
2021-07-12 20:43:26 +01:00
Stiopa Koltsov
1fac812435 In RefC, allocate the exact size of value subtype
* remove `Value.payload` field
* `IDRIS2_NEW_VALUE` macro now allocates the size needed for the struct
2021-07-12 16:27:09 +01:00
Stiopa Koltsov
c292437a28 Remove Value_Buffer.len field
It is not used.

Also change `buffer` field type to avoid confusion.
2021-07-11 12:00:01 +01:00
Stefan Höck
599d0635e9
[ refactor ] JS backend overhaul (#1609) 2021-07-10 11:15:21 +01:00
CodingCellist
fac0e32f48
[ fix ] Chez channels (#1596) 2021-07-02 13:13:50 +01:00
Stiopa Koltsov
3d5ad0ca91 Use C idris2_time for all C-based backends 2021-06-28 23:57:58 +01:00
Stiopa Koltsov
60d597fccd Use pragma once instead of include guard
Pragma once is supported by all compilers for the last ten years.
Better use it instead of include guards (which use different styles
in different files).
2021-06-28 12:05:22 +01:00
Sören Tempel
3f681d2f5e Make sure _simple_handler is not exported
Support for simple signal handling was added in
a0a417240e. This commit also adds the
`_simple_handler` function. It seems to me that this function is
intended as a helper function which should only be visible in
`idris_signal.c`, it is not used outside this file. For this purpose it
is probably also marked as inline. However, the inline keyword does not
require the compiler to actually inline the function. As such, the
`_simple_handler` symbol may still be exported if the compiler doesn't
inline the function.

On my system this seems to be the case and causes the following error
during compilation of idris2:

	Exception: (while loading libidris2_support.so) Error relocating Idris2-0.4.0/build/exec/idris2_app/libidris2_support.so: _simple_handler: symbol not found

By marking the `_simple_handler` function as `static inline` it is
ensured that the symbol is not exported, thereby preventing the
relocation error.
2021-06-28 11:55:37 +01:00
Stiopa Koltsov
a6555549ee Route System.prim__system through C function
To be able to eventually refactor/extend `system` function: to be
able to specify a directory, environment variables, specify arguments
as array etc. Ideally it should be something like Rust
[`std::process::Command`](https://doc.rust-lang.org/std/process/struct.Command.html).
2021-06-28 11:28:14 +01:00
Robert Wright
a8264f8f05 Add ability to extend RefC backend to create further backends 2021-06-18 16:59:35 +01:00
Martin Molzer
a91b45daf0 use socketaddr_storage in getsockname 2021-06-14 15:21:46 +01:00
Robert Wright
e9b42cc55e Guarantee Ref C Buffer 0 initialization 2021-06-14 15:06:44 +01:00
Robert Wright
1875f62248 Remove freeBuffer function
Each backend is now responsible for freeing Buffers in the same way as other objects
2021-06-14 15:06:44 +01:00
Robert Wright
195e690ddc Fix RefC Buffer getInt function to work with large values 2021-06-14 15:06:44 +01:00
Robert Wright
c6a5827319 Add RefC readBufferData/writeBufferData support 2021-06-14 15:06:44 +01:00
Robert Wright
d202139171 Distinguish common C and RefC Buffer functions 2021-06-14 15:06:44 +01:00
Mathew Polzin
1133658e18 Add missing unlock in signal handling C code. 2021-06-14 11:44:38 +01:00
Robert Wright
aa94dd2351 Add RefC Char pattern matching support 2021-06-07 15:15:37 +01:00
Stefan Höck
baa6051d69
[ fix ] use twos complement truncation for signed ints (#1471) 2021-06-04 10:35:07 +01:00
Johann Rudloff
18e15e2261 [ fix ] Cast CLOCKS_PER_SEC to float before division
The cast to float needs to happen before the division, otherwise integer
division will be performed, and as a result `CLOCKS_PER_NSEC` will
always be 0 if `CLOCKS_PER_SEC` < `NSEC_PER_SEC`.
2021-06-03 17:36:11 +01:00
madman-bob
98d67499db
RefC Integer Support (#1480)
* Add utility functions to treat All as a heterogeneous container
* Distinguish RefC Int and Bits types
* Change RefC Integers to be arbitrary precision
* Add RefC Bits maths operations
* Make RefC div and mod Euclidean
* Add RefC bit-ops tests
* Add RefC integer comparison tests
* Add RefC IntN support
2021-06-03 10:44:42 +01:00
Mathew Polzin
a0a417240e
Simple signal handling (#1458) 2021-05-25 16:45:46 +01:00
Kamiλ Shakirov
ad656a8d47
Remove realpath (#1457) 2021-05-25 11:01:28 +01:00
Robert Wright
5aef7a2dff fixup! 04dfba03 2021-05-20 14:25:16 +01:00
Robert Wright
c57bb5a65f Add RefC StringIterator support 2021-05-20 14:25:16 +01:00
Robert Wright
cd3906645b Add RefC getArgs support 2021-05-20 14:25:16 +01:00
Robert Wright
f3aae06b28 Add RefC Clock support 2021-05-20 14:25:16 +01:00
Robert Wright
cf2b05ce02 Add RefC Buffer support 2021-05-20 14:25:16 +01:00
Robert Wright
ecde887d7a Add RefC external type support
The external type must be a Value object for garbage collection reasons.

For completely custom types, use a GCPointer, with appropriate GC function for clearing up your data type.
2021-05-20 14:25:16 +01:00
Robert Wright
c34c6e0959 Complete RefC standard String support
- Fix off-by-one error in String reverse
- Correct order of arguments in strSubstr
- Actually use start index of strSubstr
- Reduce memory usage of strSubstr in case of overrunning string end
- Add fastPack/fastUnpack/fastConcat
- Use unsigned chars for character comparisons
- Fix generated C character encodings
2021-05-20 14:25:16 +01:00
Robert Wright
978d86f28d Fix RefC identity functions memory management 2021-05-20 14:25:16 +01:00
Robert Wright
06ca4bed5d Refactor C codegen
- Remove commented out code
- Remove unused showEitherStringInt and toIntEitherStringInt functions
- Make cTypeOfCFType pure
- Merge identical case branches of createCFunctions
- Remove unused C support functions
2021-05-20 14:25:16 +01:00
Matúš Tejiščák
4de7b2133a
[ new ] Add chez-sep codegen (#1359)
Co-authored-by: Johann Rudloff <johann@sinyax.net>
2021-05-11 08:20:19 +01:00
Edwin Brady
fafa76c55c Generalise NIL/CONS to all list shaped things
Also pairs turn into CONS, because we don't need to look at the tag if
there's only one constructor.
2021-05-09 01:43:59 +01:00
Edwin Brady
4389224694 Merge github.com:idris-lang/Idris2 into caseofcase 2021-05-08 18:19:21 +01:00
Edwin Brady
66930113bd Compile lists as scheme lists
This also involves adding a flag to constructors and case alternatives
in CExp which say whether it's a NIL or CONS. Currently, we only do this
for Prelude.List, which already has an effect, but soon I'll extend this
to work for all list-shaped things and rather than being hard coded. We
could also imagine spotting other shapes (enumerations especially) for
code generators to spot as they see fit.

This will require code generators to be fixed to recognise the new
ConInfo flag, but you can just ignore it.

Bootstrap code also updated, because we don't currently have a way of
having separate support.ss/rkt for the bootstrap and normal builds!
2021-05-08 15:42:51 +01:00
Johann Rudloff
190932fd01 [ docs ] Remove unnecessary newlines in HTML declaration lists
As a relict of the REPL output, several `<br>` tags where introduced,
where they are not needed or even permitted. This led to some spacing
issues (sometimes the docstring was closer to the next term than to the
one above that it actually described).

To counter the removed forced newlines, some extra margin is added below
each declaration.

As a side-effect, this also makes the W3 "Nu Html Checker" happy.
2021-05-06 14:38:55 +01:00
Stefan Höck
6cdf05f1ec
[ new ] Add Int(8/16/32/64) (#1352)
This adds new `Int8`, `Int16`, `Int32` and `Int64` data types
to the compiler, thus working towards properly specified integer
types as discussed in #1048.

In addition, the following changes / corrections are made:

* Support casts from `Char`, `String`, and `Double` to all integer
  types (and back). This fixes #1270.
* Make sure that all casts to limited-precision integers are properly
  bounds checked (this was not the case so far for casts from `String`
  and `Double` to `Int`)
* Add a thorough set of tests to make sure all bounds checks work
  correctly for all supported casts and arithmetic operations
2021-05-04 08:22:06 +01:00
Johann Rudloff
182a3caa3e [ docs ] Fix strange indentation on WebKit-based browsers (partial fix for #1367) 2021-05-03 11:44:42 +01:00
Johann Rudloff
1ac28921df Merge remote-tracking branch 'origin/master' into mkdoc-rework 2021-04-28 18:45:24 +02:00
Stefan Höck
bbea929cf3
[ refactor ] Cleanup integral primops (#1211) 2021-04-28 09:32:46 +01:00
Johann Rudloff
3dd5878e22 [ wip ] Improve HTML docs with better annotations 2021-04-26 23:02:25 +02:00
Johann Rudloff
ae9da0e8ce Reformat docs CSS file to comply with code style guide (and make the linter happy) 2021-04-26 22:48:24 +02:00
Johann Rudloff
68a5f1f1b7 Copy styles.css from support into generated docs/ folder 2021-04-26 22:45:14 +02:00
Niklas Larsson
473b8ee740 Windows test fixes
Translate node error codes
Strip 'b' from flags
Simplify directory wrangling in chez016
2021-04-12 18:47:57 +02:00
Niklas Larsson
b32a2593ff Node fixes
Don't assume that errno exists. There might never have been an error.

Quote executable path to handle path with spaces.
2021-04-12 16:43:54 +02:00
Raoul Hidalgo Charman
1211f860b6
Fix issues with use of unix sockets (#1284)
This change adds logic to set up sockaddr correctly for connect and
bind, handles the AF_UNIX case for getSockAddr and expands the existing
test to cover unix sockets.
2021-04-12 11:22:45 +01:00
Niklas Larsson
f81ccec40a Fix Racket blodwen-arg for real 2021-04-10 11:16:14 +02:00
Niklas Larsson
e117ab1c1c Add back the exe as first arg on Racket 2021-04-09 22:46:32 +02:00
Niklas Larsson
084997a880 Replace prim__getArgs with prim__getArgsCount and prim__getArg
This spares us from having to build Idris data structures in the foreign
code.
2021-04-03 10:45:02 +02:00
Niklas Larsson
e49916cea9 Fixes from trying to compile idris with the refc backend
* fix doublequoting in constArray
* substitute tildes in names
* Add negate functions
* Add string comparisons

Several things remain, notably missing _argList functions.
2021-04-02 15:02:40 +02:00
CodingCellist
ec77ad21ab
[ re #1185 ] Add primitive for obtaining number of processors (#1209)
Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
2021-03-26 18:27:25 +00:00
CodingCellist
89a84a34a4
Patch CVs and sleep in Racket (#1059) 2021-03-15 13:43:12 +00:00
Stefan Höck
8d4321eb9a
Add Data.Bits to base (#1033) 2021-03-04 20:59:56 +00:00
Niklas Larsson
da2ad89252
Merge pull request #910 from cypheon/createdir-permissions
Better default permissions for created directories
2021-02-28 17:04:53 +01:00
Mathew Polzin
9f8a8b5d76
Add a total way of reading files in. (#1070) 2021-02-18 11:13:25 +00:00
Stefan Hoeck
f721281bdc
[ re #1043 ] Fix typo in support.scm (#1047) 2021-02-10 01:00:42 +00:00
Wen Kokke
bd683938bf
Overhaul of concurrency primitives (#968)
Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
2021-02-05 16:16:20 +00:00
vfrinken
d04b28b62d
Update stringOps.c (#848)
Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
2021-02-02 14:01:19 +00:00
stefan-hoeck
8b96614454 fixed whitespace for *.c and *.h files 2021-01-22 15:08:49 +00:00
Edwin Brady
efae2682bd
Merge pull request #896 from Russoul/toString-iterators
Add withIteratorString
2021-01-16 15:47:45 +00:00
Fabián Heredia Montiel
d712ea288a Implement Racket Futures Support 2021-01-15 18:58:51 +00:00
Johann Rudloff
65e36fc20f Better default permissions for created directories
Change the support code for directory creation so that it sets all
permission bits (ugo=rwx). The process's currently active umask will be
subtracted from these permissions, which leads to the result that (for a
standard umask of "022") directories are created with a mode of "0755".

So by default, directories created with `prim__createDir` are now also
group-executable and other-executable by default.

Previous behaviour was to create the directories readable for group and
other, but not executable (mode "744"), and thus inaccessible to anyone
except the owner.
2021-01-10 11:54:15 +01:00
russoul
79d0cd1ba6 Add withIteratorString 2020-12-31 20:36:07 +03:00
Fabián Heredia Montiel
57a8ef4609
Implement Futures as a Parallelism Primitive (#753)
Co-authored-by: Christian Rasmussen <christian.rasmussen@me.com>
2020-12-04 10:58:26 +00:00
Edwin Brady
2e6aa126a4
Merge pull request #750 from ska80/refc-sysos
[refc] Update 'sysOS' to recognize more BSD flavors
2020-12-03 11:59:33 +00:00
Kamil Shakirov
544208ec92 [refc] Update 'sysOS' to recognize more BSD flavors 2020-10-21 17:20:51 +06:00
Kamil Shakirov
0b36a5fe3b [refc] Remove 'schemeCall' as it is not used anymore 2020-10-21 16:57:05 +06:00
Niklas Larsson
604e7ea99e Make it build on windows 2020-10-11 23:36:52 +02:00
Edwin Brady
97e5f04c34 Add believe_me and crash primitives to refc 2020-10-11 18:51:45 +01:00
Edwin Brady
2a39a6461a Merge github.com:idris-lang/Idris2 into refcount-c 2020-10-11 15:12:18 +01:00
Edwin Brady
a76a1322eb Initial merge of reference counting C back end
Written by Volkmar Frinken (@vfrinken). This is intended as a
lightweight (i.e. minimal dependencies) code generator that can be
ported to multiple platforms, especially those with memory constraints.

It shouldn't be expected to be anywhere near as fast as the Scheme back
end, for lots of reasons. The main goal is portability.
2020-10-11 15:05:00 +01:00
Matúš Tejiščák
1a58075a54
Merge pull request #716 from sysvinit/fix-network-constants
Retrieve network address family preprocessor constants from C runtime code
2020-10-11 08:37:44 +02:00
Matus Tejiscak
f64163de1f Merge branch 'unscheme' into master 2020-10-11 08:20:01 +02:00
Molly Miller
dff0f1da43 network: Retrieve AF_* magic constants from C support code.
The Network.Socket.Data code previously used hardcoded constants manually read
from auto-generated C source code, however these constants are specific to
Linux. The original code looked like this:

    export
    ToCode SocketFamily where
      -- Don't know how to read a constant value from C code in idris2...
      -- gotta to hardcode those for now
      toCode AF_UNSPEC = 0 -- unsafePerformIO (cMacro "#AF_UNSPEC" Int)
      toCode AF_UNIX   = 1
      toCode AF_INET   = 2
      toCode AF_INET6  = 10

The AF_INET6 constant is correct on my Debian 10 laptop:

    molly on flywheel ~> grep -rE '^#define AF_INET6' /usr/include
    /usr/include/x86_64-linux-gnu/bits/socket.h:#define AF_INET6	PF_INET6
    molly on flywheel ~> grep -rE '^#define PF_INET6' /usr/include
    /usr/include/x86_64-linux-gnu/bits/socket.h:#define PF_INET6    10  /* IP version 6.  */

However, this is not the case on an OpenBSD machine:

    spanner# grep -rE '^#define[[:space:]]+AF_INET6' /usr/include
    /usr/include/sys/socket.h:#define	AF_INET6	24		/* IPv6 */

This commit adds accessor functions to the C runtime support library for
retrieving the values of these macros as they appear in the system libc header
files, which can then be invoked using the normal C FFI machinery.
2020-10-01 12:05:42 +01:00
russoul
883a8df429 Fix String->Int cast on Scheme backends 2020-09-23 19:48:58 +01:00
Matus Tejiscak
cf45f43f4e Move the Buffer struct back into the .c file. 2020-09-20 17:49:25 +02:00
Matus Tejiscak
d26a9c55bf Tune Data.String.Iterator. 2020-09-20 10:02:18 +02:00
Matus Tejiscak
74f592053e Make StringIterator abstract. 2020-09-19 21:54:34 +02:00
Matus Tejiscak
bdcb2551b2 Change the way of creating directories. 2020-09-19 15:09:26 +02:00
Matus Tejiscak
76c3c3f8e8 Update the Scheme support code. 2020-09-19 14:36:57 +02:00
Matus Tejiscak
38a3145e8e Make the C code more explicit. 2020-09-19 14:32:45 +02:00
Matus Tejiscak
cf6530b387 Install headers for libidris2_support, use the right mode. 2020-09-19 14:11:12 +02:00
foss-mc
e0e883a890
remove a reference to a function of racket/string 2020-08-28 19:23:30 +08:00
foss-mc
979424c8e4
Improve Racket supporting code 2020-08-28 19:02:04 +08:00
russoul
3a9b1ac656 Add supporting code 2020-08-25 14:30:57 +03:00
Matus Tejiscak
362d2204ab Make fastAppend a foreign call. 2020-08-24 19:51:22 +02:00
karroffel
7d046652d8
add support for more casts from and to BitsN types (#548)
Co-authored-by: Guillaume ALLAIS <guillaume.allais@ens-lyon.org>
2020-08-20 15:01:09 +01:00
Thomas Dziedzic
5d1b937035
add prim__getNullAnyPtr and prim__castPtr (#525) 2020-08-20 11:52:51 +01:00
Giuseppe Lomurno
21524da0a0 Windows color fix 2020-08-19 11:30:12 +02:00