crystabit 0.3.0-preview
crystabit
CaaS (component-as-a-service) CPU emulator, written in functional-style Crystal using TDD.
Definitely a good learning experience.
Installation
First, you need Crystal 0.25.0 or above.
curl -sSL https://dist.crystal-lang.org/apt/setup.sh # Adds repo key & config
sudo !!
sudo apt install crystal
Then, clone repo and install local dependencies...
git clone git@github.com:mmKALLL/crystabit.git
shards install
Usage
You can run local specs using:
crystal spec
Run all specs, including Web API specs with Kemal test server, using:
KEMAL_ENV=test crystal spec
Run CPU emulator and its server on localhost:3000 using:
crystal src/crystabit.cr
Then you can run things using the REST API! (Examples written with HTTPie, but cURL works just as well.)
# Sum two Int64 values together:
http get localhost:3000/v1/cpu/exec?opcode=0x7c&inputs=[12,321] # => 333
# Execute from a mnemonic:
http get localhost:3000/v1/cpu/exec?opcode=set_local&inputs=["localvar",1234] # =>
http get localhost:3000/v1/cpu/exec?opcode=get_local&inputs=["localvar"] # => 1234
# Run full-blown WebAssembly from the query string!
http get localhost:3000/v1/cpu/run?program=(local $res i32)(set_local $res (i32.add (2)(7)))(get_local $res)
# ...Or upload a file for immediate interpretation:
http post localhost:3000/v1/cpu/run {program:"..."} # Results in response body
# Please no infinite loops until beta.
Development
Write specs, then write code to implement their features, and refactor when useful. Keep consistent style and have fun!
Contributing
- Fork it (https://github.com/mmKALLL/crystabit/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- [mmKALLL] Esa Koskinen - creator, maintainer
Repository
crystabit
Owner
Statistic
- 0
- 0
- 0
- 0
- 2
- about 4 years ago
- June 26, 2018
License
MIT License
Links
Synced at
Sun, 20 Jul 2025 08:15:09 GMT
Languages