@raviqqe/stak 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,12 +3,80 @@
|
|
|
3
3
|
[](https://github.com/raviqqe/stak/actions)
|
|
4
4
|
[](https://crates.io/crates/stak)
|
|
5
5
|
[](https://codecov.io/gh/raviqqe/stak)
|
|
6
|
-
[](LICENSE)
|
|
6
|
+
[](https://github.com/raviqqe/stak/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The miniature, embeddable R7RS Scheme implementation in Rust
|
|
9
9
|
|
|
10
|
-
The documentation is [here](https://raviqqe.github.io/stak).
|
|
10
|
+
The full documentation is [here](https://raviqqe.github.io/stak).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
### Library
|
|
15
|
+
|
|
16
|
+
To install Stak Scheme as a library in your Rust project, run:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
cargo add stak
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Command line tools
|
|
23
|
+
|
|
24
|
+
To install the Scheme interpreter and alike as command line tools, run:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
# Install the Scheme interpreter.
|
|
28
|
+
cargo install stak
|
|
29
|
+
|
|
30
|
+
# Install the minimal Scheme interpreter (6 times smaller!)
|
|
31
|
+
cargo install mstak
|
|
32
|
+
|
|
33
|
+
# Install the Scheme-to-bytecode compiler and bytecode interpreter.
|
|
34
|
+
cargo install stak-compile
|
|
35
|
+
cargo install stak-interpret
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
### Running a Scheme script
|
|
41
|
+
|
|
42
|
+
```rust
|
|
43
|
+
use core::error::Error;
|
|
44
|
+
use stak::{
|
|
45
|
+
build::include_bytecode,
|
|
46
|
+
device::StdioDevice,
|
|
47
|
+
file::VoidFileSystem,
|
|
48
|
+
process_context::VoidProcessContext,
|
|
49
|
+
r7rs::{SmallError, SmallPrimitiveSet},
|
|
50
|
+
time::VoidClock,
|
|
51
|
+
vm::Vm,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const HEAP_SIZE: usize = 1 << 16;
|
|
55
|
+
const BYTECODES: &[u8] = include_bytecode!("hello.scm");
|
|
56
|
+
|
|
57
|
+
fn main() -> Result<(), Box<dyn Error>> {
|
|
58
|
+
run(BYTECODES)?;
|
|
59
|
+
|
|
60
|
+
Ok(())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn run(bytecodes: &[u8]) -> Result<(), SmallError> {
|
|
64
|
+
let mut heap = [Default::default(); HEAP_SIZE];
|
|
65
|
+
let mut vm = Vm::new(
|
|
66
|
+
&mut heap,
|
|
67
|
+
SmallPrimitiveSet::new(
|
|
68
|
+
StdioDevice::new(),
|
|
69
|
+
VoidFileSystem::new(),
|
|
70
|
+
VoidProcessContext::new(),
|
|
71
|
+
VoidClock::new(),
|
|
72
|
+
),
|
|
73
|
+
)?;
|
|
74
|
+
|
|
75
|
+
vm.initialize(bytecodes.iter().copied())?;
|
|
76
|
+
vm.run()
|
|
77
|
+
}
|
|
78
|
+
```
|
|
11
79
|
|
|
12
80
|
## License
|
|
13
81
|
|
|
14
|
-
[MIT](LICENSE)
|
|
82
|
+
[MIT](https://github.com/raviqqe/stak/blob/main/LICENSE)
|