mirror of
https://github.com/janet-lang/janet
synced 2025-11-27 04:25:14 +00:00
Compare commits
63 Commits
ev-reduce-
...
debug-hook
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bda40b644 | ||
|
|
83e8aab289 | ||
|
|
85cb35e68f | ||
|
|
5b79b48ae0 | ||
|
|
7c44127bcb | ||
|
|
9338312103 | ||
|
|
a0eeb630e7 | ||
|
|
6535d72bd4 | ||
|
|
a7d424bc81 | ||
|
|
2bceba4a7a | ||
|
|
e3159bb0f5 | ||
|
|
5d1bd8a932 | ||
|
|
bafa6bfff0 | ||
|
|
e2eb7ab4b2 | ||
|
|
9f4497a5ae | ||
|
|
70de8bf092 | ||
|
|
e52575e23a | ||
|
|
10994cbc6a | ||
|
|
abad9d7db9 | ||
|
|
5e443cd29d | ||
|
|
7bf3a9d24c | ||
|
|
d80a7094ae | ||
|
|
ad77bc391c | ||
|
|
2b84fb14b4 | ||
|
|
07155ce657 | ||
|
|
046d28662d | ||
|
|
84dd3db620 | ||
|
|
282f2671ea | ||
|
|
3fc2be3e6e | ||
|
|
d10c1fe759 | ||
|
|
d18472b07d | ||
|
|
43a68dcd2a | ||
|
|
3d93028088 | ||
|
|
99f0af92bd | ||
|
|
71d81b14a2 | ||
|
|
3894f4021a | ||
|
|
72c659d1ee | ||
|
|
8f879b4adc | ||
|
|
18f2847dc1 | ||
|
|
89b7ff9daf | ||
|
|
26c263d6be | ||
|
|
2570e0f7a0 | ||
|
|
8084e4c728 | ||
|
|
ee90f9df62 | ||
|
|
906a982ace | ||
|
|
88e60c309c | ||
|
|
9694aee819 | ||
|
|
2697b0e425 | ||
|
|
c0d7a49b19 | ||
|
|
f9a6f52d9c | ||
|
|
c02c2e3f02 | ||
|
|
1fcd47dd7b | ||
|
|
384ee4f6a9 | ||
|
|
e9deec8231 | ||
|
|
2fc77a1b63 | ||
|
|
442fe8209d | ||
|
|
968a0dc4ac | ||
|
|
40c93d0786 | ||
|
|
83b0bc688c | ||
|
|
6185b253be | ||
|
|
17da53d0d9 | ||
|
|
9ffec43d2b | ||
|
|
e4f4a42751 |
@@ -19,3 +19,8 @@ tasks:
|
|||||||
ninja
|
ninja
|
||||||
ninja test
|
ninja test
|
||||||
sudo ninja install
|
sudo ninja install
|
||||||
|
- meson_min: |
|
||||||
|
cd janet
|
||||||
|
meson setup build_meson_min --buildtype=release -Dsingle_threaded=true -Dnanbox=false -Ddynamic_modules=false -Ddocstrings=false -Dnet=false -Dsourcemaps=false -Dpeg=false -Dassembler=false -Dint_types=false -Dreduced_os=true -Dffi=false
|
||||||
|
cd build_meson_min
|
||||||
|
ninja
|
||||||
|
|||||||
31
.github/workflows/release.yml
vendored
31
.github/workflows/release.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-latest, macos-latest ]
|
os: [ ubuntu-latest, macos-13 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
@@ -39,6 +39,35 @@ jobs:
|
|||||||
build/c/janet.c
|
build/c/janet.c
|
||||||
build/c/shell.c
|
build/c/shell.c
|
||||||
|
|
||||||
|
release-arm:
|
||||||
|
permissions:
|
||||||
|
contents: write # for softprops/action-gh-release to create GitHub release
|
||||||
|
name: Build release binaries
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ macos-latest ]
|
||||||
|
steps:
|
||||||
|
- name: Checkout the repository
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Set the version
|
||||||
|
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
|
||||||
|
- name: Set the platform
|
||||||
|
run: echo "platform=$(tr '[A-Z]' '[a-z]' <<< $RUNNER_OS)" >> $GITHUB_ENV
|
||||||
|
- name: Compile the project
|
||||||
|
run: make clean && make
|
||||||
|
- name: Build the artifact
|
||||||
|
run: JANET_DIST_DIR=janet-${{ env.version }}-${{ env.platform }} make build/janet-${{ env.version }}-${{ env.platform }}-aarch64.tar.gz
|
||||||
|
- name: Draft the release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
files: |
|
||||||
|
build/*.gz
|
||||||
|
build/janet.h
|
||||||
|
build/c/janet.c
|
||||||
|
build/c/shell.c
|
||||||
|
|
||||||
release-windows:
|
release-windows:
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # for softprops/action-gh-release to create GitHub release
|
contents: write # for softprops/action-gh-release to create GitHub release
|
||||||
|
|||||||
59
.github/workflows/test.yml
vendored
59
.github/workflows/test.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-latest, macos-latest ]
|
os: [ ubuntu-latest, macos-latest, macos-13 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
@@ -23,7 +23,10 @@ jobs:
|
|||||||
|
|
||||||
test-windows:
|
test-windows:
|
||||||
name: Build and test on Windows
|
name: Build and test on Windows
|
||||||
runs-on: windows-latest
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ windows-latest, windows-2019 ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
@@ -35,28 +38,61 @@ 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:
|
||||||
|
name: Build and test on Windows Minimal build
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ windows-2019 ]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout the repository
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Setup MSVC
|
||||||
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: Install Python Dependencies
|
||||||
|
run: pip install meson ninja
|
||||||
|
- name: Build
|
||||||
|
shell: cmd
|
||||||
|
run: |
|
||||||
|
meson setup build_meson_min --buildtype=release -Dsingle_threaded=true -Dnanbox=false -Ddynamic_modules=false -Ddocstrings=false -Dnet=false -Dsourcemaps=false -Dpeg=false -Dassembler=false -Dint_types=false -Dreduced_os=true -Dffi=false
|
||||||
|
cd build_meson_min
|
||||||
|
ninja
|
||||||
|
|
||||||
test-mingw:
|
test-mingw:
|
||||||
name: Build on Windows with Mingw (no test yet)
|
name: Build on Windows with Mingw
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
msystem: [ UCRT64, CLANG64 ]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout the repository
|
- name: Checkout the repository
|
||||||
uses: actions/checkout@master
|
uses: actions/checkout@master
|
||||||
- name: Setup Mingw
|
- name: Setup Mingw
|
||||||
uses: msys2/setup-msys2@v2
|
uses: msys2/setup-msys2@v2
|
||||||
with:
|
with:
|
||||||
msystem: UCRT64
|
msystem: ${{ matrix.msystem }}
|
||||||
update: true
|
update: true
|
||||||
install: >-
|
install: >-
|
||||||
base-devel
|
base-devel
|
||||||
git
|
git
|
||||||
gcc
|
gcc
|
||||||
- name: Build the project
|
- name: Build
|
||||||
shell: cmd
|
shell: cmd
|
||||||
run: make -j4 CC=gcc JANET_NO_AMALG=1
|
run: make -j4 CC=gcc
|
||||||
|
- name: Test
|
||||||
|
shell: cmd
|
||||||
|
run: make -j4 CC=gcc test
|
||||||
|
|
||||||
test-mingw-linux:
|
test-mingw-linux:
|
||||||
name: Build and test with Mingw on Linux + Wine
|
name: Build and test with Mingw on Linux + Wine
|
||||||
@@ -89,3 +125,14 @@ jobs:
|
|||||||
run: make RUN="qemu-arm -L /usr/arm-linux-gnueabi/" CC=arm-linux-gnueabi-gcc LD=arm-linux-gnueabi-gcc
|
run: make RUN="qemu-arm -L /usr/arm-linux-gnueabi/" CC=arm-linux-gnueabi-gcc LD=arm-linux-gnueabi-gcc
|
||||||
- name: Test the project
|
- name: Test the project
|
||||||
run: make RUN="qemu-arm -L /usr/arm-linux-gnueabi/" SUBRUN="qemu-arm -L /usr/arm-linux-gnueabi/" test VERBOSE=1
|
run: make RUN="qemu-arm -L /usr/arm-linux-gnueabi/" SUBRUN="qemu-arm -L /usr/arm-linux-gnueabi/" test VERBOSE=1
|
||||||
|
|
||||||
|
test-s390x-linux:
|
||||||
|
name: Build and test s390x in qemu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout the repository
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Do Qemu build and test
|
||||||
|
run: |
|
||||||
|
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"
|
||||||
|
|||||||
25
CHANGELOG.md
25
CHANGELOG.md
@@ -1,18 +1,35 @@
|
|||||||
# 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.37.1 - 2024-12-05
|
||||||
|
- 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.
|
||||||
|
- Add `*repl-prompt*` dynamic binding to allow customizing the built in repl.
|
||||||
|
- Add multiple path support in the `JANET_PATH` environment variables. This lets
|
||||||
|
user more easily import modules from many directories.
|
||||||
|
- Add `nth` and `only-tags` PEG specials to select from sub-captures while
|
||||||
|
dropping the rest.
|
||||||
|
|
||||||
|
## 1.36.0 - 2024-09-07
|
||||||
|
- Improve error messages in `bundle/add*` functions.
|
||||||
|
- Add CI testing and verify tests pass on the s390x architecture.
|
||||||
- Save `:source-form` in environment entries when `*debug*` is set.
|
- Save `:source-form` in environment entries when `*debug*` is set.
|
||||||
- Add experimental `filewatch/` module for listening to file system changes.
|
- Add experimental `filewatch/` module for listening to file system changes on Linux and Windows.
|
||||||
- Add `bundle/who-is` to query which bundle a file on disk was installed by.
|
- Add `bundle/who-is` to query which bundle a file on disk was installed by.
|
||||||
- Add `geomean` function
|
- Add `geomean` function
|
||||||
- Add `:R` and `:W` flags to `os/pipe` to create blocking pipes on Posix and Windows systems.
|
- Add `:R` and `:W` flags to `os/pipe` to create blocking pipes on Posix and Windows systems.
|
||||||
These streams cannot be directly read to and written from, but can be passed to subprocesses.
|
These streams cannot be directly read to and written from, but can be passed to subprocesses.
|
||||||
- Add `array/join`
|
- Add `array/join`
|
||||||
- Add `tuple/join`
|
- Add `tuple/join`
|
||||||
- Fix marshalling weak tables and weak arrays.
|
|
||||||
- Expose C functions for constructing weak tables in janet.h
|
|
||||||
- Add `bundle/add-bin` to make installing scripts easier. This also establishes a packaging convention for it.
|
- Add `bundle/add-bin` to make installing scripts easier. This also establishes a packaging convention for it.
|
||||||
|
- Fix marshalling weak tables and weak arrays.
|
||||||
|
- Fix bug in `ev/` module that could accidentally close sockets on accident.
|
||||||
|
- Expose C functions for constructing weak tables in janet.h
|
||||||
- Let range take non-integer values.
|
- Let range take non-integer values.
|
||||||
|
|
||||||
## 1.35.2 - 2024-06-16
|
## 1.35.2 - 2024-06-16
|
||||||
|
|||||||
13
Makefile
13
Makefile
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2023 Calvin Rose
|
# Copyright (c) 2024 Calvin Rose
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to
|
# of this software and associated documentation files (the "Software"), to
|
||||||
@@ -43,6 +43,7 @@ JANET_DIST_DIR?=janet-dist
|
|||||||
JANET_BOOT_FLAGS:=. JANET_PATH '$(JANET_PATH)'
|
JANET_BOOT_FLAGS:=. JANET_PATH '$(JANET_PATH)'
|
||||||
JANET_TARGET_OBJECTS=build/janet.o build/shell.o
|
JANET_TARGET_OBJECTS=build/janet.o build/shell.o
|
||||||
JPM_TAG?=master
|
JPM_TAG?=master
|
||||||
|
SPORK_TAG?=master
|
||||||
HAS_SHARED?=1
|
HAS_SHARED?=1
|
||||||
DEBUGGER=gdb
|
DEBUGGER=gdb
|
||||||
SONAME_SETTER=-Wl,-soname,
|
SONAME_SETTER=-Wl,-soname,
|
||||||
@@ -205,9 +206,9 @@ build/%.bin.o: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) Makefile
|
|||||||
########################
|
########################
|
||||||
|
|
||||||
ifeq ($(UNAME), Darwin)
|
ifeq ($(UNAME), Darwin)
|
||||||
SONAME=libjanet.1.35.dylib
|
SONAME=libjanet.1.37.dylib
|
||||||
else
|
else
|
||||||
SONAME=libjanet.so.1.35
|
SONAME=libjanet.so.1.37
|
||||||
endif
|
endif
|
||||||
|
|
||||||
build/c/shell.c: src/mainclient/shell.c
|
build/c/shell.c: src/mainclient/shell.c
|
||||||
@@ -359,6 +360,12 @@ install-jpm-git: $(JANET_TARGET)
|
|||||||
JANET_LIBPATH='$(LIBDIR)' \
|
JANET_LIBPATH='$(LIBDIR)' \
|
||||||
$(RUN) ../../$(JANET_TARGET) ./bootstrap.janet
|
$(RUN) ../../$(JANET_TARGET) ./bootstrap.janet
|
||||||
|
|
||||||
|
install-spork-git: $(JANET_TARGET)
|
||||||
|
mkdir -p build
|
||||||
|
rm -rf build/spork
|
||||||
|
git clone --depth=1 --branch='$(SPORK_TAG)' https://github.com/janet-lang/spork.git build/spork
|
||||||
|
$(JANET_TARGET) -e '(bundle/install "build/spork")'
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
-rm '$(DESTDIR)$(BINDIR)/janet'
|
-rm '$(DESTDIR)$(BINDIR)/janet'
|
||||||
-rm -rf '$(DESTDIR)$(INCLUDEDIR)/janet'
|
-rm -rf '$(DESTDIR)$(INCLUDEDIR)/janet'
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -1,4 +1,4 @@
|
|||||||
[](https://gitter.im/janet-language/community)
|
[](https://janet.zulipchat.com)
|
||||||
|
|
||||||
[](https://builds.sr.ht/~bakpakin/janet/commits/master/freebsd.yml?)
|
[](https://builds.sr.ht/~bakpakin/janet/commits/master/freebsd.yml?)
|
||||||
[](https://builds.sr.ht/~bakpakin/janet/commits/master/openbsd.yml?)
|
[](https://builds.sr.ht/~bakpakin/janet/commits/master/openbsd.yml?)
|
||||||
@@ -18,9 +18,6 @@ to run script files. This client program is separate from the core runtime, so
|
|||||||
Janet can be embedded in other programs. Try Janet in your browser at
|
Janet can be embedded in other programs. Try Janet in your browser at
|
||||||
<https://janet-lang.org>.
|
<https://janet-lang.org>.
|
||||||
|
|
||||||
If you'd like to financially support the ongoing development of Janet, consider
|
|
||||||
[sponsoring its primary author](https://github.com/sponsors/bakpakin) through GitHub.
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
@@ -253,8 +250,10 @@ Emacs, and Atom each have syntax packages for the Janet language, though.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
See the [Introduction](https://janet-lang.org/docs/index.html) for more details. If you just want
|
If you just want to try out the language, you don't need to install anything.
|
||||||
to try out the language, you don't need to install anything. You can also move the `janet` executable wherever you want on your system and run it.
|
In this case you can also move the `janet` executable wherever you want on
|
||||||
|
your system and run it. However, for a fuller setup, please see the
|
||||||
|
[Introduction](https://janet-lang.org/docs/index.html) for more details.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ copy README.md dist\README.md
|
|||||||
|
|
||||||
copy janet.lib dist\janet.lib
|
copy janet.lib dist\janet.lib
|
||||||
copy janet.exp dist\janet.exp
|
copy janet.exp dist\janet.exp
|
||||||
copy janet.def dist\janet.def
|
|
||||||
|
|
||||||
janet.exe tools\patch-header.janet src\include\janet.h src\conf\janetconf.h build\janet.h
|
janet.exe tools\patch-header.janet src\include\janet.h src\conf\janetconf.h build\janet.h
|
||||||
copy build\janet.h dist\janet.h
|
copy build\janet.h dist\janet.h
|
||||||
@@ -139,7 +138,8 @@ if defined APPVEYOR_REPO_TAG_NAME (
|
|||||||
set RELEASE_VERSION=%JANET_VERSION%
|
set RELEASE_VERSION=%JANET_VERSION%
|
||||||
)
|
)
|
||||||
if defined CI (
|
if defined CI (
|
||||||
set WIXBIN="c:\Program Files (x86)\WiX Toolset v3.11\bin\"
|
set WIXBIN="%WIX%bin\"
|
||||||
|
echo WIXBIN = %WIXBIN%
|
||||||
) else (
|
) else (
|
||||||
set WIXBIN=
|
set WIXBIN=
|
||||||
)
|
)
|
||||||
|
|||||||
1
examples/sample-bad-bundle/badmod.janet
Normal file
1
examples/sample-bad-bundle/badmod.janet
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(def abc 123)
|
||||||
7
examples/sample-bad-bundle/bundle.janet
Normal file
7
examples/sample-bad-bundle/bundle.janet
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
(defn install
|
||||||
|
[manifest &]
|
||||||
|
(bundle/add-file manifest "badmod.janet"))
|
||||||
|
|
||||||
|
(defn check
|
||||||
|
[&]
|
||||||
|
(error "Check failed!"))
|
||||||
3
janet.1
3
janet.1
@@ -255,7 +255,8 @@ and then arguments to the script.
|
|||||||
.RS
|
.RS
|
||||||
The location to look for Janet libraries. This is the only environment variable Janet needs to
|
The location to look for Janet libraries. This is the only environment variable Janet needs to
|
||||||
find native and source code modules. If no JANET_PATH is set, Janet will look in
|
find native and source code modules. If no JANET_PATH is set, Janet will look in
|
||||||
the default location set at compile time.
|
the default location set at compile time. This should be a list of as well as a colon
|
||||||
|
separate list of such directories.
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
.B JANET_PROFILE
|
.B JANET_PROFILE
|
||||||
|
|||||||
31
meson.build
31
meson.build
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2023 Calvin Rose and contributors
|
# Copyright (c) 2024 Calvin Rose and contributors
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to
|
# of this software and associated documentation files (the "Software"), to
|
||||||
@@ -20,14 +20,23 @@
|
|||||||
|
|
||||||
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.35.2')
|
version : '1.37.1')
|
||||||
|
|
||||||
# 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')
|
||||||
|
|
||||||
# Link math library on all systems
|
# Compilers
|
||||||
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)
|
||||||
@@ -164,11 +173,18 @@ 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 : [m_dep, dl_dep, thread_dep, android_spawn_dep],
|
dependencies : janet_native_dependencies,
|
||||||
native : true)
|
native : true)
|
||||||
|
|
||||||
# Build janet.c
|
# Build janet.c
|
||||||
@@ -181,11 +197,6 @@ 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']
|
||||||
@@ -231,7 +242,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_dependencies,
|
dependencies : janet_native_dependencies,
|
||||||
c_args : extra_native_cflags,
|
c_args : extra_native_cflags,
|
||||||
native : true)
|
native : true)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -204,6 +204,16 @@
|
|||||||
[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))`.``
|
||||||
@@ -1853,6 +1863,9 @@
|
|||||||
(defdyn *pretty-format*
|
(defdyn *pretty-format*
|
||||||
"Format specifier for the `pp` function")
|
"Format specifier for the `pp` function")
|
||||||
|
|
||||||
|
(defdyn *repl-prompt*
|
||||||
|
"Allow setting a custom prompt at the default REPL. Not all REPLs will respect this binding.")
|
||||||
|
|
||||||
(defn pp
|
(defn pp
|
||||||
``Pretty-print to stdout or `(dyn *out*)`. The format string used is `(dyn *pretty-format* "%q")`.``
|
``Pretty-print to stdout or `(dyn *out*)`. The format string used is `(dyn *pretty-format* "%q")`.``
|
||||||
[x]
|
[x]
|
||||||
@@ -2652,7 +2665,6 @@
|
|||||||
|
|
||||||
(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)
|
||||||
@@ -2827,6 +2839,24 @@
|
|||||||
(array/insert mp curall-index [(string ":cur:/:all:" ext) loader check-relative])
|
(array/insert mp curall-index [(string ":cur:/:all:" ext) loader check-relative])
|
||||||
mp)
|
mp)
|
||||||
|
|
||||||
|
# Don't expose this externally yet - could break if custom module/paths is setup.
|
||||||
|
(defn- module/add-syspath
|
||||||
|
```
|
||||||
|
Add a custom syspath to `module/paths` by duplicating all entries that being with `:sys:` and
|
||||||
|
adding duplicates with a specific path prefix instead.
|
||||||
|
```
|
||||||
|
[path]
|
||||||
|
(def copies @[])
|
||||||
|
(var last-index 0)
|
||||||
|
(def mp (dyn *module-paths* module/paths))
|
||||||
|
(eachp [index entry] mp
|
||||||
|
(def pattern (first entry))
|
||||||
|
(when (and (string? pattern) (string/has-prefix? ":sys:/" pattern))
|
||||||
|
(set last-index index)
|
||||||
|
(array/push copies [(string/replace ":sys:" path pattern) ;(drop 1 entry)])))
|
||||||
|
(array/insert mp (+ 1 last-index) ;copies)
|
||||||
|
mp)
|
||||||
|
|
||||||
(module/add-paths ":native:" :native)
|
(module/add-paths ":native:" :native)
|
||||||
(module/add-paths "/init.janet" :source)
|
(module/add-paths "/init.janet" :source)
|
||||||
(module/add-paths ".janet" :source)
|
(module/add-paths ".janet" :source)
|
||||||
@@ -3913,7 +3943,7 @@
|
|||||||
(defn make-sig []
|
(defn make-sig []
|
||||||
(ffi/signature :default real-ret-type ;computed-type-args))
|
(ffi/signature :default real-ret-type ;computed-type-args))
|
||||||
(defn make-ptr []
|
(defn make-ptr []
|
||||||
(assert (ffi/lookup (if lazy (llib) lib) raw-symbol) (string "failed to find ffi symbol " raw-symbol)))
|
(assertf (ffi/lookup (if lazy (llib) lib) raw-symbol) "failed to find ffi symbol %v" raw-symbol))
|
||||||
(if lazy
|
(if lazy
|
||||||
~(defn ,alias ,;meta [,;formal-args]
|
~(defn ,alias ,;meta [,;formal-args]
|
||||||
(,ffi/call (,(delay (make-ptr))) (,(delay (make-sig))) ,;formal-args))
|
(,ffi/call (,(delay (make-ptr))) (,(delay (make-sig))) ,;formal-args))
|
||||||
@@ -4056,15 +4086,18 @@
|
|||||||
|
|
||||||
(defn- copyfile
|
(defn- copyfile
|
||||||
[from to]
|
[from to]
|
||||||
(def mode (os/stat from :permissions))
|
(if-with [ffrom (file/open from :rb)]
|
||||||
|
(if-with [fto (file/open to :wb)]
|
||||||
|
(do
|
||||||
|
(def perm (os/stat from :permissions))
|
||||||
(def b (buffer/new 0x10000))
|
(def b (buffer/new 0x10000))
|
||||||
(with [ffrom (file/open from :rb)]
|
|
||||||
(with [fto (file/open to :wb)]
|
|
||||||
(forever
|
(forever
|
||||||
(file/read ffrom 0x10000 b)
|
(file/read ffrom 0x10000 b)
|
||||||
(when (empty? b) (buffer/trim b) (os/chmod to mode) (break))
|
(when (empty? b) (buffer/trim b) (os/chmod to perm) (break))
|
||||||
(file/write fto b)
|
(file/write fto b)
|
||||||
(buffer/clear b)))))
|
(buffer/clear b)))
|
||||||
|
(errorf "destination file %s cannot be opened for writing" to))
|
||||||
|
(errorf "source file %s cannot be opened for reading" from)))
|
||||||
|
|
||||||
(defn- copyrf
|
(defn- copyrf
|
||||||
[from to]
|
[from to]
|
||||||
@@ -4087,7 +4120,7 @@
|
|||||||
"Get the manifest for a give installed bundle"
|
"Get the manifest for a give installed bundle"
|
||||||
[bundle-name]
|
[bundle-name]
|
||||||
(def name (get-manifest-filename bundle-name))
|
(def name (get-manifest-filename bundle-name))
|
||||||
(assert (fexists name) (string "no bundle " bundle-name " found"))
|
(assertf (fexists name) "no bundle %v found" bundle-name)
|
||||||
(parse (slurp name)))
|
(parse (slurp name)))
|
||||||
|
|
||||||
(defn- get-bundle-module
|
(defn- get-bundle-module
|
||||||
@@ -4230,11 +4263,9 @@
|
|||||||
(def missing (seq [d :in deps :when (not (bundle/installed? d))] (string d)))
|
(def missing (seq [d :in deps :when (not (bundle/installed? d))] (string d)))
|
||||||
(when (next missing) (errorf "missing dependencies %s" (string/join missing ", "))))
|
(when (next missing) (errorf "missing dependencies %s" (string/join missing ", "))))
|
||||||
(def bundle-name (get config :name default-bundle-name))
|
(def bundle-name (get config :name default-bundle-name))
|
||||||
(assert bundle-name (errorf "unable to infer bundle name for %v, use :name argument" path))
|
(assertf bundle-name "unable to infer bundle name for %v, use :name argument" path)
|
||||||
(assert (not (string/check-set "\\/" bundle-name))
|
(assertf (not (string/check-set "\\/" bundle-name))
|
||||||
(string "bundle name "
|
"bundle name %v cannot contain path separators" bundle-name)
|
||||||
bundle-name
|
|
||||||
" cannot contain path separators"))
|
|
||||||
(assert (next bundle-name) "cannot use empty bundle-name")
|
(assert (next bundle-name) "cannot use empty bundle-name")
|
||||||
(assert (not (fexists (get-manifest-filename bundle-name)))
|
(assert (not (fexists (get-manifest-filename bundle-name)))
|
||||||
"bundle is already installed")
|
"bundle is already installed")
|
||||||
@@ -4271,10 +4302,10 @@
|
|||||||
(do-hook module bundle-name :clean man))
|
(do-hook module bundle-name :clean man))
|
||||||
(do-hook module bundle-name :build man)
|
(do-hook module bundle-name :build man)
|
||||||
(do-hook module bundle-name :install man)
|
(do-hook module bundle-name :install man)
|
||||||
(when check
|
|
||||||
(do-hook module bundle-name :check man))
|
|
||||||
(if (empty? (get man :files)) (print "no files installed, is this a valid bundle?"))
|
(if (empty? (get man :files)) (print "no files installed, is this a valid bundle?"))
|
||||||
(sync-manifest man))
|
(sync-manifest man)
|
||||||
|
(when check
|
||||||
|
(do-hook module bundle-name :check man)))
|
||||||
(print "installed " bundle-name)
|
(print "installed " bundle-name)
|
||||||
bundle-name)
|
bundle-name)
|
||||||
|
|
||||||
@@ -4286,7 +4317,7 @@
|
|||||||
(var i 0)
|
(var i 0)
|
||||||
(def man (bundle/manifest bundle-name))
|
(def man (bundle/manifest bundle-name))
|
||||||
(def files (get man :files @[]))
|
(def files (get man :files @[]))
|
||||||
(assert (os/mkdir dest-dir) (string "could not create directory " dest-dir " (or it already exists)"))
|
(assertf (os/mkdir dest-dir) "could not create directory %v (or it already exists)" dest-dir)
|
||||||
(def s (sep))
|
(def s (sep))
|
||||||
(os/mkdir (string dest-dir s "bundle"))
|
(os/mkdir (string dest-dir s "bundle"))
|
||||||
(def install-hook (string dest-dir s "bundle" s "init.janet"))
|
(def install-hook (string dest-dir s "bundle" s "init.janet"))
|
||||||
@@ -4382,12 +4413,15 @@
|
|||||||
[manifest src &opt dest chmod-mode]
|
[manifest src &opt dest chmod-mode]
|
||||||
(default dest src)
|
(default dest src)
|
||||||
(def s (sep))
|
(def s (sep))
|
||||||
(case (os/stat src :mode)
|
(def mode (os/stat src :mode))
|
||||||
|
(if-not mode (errorf "file %s does not exist" src))
|
||||||
|
(case mode
|
||||||
:directory
|
:directory
|
||||||
(let [absdest (bundle/add-directory manifest dest chmod-mode)]
|
(let [absdest (bundle/add-directory manifest dest chmod-mode)]
|
||||||
(each d (os/dir src) (bundle/add manifest (string src s d) (string dest s d) chmod-mode))
|
(each d (os/dir src) (bundle/add manifest (string src s d) (string dest s d) chmod-mode))
|
||||||
absdest)
|
absdest)
|
||||||
:file (bundle/add-file manifest src dest chmod-mode)))
|
:file (bundle/add-file manifest src dest chmod-mode)
|
||||||
|
(errorf "bad path %s - file is a %s" src mode)))
|
||||||
|
|
||||||
(defn bundle/add-bin
|
(defn bundle/add-bin
|
||||||
`Shorthand for adding scripts during an install. Scripts will be installed to
|
`Shorthand for adding scripts during an install. Scripts will be installed to
|
||||||
@@ -4482,7 +4516,12 @@
|
|||||||
(var error-level nil)
|
(var error-level nil)
|
||||||
(var expect-image false)
|
(var expect-image false)
|
||||||
|
|
||||||
(if-let [jp (getenv-alias "JANET_PATH")] (setdyn *syspath* jp))
|
(when-let [jp (getenv-alias "JANET_PATH")]
|
||||||
|
(def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":"))
|
||||||
|
(def paths (reverse! (string/split path-sep jp)))
|
||||||
|
(for i 1 (length paths)
|
||||||
|
(module/add-syspath (get paths i)))
|
||||||
|
(setdyn *syspath* (first paths)))
|
||||||
(if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile))
|
(if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile))
|
||||||
(set colorize (and
|
(set colorize (and
|
||||||
(not (getenv-alias "NO_COLOR"))
|
(not (getenv-alias "NO_COLOR"))
|
||||||
@@ -4614,17 +4653,15 @@
|
|||||||
(if-not quiet
|
(if-not quiet
|
||||||
(print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) "/" (os/compiler) " - '(doc)' for help"))
|
(print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch) "/" (os/compiler) " - '(doc)' for help"))
|
||||||
(flush)
|
(flush)
|
||||||
|
(def env (make-env))
|
||||||
(defn getprompt [p]
|
(defn getprompt [p]
|
||||||
|
(when-let [custom-prompt (get env *repl-prompt*)] (break (custom-prompt p)))
|
||||||
(def [line] (parser/where p))
|
(def [line] (parser/where p))
|
||||||
(string "repl:" line ":" (parser/state p :delimiters) "> "))
|
(string "repl:" line ":" (parser/state p :delimiters) "> "))
|
||||||
(defn getstdin [prompt buf _]
|
(defn getstdin [prompt buf _]
|
||||||
(file/write stdout prompt)
|
(file/write stdout prompt)
|
||||||
(file/flush stdout)
|
(file/flush stdout)
|
||||||
(file/read stdin :line buf))
|
(file/read stdin :line buf))
|
||||||
(def env (make-env))
|
|
||||||
(when-let [profile.janet (dyn *profilepath*)]
|
|
||||||
(def new-env (dofile profile.janet :exit true))
|
|
||||||
(merge-module env new-env "" false))
|
|
||||||
(when debug-flag
|
(when debug-flag
|
||||||
(put env *debug* true)
|
(put env *debug* true)
|
||||||
(put env *redef* true))
|
(put env *redef* true))
|
||||||
@@ -4636,6 +4673,9 @@
|
|||||||
(setdyn *doc-color* (if colorize true))
|
(setdyn *doc-color* (if colorize true))
|
||||||
(setdyn *lint-error* error-level)
|
(setdyn *lint-error* error-level)
|
||||||
(setdyn *lint-warn* error-level)
|
(setdyn *lint-warn* error-level)
|
||||||
|
(when-let [profile.janet (dyn *profilepath*)]
|
||||||
|
(dofile profile.janet :exit true :env env)
|
||||||
|
(put env *current-file* nil))
|
||||||
(repl getchunk nil env)))))
|
(repl getchunk nil env)))))
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
#define JANETCONF_H
|
#define JANETCONF_H
|
||||||
|
|
||||||
#define JANET_VERSION_MAJOR 1
|
#define JANET_VERSION_MAJOR 1
|
||||||
#define JANET_VERSION_MINOR 36
|
#define JANET_VERSION_MINOR 37
|
||||||
#define JANET_VERSION_PATCH 0
|
#define JANET_VERSION_PATCH 1
|
||||||
#define JANET_VERSION_EXTRA "-dev"
|
#define JANET_VERSION_EXTRA ""
|
||||||
#define JANET_VERSION "1.36.0-dev"
|
#define JANET_VERSION "1.37.1"
|
||||||
|
|
||||||
/* #define JANET_BUILD "local" */
|
/* #define JANET_BUILD "local" */
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -371,17 +371,15 @@ JANET_CORE_FN(cfun_buffer_push_uint16,
|
|||||||
janet_fixarity(argc, 3);
|
janet_fixarity(argc, 3);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
int reverse = should_reverse_bytes(argv, 1);
|
int reverse = should_reverse_bytes(argv, 1);
|
||||||
union {
|
uint16_t data = janet_getuinteger16(argv, 2);
|
||||||
uint16_t data;
|
uint8_t bytes[sizeof(data)];
|
||||||
uint8_t bytes[2];
|
memcpy(bytes, &data, sizeof(bytes));
|
||||||
} u;
|
|
||||||
u.data = janet_getuinteger16(argv, 2);
|
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
uint8_t temp = u.bytes[1];
|
uint8_t temp = bytes[1];
|
||||||
u.bytes[1] = u.bytes[0];
|
bytes[1] = bytes[0];
|
||||||
u.bytes[0] = temp;
|
bytes[0] = temp;
|
||||||
}
|
}
|
||||||
janet_buffer_push_u16(buffer, *(uint16_t *) u.bytes);
|
janet_buffer_push_bytes(buffer, bytes, sizeof(bytes));
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,14 +390,12 @@ JANET_CORE_FN(cfun_buffer_push_uint32,
|
|||||||
janet_fixarity(argc, 3);
|
janet_fixarity(argc, 3);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
int reverse = should_reverse_bytes(argv, 1);
|
int reverse = should_reverse_bytes(argv, 1);
|
||||||
union {
|
uint32_t data = janet_getuinteger(argv, 2);
|
||||||
uint32_t data;
|
uint8_t bytes[sizeof(data)];
|
||||||
uint8_t bytes[4];
|
memcpy(bytes, &data, sizeof(bytes));
|
||||||
} u;
|
|
||||||
u.data = janet_getuinteger(argv, 2);
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
reverse_u32(u.bytes);
|
reverse_u32(bytes);
|
||||||
janet_buffer_push_u32(buffer, *(uint32_t *) u.bytes);
|
janet_buffer_push_bytes(buffer, bytes, sizeof(bytes));
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,14 +406,12 @@ JANET_CORE_FN(cfun_buffer_push_uint64,
|
|||||||
janet_fixarity(argc, 3);
|
janet_fixarity(argc, 3);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
int reverse = should_reverse_bytes(argv, 1);
|
int reverse = should_reverse_bytes(argv, 1);
|
||||||
union {
|
uint64_t data = janet_getuinteger64(argv, 2);
|
||||||
uint64_t data;
|
uint8_t bytes[sizeof(data)];
|
||||||
uint8_t bytes[8];
|
memcpy(bytes, &data, sizeof(bytes));
|
||||||
} u;
|
|
||||||
u.data = janet_getuinteger64(argv, 2);
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
reverse_u64(u.bytes);
|
reverse_u64(bytes);
|
||||||
janet_buffer_push_u64(buffer, *(uint64_t *) u.bytes);
|
janet_buffer_push_bytes(buffer, bytes, sizeof(bytes));
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,14 +422,12 @@ JANET_CORE_FN(cfun_buffer_push_float32,
|
|||||||
janet_fixarity(argc, 3);
|
janet_fixarity(argc, 3);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
int reverse = should_reverse_bytes(argv, 1);
|
int reverse = should_reverse_bytes(argv, 1);
|
||||||
union {
|
float data = (float) janet_getnumber(argv, 2);
|
||||||
float data;
|
uint8_t bytes[sizeof(data)];
|
||||||
uint8_t bytes[4];
|
memcpy(bytes, &data, sizeof(bytes));
|
||||||
} u;
|
|
||||||
u.data = (float) janet_getnumber(argv, 2);
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
reverse_u32(u.bytes);
|
reverse_u32(bytes);
|
||||||
janet_buffer_push_u32(buffer, *(uint32_t *) u.bytes);
|
janet_buffer_push_bytes(buffer, bytes, sizeof(bytes));
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,14 +438,12 @@ JANET_CORE_FN(cfun_buffer_push_float64,
|
|||||||
janet_fixarity(argc, 3);
|
janet_fixarity(argc, 3);
|
||||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||||
int reverse = should_reverse_bytes(argv, 1);
|
int reverse = should_reverse_bytes(argv, 1);
|
||||||
union {
|
double data = janet_getnumber(argv, 2);
|
||||||
double data;
|
uint8_t bytes[sizeof(data)];
|
||||||
uint8_t bytes[8];
|
memcpy(bytes, &data, sizeof(bytes));
|
||||||
} u;
|
|
||||||
u.data = janet_getnumber(argv, 2);
|
|
||||||
if (reverse)
|
if (reverse)
|
||||||
reverse_u64(u.bytes);
|
reverse_u64(bytes);
|
||||||
janet_buffer_push_u64(buffer, *(uint64_t *) u.bytes);
|
janet_buffer_push_bytes(buffer, bytes, sizeof(bytes));
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -31,11 +31,13 @@
|
|||||||
#ifndef JANET_SINGLE_THREADED
|
#ifndef JANET_SINGLE_THREADED
|
||||||
#ifndef JANET_WINDOWS
|
#ifndef JANET_WINDOWS
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#else
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef JANET_USE_STDATOMIC
|
#ifdef JANET_USE_STDATOMIC
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
/* We don't need stdatomic on most compilers since we use compiler builtins for atomic operations.
|
/* We don't need stdatomic on most compilers since we use compiler builtins for atomic operations.
|
||||||
@@ -546,8 +548,8 @@ void *janet_optabstract(const Janet *argv, int32_t argc, int32_t n, const JanetA
|
|||||||
/* Atomic refcounts */
|
/* Atomic refcounts */
|
||||||
|
|
||||||
JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
|
JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef _MSC_VER
|
||||||
return InterlockedIncrement(x);
|
return _InterlockedIncrement(x);
|
||||||
#elif defined(JANET_USE_STDATOMIC)
|
#elif defined(JANET_USE_STDATOMIC)
|
||||||
return atomic_fetch_add_explicit(x, 1, memory_order_relaxed) + 1;
|
return atomic_fetch_add_explicit(x, 1, memory_order_relaxed) + 1;
|
||||||
#else
|
#else
|
||||||
@@ -556,8 +558,8 @@ JanetAtomicInt janet_atomic_inc(JanetAtomicInt volatile *x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef _MSC_VER
|
||||||
return InterlockedDecrement(x);
|
return _InterlockedDecrement(x);
|
||||||
#elif defined(JANET_USE_STDATOMIC)
|
#elif defined(JANET_USE_STDATOMIC)
|
||||||
return atomic_fetch_add_explicit(x, -1, memory_order_acq_rel) - 1;
|
return atomic_fetch_add_explicit(x, -1, memory_order_acq_rel) - 1;
|
||||||
#else
|
#else
|
||||||
@@ -566,8 +568,8 @@ JanetAtomicInt janet_atomic_dec(JanetAtomicInt volatile *x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
|
JanetAtomicInt janet_atomic_load(JanetAtomicInt volatile *x) {
|
||||||
#ifdef JANET_WINDOWS
|
#ifdef _MSC_VER
|
||||||
return InterlockedOr(x, 0);
|
return _InterlockedOr(x, 0);
|
||||||
#elif defined(JANET_USE_STDATOMIC)
|
#elif defined(JANET_USE_STDATOMIC)
|
||||||
return atomic_load_explicit(x, memory_order_acquire);
|
return atomic_load_explicit(x, memory_order_acquire);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -700,7 +700,15 @@ JANET_CORE_FN(janet_core_is_lengthable,
|
|||||||
|
|
||||||
JANET_CORE_FN(janet_core_signal,
|
JANET_CORE_FN(janet_core_signal,
|
||||||
"(signal what x)",
|
"(signal what x)",
|
||||||
"Raise a signal with payload x. ") {
|
"Raise a signal with payload x. `what` can be an integer\n"
|
||||||
|
"from 0 through 7 indicating user(0-7), or one of:\n\n"
|
||||||
|
"* :ok\n"
|
||||||
|
"* :error\n"
|
||||||
|
"* :debug\n"
|
||||||
|
"* :yield\n"
|
||||||
|
"* :user(0-7)\n"
|
||||||
|
"* :interrupt\n"
|
||||||
|
"* :await") {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
Janet payload = argc == 2 ? argv[1] : janet_wrap_nil();
|
Janet payload = argc == 2 ? argv[1] : janet_wrap_nil();
|
||||||
if (janet_checkint(argv[0])) {
|
if (janet_checkint(argv[0])) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -428,6 +428,16 @@ JANET_CORE_FN(cfun_debug_step,
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JANET_CORE_FN(cfun_debug_hook,
|
||||||
|
"(debug/hook hookfn)",
|
||||||
|
"Add a hook that will be called on certain runtime events.") {
|
||||||
|
janet_arity(argc, 0, 1);
|
||||||
|
JanetFunction *func = janet_optfunction(argv, argc, 0, NULL);
|
||||||
|
janet_vm.hook = func;
|
||||||
|
janet_vm.hook_reset = func;
|
||||||
|
return janet_wrap_nil();
|
||||||
|
}
|
||||||
|
|
||||||
/* Module entry point */
|
/* Module entry point */
|
||||||
void janet_lib_debug(JanetTable *env) {
|
void janet_lib_debug(JanetTable *env) {
|
||||||
JanetRegExt debug_cfuns[] = {
|
JanetRegExt debug_cfuns[] = {
|
||||||
@@ -440,6 +450,7 @@ void janet_lib_debug(JanetTable *env) {
|
|||||||
JANET_CORE_REG("debug/stacktrace", cfun_debug_stacktrace),
|
JANET_CORE_REG("debug/stacktrace", cfun_debug_stacktrace),
|
||||||
JANET_CORE_REG("debug/lineage", cfun_debug_lineage),
|
JANET_CORE_REG("debug/lineage", cfun_debug_lineage),
|
||||||
JANET_CORE_REG("debug/step", cfun_debug_step),
|
JANET_CORE_REG("debug/step", cfun_debug_step),
|
||||||
|
JANET_CORE_REG("debug/hook", cfun_debug_hook),
|
||||||
JANET_REG_END
|
JANET_REG_END
|
||||||
};
|
};
|
||||||
janet_core_cfuns_ext(env, NULL, debug_cfuns);
|
janet_core_cfuns_ext(env, NULL, debug_cfuns);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -625,6 +625,18 @@ 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -400,7 +400,7 @@ static JanetFFIStruct *build_struct_type(int32_t argc, const Janet *argv) {
|
|||||||
|
|
||||||
JanetFFIStruct *st = janet_abstract(&janet_struct_type,
|
JanetFFIStruct *st = janet_abstract(&janet_struct_type,
|
||||||
sizeof(JanetFFIStruct) + argc * sizeof(JanetFFIStructMember));
|
sizeof(JanetFFIStruct) + argc * sizeof(JanetFFIStructMember));
|
||||||
st->field_count = member_count;
|
st->field_count = 0;
|
||||||
st->size = 0;
|
st->size = 0;
|
||||||
st->align = 1;
|
st->align = 1;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
@@ -418,6 +418,7 @@ static JanetFFIStruct *build_struct_type(int32_t argc, const Janet *argv) {
|
|||||||
st->fields[i].type = decode_ffi_type(argv[j]);
|
st->fields[i].type = decode_ffi_type(argv[j]);
|
||||||
size_t el_size = type_size(st->fields[i].type);
|
size_t el_size = type_size(st->fields[i].type);
|
||||||
size_t el_align = type_align(st->fields[i].type);
|
size_t el_align = type_align(st->fields[i].type);
|
||||||
|
if (el_align <= 0) janet_panicf("bad field type %V", argv[j]);
|
||||||
if (all_packed || pack_one) {
|
if (all_packed || pack_one) {
|
||||||
if (st->size % el_align != 0) is_aligned = 0;
|
if (st->size % el_align != 0) is_aligned = 0;
|
||||||
st->fields[i].offset = st->size;
|
st->fields[i].offset = st->size;
|
||||||
@@ -433,6 +434,7 @@ static JanetFFIStruct *build_struct_type(int32_t argc, const Janet *argv) {
|
|||||||
st->size += (st->align - 1);
|
st->size += (st->align - 1);
|
||||||
st->size /= st->align;
|
st->size /= st->align;
|
||||||
st->size *= st->align;
|
st->size *= st->align;
|
||||||
|
st->field_count = member_count;
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -154,8 +154,7 @@ static void watcher_callback_read(JanetFiber *fiber, JanetAsyncEvent event) {
|
|||||||
janet_schedule(fiber, janet_wrap_nil());
|
janet_schedule(fiber, janet_wrap_nil());
|
||||||
janet_async_end(fiber);
|
janet_async_end(fiber);
|
||||||
break;
|
break;
|
||||||
case JANET_ASYNC_EVENT_ERR:
|
case JANET_ASYNC_EVENT_ERR: {
|
||||||
{
|
|
||||||
janet_schedule(fiber, janet_wrap_nil());
|
janet_schedule(fiber, janet_wrap_nil());
|
||||||
janet_async_end(fiber);
|
janet_async_end(fiber);
|
||||||
break;
|
break;
|
||||||
@@ -163,8 +162,7 @@ static void watcher_callback_read(JanetFiber *fiber, JanetAsyncEvent event) {
|
|||||||
read_more:
|
read_more:
|
||||||
case JANET_ASYNC_EVENT_HUP:
|
case JANET_ASYNC_EVENT_HUP:
|
||||||
case JANET_ASYNC_EVENT_INIT:
|
case JANET_ASYNC_EVENT_INIT:
|
||||||
case JANET_ASYNC_EVENT_READ:
|
case JANET_ASYNC_EVENT_READ: {
|
||||||
{
|
|
||||||
Janet name = janet_wrap_nil();
|
Janet name = janet_wrap_nil();
|
||||||
|
|
||||||
/* Assumption - read will never return partial events *
|
/* Assumption - read will never return partial events *
|
||||||
@@ -273,7 +271,8 @@ static void janet_watcher_unlisten(JanetWatcher *watcher) {
|
|||||||
#define WATCHFLAG_RECURSIVE 0x100000u
|
#define WATCHFLAG_RECURSIVE 0x100000u
|
||||||
|
|
||||||
static const JanetWatchFlagName watcher_flags_windows[] = {
|
static const JanetWatchFlagName watcher_flags_windows[] = {
|
||||||
{"all",
|
{
|
||||||
|
"all",
|
||||||
FILE_NOTIFY_CHANGE_ATTRIBUTES |
|
FILE_NOTIFY_CHANGE_ATTRIBUTES |
|
||||||
FILE_NOTIFY_CHANGE_CREATION |
|
FILE_NOTIFY_CHANGE_CREATION |
|
||||||
FILE_NOTIFY_CHANGE_DIR_NAME |
|
FILE_NOTIFY_CHANGE_DIR_NAME |
|
||||||
@@ -282,7 +281,8 @@ static const JanetWatchFlagName watcher_flags_windows[] = {
|
|||||||
FILE_NOTIFY_CHANGE_LAST_WRITE |
|
FILE_NOTIFY_CHANGE_LAST_WRITE |
|
||||||
FILE_NOTIFY_CHANGE_SECURITY |
|
FILE_NOTIFY_CHANGE_SECURITY |
|
||||||
FILE_NOTIFY_CHANGE_SIZE |
|
FILE_NOTIFY_CHANGE_SIZE |
|
||||||
WATCHFLAG_RECURSIVE},
|
WATCHFLAG_RECURSIVE
|
||||||
|
},
|
||||||
{"attributes", FILE_NOTIFY_CHANGE_ATTRIBUTES},
|
{"attributes", FILE_NOTIFY_CHANGE_ATTRIBUTES},
|
||||||
{"creation", FILE_NOTIFY_CHANGE_CREATION},
|
{"creation", FILE_NOTIFY_CHANGE_CREATION},
|
||||||
{"dir-name", FILE_NOTIFY_CHANGE_DIR_NAME},
|
{"dir-name", FILE_NOTIFY_CHANGE_DIR_NAME},
|
||||||
@@ -382,8 +382,7 @@ static void watcher_callback_read(JanetFiber *fiber, JanetAsyncEvent event) {
|
|||||||
case JANET_ASYNC_EVENT_FAILED:
|
case JANET_ASYNC_EVENT_FAILED:
|
||||||
janet_stream_close(ow->stream);
|
janet_stream_close(ow->stream);
|
||||||
break;
|
break;
|
||||||
case JANET_ASYNC_EVENT_COMPLETE:
|
case JANET_ASYNC_EVENT_COMPLETE: {
|
||||||
{
|
|
||||||
if (!watcher->is_watching) {
|
if (!watcher->is_watching) {
|
||||||
janet_stream_close(ow->stream);
|
janet_stream_close(ow->stream);
|
||||||
break;
|
break;
|
||||||
@@ -588,6 +587,7 @@ JANET_CORE_FN(cfun_filewatch_make,
|
|||||||
"* `:wd-path` -- the string path for watched directory of file. For files, will be the same as `:file-name`, and for directories, will be the same as `:dir-name`.\n\n"
|
"* `:wd-path` -- the string path for watched directory of file. For files, will be the same as `:file-name`, and for directories, will be the same as `:dir-name`.\n\n"
|
||||||
"* `:cookie` -- a randomized integer used to associate related events, such as :moved-from and :moved-to events.\n\n"
|
"* `:cookie` -- a randomized integer used to associate related events, such as :moved-from and :moved-to events.\n\n"
|
||||||
"") {
|
"") {
|
||||||
|
janet_sandbox_assert(JANET_SANDBOX_FS_READ);
|
||||||
janet_arity(argc, 1, -1);
|
janet_arity(argc, 1, -1);
|
||||||
JanetChannel *channel = janet_getchannel(argv, 0);
|
JanetChannel *channel = janet_getchannel(argv, 0);
|
||||||
JanetWatcher *watcher = janet_abstract(&janet_filewatch_at, sizeof(JanetWatcher));
|
JanetWatcher *watcher = janet_abstract(&janet_filewatch_at, sizeof(JanetWatcher));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -591,6 +591,8 @@ void janet_collect(void) {
|
|||||||
#ifdef JANET_EV
|
#ifdef JANET_EV
|
||||||
janet_ev_mark();
|
janet_ev_mark();
|
||||||
#endif
|
#endif
|
||||||
|
if (janet_vm.hook != NULL) janet_mark(janet_wrap_function(janet_vm.hook));
|
||||||
|
if (janet_vm.hook_reset != NULL) janet_mark(janet_wrap_function(janet_vm.hook_reset));
|
||||||
janet_mark_fiber(janet_vm.root_fiber);
|
janet_mark_fiber(janet_vm.root_fiber);
|
||||||
for (i = 0; i < orig_rootcount; i++)
|
for (i = 0; i < orig_rootcount; i++)
|
||||||
janet_mark(janet_vm.roots[i]);
|
janet_mark(janet_vm.roots[i]);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose & contributors
|
* Copyright (c) 2024 Calvin Rose & contributors
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose and contributors.
|
* Copyright (c) 2024 Calvin Rose and contributors.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -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 return nil. "
|
"Takes an optional timeout in seconds, after which will raise an error. "
|
||||||
"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 return nil. "
|
"Takes an optional timeout in seconds, after which will raise an error. "
|
||||||
"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 return nil.") {
|
"Takes an optional timeout in seconds, after which will raise an error.") {
|
||||||
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 return nil.") {
|
"packet came from. Takes an optional timeout in seconds, after which will raise an error.") {
|
||||||
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 return nil. "
|
"completes. Takes an optional timeout in seconds, after which will raise an error. "
|
||||||
"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 return nil. "
|
"Takes an optional timeout in seconds, after which will raise an error. "
|
||||||
"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);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose and contributors.
|
* Copyright (c) 2024 Calvin Rose and contributors.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -27,9 +27,10 @@
|
|||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef JANET_REDUCED_OS
|
#ifndef JANET_REDUCED_OS
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -174,6 +175,8 @@ JANET_CORE_FN(os_arch,
|
|||||||
"* :riscv64\n\n"
|
"* :riscv64\n\n"
|
||||||
"* :sparc\n\n"
|
"* :sparc\n\n"
|
||||||
"* :wasm\n\n"
|
"* :wasm\n\n"
|
||||||
|
"* :s390\n\n"
|
||||||
|
"* :s390x\n\n"
|
||||||
"* :unknown\n") {
|
"* :unknown\n") {
|
||||||
janet_fixarity(argc, 0);
|
janet_fixarity(argc, 0);
|
||||||
(void) argv;
|
(void) argv;
|
||||||
@@ -200,6 +203,10 @@ JANET_CORE_FN(os_arch,
|
|||||||
return janet_ckeywordv("ppc");
|
return janet_ckeywordv("ppc");
|
||||||
#elif (defined(__ppc64__) || defined(_ARCH_PPC64) || defined(_M_PPC))
|
#elif (defined(__ppc64__) || defined(_ARCH_PPC64) || defined(_M_PPC))
|
||||||
return janet_ckeywordv("ppc64");
|
return janet_ckeywordv("ppc64");
|
||||||
|
#elif (defined(__s390x__))
|
||||||
|
return janet_ckeywordv("s390x");
|
||||||
|
#elif (defined(__s390__))
|
||||||
|
return janet_ckeywordv("s390");
|
||||||
#else
|
#else
|
||||||
return janet_ckeywordv("unknown");
|
return janet_ckeywordv("unknown");
|
||||||
#endif
|
#endif
|
||||||
@@ -245,7 +252,7 @@ JANET_CORE_FN(os_exit,
|
|||||||
}
|
}
|
||||||
janet_deinit();
|
janet_deinit();
|
||||||
if (argc >= 2 && janet_truthy(argv[1])) {
|
if (argc >= 2 && janet_truthy(argv[1])) {
|
||||||
_exit(status);
|
_Exit(status);
|
||||||
} else {
|
} else {
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -231,7 +231,7 @@ static void delim_error(JanetParser *parser, size_t stack_index, char c, const c
|
|||||||
janet_buffer_push_u8(buffer, '`');
|
janet_buffer_push_u8(buffer, '`');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
janet_formatb(buffer, " opened at line %d, column %d", s->line, s->column);
|
janet_formatb(buffer, " opened at line %d, column %d", (int32_t) s->line, (int32_t) s->column);
|
||||||
}
|
}
|
||||||
parser->error = (const char *) janet_string(buffer->data, buffer->count);
|
parser->error = (const char *) janet_string(buffer->data, buffer->count);
|
||||||
parser->flag |= JANET_PARSER_GENERATED_ERROR;
|
parser->flag |= JANET_PARSER_GENERATED_ERROR;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -465,6 +465,16 @@ tail:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case RULE_ONLY_TAGS: {
|
||||||
|
CapState cs = cap_save(s);
|
||||||
|
down1(s);
|
||||||
|
const uint8_t *result = peg_rule(s, s->bytecode + rule[1], text);
|
||||||
|
up1(s);
|
||||||
|
if (!result) return NULL;
|
||||||
|
cap_load_keept(s, cs);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
case RULE_GROUP: {
|
case RULE_GROUP: {
|
||||||
uint32_t tag = rule[2];
|
uint32_t tag = rule[2];
|
||||||
int oldmode = s->mode;
|
int oldmode = s->mode;
|
||||||
@@ -486,6 +496,30 @@ tail:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case RULE_NTH: {
|
||||||
|
uint32_t nth = rule[1];
|
||||||
|
if (nth > INT32_MAX) nth = INT32_MAX;
|
||||||
|
uint32_t tag = rule[3];
|
||||||
|
int oldmode = s->mode;
|
||||||
|
CapState cs = cap_save(s);
|
||||||
|
s->mode = PEG_MODE_NORMAL;
|
||||||
|
down1(s);
|
||||||
|
const uint8_t *result = peg_rule(s, s->bytecode + rule[2], text);
|
||||||
|
up1(s);
|
||||||
|
s->mode = oldmode;
|
||||||
|
if (!result) return NULL;
|
||||||
|
int32_t num_sub_captures = s->captures->count - cs.cap;
|
||||||
|
Janet cap;
|
||||||
|
if (num_sub_captures > (int32_t) nth) {
|
||||||
|
cap = s->captures->data[cs.cap + nth];
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
cap_load_keept(s, cs);
|
||||||
|
pushcap(s, cap, tag);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
case RULE_SUB: {
|
case RULE_SUB: {
|
||||||
const uint8_t *text_start = text;
|
const uint8_t *text_start = text;
|
||||||
const uint32_t *rule_window = s->bytecode + rule[1];
|
const uint32_t *rule_window = s->bytecode + rule[1];
|
||||||
@@ -1061,6 +1095,9 @@ static void spec_thru(Builder *b, int32_t argc, const Janet *argv) {
|
|||||||
static void spec_drop(Builder *b, int32_t argc, const Janet *argv) {
|
static void spec_drop(Builder *b, int32_t argc, const Janet *argv) {
|
||||||
spec_onerule(b, argc, argv, RULE_DROP);
|
spec_onerule(b, argc, argv, RULE_DROP);
|
||||||
}
|
}
|
||||||
|
static void spec_only_tags(Builder *b, int32_t argc, const Janet *argv) {
|
||||||
|
spec_onerule(b, argc, argv, RULE_ONLY_TAGS);
|
||||||
|
}
|
||||||
|
|
||||||
/* Rule of the form [rule, tag] */
|
/* Rule of the form [rule, tag] */
|
||||||
static void spec_cap1(Builder *b, int32_t argc, const Janet *argv, uint32_t op) {
|
static void spec_cap1(Builder *b, int32_t argc, const Janet *argv, uint32_t op) {
|
||||||
@@ -1084,6 +1121,15 @@ static void spec_unref(Builder *b, int32_t argc, const Janet *argv) {
|
|||||||
spec_cap1(b, argc, argv, RULE_UNREF);
|
spec_cap1(b, argc, argv, RULE_UNREF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void spec_nth(Builder *b, int32_t argc, const Janet *argv) {
|
||||||
|
peg_arity(b, argc, 2, 3);
|
||||||
|
Reserve r = reserve(b, 4);
|
||||||
|
uint32_t nth = peg_getnat(b, argv[0]);
|
||||||
|
uint32_t rule = peg_compile1(b, argv[1]);
|
||||||
|
uint32_t tag = (argc == 3) ? emit_tag(b, argv[2]) : 0;
|
||||||
|
emit_3(r, RULE_NTH, nth, rule, tag);
|
||||||
|
}
|
||||||
|
|
||||||
static void spec_capture_number(Builder *b, int32_t argc, const Janet *argv) {
|
static void spec_capture_number(Builder *b, int32_t argc, const Janet *argv) {
|
||||||
peg_arity(b, argc, 1, 3);
|
peg_arity(b, argc, 1, 3);
|
||||||
Reserve r = reserve(b, 4);
|
Reserve r = reserve(b, 4);
|
||||||
@@ -1262,7 +1308,9 @@ static const SpecialPair peg_specials[] = {
|
|||||||
{"line", spec_line},
|
{"line", spec_line},
|
||||||
{"look", spec_look},
|
{"look", spec_look},
|
||||||
{"not", spec_not},
|
{"not", spec_not},
|
||||||
|
{"nth", spec_nth},
|
||||||
{"number", spec_capture_number},
|
{"number", spec_capture_number},
|
||||||
|
{"only-tags", spec_only_tags},
|
||||||
{"opt", spec_opt},
|
{"opt", spec_opt},
|
||||||
{"position", spec_position},
|
{"position", spec_position},
|
||||||
{"quote", spec_capture},
|
{"quote", spec_capture},
|
||||||
@@ -1619,6 +1667,7 @@ static void *peg_unmarshal(JanetMarshalContext *ctx) {
|
|||||||
break;
|
break;
|
||||||
case RULE_ERROR:
|
case RULE_ERROR:
|
||||||
case RULE_DROP:
|
case RULE_DROP:
|
||||||
|
case RULE_ONLY_TAGS:
|
||||||
case RULE_NOT:
|
case RULE_NOT:
|
||||||
case RULE_TO:
|
case RULE_TO:
|
||||||
case RULE_THRU:
|
case RULE_THRU:
|
||||||
@@ -1632,6 +1681,12 @@ static void *peg_unmarshal(JanetMarshalContext *ctx) {
|
|||||||
if (rule[1] > JANET_MAX_READINT_WIDTH) goto bad;
|
if (rule[1] > JANET_MAX_READINT_WIDTH) goto bad;
|
||||||
i += 3;
|
i += 3;
|
||||||
break;
|
break;
|
||||||
|
case RULE_NTH:
|
||||||
|
/* [nth, rule, tag] */
|
||||||
|
if (rule[2] >= blen) goto bad;
|
||||||
|
op_flags[rule[2]] |= 0x01;
|
||||||
|
i += 4;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -87,6 +87,10 @@ struct JanetVM {
|
|||||||
/* How many VM stacks have been entered */
|
/* How many VM stacks have been entered */
|
||||||
int stackn;
|
int stackn;
|
||||||
|
|
||||||
|
/* Debug hook for advanced tracing */
|
||||||
|
JanetFunction *hook;
|
||||||
|
JanetFunction *hook_reset; /* In case of error/signal inside a hook */
|
||||||
|
|
||||||
/* If this flag is true, suspend on function calls and backwards jumps.
|
/* If this flag is true, suspend on function calls and backwards jumps.
|
||||||
* When this occurs, this flag will be reset to 0. */
|
* When this occurs, this flag will be reset to 0. */
|
||||||
volatile JanetAtomicInt auto_suspend;
|
volatile JanetAtomicInt auto_suspend;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -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 (lhs == rhs)
|
|
||||||
return 1;
|
|
||||||
if (lhash != rhash || llen != rlen)
|
if (lhash != rhash || llen != rlen)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (lhs == rhs)
|
||||||
|
return 1;
|
||||||
return !memcmp(lhs, rhs, rlen);
|
return !memcmp(lhs, rhs, rlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -79,6 +79,7 @@ const char *const janet_type_names[16] = {
|
|||||||
"pointer"
|
"pointer"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Docstring for signal lists these */
|
||||||
const char *const janet_signal_names[14] = {
|
const char *const janet_signal_names[14] = {
|
||||||
"ok",
|
"ok",
|
||||||
"error",
|
"error",
|
||||||
@@ -96,6 +97,7 @@ const char *const janet_signal_names[14] = {
|
|||||||
"await"
|
"await"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Docstring for fiber/status lists these */
|
||||||
const char *const janet_status_names[16] = {
|
const char *const janet_status_names[16] = {
|
||||||
"dead",
|
"dead",
|
||||||
"error",
|
"error",
|
||||||
@@ -115,14 +117,20 @@ 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) return 5381;
|
if (NULL == str || len == 0) 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,11 +246,6 @@ 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;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -80,12 +80,22 @@
|
|||||||
func = janet_stack_frame(stack)->func; \
|
func = janet_stack_frame(stack)->func; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vm_return(sig, val) do { \
|
#define vm_return(sig, val) do { \
|
||||||
janet_vm.return_reg[0] = (val); \
|
Janet val2 = (val); \
|
||||||
|
janet_vm.return_reg[0] = val2; \
|
||||||
vm_commit(); \
|
vm_commit(); \
|
||||||
|
if (janet_vm.hook) { \
|
||||||
|
vm_do_hook_return(val2); \
|
||||||
|
janet_vm.return_reg[0] = val2; \
|
||||||
|
} \
|
||||||
return (sig); \
|
return (sig); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define vm_return_no_restore(sig, val) do { \
|
#define vm_return_no_restore(sig, val) do { \
|
||||||
janet_vm.return_reg[0] = (val); \
|
Janet val2 = (val); \
|
||||||
|
janet_vm.return_reg[0] = val2; \
|
||||||
|
if (janet_vm.hook) { \
|
||||||
|
vm_do_hook_return(val2); \
|
||||||
|
janet_vm.return_reg[0] = val2; \
|
||||||
|
} \
|
||||||
return (sig); \
|
return (sig); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -280,6 +290,36 @@ static Janet call_nonfn(JanetFiber *fiber, Janet callee) {
|
|||||||
return janet_method_invoke(callee, argc, fiber->data + fiber->stacktop);
|
return janet_method_invoke(callee, argc, fiber->data + fiber->stacktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void vm_do_hook(int32_t argc, const Janet *argv) {
|
||||||
|
JanetFunction *old_hook = janet_vm.hook;
|
||||||
|
janet_vm.hook = NULL;
|
||||||
|
janet_call(old_hook, argc, argv);
|
||||||
|
janet_vm.hook = old_hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vm_do_hook_call(Janet callee, int32_t argc, const Janet *argv) {
|
||||||
|
Janet argvv[3];
|
||||||
|
argvv[0] = janet_ckeywordv("call");
|
||||||
|
argvv[1] = callee;
|
||||||
|
argvv[2] = janet_wrap_tuple(janet_tuple_n(argv, argc));
|
||||||
|
vm_do_hook(3, argvv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vm_do_hook_tailcall(Janet callee, int32_t argc, const Janet *argv) {
|
||||||
|
Janet argvv[3];
|
||||||
|
argvv[0] = janet_ckeywordv("tailcall");
|
||||||
|
argvv[1] = callee;
|
||||||
|
argvv[2] = janet_wrap_tuple(janet_tuple_n(argv, argc));
|
||||||
|
vm_do_hook(3, argvv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vm_do_hook_return(Janet result) {
|
||||||
|
Janet argvv[2];
|
||||||
|
argvv[0] = janet_ckeywordv("return");
|
||||||
|
argvv[1] = result;
|
||||||
|
vm_do_hook(2, argvv);
|
||||||
|
}
|
||||||
|
|
||||||
/* Method lookup could potentially handle tables specially... */
|
/* Method lookup could potentially handle tables specially... */
|
||||||
static Janet method_to_fun(Janet method, Janet obj) {
|
static Janet method_to_fun(Janet method, Janet obj) {
|
||||||
return janet_get(obj, method);
|
return janet_get(obj, method);
|
||||||
@@ -663,6 +703,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
if (entrance_frame) vm_return_no_restore(JANET_SIGNAL_OK, retval);
|
if (entrance_frame) vm_return_no_restore(JANET_SIGNAL_OK, retval);
|
||||||
vm_restore();
|
vm_restore();
|
||||||
stack[A] = retval;
|
stack[A] = retval;
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_do_hook_return(retval);
|
||||||
|
}
|
||||||
vm_checkgc_pcnext();
|
vm_checkgc_pcnext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -673,6 +716,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
if (entrance_frame) vm_return_no_restore(JANET_SIGNAL_OK, retval);
|
if (entrance_frame) vm_return_no_restore(JANET_SIGNAL_OK, retval);
|
||||||
vm_restore();
|
vm_restore();
|
||||||
stack[A] = retval;
|
stack[A] = retval;
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_do_hook_return(retval);
|
||||||
|
}
|
||||||
vm_checkgc_pcnext();
|
vm_checkgc_pcnext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1013,6 +1059,10 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
if (fiber->stacktop > fiber->maxstack) {
|
if (fiber->stacktop > fiber->maxstack) {
|
||||||
vm_throw("stack overflow");
|
vm_throw("stack overflow");
|
||||||
}
|
}
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_commit();
|
||||||
|
vm_do_hook_call(callee, fiber->stacktop - fiber->stackstart, fiber->data + fiber->stackstart);
|
||||||
|
}
|
||||||
if (janet_checktype(callee, JANET_KEYWORD)) {
|
if (janet_checktype(callee, JANET_KEYWORD)) {
|
||||||
vm_commit();
|
vm_commit();
|
||||||
callee = resolve_method(callee, fiber);
|
callee = resolve_method(callee, fiber);
|
||||||
@@ -1039,10 +1089,16 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
janet_fiber_popframe(fiber);
|
janet_fiber_popframe(fiber);
|
||||||
stack = fiber->data + fiber->frame;
|
stack = fiber->data + fiber->frame;
|
||||||
stack[A] = ret;
|
stack[A] = ret;
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_do_hook_return(stack[A]);
|
||||||
|
}
|
||||||
vm_checkgc_pcnext();
|
vm_checkgc_pcnext();
|
||||||
} else {
|
} else {
|
||||||
vm_commit();
|
vm_commit();
|
||||||
stack[A] = call_nonfn(fiber, callee);
|
stack[A] = call_nonfn(fiber, callee);
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_do_hook_return(stack[A]);
|
||||||
|
}
|
||||||
vm_pcnext();
|
vm_pcnext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1053,6 +1109,10 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
if (fiber->stacktop > fiber->maxstack) {
|
if (fiber->stacktop > fiber->maxstack) {
|
||||||
vm_throw("stack overflow");
|
vm_throw("stack overflow");
|
||||||
}
|
}
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_commit();
|
||||||
|
vm_do_hook_tailcall(callee, fiber->stacktop - fiber->stackstart, fiber->data + fiber->stackstart);
|
||||||
|
}
|
||||||
if (janet_checktype(callee, JANET_KEYWORD)) {
|
if (janet_checktype(callee, JANET_KEYWORD)) {
|
||||||
vm_commit();
|
vm_commit();
|
||||||
callee = resolve_method(callee, fiber);
|
callee = resolve_method(callee, fiber);
|
||||||
@@ -1089,6 +1149,9 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
|||||||
}
|
}
|
||||||
vm_restore();
|
vm_restore();
|
||||||
stack[A] = retreg;
|
stack[A] = retreg;
|
||||||
|
if (janet_vm.hook) {
|
||||||
|
vm_do_hook_return(stack[A]);
|
||||||
|
}
|
||||||
vm_checkgc_pcnext();
|
vm_checkgc_pcnext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1440,6 +1503,8 @@ void janet_restore(JanetTryState *state) {
|
|||||||
janet_vm.fiber = state->vm_fiber;
|
janet_vm.fiber = state->vm_fiber;
|
||||||
janet_vm.signal_buf = state->vm_jmp_buf;
|
janet_vm.signal_buf = state->vm_jmp_buf;
|
||||||
janet_vm.return_reg = state->vm_return_reg;
|
janet_vm.return_reg = state->vm_return_reg;
|
||||||
|
/* In case of error/signal thrown when inside a temporarily disabled hook */
|
||||||
|
janet_vm.hook = janet_vm.hook_reset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JanetSignal janet_continue_no_check(JanetFiber *fiber, Janet in, Janet *out) {
|
static JanetSignal janet_continue_no_check(JanetFiber *fiber, Janet in, Janet *out) {
|
||||||
@@ -1631,6 +1696,10 @@ int janet_init(void) {
|
|||||||
/* Dynamic bindings */
|
/* Dynamic bindings */
|
||||||
janet_vm.top_dyns = NULL;
|
janet_vm.top_dyns = NULL;
|
||||||
|
|
||||||
|
/* Hooks */
|
||||||
|
janet_vm.hook = NULL;
|
||||||
|
janet_vm.hook_reset = NULL;
|
||||||
|
|
||||||
/* Seed RNG */
|
/* Seed RNG */
|
||||||
janet_rng_seed(janet_default_rng(), 0);
|
janet_rng_seed(janet_default_rng(), 0);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
@@ -1442,6 +1442,7 @@ 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);
|
||||||
|
|
||||||
@@ -2180,7 +2181,9 @@ typedef enum {
|
|||||||
RULE_UNREF, /* [rule, tag] */
|
RULE_UNREF, /* [rule, tag] */
|
||||||
RULE_CAPTURE_NUM, /* [rule, tag] */
|
RULE_CAPTURE_NUM, /* [rule, tag] */
|
||||||
RULE_SUB, /* [rule, rule] */
|
RULE_SUB, /* [rule, rule] */
|
||||||
RULE_SPLIT /* [rule, rule] */
|
RULE_SPLIT, /* [rule, rule] */
|
||||||
|
RULE_NTH, /* [nth, rule, tag] */
|
||||||
|
RULE_ONLY_TAGS, /* [rule] */
|
||||||
} JanetPegOpcod;
|
} JanetPegOpcod;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
@@ -986,4 +986,13 @@
|
|||||||
(assert (deep= (get (dyn 'a) :source-form) source))
|
(assert (deep= (get (dyn 'a) :source-form) source))
|
||||||
(setdyn *debug* nil)
|
(setdyn *debug* nil)
|
||||||
|
|
||||||
|
# issue #1516
|
||||||
|
(assert-error "assertf 1 argument" (macex '(assertf true)))
|
||||||
|
(assert (assertf true "fun message") "assertf 2 arguments")
|
||||||
|
(assert (assertf true "%s message" "mystery") "assertf 3 arguments")
|
||||||
|
(assert (assertf (not nil) "%s message" "ordinary") "assertf not nil")
|
||||||
|
(assert-error "assertf error 2" (assertf false "fun message"))
|
||||||
|
(assert-error "assertf error 3" (assertf false "%s message" "mystery"))
|
||||||
|
(assert-error "assertf error 4" (assertf nil "%s %s" "alice" "bob"))
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
|||||||
@@ -117,6 +117,11 @@
|
|||||||
(assert (= 0 (length (bundle/list))) "bundles are listed correctly 7")
|
(assert (= 0 (length (bundle/list))) "bundles are listed correctly 7")
|
||||||
(assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8")
|
(assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8")
|
||||||
|
|
||||||
|
# Try installing a bundle that fails check
|
||||||
|
(assert-error "bad test" (bundle/install "./examples/sample-bad-bundle" :check true))
|
||||||
|
(assert (= 0 (length (bundle/list))) "check failure 0")
|
||||||
|
(assert (= 0 (length (bundle/topolist))) "check failure 1")
|
||||||
|
|
||||||
(rmrf syspath)
|
(rmrf syspath)
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
|||||||
@@ -52,5 +52,7 @@
|
|||||||
(assert (= 26 (ffi/size [:char :pack :int @[:char 21]]))
|
(assert (= 26 (ffi/size [:char :pack :int @[:char 21]]))
|
||||||
"array struct size"))
|
"array struct size"))
|
||||||
|
|
||||||
(end-suite)
|
(compwhen has-ffi
|
||||||
|
(assert-error "bad struct issue #1512" (ffi/struct :void)))
|
||||||
|
|
||||||
|
(end-suite)
|
||||||
|
|||||||
@@ -664,6 +664,8 @@
|
|||||||
@[]) "peg if not")
|
@[]) "peg if not")
|
||||||
|
|
||||||
(defn test [name peg input expected]
|
(defn test [name peg input expected]
|
||||||
|
(assert-no-error "compile peg" (peg/compile peg))
|
||||||
|
(assert-no-error "marshal/unmarshal peg" (-> peg marshal unmarshal))
|
||||||
(assert (deep= (peg/match peg input) expected) name))
|
(assert (deep= (peg/match peg input) expected) name))
|
||||||
|
|
||||||
(test "sub: matches the same input twice"
|
(test "sub: matches the same input twice"
|
||||||
@@ -756,5 +758,19 @@
|
|||||||
"a,b,c"
|
"a,b,c"
|
||||||
@["a" "b" "c"])
|
@["a" "b" "c"])
|
||||||
|
|
||||||
|
(test "nth 1"
|
||||||
|
~{:prefix (number :d+ nil :n)
|
||||||
|
:word '(lenprefix (-> :n) :w)
|
||||||
|
:main (some (nth 1 (* :prefix ":" :word)))}
|
||||||
|
"5:apple6:banana6:cherry"
|
||||||
|
@["apple" "banana" "cherry"])
|
||||||
|
|
||||||
|
(test "only-tags 1"
|
||||||
|
~{:prefix (number :d+ nil :n)
|
||||||
|
:word (capture (lenprefix (-> :n) :w) :W)
|
||||||
|
:main (some (* (only-tags (* :prefix ":" :word)) (-> :W)))}
|
||||||
|
"5:apple6:banana6:cherry"
|
||||||
|
@["apple" "banana" "cherry"])
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 Calvin Rose
|
* Copyright (c) 2024 Calvin Rose
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to
|
* of this software and associated documentation files (the "Software"), to
|
||||||
|
|||||||
Reference in New Issue
Block a user