1
0
mirror of https://github.com/janet-lang/janet synced 2024-07-01 17:43:15 +00:00
Commit Graph

176 Commits

Author SHA1 Message Date
Calvin Rose
5ed76f197a Differentiate error from resume and error from resumed fiber. 2020-04-10 18:29:10 -05:00
Calvin Rose
72beeeeaaa Move funcenv verification to runtime.
Lazy verification makes it easier to not leave funcenvs
in an invalid state, as well as be more precise with the validation.
We needed to verify the FuncEnvs actually pointed to a stack frame if
they were of the "on-stack" variant. There was some minor checking
before, but it was not enough to prevent func envs from pointing to
memory that was off of the fiber stack, overlapping stack frames, etc.
2020-04-06 10:58:47 -05:00
Calvin Rose
a3aaa6634d Use separate registry table for abstract types.
This avoids overloading the registry table, which is intended
for names of c functions.
2020-03-14 10:25:39 -05:00
Calvin Rose
65403ec9fe Merge branch 'master' into net 2020-03-07 14:06:51 -06:00
Calvin Rose
3d3d314fb7 Remove warning about math.h on aarch64 ubuntu gcc. 2020-03-07 14:05:28 -06:00
Calvin Rose
16202216b2 Address #291
When resuming a fiber with a child, the root fiber was set incorrectly.
2020-03-05 19:18:45 -06:00
Calvin Rose
8f1527712e Merge branch 'master' into net 2020-03-05 18:08:35 -06:00
Calvin Rose
738490e674 Allow function that takes 1 argument to fiber/new.
This allows reuse of closures when creating many fibers.
2020-02-23 14:47:29 -06:00
Calvin Rose
6a13703e32 Add signal and fiber/can-resume?.
These additions, along with the change that user signals 0-4 cannot
be resumed, allow delimited continuation semantics, while repsecting
existing forms like `defer`, `with`, `with-vars`, etc.
2020-02-23 13:31:27 -06:00
Calvin Rose
0df220780a Fix issues with #282
Bad handling of write errors, as well as janet_root_fiber().
2020-02-20 19:54:31 -06:00
Calvin Rose
f4d7fd97f6 Working TCP echo server and client.
Required a few changes to APIs, namely janet_root_fiber()
to get topmost fiber that is active in the current scheduler.
This is distinct from janet_current_fiber(), which gets the bottom
most fiber in the fiber stack - it might have a parent, and so cannot
be reliably resumed.
This is the kind of situation that makes symmetric coroutines more
attractive.
2020-02-09 20:00:50 -06:00
Calvin Rose
e36334e14b Revert issue with removing buffer self print check. 2020-01-23 23:39:49 -06:00
Calvin Rose
28d41039b8 Add mod function to core.
The `mod` function is a pair function with `%`, or te remainder
function and is distinct from it. This is taken from common lisp.
2020-01-23 18:54:30 -06:00
Calvin Rose
b8d530da36 Remove file/fileno and file/fdopen.
Also fully add call function pointer to
abstract types, including in methods, etc.
2020-01-23 09:01:33 -06:00
Calvin Rose
4fe005e3c3 Add righthand operator overloading.
This is like python. Now, we just need to readd fuzzy
comparisons to have what python needs. Overloading
math functions would be neat, too.
2020-01-22 18:59:41 -06:00
Calvin Rose
e179f26d50 Add call function pointer to abstract types.
This will allow better JITs, FFIs, DSLs, etc.
2020-01-21 18:22:24 -06:00
Calvin Rose
51678c1aba Extend power of the each form
This changes the implementation of the `next` function which
is now used to implement each. This let's us iterate over
more types, not just tables and structs.
2020-01-18 17:55:07 -06:00
Calvin Rose
a68ee7aac6 Update Copyright 2020. 2020-01-12 10:50:37 -06:00
Calvin Rose
3d40c95e80 Add ability to Janet signal from C functions.
While C functions are not re-entrant, signaling from a C function
can be used to implement async returns. When resuming a fiber that
signalled from within a C function, the fiber is started after the
instruction that emitted the signal. The resume argument is used
as the return result from the c function.
2020-01-10 20:44:16 -06:00
Calvin Rose
6c7f376410 Try to remove potential overflow bugs.
Also make integer to size_t casts explicit rather than relying on
int32_t * sizeof(x) = size_t. This is kind of a personal preference for
this problem.
2020-01-02 22:08:17 -06:00
Calvin Rose
9dd152dc28 Add features.h for feature test macros.
Because we use an amalgated build, feature
test macros should be set in a single file that
is included before any other headers, and is placed
at the top of the amalgamated build.
2019-12-30 19:06:15 -05:00
Calvin Rose
022be217a2 Remove ==, not==, and order[<,<=,>,>=].
This unifies equality and comparison checking. Before, we had
separate functions and vm opcodes for comparing general values vs.
for comparing numbers, where the numberic functions were polymorphic and
had special cases for handling NaNs. By unfiying them, abstract types
can now better integrate with other number types and behave as keys.

For now, the old functions are aliased but will eventually be removed.
2019-12-28 16:04:15 -05:00
Calvin Rose
4238379552 Use _setjmp/_longjmp on BSDs.
This doesn't save the signal mask so should be a bit faster.
2019-12-18 12:18:31 -05:00
Calvin Rose
36b2f27873 Merge branch 'master' into threads-3 2019-12-12 17:07:03 -06:00
Andrew Chambers
57ccfb692c Abstract type getters can indicate key absence.
This change to the c api allows abstract types to indicate
to the runtime if a key was absent, or if it meant to return nil.
2019-12-09 16:50:33 +13:00
Calvin Rose
eb1c21b0da Fix some example issue and warnings under -Os. 2019-12-08 12:40:05 -06:00
Calvin Rose
fd4220f254 Keep single global pthread_cond_t per thread.
This will allow thread/select to be implemented.
Also add thread/close and close method to threads.
2019-12-04 21:44:53 -06:00
Calvin Rose
a1f35e21c7 Merge branch 'master' into threads-3 2019-12-03 18:11:32 -06:00
Calvin Rose
cecc7e6b9d Rename 'get' opcode to 'in', add new 'get' opcode.
This makes the names of the opcodes match their implied functionality.
We also rename the C functions to match the opcodes and source level
functionality.
2019-12-02 21:26:28 -06:00
Calvin Rose
70c8b6838d Use make-image-dict and load-image-dict in thread/new
Rather than messing with janet_core_dictionary, we
instead cache the core enevironment, and pull out the
needed tables from there. This is more flexible, more correct, and
also exposes janet_resolve_core, which can be easily used from the C
API.
2019-12-02 04:15:22 -06:00
Calvin Rose
6a763aac95 Work on threads.
Add send and receive.
2019-12-01 20:28:12 -06:00
Calvin Rose
7df0ec6aed Fix up debug/step and janet_step.
Also allow debugging on all signals, including errors.
This is gated behind (setdyn :debug true) in the repl.
2019-11-25 20:00:13 -06:00
Calvin Rose
6988fd3cab Add debug/step to single step a fiber.
Very useful for implementing debuggers.
2019-11-25 18:14:34 -06:00
Calvin Rose
d37c43716a Lots of work on improving debugging.
doc macro can take no arguments and print out
all bindings. Fix an issues with the vm skipping
over a breakpoint in some situations.

Add examples/debugger.janet for proof of concept
debugger.
2019-11-24 17:45:53 -06:00
Calvin Rose
aee1687215 Add RNG functionality to the math/ module.
The new RNG wraps up state for random number generation, so
one can have many rngs and even marshal and unmarshal them.
Adds math/rng, math/rng-uniform, and math/rng-int.

Also introduce `in` and change semantics for
indexing out of range. This commit enforces stricter
invariants on keys when indexing via a function call
on the data structure, or the new `in` function.

The `get` function is now more lax about keys, and will
not throw an error when a bad key is used for a data structure, instead
returning the default value.
2019-11-08 17:40:04 -06:00
Calvin Rose
a18a251d16 Address some issues found in lgtm
Caught a few potentially issues with overflows, as well as use of
unsafe function localtime.
2019-10-10 22:59:43 -05:00
Calvin Rose
8cda06b995 GCC seemed to not fill array of computed gotos.
This is expected as per the C standard, but segfaulted
unless all 255 labels were added.
2019-09-22 17:56:33 -05:00
Calvin Rose
a8afc5b81f Sourcemapping uses line, column instead of offsets.
This should be friendlier to most users. It does, however, mean
we lose range information. However, range information could be
recovered by re-parsing, as janet's grammar is simple enough to do this.
2019-09-22 17:18:28 -05:00
Calvin Rose
39f1d81fd4 Use :length method for (length abstract)
Also adds the janet_lengthv API call. This is
needed because janet_length returns a 32 bit integer, where
as lengthv lets us return larger values (useful for typed arrays).

janet_mcall is an api function that should make it easier to call
a janet method from C code. It shares a similar signature with
janet_call.
2019-09-08 19:26:16 -05:00
Calvin Rose
292be33b9d Fix some stack overflow bugs. 2019-08-19 01:19:51 -04:00
Calvin Rose
54170d92db Add some color to stacktraces in repl. 2019-08-12 19:20:01 -05:00
Calvin Rose
2193193b12 Improve error message on bad method calls. 2019-08-05 19:06:58 -05:00
Calvin Rose
0ca0180f27 More "correct" emscripten support. 2019-07-14 16:11:00 -05:00
Calvin Rose
21a355c89f Small changes to help with latest emscripten. 2019-07-14 09:58:11 -05:00
Calvin Rose
b8032ec61d Add propagate function and opcode
This allows better stacktraces when manually intercepting
signals to clean up resources. Also allows functionality
from Common Lisp's unwind-protect, such as calling cleanup code
while unwindinding the stack, restarting on certain signals, and
just in general having more control over signal and signal propagation.

Also fix a bug encountered while implementing with-resource in the
compiler. Desturcturing arguments that were not the last argument
would often result in bad code generation, as slots used to destructure
the earlier arguments would invalidate the later parameters. This is
fixed by allocating all named parameters before doing any destructuring.
2019-06-24 12:44:13 -04:00
Calvin Rose
c150f2f2c1 Add scratch memory API.
This should make it easier to write
code that does not leak memory on panics.
2019-06-01 23:31:39 -04:00
Calvin Rose
ddedae6831 Reenable computed gotos - they were disabled. 2019-05-24 13:54:23 -04:00
Calvin Rose
88b8418253 Add simple tracing functionality to VM.
Also disable debugger for normal errors.
2019-05-04 15:05:00 -04:00
Calvin Rose
1596511175 Fix undefined behavior bug with errors.
janet_vm_return_reg should only be set when janet_continue
is called. Otherwise, a panic may dump it's error message in
the wrong place, resulting in undefined behavior (often showing
the last return value or worse, segfaulting).
2019-04-10 23:29:40 -04:00
Calvin Rose
675c1030fd Fix error message on an arity mismatch.
janet_call had a bad janet_printf.
2019-04-07 23:53:50 -04:00
Calvin Rose
e239980da7 Quasiquoting bracketed tuples. 2019-03-31 14:15:26 -04:00
Calvin Rose
b14fcb068b Update janet_pcall interface
The programmer can now not only get the used fiber, but
provide a fiber to reuse if many calls are made in succession.
2019-02-22 17:10:24 -05:00
Calvin Rose
9d4effc02e Add make format to format code.
A consistent style should help with contributors and
readability. We use astyle as the formatter as can make a pretty
good approximation of the current style and my preferred style.

Astyle can be found at http://astyle.sourceforge.net/astyle.html
2019-02-19 20:51:34 -05:00
Dan Skorupski
ef5f80ad38 Fix indentation, converting some tabs to spaces. 2019-02-19 17:54:13 -06:00
Calvin Rose
ed72dcf82d Rename the header <janet/janet.h> to <janet.h>
Makes it easier to use and remember, and makes the
variable `module/*headerpath*` make more sense.
2019-02-18 20:13:35 -05:00
J.-F. Cap
e0d26629e0 Fix buffer (and string) used as callee for indexing. 2019-02-12 23:40:59 +01:00
Calvin Rose
f6a3853131
Merge pull request #30 from jfcap/get-set-abstract
Get set abstract
2019-02-05 19:09:56 -05:00
J.-F. Cap
960cf76eb5 Experimental getter/setter for abstract types 2019-02-05 17:14:13 +01:00
Calvin Rose
cb5263d2d8 Remove extra comment. 2019-02-03 15:32:39 -05:00
Calvin Rose
8a3f512746 Experimental changes to janet_call to make it faster.
Remove setjmp and fiber creationg from janet_call. This
adds the constraint to janet_call can only be called when there
is already a current fiber.
2019-02-01 11:56:25 -05:00
Calvin Rose
611543c48b Add source amalgamation
The amalgamated source concatenates all sources
to a file janet.c which can be used for
embedding janet, much in the same way as sqlite
or mongoose.
2019-01-24 00:15:58 -05:00
Calvin Rose
95f2bbe0a0 Add highlight.janet tool which can highlight
janet source code and output html or terminal escaped code.
Also made re entrant calls into the vm provide better
error messages.
2019-01-17 18:12:26 -05:00
Calvin Rose
612a245961 More work on peg. Disable indexed backrefs and replace substitution
with accumulation.
2019-01-16 21:11:55 -05:00
Calvin Rose
798c88b4c8 Update peg to allow functions over captures. Update C API
to make janet function calls easier and faster from C (still
needs an object pool for fibers, though). Fix bug in scan-number
and add many more peg tests.
2019-01-12 17:31:15 -05:00
Calvin Rose
b1e0849a2f Restore old status logic - (status checks in run_vm should be using
the previous status, not the current which is always JANET_STATUS_ALIVE)
2019-01-08 13:42:29 -05:00
Calvin Rose
d64a57297d Update examples, add method like semantics to calling keywords. 2019-01-07 14:47:47 -05:00
Calvin Rose
63dd6d03f4 Fix english 2019-01-06 12:05:40 -05:00
Calvin Rose
2a79d2e749 Remove check for function calls to enable all types,
even nil. Now any value can be called as a function, usually
looking itself up in an associative data structure.
2019-01-06 11:56:40 -05:00
Calvin Rose
6f3bc3d577 Update copyright date, fix types, remove trailing whitespace. 2019-01-06 03:23:03 -05:00
Calvin Rose
b60e3e302a Update C API to use friendlier functions rather than macros.
Error handling is implemented with setjmp/longjmp so code
can be more concise. This required a very large but straight forward refactor for all
of the libraries.
2019-01-05 20:09:03 -05:00
Calvin Rose
5b62c8e6db Better working panic implementation and more cleanup in main vm loop. 2019-01-05 00:33:20 -05:00
Calvin Rose
cd6a7793e8 WIP panic functionality. 2019-01-04 23:20:34 -05:00
Calvin Rose
5afb00859a More cleanup in vm.c 2019-01-04 21:15:37 -05:00
Calvin Rose
001917f8d9 Begin clean up of vm.c
Replace the oparg macro with 5 named virtual registers, combine
pc++ with vm_next() macro to be more terse, and move setup and
teardown logic of janet_continue into a separate function.

These changes are preparation for using setjmp/longjmp to do
error handling in the VM. Introducing longjmp for error handling in
the VM would allow it to be used in the C API, which could result in
simpler, more compact code.
2019-01-04 20:08:43 -05:00
Calvin Rose
b9c0fc8201 Allow calling keywords and symbols as functions to look
themselves up in a data structure. Allow calling  a data
structure to look up the argument.
2019-01-03 22:48:43 -05:00
Calvin Rose
337a498edb Fix some keyword related issues. 2019-01-02 22:08:51 -05:00
Calvin Rose
6b4824c2ab Fix error behavior when calling functions with incorrect arities. 2018-12-30 18:41:44 -05:00
Calvin Rose
6b95326d7c First commit removing the integer number type. This should
remove some complexity and unexpected behavior around numbers in
general as all numbers are the same number type, IEEE 754 double
precision numbers. Also update examples and tests, some of which were
out of date.

Some more testing may be needed for new changes to numbers.
2018-12-27 13:05:29 -05:00
Calvin Rose
e8c0dcd14e Make source mapping use byte offset instead of line and col
for better debugging support in repl. Add debug module for better
debugging support.
2018-12-13 18:46:53 -05:00
Calvin Rose
8bfea73ee7 Fix web build again, simplify fibers and fiber
implementation code.
2018-11-26 09:03:26 -05:00
Calvin Rose
2a127af1ca A few fixes to things like macro expand, etc. 2018-11-07 22:27:06 -05:00
Calvin Rose
9b579c9ce6 Merge code back from correctgc. 2018-09-23 17:53:55 -04:00
Calvin Rose
f5372dd188 Allow use of stack in gc. 2018-09-23 17:35:44 -04:00
Calvin Rose
7131379021 Update for old osx versions. 2018-09-22 21:46:50 -04:00
Calvin Rose
d9752a9028 Garbage collection no longer blows stack. 2018-09-22 14:59:50 -04:00
Calvin Rose
2a907f8290 Fix number parsing. 2018-09-06 14:12:10 -04:00
Calvin Rose
c8ef2a0d88 Rename to janet 2018-09-05 22:18:42 -04:00
Calvin Rose
285f2d7ea9 More gracefully handle. 2018-09-03 12:51:57 -04:00
Calvin Rose
9cad4eb91d Change function arity error message. 2018-08-03 19:46:15 -04:00
Calvin Rose
06c755c98a Be stricter with function arity. 2018-08-03 13:41:44 -04:00
Calvin Rose
1acd2d1de7 Inlining for all built in comparators. 2018-07-09 21:24:22 -04:00
Calvin Rose
b860b0a3c5 Port some cfunctions in math.c to corelib as
assembled functions.
2018-07-08 23:10:02 -04:00
Calvin Rose
5b15ad9ff8 Try and fix os.clock on windows. 2018-07-08 20:54:41 -04:00
Calvin Rose
547529ebb2 Refactor dst_view_* functions. 2018-07-04 13:21:30 -04:00
Calvin Rose
a018f9f54a Major refactor. Move files around, merge compiler into
core and other changes, work on inlining many c functions.
2018-07-03 23:07:35 -04:00
Calvin Rose
5e2de33ae7 Remove some c functions in favor of bytecode. 2018-07-02 00:12:36 -04:00
Calvin Rose
363a17ff8c Convert get, put and length to normal functions, not c functions. 2018-06-17 13:55:02 -04:00
Calvin Rose
0cf10946b0 Add first version of marsh (marshaling). 2018-06-12 14:24:45 -04:00
Calvin Rose
2a87dada47 Rename fiber.resume and fiber.yield to
resume and yield.
2018-06-09 13:08:30 -04:00
Calvin Rose
fb409201b4 Strip trailing whitespace from many files.
Add native modules to import with module.native-path.
2018-05-19 21:16:00 -04:00