Skip to content

magi8101/byte-calci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bytecode Calculator

A GUI calculator built in Rust with a complete bytecode compilation pipeline. Runs natively on Windows/Mac/Linux and in web browsers via WebAssembly.

Features

  • Bytecode Compiler Pipeline: Tokenizer → Parser → AST → CodeGenerator → Bytecode → VM
  • GUI Interface: Built with egui/eframe
  • Cross-Platform: Native desktop + WebAssembly

Math Operations

  • Basic: +, -, *, /, %, ^ (power), ** (power)
  • Functions: sin, cos, tan, sqrt, abs, ln, log, exp, floor, ceil, round
  • Extended: sinh, cosh, tanh, factorial, gcd, lcm, nPr, nCr

Arrays

[1, 2, 3, 4, 5]
sum([1,2,3])    → 6
avg([1,2,3])    → 2
min([1,2,3])    → 1
max([1,2,3])    → 3
len([1,2,3])    → 3

Build

Native

cargo build --release
cargo run --release

Web (WebAssembly)

Prerequisites:

rustup target add wasm32-unknown-unknown
cargo install trunk

Development server:

trunk serve

Production build:

trunk build --release

Output in dist/ folder - deploy to any static hosting.

Architecture

src/
├── main.rs          # Entry point (native + wasm)
├── lib.rs           # Library exports
├── tokenizer.rs     # Lexical analysis
├── ast.rs           # Abstract Syntax Tree
├── parser.rs        # Expression parser
├── bytecode.rs      # Bytecode definitions
├── codegen.rs       # Bytecode generator
├── vm.rs            # Virtual machine
├── disassembler.rs  # Bytecode disassembly
└── gui.rs           # egui interface

License

MIT

About

this is a calculator with a vm architecture for learning purpose

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published