Skip to content

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Apr 22, 2025

This PRs adds an example implementation of a LC3 virtual machine, based on Write your Own Virtual Machine, by Justin Meiners and Ryan Pendleton.

I added the full implementation to examples/lc3. Additionally, I changed some elements of the standard library.

The implementation contains some FIX notes, that indicate that I had to use a hacky solution to workaround a current limitation of the language.

Some important features that are missing are:

  • Call a method from inside of a method
  • Take references of struct indexes or array elements: &self.field.inner or &self.field[3].
    • This allows for calling method on struct field elements.
  • If-Else chains.
  • Match statement for non enum values.
  • C-like Enums?
  • Initializing static arrays without specifying every value: [0; 3] instead of [0, 0, 0].
  • Bitwise operations: &, <<, >>.

Debugging is also bit difficult right now, as we don't have a good way to format values. The workaround I found is to write raw data to a file, and read it with another tool. As an example, I added a justfile with some commands that allowed me to inspect the raw data.

Implementation

  • Inst: BR
  • Inst: ADD
  • Inst: LD
  • Inst: ST
  • Inst: JSR
  • Inst: AND
  • Inst: LDR
  • Inst: STR
  • Inst: RTI
  • Inst: NOT
  • Inst: LDI
  • Inst: STI
  • Inst: JMP
  • Inst: RES
  • Inst: LEA
  • Inst: TRA
    • Trap: GETC
    • Trap: OUT
    • Trap: PUTS
    • Trap: IN
    • Trap: PUTSP
    • Trap: HALT

@github-actions
Copy link

github-actions bot commented Apr 22, 2025

Benchmarking (Linux) factorial

Compiling factorial (factorial.con)
Finished release in 34.454042ms
Running 5000000 iterations
Using input value: 20
Concrete Result = 2432902008176640000 Time taken : 97.03 ms
Rust Result = 2432902008176640000 Time taken : 60.42 ms

Benchmarking (Linux) fib

Compiling fib (fib.con)
Finished release in 27.514688ms
Running 5000 iterations
Using input value: 20
Concrete Result = 6765 Time taken : 136.85 ms
Rust Result = 6765 Time taken : 85.67 ms

@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.29%. Comparing base (4802a28) to head (ff12de7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #231   +/-   ##
=======================================
  Coverage   56.29%   56.29%           
=======================================
  Files          25       25           
  Lines        5516     5516           
=======================================
  Hits         3105     3105           
  Misses       2411     2411           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Apr 22, 2025

Benchmarking (macOS) factorial

Compiling factorial (factorial.con)
Finished release in 632.687042ms
Running 5000000 iterations
Using input value: 20
Concrete Result = 2432902008176640000 Time taken : 29.77 ms
Rust Result = 2432902008176640000 Time taken : 23.50 ms

Benchmarking (macOS) fib

Compiling fib (fib.con)
Finished release in 107.599833ms
Running 5000 iterations
Using input value: 20
Concrete Result = 6765 Time taken : 92.85 ms
Rust Result = 6765 Time taken : 101.89 ms

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.

2 participants