1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-05 08:16:16 +00:00
Commit Graph

1062 Commits

Author SHA1 Message Date
Calvin Rose
a964a95c1e Fix warnings on BSDs. 2019-12-29 19:53:35 -05:00
Andrew Chambers
c2f8441572 Add file/temp. 2019-12-30 12:00:35 +13:00
Calvin Rose
099a957e6c Update macex1 to properly handle break
Things mostly worked fine, but technically
break should be handled as a special form not a function call.
2019-12-29 16:44:53 -05:00
Andrew Chambers
2bebace8eb Extend file api to allow creating and checking. 2019-12-30 04:02:46 +13:00
Calvin Rose
5142722da3 Remove aliases for deprectaed functions. 2019-12-28 17:51:05 -05:00
Calvin Rose
52dd0f132a Remove emscripten build.
Prefer using custom toolchain with amalgmated build.
2019-12-28 16:11: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
5528bca7a9 Version bump to dev version. 2019-12-28 11:58:40 -05:00
Andrew Chambers
ddc4274314 Expand docs to explain pclose semantics. 2019-12-28 15:24:10 +13:00
Calvin Rose
da93a73dbd Version bump to 1.6.0. 2019-12-22 12:09:56 -05:00
Calvin Rose
3492ed6d88 Windows installer pulls version from interpreter.
This should make version updates simpler. Also
try an make installer write to ProgramFiles instead
of ProgramFiles (x86) for 64 bit build.
2019-12-19 13:18:46 -05:00
Calvin Rose
e28262f5ab Add array/fill
This function has similar semantics to buffer/fill.
2019-12-19 12:58:11 -05:00
Calvin Rose
94246f7574 Use infinite timeout to indicate non-blocking.
Makes more sense than negative numbers.
2019-12-18 16:07:06 -05:00
Calvin Rose
07b0ef1648 Throw error on bad thread creation. 2019-12-18 15:49:57 -05:00
Calvin Rose
6a39c4b91d Pass thread body explicitly in thread/new.
Doing it via thread/send make sense, but is a bit
strange. Passing the body explicitly will make more
sense to API users.
2019-12-18 15:07:46 -05:00
Calvin Rose
b9f0f14e31 Add array/new-filled
Similar function signature to buffer/new-filled.
2019-12-18 13:02:50 -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
2b2c1ff917 Get rid of warning on BSDs. 2019-12-15 16:04:43 -06:00
Calvin Rose
c7912249b2 Typo in #ifdef. 2019-12-15 15:56:26 -06:00
Calvin Rose
b8004555ea Start cleaning up defines in janet.h 2019-12-15 15:41:58 -06:00
Calvin Rose
58ff7f0788 BSD os.c fix with arc4random. 2019-12-15 12:47:12 -06:00
Calvin Rose
f1afc5b0b4 Address #214
This adds several common patterns, which are defined in
boot.janet. This essentially gives more primitive patterns
to work with out of the box.

Fix build when JANET_REDUCED_OS is defined.
2019-12-14 20:39:14 -06:00
Calvin Rose
bc8ee207d5 Address #219.
Adds several shorthands to the C API.
2019-12-14 11:31:46 -06:00
Calvin Rose
76342540dc Add buffer/fill. Address #221 2019-12-14 10:54:29 -06:00
Calvin Rose
56784a34a1 Address #224 - Exposed file flags in janet.h
A caller can check if a file is closed with
if (flags & JANET_FILE_CLOSED) ...
2019-12-14 09:03:56 -06:00
Calvin Rose
c3f1b54171 Update jpm path settings.
This will make it easier to use jpm as a per-project
management tool, as well as easier to set up individual
module trees.
2019-12-12 19:35:40 -06:00
Calvin Rose
9b7d642c38 Window x86 needs isnan. 2019-12-12 19:04:13 -06:00
Calvin Rose
aa7f3411f5 Use JANET_SINGLE_THREADED to disable threads. 2019-12-12 17:39:22 -06:00
Calvin Rose
5b9eda5e87 Add root-env
This makes images smaller without needing to make sure
that no references to the root environment occur in the final
image.
2019-12-12 17:25:04 -06:00
Calvin Rose
7c2ae45809 Fix some merge issues.
Make everything compile, and test-install pass.
2019-12-12 17:14:36 -06:00
Calvin Rose
36b2f27873 Merge branch 'master' into threads-3 2019-12-12 17:07:03 -06:00
Calvin Rose
b8e02afd1a Improve error messages in os.c and jpm
In os/* functions, show failed path name. In jpm, indicate
a permission issue if we can't stat the file.
2019-12-12 03:20:20 -06:00
Calvin Rose
0fc36aa5d0 Signal to pending threads more often. 2019-12-12 02:19:56 -06:00
Calvin Rose
38f7e256d0 Port threads code to Windows API
Can run demo in examples/threads.janet
2019-12-10 20:32:41 -05:00
Calvin Rose
4187c972a3 Switch to multiple buffers per mailbox.
Needs less copying.
2019-12-10 13:26:00 -06:00
Calvin Rose
2d5af32660 Refine typedefs. 2019-12-09 20:12:10 -06:00
Calvin Rose
e592b24333 Added some type aliases to janet.h
This should make it clearer if a pointer is really just a
plain pointer, or a pointer with a header.
2019-12-09 20:05:53 -06:00
Calvin Rose
8700a407ce Update janet_getmethod to better match new get api. 2019-12-09 18:45:05 -06:00
Calvin Rose
8ecf359bbe
Merge pull request #226 from andrewchambers/abstractget
Abstract type getters can indicate key absence.
2019-12-09 18:39:40 -06:00
Calvin Rose
5b6dffe93d Version bump. 2019-12-09 18:04:38 -06:00
Calvin Rose
1a6eb52f11 Add protect macro.
A more functional version of try catch.
2019-12-09 17:32:02 -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
66d82c4513 Add mailbox capacity for back pressure.
(thread/send thread msg &opt timeout) can now timeout. Also
changed thread/self to thread/current for better consistency with
fibers, and all blocking operations will by default timeout after 1
second. I think its bad to make things block forerver by default.
2019-12-08 12:30:30 -06:00
Calvin Rose
c9c4424261 Add thread/self. 2019-12-07 17:54:08 -06:00
Calvin Rose
131733549d Get mailbox API working. 2019-12-07 16:51:00 -06:00
Calvin Rose
ee646dadf2 Merge branch 'master' into threads-3 2019-12-07 12:14:44 -06:00
Calvin Rose
73f5314141 Work on moving to mailbox abstraction.
Should be more efficient in the common case.
2019-12-07 12:14:16 -06:00
Calvin Rose
546669082f New unmarshal proposal.
Gives more control over unmarshalling
abstract types. This should also
make it possible/easy to write abstract types that cannot
cause unmarshal to segfault.
2019-12-06 22:12:18 -06:00
Calvin Rose
4a0ee5df7d Address #215
Also update docs for module/expand-path.
2019-12-06 19:54:11 -06:00
Calvin Rose
4de6c2ad61 Address #211
Scripts run from the command line will automatically
call a main function if it exists.
2019-12-06 19:14:12 -06:00
Calvin Rose
0e690b4fa0 Add timeout to thread/receive.
If provided, throws an error if no message is received before
timeout. Perhaps should return nil?.
2019-12-06 09:21:36 -06:00
Calvin Rose
c804ae9f7c Update threads.c to avoid a deadlock. 2019-12-06 01:46:23 -06:00
Calvin Rose
dbcceefc20 Fix bad merge. 2019-12-04 22:41:30 -06:00
Calvin Rose
1a4035b02c Merge branch 'master' into threads-3 2019-12-04 22:39:30 -06:00
Calvin Rose
e908029392 Work on thread/receive doubling as select. 2019-12-04 22:31:01 -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
de6c3d6d70 Simplify structure JanetThread and JanetChannel.
Remove JanetThreadShared.
2019-12-04 21:04:43 -06:00
Calvin Rose
49954c7a30 Remove top-level unquote for comptime macro
True top level unquote currently requires basically double compilation
as it currently stands. Also, implementing such double compilation
looses all source mapping information. This is a compromise
implementation that makes it clear that this works differently than
a true top-level unquote.
2019-12-04 19:53:13 -06:00
Calvin Rose
2487162ccf Add top level unquote and macro envs.
This improves macros that eval their arguments and
makes them easier to write.
2019-12-04 18:39:13 -06:00
Calvin Rose
4199c42fe2 Add support for nested quasiquotation.
This brings Janet more in line with Scheme,
Common Lisp, and Clojure.
2019-12-04 16:40:53 -06:00
Calvin Rose
f39cf702db Address #212 - don't include janet args in script args. 2019-12-04 08:30:36 -06:00
Calvin Rose
db9e431bf7 Address #213 - disallow non-indexed ds for loop range. 2019-12-04 08:18:54 -06:00
Calvin Rose
328454729e Add nan? 2019-12-03 21:24:22 -06:00
Calvin Rose
70328437f1 Add math/rng-buffer.
Allow math/seedrandom to use buffer as seed.
2019-12-03 20:33:21 -06:00
Calvin Rose
600bed9f6d
Merge pull request #209 from andrewchambers/cryptorand2
Add os/cryptorand.
2019-12-03 19:12:32 -06:00
Andrew Chambers
0ac5b243c7 Add os/cryptorand. 2019-12-04 14:02:37 +13:00
Andrew Chambers
9911c90b1d Handle missing get case. 2019-12-04 13:58:21 +13:00
Calvin Rose
a1f35e21c7 Merge branch 'master' into threads-3 2019-12-03 18:11:32 -06:00
Calvin Rose
9ccdab0bc7
Merge pull request #208 from andrewchambers/explain_why
Explain the logic behind negative slice indices.
2019-12-03 10:42:46 -05:00
Andrew Chambers
a20e956f6d Explain the logic behind negative slice indices. 2019-12-03 22:05:43 +13:00
Calvin Rose
59668133a2
Merge pull request #206 from andrewchambers/unkown
Fix typo.
2019-12-03 03:34:46 -05:00
Andrew Chambers
73db8584e0 Fix typo. 2019-12-03 21:14:00 +13: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
3a14aad615 Address issue #205. 2019-12-02 18:34:08 -06:00
Calvin Rose
8368e55151 Merge branch 'master' into threads-3 2019-12-02 17:49:39 -06:00
Calvin Rose
ac85fca8a1 Fix warnings for appveyor. 2019-12-02 09:07:49 -06:00
Calvin Rose
e5fbe5c557 Change printf to add trailing newlines.
Also add prinf and eprinf for old behavior. This
is consistent with the naming of print and prin.
2019-12-02 04:45:03 -06:00
Calvin Rose
474bcd50a1 Add methods to threads. 2019-12-02 04:39:13 -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
212479188a Have separate encode and decode dicts for threads
This is more correct and mirrors the way marshal -> unmarshal works.
2019-12-01 21:53:39 -06:00
Calvin Rose
5b1e59b535 Merge branch 'master' of github.com:janet-lang/janet into threads-3 2019-12-01 21:26:22 -06:00
Calvin Rose
779d788efa
Merge pull request #204 from andrewchambers/get_permissive
New capi janet_get_permissive
2019-12-01 22:06:44 -05:00
Andrew Chambers
6233d804c8 New capi janet_get_permissive
The janet_get_permissive function implements the core semantics
of the 'get' function. The original janet_get implements the semantics of
the 'in' function and also the OP_GET opcode. This slight oddity is
to avoid a backwards incompatible change.
2019-12-02 15:49:51 +13:00
Calvin Rose
8f31a53276 Add thread example.
Also remove reference to pthread_t in the JanetThread structure.
2019-12-01 20:47:22 -06:00
Calvin Rose
6a763aac95 Work on threads.
Add send and receive.
2019-12-01 20:28:12 -06:00
Calvin Rose
5cd6580c2d Merge branch 'threads-3' of github.com:janet-lang/janet into threads-3 2019-12-01 20:25:57 -06:00
Andrew Chambers
8a58be81ba Update documentation for in and get builtins.
Try to clarify documentation and teach users the correct
way to read the 'in' so it is less likely to be confused
with python's usage of the keyword.
2019-12-02 12:35:54 +13:00
Calvin Rose
fc53445d08
Merge pull request #198 from andrewchambers/intprint
Integers convert to plain number strings.
2019-12-01 13:00:09 -05:00
Calvin Rose
db261aabf4 Fix bad integer printing range. 2019-12-01 09:46:20 -05:00
Calvin Rose
36ef1c4749 Print proper integers as integers. 2019-12-01 09:40:34 -05:00
Andrew Chambers
5ae520a2c9 Integers convert to plain number strings.
A user can use (type n) to find the true type, the old behavior did not
seem useful for most uses of the string function.
2019-12-01 23:10:52 +13:00
Calvin Rose
474aed8cfe Merge branch 'master' of github.com:janet-lang/janet 2019-11-30 21:34:38 -05:00
Calvin Rose
570f04ca05 Fix typo. 2019-11-30 21:27:36 -05:00
Andrew Chambers
ded08b6e1e Add truthy? to core. 2019-12-01 14:34:41 +13:00
Calvin Rose
bf609445c1
Merge pull request #186 from quexxon/fix-array-ensure-documentation
Add missing documentation for array/ensure's growth parameter
2019-11-29 22:39:04 -05:00
Calvin Rose
4e4cdb6356 Run formatter. 2019-11-28 23:26:11 -05:00
Calvin Rose
688d297a18 Address Issue #184.
Fix strtod.c with better range checking to prevent DOS.
2019-11-28 23:23:37 -05:00
Will Clardy
9e1c3e0f41
Add missing documentation for array/ensure's growth parameter 2019-11-28 23:16:32 -05:00
Calvin Rose
967a8b5a70
Merge pull request #183 from andrewchambers/environ
Add os/environ.
2019-11-28 21:33:43 -05:00
Calvin Rose
92b7d91697
Merge pull request #182 from andrewchambers/scratch_finalizer
Add an optional finalizer to scratch resources.
2019-11-28 21:07:42 -05:00
Andrew Chambers
07db4c530e Add os/environ. 2019-11-28 19:00:52 +13:00
Andrew Chambers
a3fb2d6e0a Add an optional finalizer to scratch resources.
A finalizer can be attached to scratch allocations efficiently at any point in
it's lifecycle via janet_sfinalizer. Care was taken to keep allocations aligned
with  platform alignment requirements.

A big drawbacks to this approach is the waste of up to 16 bytes per scratch
allocation in the case the scratch memory does not require a finalizer.
2019-11-28 17:32:12 +13:00
Andrew Chambers
88f28773da Add missing fileno method to file, sort method list. 2019-11-28 14:47:16 +13:00
Calvin Rose
e542ba7e4d Fix amalg build. 2019-11-27 12:43:45 -06:00
Calvin Rose
bca0392738 First work on threading.
Posix only, needs to be disabled on windows. Also
the Makefile needs to be configurable, and meson.build
needs to take pthreads into account.
2019-11-26 23:13:53 -06:00
Calvin Rose
74d51ab08b Address issue #180 - string/check-set
Fix the function and add test to further clarify that
implementation is correct. Also fix empty string case.
2019-11-25 20:33:16 -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
c3273e8751 Merge branch 'master' of github.com:janet-lang/janet 2019-11-24 17:54:14 -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
Andrew Chambers
976dfc7195 Minor fixes for parser
Check length before dereferencing buffer in tokenchar.
Check keywords are valid utf-8.
Fix minor typos.
2019-11-24 08:19:04 +13:00
Calvin Rose
8372d1e499 uint32_t -> uint8_t 2019-11-21 23:31:35 -06:00
Calvin Rose
e65716f6ee Add janet_rng_longseed to janet.h 2019-11-21 23:26:31 -06:00
Calvin Rose
4b24d77b2c Switch back to well tested RNG. 2019-11-21 23:22:21 -06:00
Calvin Rose
02fc4ae27b Allow seeding RNG with a byte sequence. 2019-11-21 22:53:39 -06:00
Calvin Rose
624f5f428e Add a number of math functions.
Most of these functions are wrappers around math.h.
2019-11-17 10:54:44 -06:00
Calvin Rose
5171dfd2a8 Fix docstring. 2019-11-16 20:43:21 -06:00
Jon Staab
134163708a Fix formatting 2019-11-16 16:07:15 -08:00
Jon Staab
40e6616df0 Add support for delete key in repl 2019-11-16 16:01:52 -08:00
Calvin Rose
bcd2089f71 Version 1.5.1 2019-11-16 17:17:13 -06:00
Calvin Rose
7553b277db Fix return value of update. 2019-11-16 15:50:21 -06:00
Calvin Rose
c9521e093e Fix windows issue with (file/read file :all)
When file was created with file/popen, the current optimization
of using fseek on windows fails due to windows not properly returning
and error code and just returning 0. Windows :(.
2019-11-11 20:05:00 -05:00
Calvin Rose
16f6261b44 Improve randomness of numbers from new rng.
First few numbers are very biased.
2019-11-10 17:44:59 -06:00
Calvin Rose
6b76ac3d18 Fix bug when appending buffer to self.
janet_to_string_b had a bug when printing buffers.
2019-11-10 14:57:09 -06:00
Calvin Rose
0d2844b7c9 Update to 1.5.0 2019-11-10 10:57:18 -06:00
Calvin Rose
719f7ba0c4 Default to UTC for date. 2019-11-09 16:57:21 -06:00
Calvin Rose
c9292ef648 Use /MD on windows.
Just makes things easier. Assume machines have msvcrt.dll
on them. If not, we can add msvcrt.dll to the dist folder and add to
installer.
2019-11-09 16:05:07 -05:00
Calvin Rose
dca247f01d Fix MSVC build warnings. 2019-11-09 10:12:40 -06:00
Calvin Rose
63e7ca4623 Fix warning on travis CI with Clang. 2019-11-09 10:10:07 -06:00
Calvin Rose
1f55d40a10 Fix janet_opt* api.
Inverted conditional made behavior incorrect. These
were not used in the core library, so were not tested.
2019-11-09 09:39:14 -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
9b605b27bd Address #174 - fix string/trim 2019-11-08 08:47:37 -06:00
Calvin Rose
c5010dffb4 Print error message on bad CLI usage.
This was a small regression when bundling cli-main
into boot.janet.
2019-11-05 12:51:15 -06:00
Calvin Rose
026f26f05f Improve error message in slice functions.
Check the first argument before trying to do range
checks.
2019-11-05 09:41:30 -06:00
Calvin Rose
cf2d3861d6 Make slice a c function.
This will allow future integration into the compiler
for more general destructuring.
2019-11-05 09:29:32 -06:00
Calvin Rose
6ceaf9d28d Add with-vars
This helps for temporarily setting vars in a safe
manner that is guaranteed not to leave vars in a bad state
(assuming that a fiber does not emit debug or use signal and
 is never resumed).
2019-10-31 21:58:43 -05:00
Calvin Rose
280dca3998 Add shell.c to the amalgamation.
This allows easy builds of the full interpreter with no
build system.

  1. Get janet.c, janet.h, janetconf.h, and shell.c in a directory. Edit
     janetconf.h as desired.
  2. gcc shell.c janet.c -lm -ldl -O2 -o janet (on GNU-Linux for example)
  3. ./janet -h (Yay!)
2019-10-29 19:18:44 -05:00
Calvin Rose
427b2638e0 Fix startup environment. 2019-10-29 18:47:54 -05:00
Calvin Rose
2541806dc1 Fix suite7 failing when run with no docstrings. 2019-10-29 18:28:41 -05:00
Calvin Rose
0d16b9e1a1 Move init.janet into cli-main in boot.janet
This makes it easier to get the CLI functionality when
embedding Janet, although the main reason is the init script
is now pre-compiled to bytecode when generating the boot image.
2019-10-29 18:16:32 -05:00
Calvin Rose
45c2819068 Improve flychecking.
Flychecking will now work correctly with arity checking, and
will better handle imports. Well structured modules should interact
cleanly with the flychecker in a mostly safe manner, but maliciously
crafted modules can execute arbitrary code. As such, the flychecker is
not a good way to validate completely untrusted modules.

We also extend run-context with an :evaluator option to replace
:compile-only. This is more flexible and allows users to create their
own flychecker like functionality.
2019-10-27 16:15:41 -05:00
Calvin Rose
d28925fdab Relax type checking when fuction position is nil
This lets the flychecker work as expected.
2019-10-24 15:17:19 -05:00
Calvin Rose
9097e36ea0 [] should evaluate to ()
This is consistent with most bracket tuples.
2019-10-20 14:06:28 -05:00
Calvin Rose
423b6db855 Fix memory leak with some string/ functions.
kmp_init leaked memory when called with an empty string.
2019-10-19 15:14:19 -05:00
Calvin Rose
bb54b940c0 Don't call fwrite with size = 0 2019-10-19 10:51:11 -05:00
Calvin Rose
8dd8af742a Add eprintf and make printf a C function.
This allows some more optimizations when printing to
buffers or when output is disabled. It also makes printf
more consistent with print and prin (Same with eprintf).
2019-10-19 10:30:29 -05:00
Calvin Rose
d47804d222 Add prin, eprint, and eprin functions.
The print family of functions now writes output
to an optional buffer instead of a file bound to :out.
This means output can be more easily captured an redirected.
2019-10-19 09:44:27 -05:00
Calvin Rose
8dd322c0be Fix webclient. 2019-10-14 20:55:04 -05:00
Calvin Rose
7fd0748c19 Update to 1.4.0 2019-10-14 20:35:13 -05:00