1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-21 17:54:49 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Calvin Rose
32922ec376 try older ubuntu version 2024-11-02 15:22:41 -05:00
Calvin Rose
9aae9f3add Check if -t option helps. 2024-11-02 15:11:20 -05:00
12 changed files with 39 additions and 77 deletions

View File

@@ -38,9 +38,6 @@ jobs:
- name: Test the project - name: Test the project
shell: cmd shell: cmd
run: build_win test run: build_win test
- name: Test installer build
shell: cmd
run: build_win dist
test-windows-min: test-windows-min:
name: Build and test on Windows Minimal build name: Build and test on Windows Minimal build
@@ -128,11 +125,11 @@ jobs:
test-s390x-linux: test-s390x-linux:
name: Build and test s390x in qemu name: Build and test s390x in qemu
runs-on: ubuntu-latest runs-on: ubuntu-22.04
steps: steps:
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@master uses: actions/checkout@master
- name: Do Qemu build and test - name: Do Qemu build and test
run: | run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker run --rm -v .:/janet --platform linux/s390x ubuntu bash -c "apt-get -y update && apt-get -y install git build-essential && cd /janet && make -j3 && make test" docker run --rm -v .:/janet -t s390x/ubuntu bash -c "apt-get -y update && apt-get -y install git build-essential && cd /janet && make -j3 && make test"

View File

@@ -1,13 +1,7 @@
# 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.
## 1.37.1 - 2024-12-05 ## ??? - Unreleased
- Fix meson cross compilation
- Update timeout documentation for networking APIs: timeouts raise errors and do not return nil.
- Add `janet_addtimeout_nil(double sec);` to the C API.
- Change string hashing.
- Fix string equality bug.
- Add `assertf`
- Change how JANET_PROFILE is loaded to allow more easily customizing the environment. - Change how JANET_PROFILE is loaded to allow more easily customizing the environment.
- Add `*repl-prompt*` dynamic binding to allow customizing the built in repl. - Add `*repl-prompt*` dynamic binding to allow customizing the built in repl.
- Add multiple path support in the `JANET_PATH` environment variables. This lets - Add multiple path support in the `JANET_PATH` environment variables. This lets

View File

@@ -138,8 +138,7 @@ if defined APPVEYOR_REPO_TAG_NAME (
set RELEASE_VERSION=%JANET_VERSION% set RELEASE_VERSION=%JANET_VERSION%
) )
if defined CI ( if defined CI (
set WIXBIN="%WIX%bin\" set WIXBIN="c:\Program Files (x86)\WiX Toolset v3.11\bin\"
echo WIXBIN = %WIXBIN%
) else ( ) else (
set WIXBIN= set WIXBIN=
) )

View File

@@ -20,23 +20,14 @@
project('janet', 'c', project('janet', 'c',
default_options : ['c_std=c99', 'build.c_std=c99', 'b_lundef=false', 'default_library=both'], default_options : ['c_std=c99', 'build.c_std=c99', 'b_lundef=false', 'default_library=both'],
version : '1.37.1') version : '1.37.0')
# Global settings # Global settings
janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet') janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet')
header_path = join_paths(get_option('prefix'), get_option('includedir'), 'janet') header_path = join_paths(get_option('prefix'), get_option('includedir'), 'janet')
# Compilers # Link math library on all systems
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
native_cc = meson.get_compiler('c', native : true)
# Native deps
native_m_dep = native_cc.find_library('m', required : false)
native_dl_dep = native_cc.find_library('dl', required : false)
native_android_spawn_dep = native_cc.find_library('android-spawn', required : false)
native_thread_dep = dependency('threads', native : true)
# Deps
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) android_spawn_dep = cc.find_library('android-spawn', required : false)
@@ -173,18 +164,11 @@ mainclient_src = [
'src/mainclient/shell.c' 'src/mainclient/shell.c'
] ]
janet_dependencies = [m_dep, dl_dep, android_spawn_dep]
janet_native_dependencies = [native_m_dep, native_dl_dep, native_android_spawn_dep]
if not get_option('single_threaded')
janet_dependencies += thread_dep
janet_native_dependencies += native_thread_dep
endif
# Build boot binary # Build boot binary
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 : janet_native_dependencies, dependencies : [m_dep, dl_dep, thread_dep, android_spawn_dep],
native : true) native : true)
# Build janet.c # Build janet.c
@@ -197,6 +181,11 @@ janetc = custom_target('janetc',
'JANET_PATH', janet_path 'JANET_PATH', janet_path
]) ])
janet_dependencies = [m_dep, dl_dep, android_spawn_dep]
if not get_option('single_threaded')
janet_dependencies += thread_dep
endif
# Allow building with no shared library # Allow building with no shared library
if cc.has_argument('-fvisibility=hidden') if cc.has_argument('-fvisibility=hidden')
lib_cflags = ['-fvisibility=hidden'] lib_cflags = ['-fvisibility=hidden']
@@ -242,7 +231,7 @@ if meson.is_cross_build()
endif endif
janet_nativeclient = executable('janet-native', janetc, mainclient_src, janet_nativeclient = executable('janet-native', janetc, mainclient_src,
include_directories : incdir, include_directories : incdir,
dependencies : janet_native_dependencies, dependencies : janet_dependencies,
c_args : extra_native_cflags, c_args : extra_native_cflags,
native : true) native : true)
else else

View File

@@ -154,6 +154,11 @@
,v ,v
(,error ,(if err err (string/format "assert failure in %j" x)))))) (,error ,(if err err (string/format "assert failure in %j" x))))))
(defmacro assertf
"Convenience macro that combines `assert` and `string/format`."
[x & args]
~(as-macro ,assert ,x (,string/format ,;args)))
(defmacro defdyn (defmacro defdyn
``Define an alias for a keyword that is used as a dynamic binding. The ``Define an alias for a keyword that is used as a dynamic binding. The
alias is a normal, lexically scoped binding that can be used instead of alias is a normal, lexically scoped binding that can be used instead of
@@ -204,16 +209,6 @@
[fmt & args] [fmt & args]
(error (string/format fmt ;args))) (error (string/format fmt ;args)))
(defmacro assertf
"Convenience macro that combines `assert` and `string/format`."
[x fmt & args]
(def v (gensym))
~(do
(def ,v ,x)
(if ,v
,v
(,errorf ,fmt ,;args))))
(defmacro default (defmacro default
``Define a default value for an optional argument. ``Define a default value for an optional argument.
Expands to `(def sym (if (= nil sym) val sym))`.`` Expands to `(def sym (if (= nil sym) val sym))`.``
@@ -2665,6 +2660,7 @@
(do (do
(var pindex 0) (var pindex 0)
(var pstatus nil)
(def len (length buf)) (def len (length buf))
(when (= len 0) (when (= len 0)
(:eof p) (:eof p)

View File

@@ -5,9 +5,9 @@
#define JANET_VERSION_MAJOR 1 #define JANET_VERSION_MAJOR 1
#define JANET_VERSION_MINOR 37 #define JANET_VERSION_MINOR 37
#define JANET_VERSION_PATCH 1 #define JANET_VERSION_PATCH 0
#define JANET_VERSION_EXTRA "" #define JANET_VERSION_EXTRA "-dev"
#define JANET_VERSION "1.37.1" #define JANET_VERSION "1.37.0-dev"
/* #define JANET_BUILD "local" */ /* #define JANET_BUILD "local" */

View File

@@ -625,18 +625,6 @@ void janet_addtimeout(double sec) {
add_timeout(to); add_timeout(to);
} }
/* Set timeout for the current root fiber but resume with nil instead of raising an error */
void janet_addtimeout_nil(double sec) {
JanetFiber *fiber = janet_vm.root_fiber;
JanetTimeout to;
to.when = ts_delta(ts_now(), sec);
to.fiber = fiber;
to.curr_fiber = NULL;
to.sched_id = fiber->sched_id;
to.is_error = 0;
add_timeout(to);
}
void janet_ev_inc_refcount(void) { void janet_ev_inc_refcount(void) {
janet_atomic_inc(&janet_vm.listener_count); janet_atomic_inc(&janet_vm.listener_count);
} }

View File

@@ -829,7 +829,7 @@ JANET_CORE_FN(cfun_stream_accept_loop,
JANET_CORE_FN(cfun_stream_accept, JANET_CORE_FN(cfun_stream_accept,
"(net/accept stream &opt timeout)", "(net/accept stream &opt timeout)",
"Get the next connection on a server stream. This would usually be called in a loop in a dedicated fiber. " "Get the next connection on a server stream. This would usually be called in a loop in a dedicated fiber. "
"Takes an optional timeout in seconds, after which will raise an error. " "Takes an optional timeout in seconds, after which will return nil. "
"Returns a new duplex stream which represents a connection to the client.") { "Returns a new duplex stream which represents a connection to the client.") {
janet_arity(argc, 1, 2); janet_arity(argc, 1, 2);
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
@@ -844,7 +844,7 @@ JANET_CORE_FN(cfun_stream_read,
"Read up to n bytes from a stream, suspending the current fiber until the bytes are available. " "Read up to n bytes from a stream, suspending the current fiber until the bytes are available. "
"`n` can also be the keyword `:all` to read into the buffer until end of stream. " "`n` can also be the keyword `:all` to read into the buffer until end of stream. "
"If less than n bytes are available (and more than 0), will push those bytes and return early. " "If less than n bytes are available (and more than 0), will push those bytes and return early. "
"Takes an optional timeout in seconds, after which will raise an error. " "Takes an optional timeout in seconds, after which will return nil. "
"Returns a buffer with up to n more bytes in it, or raises an error if the read failed.") { "Returns a buffer with up to n more bytes in it, or raises an error if the read failed.") {
janet_arity(argc, 2, 4); janet_arity(argc, 2, 4);
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
@@ -864,7 +864,7 @@ JANET_CORE_FN(cfun_stream_read,
JANET_CORE_FN(cfun_stream_chunk, JANET_CORE_FN(cfun_stream_chunk,
"(net/chunk stream nbytes &opt buf timeout)", "(net/chunk stream nbytes &opt buf timeout)",
"Same a net/read, but will wait for all n bytes to arrive rather than return early. " "Same a net/read, but will wait for all n bytes to arrive rather than return early. "
"Takes an optional timeout in seconds, after which will raise an error.") { "Takes an optional timeout in seconds, after which will return nil.") {
janet_arity(argc, 2, 4); janet_arity(argc, 2, 4);
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
janet_stream_flags(stream, JANET_STREAM_READABLE | JANET_STREAM_SOCKET); janet_stream_flags(stream, JANET_STREAM_READABLE | JANET_STREAM_SOCKET);
@@ -878,7 +878,7 @@ JANET_CORE_FN(cfun_stream_chunk,
JANET_CORE_FN(cfun_stream_recv_from, JANET_CORE_FN(cfun_stream_recv_from,
"(net/recv-from stream nbytes buf &opt timeout)", "(net/recv-from stream nbytes buf &opt timeout)",
"Receives data from a server stream and puts it into a buffer. Returns the socket-address the " "Receives data from a server stream and puts it into a buffer. Returns the socket-address the "
"packet came from. Takes an optional timeout in seconds, after which will raise an error.") { "packet came from. Takes an optional timeout in seconds, after which will return nil.") {
janet_arity(argc, 3, 4); janet_arity(argc, 3, 4);
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
janet_stream_flags(stream, JANET_STREAM_UDPSERVER | JANET_STREAM_SOCKET); janet_stream_flags(stream, JANET_STREAM_UDPSERVER | JANET_STREAM_SOCKET);
@@ -892,7 +892,7 @@ JANET_CORE_FN(cfun_stream_recv_from,
JANET_CORE_FN(cfun_stream_write, JANET_CORE_FN(cfun_stream_write,
"(net/write stream data &opt timeout)", "(net/write stream data &opt timeout)",
"Write data to a stream, suspending the current fiber until the write " "Write data to a stream, suspending the current fiber until the write "
"completes. Takes an optional timeout in seconds, after which will raise an error. " "completes. Takes an optional timeout in seconds, after which will return nil. "
"Returns nil, or raises an error if the write failed.") { "Returns nil, or raises an error if the write failed.") {
janet_arity(argc, 2, 3); janet_arity(argc, 2, 3);
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
@@ -911,7 +911,7 @@ JANET_CORE_FN(cfun_stream_write,
JANET_CORE_FN(cfun_stream_send_to, JANET_CORE_FN(cfun_stream_send_to,
"(net/send-to stream dest data &opt timeout)", "(net/send-to stream dest data &opt timeout)",
"Writes a datagram to a server stream. dest is a the destination address of the packet. " "Writes a datagram to a server stream. dest is a the destination address of the packet. "
"Takes an optional timeout in seconds, after which will raise an error. " "Takes an optional timeout in seconds, after which will return nil. "
"Returns stream.") { "Returns stream.") {
janet_arity(argc, 3, 4); janet_arity(argc, 3, 4);
JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);

View File

@@ -71,10 +71,10 @@ int janet_string_compare(const uint8_t *lhs, const uint8_t *rhs) {
int janet_string_equalconst(const uint8_t *lhs, const uint8_t *rhs, int32_t rlen, int32_t rhash) { int janet_string_equalconst(const uint8_t *lhs, const uint8_t *rhs, int32_t rlen, int32_t rhash) {
int32_t lhash = janet_string_hash(lhs); int32_t lhash = janet_string_hash(lhs);
int32_t llen = janet_string_length(lhs); int32_t llen = janet_string_length(lhs);
if (lhash != rhash || llen != rlen)
return 0;
if (lhs == rhs) if (lhs == rhs)
return 1; return 1;
if (lhash != rhash || llen != rlen)
return 0;
return !memcmp(lhs, rhs, rlen); return !memcmp(lhs, rhs, rlen);
} }

View File

@@ -117,20 +117,14 @@ const char *const janet_status_names[16] = {
"alive" "alive"
}; };
uint32_t janet_hash_mix(uint32_t input, uint32_t more) {
uint32_t mix1 = (more + 0x9e3779b9 + (input << 6) + (input >> 2));
return input ^ (0x9e3779b9 + (mix1 << 6) + (mix1 >> 2));
}
#ifndef JANET_PRF #ifndef JANET_PRF
int32_t janet_string_calchash(const uint8_t *str, int32_t len) { int32_t janet_string_calchash(const uint8_t *str, int32_t len) {
if (NULL == str || len == 0) return 5381; if (NULL == str) return 5381;
const uint8_t *end = str + len; const uint8_t *end = str + len;
uint32_t hash = 5381; uint32_t hash = 5381;
while (str < end) while (str < end)
hash = (hash << 5) + hash + *str++; hash = (hash << 5) + hash + *str++;
hash = janet_hash_mix(hash, (uint32_t) len);
return (int32_t) hash; return (int32_t) hash;
} }
@@ -246,6 +240,11 @@ int32_t janet_string_calchash(const uint8_t *str, int32_t len) {
#endif #endif
uint32_t janet_hash_mix(uint32_t input, uint32_t more) {
uint32_t mix1 = (more + 0x9e3779b9 + (input << 6) + (input >> 2));
return input ^ (0x9e3779b9 + (mix1 << 6) + (mix1 >> 2));
}
/* Computes hash of an array of values */ /* Computes hash of an array of values */
int32_t janet_array_calchash(const Janet *array, int32_t len) { int32_t janet_array_calchash(const Janet *array, int32_t len) {
const Janet *end = array + len; const Janet *end = array + len;

View File

@@ -1442,7 +1442,6 @@ JANET_NO_RETURN JANET_API void janet_sleep_await(double sec);
/* For use inside listeners - adds a timeout to the current fiber, such that /* For use inside listeners - adds a timeout to the current fiber, such that
* it will be resumed after sec seconds if no other event schedules the current fiber. */ * it will be resumed after sec seconds if no other event schedules the current fiber. */
JANET_API void janet_addtimeout(double sec); JANET_API void janet_addtimeout(double sec);
JANET_API void janet_addtimeout_nil(double sec);
JANET_API void janet_ev_inc_refcount(void); JANET_API void janet_ev_inc_refcount(void);
JANET_API void janet_ev_dec_refcount(void); JANET_API void janet_ev_dec_refcount(void);

View File

@@ -987,10 +987,11 @@
(setdyn *debug* nil) (setdyn *debug* nil)
# issue #1516 # issue #1516
(assert-error "assertf 1 argument" (macex '(assertf true))) (assert (assertf true) "assertf 1 argument")
(assert (assertf true "fun message") "assertf 2 arguments") (assert (assertf true "fun message") "assertf 2 arguments")
(assert (assertf true "%s message" "mystery") "assertf 3 arguments") (assert (assertf true "%s message" "mystery") "assertf 3 arguments")
(assert (assertf (not nil) "%s message" "ordinary") "assertf not nil") (assert (assertf (not nil) "%s message" "ordinary") "assertf not nil")
(assert-error "assertf error 1" (assertf false))
(assert-error "assertf error 2" (assertf false "fun message")) (assert-error "assertf error 2" (assertf false "fun message"))
(assert-error "assertf error 3" (assertf false "%s message" "mystery")) (assert-error "assertf error 3" (assertf false "%s message" "mystery"))
(assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob")) (assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob"))