Skip to content

[WIP] map constructors for the VM #2153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 55 commits into
base: canary
Choose a base branch
from
Draft

Conversation

ba11b0y
Copy link
Contributor

@ba11b0y ba11b0y commented Jul 16, 2025

No description provided.

antoniosarosi and others added 30 commits June 20, 2025 01:44
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Add support for storing string constants in the VM's object pool
during compilation and update tests and documentation accordingly.
> 
>   - **Compiler Changes**:
> - Add `objects` field to `Compiler` struct in `lib.rs` to store
heap-allocated objects like string constants.
> - Modify `compile_expression()` in `lib.rs` to handle
`Expression::StringValue` by storing strings in the `objects` pool and
emitting `LoadConst` instructions.
>   - **Testing**:
> - Add `function_returning_string` and `multiple_strings` tests in
`vm.rs` to verify string handling in the VM.
>   - **Documentation**:
> - Add `CLAUDE.md` to provide guidance for working with the BAML
compiler and related components.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for e1a7267. You can
[customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
antoniosarosi and others added 22 commits July 11, 2025 18:16
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Add source line number tracking to bytecode generation and display for
improved debugging context.
> 
>   - **Behavior**:
> - Track source line numbers in `Compiler` in `lib.rs` using
`current_source_line` and `set_source_line_from_span()`.
> - Update `emit()` in `lib.rs` to push `current_source_line` to
`source_lines` in `Bytecode`.
> - Modify `display_bytecode()` in `debug.rs` to include source line
numbers in output.
>   - **Data Structures**:
> - Add `source_lines: Vec<usize>` to `Bytecode` in `bytecode.rs` to map
instructions to source lines.
>   - **Misc**:
> - Remove unused span variables in `compile_expression()` in `lib.rs`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for d0aa17a. You can
[customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
100% vibe coded to pretty print instructions based on their type.

<img width="443" height="223" alt="image"
src="https://github.com/user-attachments/assets/4630630d-6b2a-478e-abde-ed2d356658c5"
/>

<img width="443" height="223" alt="image"
src="https://github.com/user-attachments/assets/679fa3cb-e6c8-4414-ab97-35a5000185c7"
/>

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Add color-coded pretty printing for bytecode instructions in BAML VM
using the `colored` crate.
> 
>   - **Behavior**:
> - `display_bytecode()` in `debug.rs` now pretty prints bytecode with
colors based on instruction type.
>     - Uses `colored` crate to apply colors if output is to a TTY.
>   - **Functions**:
> - Adds `get_instruction_color()` in `debug.rs` to map instructions to
colors.
>   - **Dependencies**:
>     - Adds `colored = "2.1.0"` to `Cargo.toml`.
>   - **Versioning**:
>     - Updates `baml-vm` and `baml-compiler` versions in `Cargo.lock`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for ef0124e. You can
[customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
TODO: nested for loops don't work right now.
<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> Implement for loop support in Baml compiler and VM, adding iterator
instructions and tests.
> 
>   - **Behavior**:
> - Implement for loop compilation in `lib.rs`, handling iterator
creation and loop execution.
> - Add `CreateIterator` and `IterNext` instructions in `bytecode.rs`
for iterator operations.
> - Update VM execution in `vm.rs` to handle new instructions and manage
iterators.
>   - **Testing**:
> - Add tests for for loops and iterator instructions in `vm.rs` and
`tests/vm.rs`.
> - Ensure correct execution of simple and nested for loops, and
iterator operations.
>   - **Misc**:
>     - Update `debug.rs` to display new instructions.
> - Add comments and TODOs for future improvements and nested loop
support.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for e5bd0bb. You can
[customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Antonio Sarosi <sarosiantonio@gmail.com>
Copy link

vercel bot commented Jul 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2025 10:41pm

@ba11b0y ba11b0y changed the title map constructors for the VM [WIP] map constructors for the VM Jul 16, 2025
Base automatically changed from antonio/vm to canary August 12, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants