Skip to content

Commit

Permalink
Update REPL docs and switch to MEMPHIS_ENGINE envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
JonesBeach committed Oct 21, 2024
1 parent 35cba88 commit 547fa0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Use `memphis` as if it were `python`/`python3` and provide the path to a Python
```bash
memphis examples/test.py

# or run using the bytecode VM (many features currently unsupported)
memphis examples/test.py vm
# or run using the bytecode VM (WARNING: many features currently unsupported)
MEMPHIS_ENGINE=vm memphis examples/test.py
```
Or launch the REPL.
Or launch the REPL (requires a build with the `repl` feature flag).
```bash
> memphis
memphis 0.1.0 REPL (Type 'exit()' to quit)
Expand Down
13 changes: 9 additions & 4 deletions docs/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ cargo build
cargo test
cargo run examples/test.py
```
## REPL
The REPL is useful for interactive mode.
```bash
cargo run --features repl
```
## Feature Flags
Feature flags are needed to enable C stdlib or REPL support (or the experimental LLVM backend).
```bash
Expand All @@ -19,15 +24,15 @@ cargo run --features c_stdlib examples/test.py
To compare runtime, we can build in release mode and use the different engines.
```bash
cargo install --path . --all-features
hyperfine "memphis examples/loop_perf.py tw" "memphis examples/loop_perf.py vm" "memphis examples/loop_perf.py llvm" --warmup 5
hyperfine "memphis examples/loop_perf.py" "MEMPHIS_ENGINE=vm memphis examples/loop_perf.py" "MEMPHIS_ENGINE=llvm_backend memphis examples/loop_perf.py" --warmup 5
```
### Flamegraph
This is a cool way to visualize why a bytecode VM is more performant than a treewalk interpreter.
```bash
cargo install flamegraph
cargo build --all-features
# we require debug symbols to produce a flamegraph, hence invoking the binary from `target/debug`.
sudo flamegraph -v -o tw.svg -- target/debug/memphis examples/loop_perf.py tw
sudo flamegraph -v -o vm.svg -- target/debug/memphis examples/loop_perf.py vm
sudo flamegraph -v -o llvm.svg -- target/debug/memphis examples/loop_perf.py llvm
sudo flamegraph -v -o tw.svg -- target/debug/memphis examples/loop_perf.py
sudo flamegraph -v -o vm.svg -- MEMPHIS_ENGINE=vm target/debug/memphis examples/loop_perf.py
sudo flamegraph -v -o llvm.svg -- MEMPHIS_ENGINE=llvm_backend target/debug/memphis examples/loop_perf.py
```
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_ENGINE: Engine = Engine::TreeWalk;
fn main() {
let args: Vec<String> = env::args().collect();

let engine = if let Some(mode) = args.get(2) {
let engine = if let Ok(mode) = env::var("MEMPHIS_ENGINE") {
match mode.to_lowercase().as_str() {
"vm" | "bytecode_vm" => Engine::BytecodeVm,
#[cfg(feature = "llvm_backend")]
Expand All @@ -30,7 +30,7 @@ fn main() {
eprintln!("Must enable 'repl' feature flag!");
process::exit(1);
}
2 | 3 => Memphis::start(&args[1], engine),
2 => Memphis::start(&args[1], engine),
_ => {
eprintln!("Usage: memphis [<filename>]");
process::exit(1);
Expand Down
1 change: 1 addition & 0 deletions test_features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ features=(
"c_stdlib"
"repl"
"c_stdlib repl"
"llvm_backend" # test this by itself for now just to ensure we didn't break it
)

for feature_set in "${features[@]}"; do
Expand Down
4 changes: 2 additions & 2 deletions tests/other_backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process::Command;
fn run_script_and_compare(script: &'static str) {
let output = Command::new("target/debug/memphis")
.arg(script)
.arg("vm")
.env("MEMPHIS_ENGINE", "vm")
.output()
.expect("Failed to run test script");

Expand Down Expand Up @@ -54,7 +54,7 @@ mod llvm_backend_tests {
fn run_script(script: &'static str) {
let output = Command::new("target/debug/memphis")
.arg(script)
.arg("llvm")
.env("MEMPHIS_ENGINE", "llvm")
.output()
.expect("Failed to run test script");

Expand Down

0 comments on commit 547fa0a

Please sign in to comment.