Felix Riedel
2ec12fe06f
Improve hashing of numbers
...
Using an integer hash (https://stackoverflow.com/a/12996028/60617 ) on
the number casted to int32 combined with lower bits of the number.
2020-12-26 13:09:11 +00:00
Felix Riedel
c76e0ae685
Use boost's way of combining hash values for arrays and kv pairs.
...
`seed ^= hash_value(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);`
from https://www.boost.org/doc/libs/1_35_0/doc/html/boost/hash_combine_id241013.html
The current way of combining hashes peforms poorly on hash values of
numbers. Changing the way hashes are combined canlead to a significant speed up:
```
time janet_new -e '(def tbl @{}) (loop [x :in (range 1000) y :in (range 1000)] (put tbl {0 x 1 y} true))'
3.77s user 0.08s system 99% cpu 3.843 total
time janet_orig -e '(def tbl @{}) (loop [x :in (range 1000) y :in (range 1000)] (put tbl {0 x 1 y} true))'
48.98s user 0.15s system 99% cpu 49.136 total
```
2020-12-26 13:05:03 +00:00
Calvin Rose
25ded775ad
Add array/clear.
...
Also improve map, find-index, and find to work on data structures
which do not defined length.
2020-12-18 12:37:58 -06:00
Michael Camilleri
04f6c7b156
Clarify docstring of parser/where
2020-12-15 16:41:45 +09:00
Michael Camilleri
77b79e9899
Update (parser/where) to support optional line and column
2020-12-15 14:12:33 +09:00
Calvin Rose
7b709d4c68
Prevent buffer/trim from shrinking buffer to 0 bytes as well.
2020-12-13 09:38:35 -06:00
Calvin Rose
eab5f67c5c
Fix buffer with NULL data pointer issue.
...
Simply prevent buffers from ever having a NULL data pointer.
2020-12-13 09:33:57 -06:00
Calvin Rose
12f470ed10
Use :_name instead of :name for printing tagged tables.
2020-12-11 18:28:09 -06:00
Calvin Rose
d53007739e
Invert read/write bits on pipe in os/execute.
...
It was backwards, breaking this functionality.
2020-12-09 19:04:05 -06:00
Calvin Rose
6eaf8272e1
Merge pull request #525 from uvtc/patch-1
...
light markup in some docs in corelib
2020-12-07 15:57:09 -06:00
John Gabriele
52addc877d
Use xs
2020-12-07 14:07:13 -05:00
sogaiu
53a5f3d2dc
Tweak comment for janet_fiber_popframe
2020-12-07 12:23:27 +09:00
John Gabriele
df1ca255a9
parts/xs --> pieces
2020-12-06 21:29:30 -05:00
John Gabriele
adbe361b9b
light markup in some docs in corelib
2020-12-06 17:51:48 -05:00
Calvin Rose
0f16f21677
Make builds deterministic again.
...
Also prevent marshal from creating multiple copies of
a function - (marshal function pointer before function def pointer).
2020-12-06 16:32:23 -06:00
Calvin Rose
aa0de01e5f
Fix some formatting and undefined behavior.
2020-12-06 14:33:08 -06:00
Calvin Rose
9d23192614
Add ev/deadline and ev/with-deadline.
...
This should be more useful than timeouts in real-world
use cases. The deadline system is based on fibers and is target
to much more coarse-grained (and therfor reliable) timeouts than things
like ev/sleep and timeout arguments.
2020-12-05 10:32:34 -06:00
Calvin Rose
c4a4916055
Address #500 - update docs and add buffer/push
...
This updates the documentation and adds a function buffer/push, which
is a more useful function than buffer/push-string or buffer/push-byte by
combining both.
2020-12-04 17:56:47 -06:00
John Gabriele
4d38fcb289
corelib.c, describe, add hyphen
2020-12-01 11:56:53 -05:00
Calvin Rose
cbdea8f331
Make os/execute cooperate with ev module.
...
os/execute, os/proc-wait do not block (currently posix only).
This uses the self-pipe trick to turn signals into a pollable entity.
2020-11-29 15:36:21 -06:00
Tim Gates
128d72785f
docs: fix simple typo, soucre -> source
...
There is a small typo in src/core/features.h.
Should read `source` rather than `soucre`.
2020-11-28 09:45:46 +11:00
Calvin Rose
a0964d44d5
Fix some valgrind errors.
...
A null pointer dereference and a memory leak with the line/col mapping.
2020-11-27 12:21:23 -06:00
Calvin Rose
dadd6037bb
Merge branch 'master' into longstring-autoindent
2020-11-27 10:40:10 -06:00
Calvin Rose
ca7c5b8b10
ev/call uses current env as prototype of environment.
2020-11-26 21:13:41 -06:00
Calvin Rose
6c43489fb2
Fix #508 - nil fiber environment.
...
run-context did not handle a nil environment well, so that was fixed
and ev/call inherits the environment when creating the fiber.
2020-11-26 19:04:45 -06:00
Calvin Rose
d76f671d37
Update changelog and make arg to peg's error optional.
2020-11-26 18:57:24 -06:00
Calvin Rose
776ce586bc
Add line and column combinators to peg.
...
These capture the line and column number of the current position
in the matched text. This is useful for error reporting as well
as indentation checking.
This works by lazily creating an index on first use that stores all
newline character indices in order. We can then do a binary search on
this to get both line number and column number in log(n) time.
This is good enough for most use cases and doesn't slow down the common case at all
- these will not be commonly used patterns in a hot loop so it is not worth to try and
optimize this at all. Constant time look up should be possible but at
the cost of complicating code and slowing down all matching to check for
new lines.
2020-11-26 18:32:56 -06:00
Calvin Rose
adc3066dc8
Update doc-format and boot.janet docstrings.
...
Make doc-format respect leading indents, increase the default format
width to better accommodate markdown formatted documentation. We still
need to support single line style doc strings, such as those used
for most c functions which can be a single line of much longer than
80 or 120 characters.
Consecutive whitespace internal to lines is not preserved, though.
2020-11-26 14:58:36 -06:00
Calvin Rose
7fd2da1096
Add code in parser to automatically indent long strings.
...
Leading spaces are stripped based on the column index of the first
backtick character in the first delimiter. If there are
characters that are not newline or space before that column in the
string, then the behavior is the same as the old behvaior - no
re-indentation is performed.
2020-11-26 13:20:58 -06:00
Calvin Rose
a3e812b86d
Fix #505 - bat int64 parsing.
...
Fixes an off-by-1 error.
Also makes windows testing hopefully a bit less flaky.
2020-11-25 09:45:46 -06:00
Calvin Rose
a3f98091c4
Fix #509
...
janet_fiber returns NULL if there is a bad arity, check that before
continuing.
2020-11-23 15:28:28 -06:00
Calvin Rose
53aa19a916
Several changes to move pipe creation back into ev.c
2020-11-18 10:53:36 -06:00
Calvin Rose
cff52ded58
Add JANET_ASYNC_EVENT_CANCEL
...
also fix bug that could cause event loop to hang.
2020-11-16 18:46:59 -06:00
Calvin Rose
078f50d45a
When reading from a stream, EPIPE is considered EOS.
...
Before, EPIPE caused an error, but in most cases it is better
to consider it an end of stream. In the future, we may want to allow
cusomtization of this behavior with flags on the stream but for now
let's keep it simpler.
2020-11-16 16:49:27 -06:00
Calvin Rose
760e4e3d68
Add upscope special form.
...
Upscope is similar to do, but does not introduce a new lexical scope.
2020-11-16 16:41:27 -06:00
Calvin Rose
9ec5689d6b
Don't use gcroot/unroot for tracking IO operations.
...
This could have bad effects in higher load situations, and
duplicates code. It is better to keep a dedicated list of
scheduled IO operations which can be efficiently added and
removed from. It also provides and easy way to enumerate
scheduled IO operations.
2020-11-16 09:30:04 -06:00
Calvin Rose
1b6272db2e
Fix windows ifdef.
2020-11-15 19:55:58 -06:00
Calvin Rose
a25b030e36
Fix EPOLL implementation.
2020-11-15 19:40:47 -06:00
Calvin Rose
6e6900fa3a
os/execute and os/spawn can take streams.
2020-11-15 12:17:29 -06:00
Calvin Rose
d7af4596e1
Move math.h include out of windows ifdef
2020-11-15 10:21:37 -06:00
Calvin Rose
a7ed3dea4b
Remove some flags in os/open.
2020-11-15 10:06:20 -06:00
Calvin Rose
cdcb774dc8
Add os/pipe and os/open.
...
ev/pipe -> os/pipe, and os/open is a wrapper
around the open system call.
2020-11-15 09:57:29 -06:00
Calvin Rose
d199c817dc
Broken Pipe error on windows should just be end of stream.
2020-11-14 16:03:51 -06:00
Calvin Rose
139e3fab25
Invert status check for (Read/Write)File
2020-11-14 15:52:01 -06:00
Calvin Rose
7a98f9aa02
Improve windows error messages on write failures.
2020-11-14 15:48:21 -06:00
Calvin Rose
b53dd67e74
Use custom pipe implementation for overlapped io.
2020-11-14 15:44:19 -06:00
Calvin Rose
e546731093
ev_lasterr -> janet_ev_lasterr
2020-11-14 15:24:13 -06:00
Calvin Rose
d50c4ef6da
Try again for windows build.
2020-11-14 15:01:52 -06:00
Calvin Rose
7d0b1955a2
typo
2020-11-14 14:55:26 -06:00
Calvin Rose
16cf7681f0
Fix some windows issues.
2020-11-14 14:40:39 -06:00
Calvin Rose
12f09ad2d7
Add ev/pipe and move stream code into ev.c
...
Also adds a lot to the C API and changes things up.
2020-11-14 14:29:11 -06:00
Calvin Rose
b3e88a8d80
Move read/write functions into ev.c from net.c
...
This code can also be used for non-network streams.
2020-11-14 11:48:23 -06:00
Calvin Rose
761273bcc4
Add janet_thread_current() to C api.
2020-11-12 18:42:41 -06:00
Calvin Rose
1a75f68cb2
Fix windows build.
2020-11-12 14:52:02 -06:00
Calvin Rose
1b0edf54f1
Fix gc leak.
...
Rather than trying to be clever with pinning/unpinning, always
mark the root fiber and that should serve as thei singular common root in almost
all cases.
2020-11-12 14:29:38 -06:00
Calvin Rose
caa6576719
Fix formatting.
2020-11-11 15:35:44 -06:00
Calvin Rose
6f1d5d3b73
Add net/listen and net/accept-loop.
...
These are the elements that make up net/server, which has been moved
into pure Janet instead.
2020-11-09 11:18:09 -06:00
Calvin Rose
099a912992
Fix posix regression.
2020-11-08 19:48:44 -06:00
Calvin Rose
56b1ea3726
Include math.h to fix some bugs on 32 bit windows.
2020-11-08 19:06:35 -06:00
Calvin Rose
d6391f2d70
Get windows IOCP working for accept.
...
This also changes the api of servers slightly -
in light of having support for ev tasks, it is probably better
to remove the "simple" server code and replace it with some Janet
or remove it all together. While convenient, it has issues with error
handling and rigidity.
2020-11-08 18:56:13 -06:00
Calvin Rose
07910272e2
Get socket reads and writes working with IOCP.
2020-11-08 10:38:28 -06:00
Calvin Rose
1092013c2b
Merge branch 'master' into ev
2020-11-07 14:36:25 -06:00
Calvin Rose
f55316eabc
Merge pull request #494 from harryvederci/patch-1
...
Fix typo
2020-11-07 14:34:43 -06:00
Calvin Rose
840f59934e
Merge pull request #497 from ahungry/bugfix/Adjust-popen-doc
...
Fix function doc to match that of C POPEN
2020-11-07 14:34:11 -06:00
sogaiu
adfccd33ae
Tweak disasm doc
2020-11-05 13:56:42 +09:00
Matthew Carter
4dffd662f0
Fix function doc to match that of C POPEN
...
It may be misleading to some user to believe it is taking a path to a
file, when it is executing an arbitrary shell command for the first argument.
2020-11-03 20:52:02 -05:00
Calvin Rose
5064d579d4
Add net header instead of ifdef check.
2020-11-03 17:49:09 -06:00
Calvin Rose
540425a41b
Make docstring less confusing - Fix #493 .
2020-11-02 09:09:22 -06:00
Calvin Rose
4d21b582c7
Improve reading and writing from streams.
...
Handle errors earlier, and allow 0 length packets from UDP
but not from TCP. This should more closely follow the exact specs
of send and recv calls.
2020-11-02 09:06:31 -06:00
Calvin Rose
8942e348bd
Small change to windows ev.
2020-11-02 08:27:45 -06:00
Calvin Rose
9f27336827
Update windows ev code.
2020-11-02 08:19:53 -06:00
Calvin Rose
f517cccf7b
Fix unix domain sockets.
...
Also allow abstract unix domain sockets on Linux
(prefixed with '@' as is customary).
2020-11-02 08:16:28 -06:00
Harry Prins
3a937ace51
Fix typo
2020-10-29 08:45:04 +00:00
Calvin Rose
2891d2b260
Address #489
...
Add gc pressure when resizing fiber stack.
2020-10-18 18:41:18 -05:00
Calvin Rose
88c1cf3ee7
Reformat files.
2020-10-11 09:33:07 -05:00
Calvin Rose
813e3fdcfd
Merge branch 'windows-ev' into ev
2020-10-11 09:32:17 -05:00
Calvin Rose
cb4903fa86
Overhaul of poll loop, redo ev/select.
2020-10-11 09:14:14 -05:00
Calvin Rose
ea45165db8
Merge branch 'master' into ev
2020-10-10 09:04:05 -05:00
Calvin Rose
ebfa07f8ce
Registering an abstract type is idemptotent.
2020-10-06 19:11:29 -05:00
Calvin Rose
964a800d51
More work on windows event loop code.
2020-10-06 19:07:29 -05:00
Calvin Rose
2e944931b3
Update timestamp function to work on windows.
2020-10-04 15:18:31 -05:00
Calvin Rose
db67538311
Work on getting ev support on windows.
2020-10-04 12:46:15 -05:00
Calvin Rose
307c7e00e2
Merge branch 'master' into ev
2020-10-03 11:09:21 -05:00
Calvin Rose
45feb55483
Add integer parsing to pegs.
2020-09-27 12:19:00 -05:00
Calvin Rose
959a577b5f
Merge branch 'master' into ev
2020-09-26 11:50:13 -05:00
Calvin Rose
d1f0a13ddc
janet_try macro and janet_restore function.
...
This allows catching panics without using pcall.
2020-09-19 18:47:47 -05:00
Calvin Rose
32bf70571a
Fix os/spawn piping on windows and free handles on errors.
2020-09-13 20:49:38 -05:00
Calvin Rose
95f4bd8e23
Merge branch 'master' into ev
2020-09-13 11:24:27 -05:00
Calvin Rose
2cbf4d8ad1
Update documentation for thread/send and thread/receive.
2020-09-13 08:38:37 -05:00
Calvin Rose
524c9b50d4
Add windows implementation for piping.
2020-09-12 19:56:48 -05:00
Calvin Rose
d3147b661b
Add :pipe to os/spawn for piping to subprocess.
...
Similar to Python's subprocess.PIPE, this creates and manages pipes
automatically for the caller.
2020-09-12 19:48:12 -05:00
Calvin Rose
d3182dce51
Merge branch 'master' into ev
2020-09-12 10:02:01 -05:00
Calvin Rose
8763df1cd0
Fix some typos.
2020-09-12 09:38:29 -05:00
Calvin Rose
b53890ddae
Make some changes for WASM build.
2020-09-07 16:08:43 -05:00
Calvin Rose
191d0001f4
Add header on BSDs.
2020-09-07 15:22:18 -05:00
Calvin Rose
1a04ce33f1
Conditionally include epoll headers.
2020-09-07 13:13:28 -05:00
Calvin Rose
babfe50550
Merge branch 'master' into ev
...
Also add poll implementation for ev.
2020-09-07 12:52:50 -05:00
Calvin Rose
24b8b0e382
Fix NaNboxing bug that cause flaky builds.
...
The macro janet_checktype(x, JANET_NUMBER) was incorrect when
x was NaN. This caused the initial unmarshalling dictionary to be missing
entries in certain cases.
2020-09-06 14:59:29 -05:00
Calvin Rose
321a758ab9
Change hash implementation for pointers.
2020-09-06 11:41:45 -05:00
Calvin Rose
3c64596ea1
Add %t formatter to janet.
...
Was not present in printf and family.
2020-09-05 20:21:49 -05:00
Calvin Rose
39032b45c9
Remove extra file.
2020-09-04 14:55:47 -05:00
Calvin Rose
821a8dca3b
Fix os/spawn - os/execute switch.
2020-09-04 14:54:58 -05:00
Calvin Rose
0145b133a1
Add os/spawn instead of os/execute with :a
2020-09-04 08:09:05 -05:00
Calvin Rose
b0b137d7f0
Apply formatting to windows changes.
2020-09-02 19:12:27 -05:00
Calvin Rose
b0c09153c2
Allow IO redirection on windows.
2020-09-02 19:07:45 -05:00
Calvin Rose
0485078c6c
Fix some issues on BSD and Windows.
2020-09-01 21:47:08 -05:00
Calvin Rose
7079cc43c9
Make some improvements and add os/proc-kill as well.
2020-09-01 21:36:49 -05:00
Calvin Rose
e7fca0051e
Add :a option to os/execute, and allow redirecting stdio.
...
This should help cover a number of common cases for
use of subprocesses. This should also eventually work well
with the ev branch via
2020-09-01 20:06:35 -05:00
Calvin Rose
6273e56886
Add janet_getjfile to C API.
2020-08-29 17:36:14 -05:00
Calvin Rose
8b9ad2dce8
Add :x flag to os/execute.
2020-08-29 10:27:32 -05:00
Calvin Rose
a31e079f93
Fix import macro to not coerce everything to string.
2020-08-27 08:19:41 -05:00
Calvin Rose
86e00e865e
Merge branch 'master' into ev
2020-08-23 11:25:04 -05:00
Calvin Rose
5dda83dc73
Add second argument to disasm.
2020-08-22 16:18:10 -05:00
Calvin Rose
28439d822a
Add cancel function.
...
This should allow better stack unwinding on a fiber that
no longer needs to complete.
2020-08-22 15:35:37 -05:00
Calvin Rose
5377e10532
Address #466 ?
...
Do not restore pc when returning from top most fiber frame.
Also add JANET_DEBUG config define for various debugging related
configurations. In fiber.c, when debug is enabled we reallocate the
entire stack everytime we push a frame to help uncover use after free
errors.
2020-08-17 07:01:58 -05:00
Calvin Rose
30522bbf7d
Merge branch 'master' into ev
2020-08-16 17:52:36 -05:00
Calvin Rose
58374623b7
Add a vm_commit before JOP_NEXT.
2020-08-13 22:28:50 -05:00
Calvin Rose
06c268c274
Start working on throwing errors from async functions.
2020-08-11 08:33:24 -05:00
Calvin Rose
9b36e2b145
Be aggressive with setting SO_NOSIGPIPE on BSD/Apple.
2020-08-10 18:59:53 -05:00
Calvin Rose
ca75f8dc20
Address #463 - prevent sigpipe on client connections.
...
We erroneously did not set SO_NOSIGPIPE on connections aquired with
net/connect, only those quired thorugh net/server. This meant that
failed writes by a client could send sigpipe.
2020-08-10 18:45:44 -05:00
Calvin Rose
6f2f3fdb68
Return an error message if writes fail. Address #462 .
2020-08-10 11:06:31 -05:00
Calvin Rose
c903e49a4f
Change feature flags for BSD.
2020-08-10 10:42:56 -05:00
Calvin Rose
7b42ed66f2
Add xprint, xprin, xprintf, and xprinf.
2020-08-09 09:30:58 -05:00
Calvin Rose
fb26c9b2c4
Add ev/select and ev/rselect initial implementation.
...
Getting closer to a CSP implmententation. Probably
useful to move scheduling fields outside of fibers
and into an external table.
2020-08-09 00:20:27 -05:00
Calvin Rose
78ffb63429
Disallow mutlitple state machines waiting for a single fiber.
...
A 'select' operator will be channel based, not state machine based.
2020-08-08 07:51:46 -05:00
Calvin Rose
1213990b7d
Merge branch 'master' into ev
2020-08-07 19:51:37 -05:00
Calvin Rose
c3af30d520
Fix broken links in README.md
2020-08-07 19:48:06 -05:00
Calvin Rose
70ad98cc6f
Fix arc4random_buf implementation.
2020-08-03 21:49:49 -05:00
Andrew Chambers
4d4ca7bb36
Initialize PRF with random data when it is enabled.
2020-08-04 12:13:36 +12:00
Calvin Rose
cb898fabf4
Set default channel size to 0.
2020-08-03 07:57:02 -05:00
Calvin Rose
5899671d96
Merge branch 'master' into ev
2020-08-03 07:54:53 -05:00
Calvin Rose
742c5bb639
Use a common queue implementation.
...
Queues occur in three places, so we use a single
implementation rather than three separate ones. This also
has the result that janet_vm_spawn will not overflow in the case
of channel-heavy, IO-light operation.
2020-08-01 14:20:58 -05:00
Calvin Rose
297de01d95
Add preliminary channel implementation.
2020-08-01 13:13:58 -05:00
Calvin Rose
2eb2dddb59
Begin work on channels.
2020-07-26 23:45:25 -05:00
nia
b731f6ab03
Fix build on NetBSD.
...
The NetBSD C library's headers do not expose extensions when
compiling with -std=c99 (as opposed to -std=gnu99 or no -std=
option), so define _NETBSD_SOURCE to get timegm, and functions
that would otherwise require an _XOPEN_SOURCE definition, e.g.
realpath.
Note that, as with FreeBSD, you need gmake to compile janet
on NetBSD, and can also install it from packages.
2020-07-27 00:21:15 +01:00
Calvin Rose
0403e306ed
Silence warnings from some compilers.
2020-07-26 08:48:22 -05:00
Calvin Rose
d393fbf360
Merge branch 'master' into ev
2020-07-25 14:07:47 -05:00
Calvin Rose
ba08e487cb
Disable PRF by default.
...
Since it is not any better by default without initializing the key, we
disable it by default. It can be turned on with JANET_PRF in
janetconf.h.
2020-07-25 13:34:40 -05:00
Calvin Rose
3960d0f6de
Merge branch 'master' into ev
2020-07-25 13:17:05 -05:00
Calvin Rose
409a8a3a43
Fix #452 - Bad file marshal
...
We forgot a call to janet_marshal_abstract, which corrupted the output.
2020-07-25 08:09:22 -05:00
Calvin Rose
02e5e49de2
Fix buffer overflow.
2020-07-24 07:04:32 -05:00
Calvin Rose
43438d3824
Allow getting typed arrays from byte sequences.
...
Fix native importing for .so files in current directory.
2020-07-24 07:01:34 -05:00
Calvin Rose
553b4d9428
Add timeouts to net functions.
...
Further debugging of the general timeout system, as well
as having a single fiber wait on multiple state machines (select).
2020-07-19 19:41:12 -05:00
Calvin Rose
cd197e8be3
Add ev/call.
...
This is a common operation, and making fibers manually can be tedious.
2020-07-06 19:13:32 -05:00
Calvin Rose
bd95f742c0
Merge branch 'master' into ev
2020-07-05 23:14:49 -05:00
Calvin Rose
463e6d9316
Merge pull request #448 from GrayJack/fix-table-remove
...
Fix janet_table_remove returning the key instead of the value
2020-07-05 18:36:54 -05:00
Calvin Rose
9ba94d2c6b
More work on timeouts and racing listeners.
...
When two listeners are racing to resume the same fiber, the
first should cancel out the other.
2020-07-05 17:26:17 -05:00
Calvin Rose
a4de83b3a3
Merge branch 'master' into ev
2020-07-05 10:11:23 -05:00
Calvin Rose
68a12d1d17
Minor fixes for meson minimum build.
...
Also, fix regression that looses function name information.
2020-07-03 20:41:55 -05:00
Calvin Rose
4721337c7c
issues with gettime on mach kernel.
2020-07-03 20:19:36 -05:00