@raviqqe/stak 0.3.10 → 0.3.11
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 +31 -29
- package/package.json +1 -1
- package/stak_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -7,32 +7,33 @@
|
|
|
7
7
|
|
|
8
8
|
The miniature, embeddable R7RS Scheme implementation in Rust
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Stak Scheme aims to be:
|
|
11
|
+
|
|
12
|
+
- An embeddable Scheme interpreter for Rust with very small memory footprint and reasonable performance
|
|
13
|
+
- The minimal implementation of [the R7RS-small standard][r7rs-small]
|
|
14
|
+
- A subset of [Chibi Scheme](https://github.com/ashinn/chibi-scheme), [Gauche](https://github.com/shirok/Gauche), and [Guile](https://www.gnu.org/software/guile/)
|
|
15
|
+
|
|
16
|
+
For more information and usage, visit [the full documentation](https://raviqqe.github.io/stak).
|
|
11
17
|
|
|
12
18
|
## Install
|
|
13
19
|
|
|
14
|
-
###
|
|
20
|
+
### Libraries
|
|
15
21
|
|
|
16
22
|
To install Stak Scheme as a library in your Rust project, run:
|
|
17
23
|
|
|
18
24
|
```sh
|
|
19
25
|
cargo add stak
|
|
26
|
+
cargo add --build stak-build
|
|
20
27
|
```
|
|
21
28
|
|
|
29
|
+
For full examples, see [the `examples` directory](./examples).
|
|
30
|
+
|
|
22
31
|
### Command line tools
|
|
23
32
|
|
|
24
|
-
To install the Scheme interpreter
|
|
33
|
+
To install the Scheme interpreter as a command, run:
|
|
25
34
|
|
|
26
35
|
```sh
|
|
27
|
-
# Install the Scheme interpreter.
|
|
28
36
|
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
|
```
|
|
37
38
|
|
|
38
39
|
## Examples
|
|
@@ -57,7 +58,7 @@ fn main() -> Result<(), BuildError> {
|
|
|
57
58
|
}
|
|
58
59
|
```
|
|
59
60
|
|
|
60
|
-
Now, you can include the Scheme script into a program in Rust using [the `stak::include_module` macro](https://docs.rs/stak/latest/stak/macro.
|
|
61
|
+
Now, you can include the Scheme script into a program in Rust using [the `stak::include_module` macro](https://docs.rs/stak/latest/stak/macro.include_module.html).
|
|
61
62
|
|
|
62
63
|
```rust
|
|
63
64
|
use core::error::Error;
|
|
@@ -111,7 +112,7 @@ fn run(bytecodes: &[u8]) -> Result<(), SmallError> {
|
|
|
111
112
|
Currently, in-memory standard input (`stdin`) and output (`stdout`) to Scheme scripts are the only way to communicate information between Rust programs and Scheme scripts.
|
|
112
113
|
|
|
113
114
|
```rust
|
|
114
|
-
use core::{error::Error,
|
|
115
|
+
use core::{error::Error, str::{self, FromStr}};
|
|
115
116
|
use stak::{
|
|
116
117
|
device::ReadWriteDevice,
|
|
117
118
|
file::VoidFileSystem,
|
|
@@ -129,21 +130,19 @@ const HEAP_SIZE: usize = 1 << 16;
|
|
|
129
130
|
static MODULE: UniversalModule = include_module!("fibonacci.scm");
|
|
130
131
|
|
|
131
132
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
132
|
-
let
|
|
133
|
-
let mut output = [
|
|
134
|
-
let mut error = [
|
|
133
|
+
let input = 24;
|
|
134
|
+
let mut output = vec![];
|
|
135
|
+
let mut error = vec![];
|
|
135
136
|
|
|
136
137
|
run(&MODULE.bytecode(), input.to_string().as_bytes(), &mut output, &mut error)?;
|
|
137
138
|
|
|
138
|
-
let error = decode_buffer(&error)?;
|
|
139
|
-
|
|
140
139
|
// If stderr is not empty, we assume that some error has occurred.
|
|
141
140
|
if !error.is_empty() {
|
|
142
|
-
return Err(error
|
|
141
|
+
return Err(str::from_utf8(&error)?.into());
|
|
143
142
|
}
|
|
144
143
|
|
|
145
144
|
// Decode and print the output.
|
|
146
|
-
println!("Answer: {}", isize::from_str(&
|
|
145
|
+
println!("Answer: {}", isize::from_str(&str::from_utf8(&output)?)?);
|
|
147
146
|
|
|
148
147
|
Ok(())
|
|
149
148
|
}
|
|
@@ -151,8 +150,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|
|
151
150
|
fn run(
|
|
152
151
|
bytecodes: &[u8],
|
|
153
152
|
input: &[u8],
|
|
154
|
-
output: &mut
|
|
155
|
-
error: &mut
|
|
153
|
+
output: &mut Vec<u8>,
|
|
154
|
+
error: &mut Vec<u8>,
|
|
156
155
|
) -> Result<(), SmallError> {
|
|
157
156
|
let mut heap = [Default::default(); HEAP_SIZE];
|
|
158
157
|
let mut vm = Vm::new(
|
|
@@ -169,15 +168,18 @@ fn run(
|
|
|
169
168
|
vm.initialize(bytecodes.iter().copied())?;
|
|
170
169
|
vm.run()
|
|
171
170
|
}
|
|
172
|
-
|
|
173
|
-
fn decode_buffer(buffer: &[u8]) -> Result<String, Box<dyn Error>> {
|
|
174
|
-
Ok(CStr::from_bytes_until_nul(buffer)
|
|
175
|
-
.map_err(|error| error.to_string())?
|
|
176
|
-
.to_string_lossy()
|
|
177
|
-
.into())
|
|
178
|
-
}
|
|
179
171
|
```
|
|
180
172
|
|
|
173
|
+
## References
|
|
174
|
+
|
|
175
|
+
- This project is based on [Ribbit Scheme][ribbit], the small and portable R4RS implementation.
|
|
176
|
+
- [Scheme][scheme]
|
|
177
|
+
- [The R7RS-small standard][r7rs-small]
|
|
178
|
+
|
|
181
179
|
## License
|
|
182
180
|
|
|
183
181
|
[MIT](https://github.com/raviqqe/stak/blob/main/LICENSE)
|
|
182
|
+
|
|
183
|
+
[scheme]: https://www.scheme.org/
|
|
184
|
+
[r7rs-small]: https://small.r7rs.org/
|
|
185
|
+
[ribbit]: https://github.com/udem-dlteam/ribbit
|
package/package.json
CHANGED
package/stak_wasm_bg.wasm
CHANGED
|
Binary file
|