1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

Merge branch 'master' into jgarte-patch-typo

This commit is contained in:
Calvin Rose 2021-10-16 12:51:38 -05:00 committed by GitHub
commit c3d7b1541e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 22 deletions

View File

@ -1,7 +1,10 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## Unreleased - ??? ## 1.18.0 - 2021-10-10
- Allow `ev/cancel` to work on already scheduled fibers.
- Fix bugs with ev/ module.
- Add optional `base` argument to scan-number
- Add `-i` flag to janet binary to make it easier to run image files from the command line - Add `-i` flag to janet binary to make it easier to run image files from the command line
- Remove `thread/` module. - Remove `thread/` module.
- Add `(number ...)` pattern to peg for more efficient number parsing using Janet's - Add `(number ...)` pattern to peg for more efficient number parsing using Janet's

View File

@ -67,6 +67,10 @@ ifeq ($(UNAME), Haiku)
LDCONFIG:=true LDCONFIG:=true
LDFLAGS=-Wl,--export-dynamic LDFLAGS=-Wl,--export-dynamic
endif endif
# For Android (termux)
ifeq ($(shell uname -o), Android)
CLIBS:=$(CLIBS) -landroid-spawn
endif
$(shell mkdir -p build/core build/c build/boot) $(shell mkdir -p build/core build/c build/boot)
all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h

View File

@ -30,6 +30,7 @@ header_path = join_paths(get_option('prefix'), get_option('includedir'), 'janet'
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false) m_dep = cc.find_library('m', required : false)
dl_dep = cc.find_library('dl', required : false) dl_dep = cc.find_library('dl', required : false)
android_spawn_dep = cc.find_library('android-spawn', required : false)
thread_dep = dependency('threads') thread_dep = dependency('threads')
# Link options # Link options
@ -160,7 +161,7 @@ mainclient_src = [
janet_boot = executable('janet-boot', core_src, boot_src, janet_boot = executable('janet-boot', core_src, boot_src,
include_directories : incdir, include_directories : incdir,
c_args : '-DJANET_BOOTSTRAP', c_args : '-DJANET_BOOTSTRAP',
dependencies : [m_dep, dl_dep, thread_dep], dependencies : [m_dep, dl_dep, thread_dep, android_spawn_dep],
native : true) native : true)
# Build janet.c # Build janet.c
@ -173,7 +174,7 @@ janetc = custom_target('janetc',
'JANET_PATH', janet_path 'JANET_PATH', janet_path
]) ])
janet_dependencies = [m_dep, dl_dep] janet_dependencies = [m_dep, dl_dep, android_spawn_dep]
if not get_option('single_threaded') if not get_option('single_threaded')
janet_dependencies += thread_dep janet_dependencies += thread_dep
endif endif

View File

@ -3573,7 +3573,7 @@
1) 1)
"v" (fn [&] (print janet/version "-" janet/build) (os/exit 0) 1) "v" (fn [&] (print janet/version "-" janet/build) (os/exit 0) 1)
"s" (fn [&] (set raw-stdin true) (set should-repl true) 1) "s" (fn [&] (set raw-stdin true) (set should-repl true) 1)
"r" (fn [&] (set should-repl true) 0) "r" (fn [&] (set should-repl true) 1)
"p" (fn [&] (set exit-on-error false) 1) "p" (fn [&] (set exit-on-error false) 1)
"q" (fn [&] (set quiet true) 1) "q" (fn [&] (set quiet true) 1)
"i" (fn [&] (set expect-image true) 1) "i" (fn [&] (set expect-image true) 1)

View File

@ -6,8 +6,8 @@
#define JANET_VERSION_MAJOR 1 #define JANET_VERSION_MAJOR 1
#define JANET_VERSION_MINOR 18 #define JANET_VERSION_MINOR 18
#define JANET_VERSION_PATCH 0 #define JANET_VERSION_PATCH 0
#define JANET_VERSION_EXTRA "-dev" #define JANET_VERSION_EXTRA ""
#define JANET_VERSION "1.18.0-dev" #define JANET_VERSION "1.18.0"
/* #define JANET_BUILD "local" */ /* #define JANET_BUILD "local" */

View File

@ -137,7 +137,7 @@ static const char *janet_dyncstring(const char *name, const char *dflt) {
const uint8_t *jstr = janet_unwrap_string(x); const uint8_t *jstr = janet_unwrap_string(x);
const char *cstr = (const char *)jstr; const char *cstr = (const char *)jstr;
if (strlen(cstr) != (size_t) janet_string_length(jstr)) { if (strlen(cstr) != (size_t) janet_string_length(jstr)) {
janet_panicf("string %v contains embedded 0s"); janet_panicf("string %v contains embedded 0s", x);
} }
return cstr; return cstr;
} }
@ -398,15 +398,21 @@ JANET_CORE_FN(janet_core_is_abstract,
} }
JANET_CORE_FN(janet_core_scannumber, JANET_CORE_FN(janet_core_scannumber,
"(scan-number str)", "(scan-number str &opt base)",
"Parse a number from a byte sequence and return that number, either an integer " "Parse a number from a byte sequence and return that number, either an integer "
"or a real. The number " "or a real. The number "
"must be in the same format as numbers in janet source code. Will return nil " "must be in the same format as numbers in janet source code. Will return nil "
"on an invalid number.") { "on an invalid number. Optionally provide a base - if a base is provided, no "
"radix specifier is expected at the beginning of the number.") {
double number; double number;
janet_fixarity(argc, 1); janet_arity(argc, 1, 2);
JanetByteView view = janet_getbytes(argv, 0); JanetByteView view = janet_getbytes(argv, 0);
if (janet_scan_number(view.bytes, view.len, &number)) int32_t base = janet_optinteger(argv, argc, 1, 0);
int valid = base == 0 || (base >= 2 && base <= 36);
if (!valid) {
janet_panicf("expected base between 2 and 36, got %d", base);
}
if (janet_scan_number_base(view.bytes, view.len, base, &number))
return janet_wrap_nil(); return janet_wrap_nil();
return janet_wrap_number(number); return janet_wrap_number(number);
} }

View File

@ -1511,8 +1511,8 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
JanetStream *stream = p; JanetStream *stream = p;
int mask = events[i].events; int mask = events[i].events;
JanetListenerState *state = stream->state; JanetListenerState *state = stream->state;
state->event = events + i;
while (NULL != state) { while (NULL != state) {
state->event = events + i;
JanetListenerState *next_state = state->_next; JanetListenerState *next_state = state->_next;
JanetAsyncStatus status1 = JANET_ASYNC_STATUS_NOT_DONE; JanetAsyncStatus status1 = JANET_ASYNC_STATUS_NOT_DONE;
JanetAsyncStatus status2 = JANET_ASYNC_STATUS_NOT_DONE; JanetAsyncStatus status2 = JANET_ASYNC_STATUS_NOT_DONE;
@ -2558,15 +2558,16 @@ void janet_ev_sendto_string(JanetStream *stream, JanetString str, void *dest, in
static volatile long PipeSerialNumber; static volatile long PipeSerialNumber;
#endif #endif
/*
* mode = 0: both sides non-blocking.
* mode = 1: only read side non-blocking: write side sent to subprocess
* mode = 2: only write side non-blocking: read side sent to subprocess
*/
int janet_make_pipe(JanetHandle handles[2], int mode) { int janet_make_pipe(JanetHandle handles[2], int mode) {
#ifdef JANET_WINDOWS #ifdef JANET_WINDOWS
/* /*
* On windows, the built in CreatePipe function doesn't support overlapped IO * On windows, the built in CreatePipe function doesn't support overlapped IO
* so we lift from the windows source code and modify for our own version. * so we lift from the windows source code and modify for our own version.
*
* mode = 0: both sides non-blocking.
* mode = 1: only read side non-blocking: write side sent to subprocess
* mode = 2: only write side non-blocking: read side sent to subprocess
*/ */
JanetHandle shandle, chandle; JanetHandle shandle, chandle;
UCHAR PipeNameBuffer[MAX_PATH]; UCHAR PipeNameBuffer[MAX_PATH];
@ -2616,10 +2617,9 @@ int janet_make_pipe(JanetHandle handles[2], int mode) {
} }
return 0; return 0;
#else #else
(void) mode;
if (pipe(handles)) return -1; if (pipe(handles)) return -1;
if (fcntl(handles[0], F_SETFL, O_NONBLOCK)) goto error; if (mode != 2 && fcntl(handles[0], F_SETFL, O_NONBLOCK)) goto error;
if (fcntl(handles[1], F_SETFL, O_NONBLOCK)) goto error; if (mode != 1 && fcntl(handles[1], F_SETFL, O_NONBLOCK)) goto error;
return 0; return 0;
error: error:
close(handles[0]); close(handles[0]);

View File

@ -79,7 +79,9 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
const char *e = janet_parser_error(&parser); const char *e = janet_parser_error(&parser);
errflags |= 0x04; errflags |= 0x04;
ret = janet_cstringv(e); ret = janet_cstringv(e);
janet_eprintf("parse error in %s: %s\n", sourcePath, e); int32_t line = parser.line;
int32_t col = parser.column;
janet_eprintf("%s:%d:%d: parse error: %s\n", sourcePath, line, col, e);
done = 1; done = 1;
break; break;
} }

View File

@ -218,7 +218,7 @@ JANET_CORE_FN(cfun_string_repeat,
JANET_CORE_FN(cfun_string_bytes, JANET_CORE_FN(cfun_string_bytes,
"(string/bytes str)", "(string/bytes str)",
"Returns an array of integers that are the byte values of the string.") { "Returns a tuple of integers that are the byte values of the string.") {
janet_fixarity(argc, 1); janet_fixarity(argc, 1);
JanetByteView view = janet_getbytes(argv, 0); JanetByteView view = janet_getbytes(argv, 0);
Janet *tup = janet_tuple_begin(view.len); Janet *tup = janet_tuple_begin(view.len);

View File

@ -1493,7 +1493,9 @@ JanetSignal janet_pcall(
Janet janet_mcall(const char *name, int32_t argc, Janet *argv) { Janet janet_mcall(const char *name, int32_t argc, Janet *argv) {
/* At least 1 argument */ /* At least 1 argument */
if (argc < 1) janet_panicf("method :%s expected at least 1 argument"); if (argc < 1) {
janet_panicf("method :%s expected at least 1 argument", name);
}
/* Find method */ /* Find method */
Janet method = janet_method_lookup(argv[0], name); Janet method = janet_method_lookup(argv[0], name);
if (janet_checktype(method, JANET_NIL)) { if (janet_checktype(method, JANET_NIL)) {