Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/badboy/small-step-simple-rust
https://fnordig.de/2014/08/12/first-experience-with-rust/
https://github.com/badboy/small-step-simple-rust
Last synced: 9 days ago
JSON representation
https://fnordig.de/2014/08/12/first-experience-with-rust/
- Host: GitHub
- URL: https://github.com/badboy/small-step-simple-rust
- Owner: badboy
- Created: 2014-08-12T10:33:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-03T19:50:04.000Z (almost 10 years ago)
- Last Synced: 2024-12-24T02:01:36.465Z (12 days ago)
- Language: Rust
- Size: 693 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# small-step approach to the SIMPLE language in Rust
[Blog post about my first experience with Rust](https://fnordig.de/2014/08/12/first-experience-with-rust/)
---
This is an implementation of the small-step approach to the SIMPLE language as introduced by
[Tom Stuart](https://twitter.com/tomstuart) in "Understanding Computation", Chapter 1, "The Meaning of Programs".
See his website: .The usage is pretty simple. As there is no parser for SIMPLE (yet?) you have to write the AST
yourself. A few macros are provided for easy access. You can then create a virtual machine and
pass this AST plus an environment hash. When calling `run`, the machine steps through the code,
reducing it until it reaches a point where no further reduction is possible.```rust
let mut env = HashMap::new();
env.insert("y".to_string(), number!(1));let mut m = Machine::new(
sequence!(
assign!("x", number!(3)),
assign!("res", add!(add!(number!(38), variable!("x")), variable!("y")))
),
env
);m.run();
// At this point `res` in the HashMap will be `Number(42)`
```The code is much larger as the equivalent Ruby code. This is both due to the restricitions
of Rust (explicit types and everything, a good thing) and my non-existing experience with Rust
at all (this is my first Rust code larger than a simple "Hello World")## License
Just like the [original Ruby source code](https://github.com/tomstuart/computationbook), this Rust source code is released under the [CC0 1.0 Public Domain Dedication](http://creativecommons.org/publicdomain/zero/1.0/), which means that you can do whatever you like with it.