mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Merge branch 'master' into ev
This commit is contained in:
commit
1092013c2b
44
README.md
44
README.md
@ -14,9 +14,9 @@ lisp-like language, but lists are replaced
|
|||||||
by other data structures (arrays, tables (hash table), struct (immutable hash table), tuples).
|
by other data structures (arrays, tables (hash table), struct (immutable hash table), tuples).
|
||||||
The language also supports bridging to native code written in C, meta-programming with macros, and bytecode assembly.
|
The language also supports bridging to native code written in C, meta-programming with macros, and bytecode assembly.
|
||||||
|
|
||||||
There is a repl for trying out the language, as well as the ability
|
There is a REPL for trying out the language, as well as the ability
|
||||||
to run script files. This client program is separate from the core runtime, so
|
to run script files. This client program is separate from the core runtime, so
|
||||||
Janet can be embedded into 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).
|
[https://janet-lang.org](https://janet-lang.org).
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
@ -30,10 +30,10 @@ Lua, but smaller than GNU Guile or Python.
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
* Minimal setup - one binary and you are good to go!
|
* Minimal setup - one binary and you are good to go!
|
||||||
* First class closures
|
* First-class closures
|
||||||
* Garbage collection
|
* Garbage collection
|
||||||
* First class green threads (continuations)
|
* First-class green threads (continuations)
|
||||||
* Python style generators (implemented as a plain macro)
|
* Python-style generators (implemented as a plain macro)
|
||||||
* Mutable and immutable arrays (array/tuple)
|
* Mutable and immutable arrays (array/tuple)
|
||||||
* Mutable and immutable hashtables (table/struct)
|
* Mutable and immutable hashtables (table/struct)
|
||||||
* Mutable and immutable strings (buffer/string)
|
* Mutable and immutable strings (buffer/string)
|
||||||
@ -56,7 +56,7 @@ Lua, but smaller than GNU Guile or Python.
|
|||||||
* For a quick tutorial, see [the introduction](https://janet-lang.org/docs/index.html) for more details.
|
* For a quick tutorial, see [the introduction](https://janet-lang.org/docs/index.html) for more details.
|
||||||
* For the full API for all functions in the core library, see [the core API doc](https://janet-lang.org/api/index.html)
|
* For the full API for all functions in the core library, see [the core API doc](https://janet-lang.org/api/index.html)
|
||||||
|
|
||||||
Documentation is also available locally in the repl.
|
Documentation is also available locally in the REPL.
|
||||||
Use the `(doc symbol-name)` macro to get API
|
Use the `(doc symbol-name)` macro to get API
|
||||||
documentation for symbols in the core library. For example,
|
documentation for symbols in the core library. For example,
|
||||||
```
|
```
|
||||||
@ -66,7 +66,7 @@ Shows documentation for the doc macro.
|
|||||||
|
|
||||||
To get a list of all bindings in the default
|
To get a list of all bindings in the default
|
||||||
environment, use the `(all-bindings)` function. You
|
environment, use the `(all-bindings)` function. You
|
||||||
can also use the `(doc)` macro with no arguments if you are in the repl
|
can also use the `(doc)` macro with no arguments if you are in the REPL
|
||||||
to show bound symbols.
|
to show bound symbols.
|
||||||
|
|
||||||
## Source
|
## Source
|
||||||
@ -92,7 +92,7 @@ Find out more about the available make targets by running `make help`.
|
|||||||
|
|
||||||
### 32-bit Haiku
|
### 32-bit Haiku
|
||||||
|
|
||||||
32-bit Haiku build instructions are the same as the unix-like build instructions,
|
32-bit Haiku build instructions are the same as the UNIX-like build instructions,
|
||||||
but you need to specify an alternative compiler, such as `gcc-x86`.
|
but you need to specify an alternative compiler, such as `gcc-x86`.
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -104,7 +104,7 @@ make repl
|
|||||||
|
|
||||||
### FreeBSD
|
### FreeBSD
|
||||||
|
|
||||||
FreeBSD build instructions are the same as the unix-like build instuctions,
|
FreeBSD build instructions are the same as the UNIX-like build instructions,
|
||||||
but you need `gmake` to compile. Alternatively, install directly from
|
but you need `gmake` to compile. Alternatively, install directly from
|
||||||
packages, using `pkg install lang/janet`.
|
packages, using `pkg install lang/janet`.
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ gmake repl
|
|||||||
|
|
||||||
### NetBSD
|
### NetBSD
|
||||||
|
|
||||||
NetBSD build instructions are the same as the FreeBSD build instuctions.
|
NetBSD build instructions are the same as the FreeBSD build instructions.
|
||||||
Alternatively, install directly from packages, using `pkgin install janet`.
|
Alternatively, install directly from packages, using `pkgin install janet`.
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
@ -136,11 +136,11 @@ Now you should have an `.msi`. You can run `build_win install` to install the `.
|
|||||||
|
|
||||||
### Meson
|
### Meson
|
||||||
|
|
||||||
Janet also has a build file for [Meson](https://mesonbuild.com/), a cross platform build
|
Janet also has a build file for [Meson](https://mesonbuild.com/), a cross-platform build
|
||||||
system. Although Meson has a python dependency, Meson is a very complete build system that
|
system. Although Meson has a Python dependency, Meson is a very complete build system that
|
||||||
is maybe more convenient and flexible for integrating into existing pipelines.
|
is maybe more convenient and flexible for integrating into existing pipelines.
|
||||||
Meson also provides much better IDE integration than Make or batch files, as well as support
|
Meson also provides much better IDE integration than Make or batch files, as well as support
|
||||||
for cross compilation.
|
for cross-compilation.
|
||||||
|
|
||||||
For the impatient, building with Meson is as follows. The options provided to
|
For the impatient, building with Meson is as follows. The options provided to
|
||||||
`meson setup` below emulate Janet's Makefile.
|
`meson setup` below emulate Janet's Makefile.
|
||||||
@ -177,11 +177,11 @@ to try out the language, you don't need to install anything. You can also move t
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
A repl is launched when the binary is invoked with no arguments. Pass the -h flag
|
A REPL is launched when the binary is invoked with no arguments. Pass the -h flag
|
||||||
to display the usage information. Individual scripts can be run with `./janet myscript.janet`
|
to display the usage information. Individual scripts can be run with `./janet myscript.janet`
|
||||||
|
|
||||||
If you are looking to explore, you can print a list of all available macros, functions, and constants
|
If you are looking to explore, you can print a list of all available macros, functions, and constants
|
||||||
by entering the command `(all-bindings)` into the repl.
|
by entering the command `(all-bindings)` into the REPL.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ janet
|
$ janet
|
||||||
@ -199,13 +199,13 @@ Options are:
|
|||||||
-v : Print the version string
|
-v : Print the version string
|
||||||
-s : Use raw stdin instead of getline like functionality
|
-s : Use raw stdin instead of getline like functionality
|
||||||
-e code : Execute a string of janet
|
-e code : Execute a string of janet
|
||||||
-r : Enter the repl after running all scripts
|
-r : Enter the REPL after running all scripts
|
||||||
-p : Keep on executing if there is a top level error (persistent)
|
-p : Keep on executing if there is a top-level error (persistent)
|
||||||
-q : Hide prompt, logo, and repl output (quiet)
|
-q : Hide prompt, logo, and REPL output (quiet)
|
||||||
-k : Compile scripts but do not execute (flycheck)
|
-k : Compile scripts but do not execute (flycheck)
|
||||||
-m syspath : Set system path for loading global modules
|
-m syspath : Set system path for loading global modules
|
||||||
-c source output : Compile janet source code into an image
|
-c source output : Compile janet source code into an image
|
||||||
-n : Disable ANSI color output in the repl
|
-n : Disable ANSI color output in the REPL
|
||||||
-l path : Execute code in a file before running the main script
|
-l path : Execute code in a file before running the main script
|
||||||
-- : Stop handling options
|
-- : Stop handling options
|
||||||
```
|
```
|
||||||
@ -232,16 +232,16 @@ See the examples directory for some example janet code.
|
|||||||
|
|
||||||
## Discussion
|
## Discussion
|
||||||
|
|
||||||
Feel free to ask questions and join discussion on the [Janet Gitter Channel](https://gitter.im/janet-language/community).
|
Feel free to ask questions and join the discussion on the [Janet Gitter Channel](https://gitter.im/janet-language/community).
|
||||||
Alternatively, check out [the #janet channel on Freenode](https://webchat.freenode.net/)
|
Alternatively, check out [the #janet channel on Freenode](https://webchat.freenode.net/)
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
### Why is my terminal spitting out junk when I run the repl?
|
### Why is my terminal spitting out junk when I run the REPL?
|
||||||
|
|
||||||
Make sure your terminal supports ANSI escape codes. Most modern terminals will
|
Make sure your terminal supports ANSI escape codes. Most modern terminals will
|
||||||
support these, but some older terminals, Windows consoles, or embedded terminals
|
support these, but some older terminals, Windows consoles, or embedded terminals
|
||||||
will not. If your terminal does not support ANSI escape codes, run the repl with
|
will not. If your terminal does not support ANSI escape codes, run the REPL with
|
||||||
the `-n` flag, which disables color output. You can also try the `-s` if further issues
|
the `-n` flag, which disables color output. You can also try the `-s` if further issues
|
||||||
ensue.
|
ensue.
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# Example of dst bytecode assembly
|
# Example of dst bytecode assembly
|
||||||
|
|
||||||
# Fibonacci sequence, implemented with naive recursion.
|
# Fibonacci sequence, implemented with naive recursion.
|
||||||
(def fibasm (asm '{
|
(def fibasm
|
||||||
arity 1
|
(asm
|
||||||
bytecode [
|
'{:arity 1
|
||||||
(ltim 1 0 0x2) # $1 = $0 < 2
|
:bytecode @[(ltim 1 0 0x2) # $1 = $0 < 2
|
||||||
(jmpif 1 :done) # if ($1) goto :done
|
(jmpif 1 :done) # if ($1) goto :done
|
||||||
(lds 1) # $1 = self
|
(lds 1) # $1 = self
|
||||||
(addim 0 0 -0x1) # $0 = $0 - 1
|
(addim 0 0 -0x1) # $0 = $0 - 1
|
||||||
@ -16,8 +16,7 @@
|
|||||||
(add 0 0 2) # $0 = $0 + $2 (integers)
|
(add 0 0 2) # $0 = $0 + $2 (integers)
|
||||||
:done
|
:done
|
||||||
(ret 0) # return $0
|
(ret 0) # return $0
|
||||||
]
|
]}))
|
||||||
}))
|
|
||||||
|
|
||||||
# Test it
|
# Test it
|
||||||
|
|
||||||
|
@ -2786,14 +2786,14 @@
|
|||||||
-v : Print the version string
|
-v : Print the version string
|
||||||
-s : Use raw stdin instead of getline like functionality
|
-s : Use raw stdin instead of getline like functionality
|
||||||
-e code : Execute a string of janet
|
-e code : Execute a string of janet
|
||||||
-d : Set the debug flag in the repl
|
-d : Set the debug flag in the REPL
|
||||||
-r : Enter the repl after running all scripts
|
-r : Enter the REPL after running all scripts
|
||||||
-p : Keep on executing if there is a top level error (persistent)
|
-p : Keep on executing if there is a top-level error (persistent)
|
||||||
-q : Hide logo (quiet)
|
-q : Hide logo (quiet)
|
||||||
-k : Compile scripts but do not execute (flycheck)
|
-k : Compile scripts but do not execute (flycheck)
|
||||||
-m syspath : Set system path for loading global modules
|
-m syspath : Set system path for loading global modules
|
||||||
-c source output : Compile janet source code into an image
|
-c source output : Compile janet source code into an image
|
||||||
-n : Disable ANSI color output in the repl
|
-n : Disable ANSI color output in the REPL
|
||||||
-l lib : Import a module before processing more arguments
|
-l lib : Import a module before processing more arguments
|
||||||
-- : Stop handling options`)
|
-- : Stop handling options`)
|
||||||
(os/exit 0)
|
(os/exit 0)
|
||||||
|
@ -988,7 +988,7 @@ static const JanetReg asm_cfuns[] = {
|
|||||||
{
|
{
|
||||||
"disasm", cfun_disasm,
|
"disasm", cfun_disasm,
|
||||||
JDOC("(disasm func &opt field)\n\n"
|
JDOC("(disasm func &opt field)\n\n"
|
||||||
"Returns assembly that could be used be compile the given function.\n"
|
"Returns assembly that could be used to compile the given function.\n"
|
||||||
"func must be a function, not a c function. Will throw on error on a badly\n"
|
"func must be a function, not a c function. Will throw on error on a badly\n"
|
||||||
"typed argument. If given a field name, will only return that part of the function assembly.\n"
|
"typed argument. If given a field name, will only return that part of the function assembly.\n"
|
||||||
"Possible fields are:\n\n"
|
"Possible fields are:\n\n"
|
||||||
|
@ -108,12 +108,15 @@ static void janet_fiber_refresh_memory(JanetFiber *fiber) {
|
|||||||
|
|
||||||
/* Ensure that the fiber has enough extra capacity */
|
/* Ensure that the fiber has enough extra capacity */
|
||||||
void janet_fiber_setcapacity(JanetFiber *fiber, int32_t n) {
|
void janet_fiber_setcapacity(JanetFiber *fiber, int32_t n) {
|
||||||
|
int32_t old_size = fiber->capacity;
|
||||||
|
int32_t diff = n - old_size;
|
||||||
Janet *newData = realloc(fiber->data, sizeof(Janet) * n);
|
Janet *newData = realloc(fiber->data, sizeof(Janet) * n);
|
||||||
if (NULL == newData) {
|
if (NULL == newData) {
|
||||||
JANET_OUT_OF_MEMORY;
|
JANET_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
fiber->data = newData;
|
fiber->data = newData;
|
||||||
fiber->capacity = n;
|
fiber->capacity = n;
|
||||||
|
janet_vm_next_collection += sizeof(Janet) * diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grow fiber if needed */
|
/* Grow fiber if needed */
|
||||||
|
@ -777,7 +777,7 @@ static const JanetReg io_cfuns[] = {
|
|||||||
#ifndef JANET_NO_PROCESSES
|
#ifndef JANET_NO_PROCESSES
|
||||||
{
|
{
|
||||||
"file/popen", cfun_io_popen,
|
"file/popen", cfun_io_popen,
|
||||||
JDOC("(file/popen path &opt mode)\n\n"
|
JDOC("(file/popen command &opt mode)\n\n"
|
||||||
"Open a file that is backed by a process. The file must be opened in either "
|
"Open a file that is backed by a process. The file must be opened in either "
|
||||||
"the :r (read) or the :w (write) mode. In :r mode, the stdout of the "
|
"the :r (read) or the :w (write) mode. In :r mode, the stdout of the "
|
||||||
"process can be read from the file. In :w mode, the stdin of the process "
|
"process can be read from the file. In :w mode, the stdin of the process "
|
||||||
|
@ -256,7 +256,7 @@ static void janet_table_mergekv(JanetTable *table, const JanetKV *kvs, int32_t c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Merge a table other into another table */
|
/* Merge a table into another table */
|
||||||
void janet_table_merge_table(JanetTable *table, JanetTable *other) {
|
void janet_table_merge_table(JanetTable *table, JanetTable *other) {
|
||||||
janet_table_mergekv(table, other->data, other->capacity);
|
janet_table_mergekv(table, other->data, other->capacity);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user