Skip to content

Commit

Permalink
Encoding v2 (#1626)
Browse files Browse the repository at this point in the history
# Todo

- [ ] Re-add unit tests in the `vm` module.
- [x] Share all types of values.
- [x] Strip `nop` instructions.
- [x] Support encoding of floating-point numbers.
- [x] Optimize cons allocation in decoding.

# References

- #1650
  • Loading branch information
raviqqe authored Nov 11, 2024
1 parent 8c40c89 commit 9d3f4ed
Show file tree
Hide file tree
Showing 22 changed files with 502 additions and 1,070 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ jobs:
- ubuntu-latest
- macos-14
interpreter:
- name: stak-tools
host: chibi-scheme
- name: stak-tools
host: gosh
- name: stak-tools
host: guile
- name: stak-tools
host: gosh
features:
- gc_always
tags: not @long
# TODO Enable `stak-tools` tests.
# - name: stak-tools
# host: chibi-scheme
# - name: stak-tools
# host: gosh
# - name: stak-tools
# host: guile
# - name: stak-tools
# host: gosh
# features:
# - gc_always
# tags: not @long
- name: chibi
tags: (not @stak or @chibi) and not @library
- name: gauche
Expand Down
2 changes: 2 additions & 0 deletions cmd/decode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//! stak-decode < foo.bc
//! ```
// TODO Rewrite in Scheme.

use main_error::MainError;
use stak_code::decode;
use std::io::{stdin, Read};
Expand Down
14 changes: 14 additions & 0 deletions code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub use encode::encode;
pub use error::Error;
pub use ir::*;

// TODO Migrate to v2.

/// A number of bits required to encode an instruction in bytecodes.
pub const INSTRUCTION_BITS: u64 = 4;
/// A mask for instruction bits in bytecodes.
Expand All @@ -38,6 +40,18 @@ pub const SYMBOL_SEPARATOR: u8 = 0xFE;
/// A symbol terminator.
pub const SYMBOL_TERMINATOR: u8 = 0xFF;

/// Encoding v2
pub mod v2 {
/// A base for integer encoding in bytecodes.
pub const INTEGER_BASE: u128 = 1 << 7;
/// A base for runtime number encoding in bytecodes.
pub const NUMBER_BASE: u128 = 1 << 6;
/// A base for tag encoding in bytecodes.
pub const TAG_BASE: u128 = 1 << 5;
/// A base for shared node encoding in bytecodes.
pub const SHARE_BASE: u128 = (1 << 5) - 1;
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 9d3f4ed

Please sign in to comment.