Crates.io | ashpaper |
lib.rs | ashpaper |
version | 0.3.0 |
source | src |
created_at | 2019-10-18 04:08:16.812186 |
updated_at | 2019-10-23 04:08:18.372948 |
description | Rust Inpterpreter for Esopo language AshPaper conceived by William Hicks |
homepage | https://github.com/shnewto/ashpaper |
repository | https://github.com/shnewto/ashpaper |
max_upload_size | |
id | 173602 |
size | 23,607 |
An inpterpreter for the Esopo language AshPaper conceived by William Hicks. You can read about it and the Esopo project n Willian Hick's own words here. Daniel Temkin also wrote about it on esoteric.codes, you can read that here. And of course the spec! Checkout that out here.
Poetry is your program.
You have two registers at your disposal, r0 and r1 which store signed integers (i64
).
You also have an stack which can store signed integers (bounds are only that of Vec<i64>
).
Here are the instructions at your disposal (in order that they get precedence):
End rhyme with previous line: Unimplemented.
Line contains /
: If the value in the active register is greater than the number of syllables in the line, go to the line number that corresponds to the value in the non-active register. If abs(n) <= lines then n, else n % lines.
Capital letter appears inside a word: Negate the active register.
Capital letter appears at the beginning of a word: Multiply registers and store result in the active register.
Line contains the words 'like' or 'as': Add registers and store in the active register.
Line contains ?
: Print ASCII character associated with value of the active register. If abs(n) <= u8::MAX n, else n % u8::MAX.
Line contains .
: Print integer value of the active register.
Line contains ,
: Pop from the stack and store in the active register.
Line contains -
: Push the value of the active register to the stack.
Alleteration of consecutive words: Unimplemented.
Blank line: no-op.
Everything else: Store number of syllables in the line to the active register.
Let's take this poem in a file called lovely-poem.eso
.This poem-program (poegram?) calculates factorials and input in the number of syllables in the title. (I learned a lot from reading the poem "other woodwork" by William Hicks)
lovely poem
it is a calculator, like a
poem, is a poem, and finds
factori-
als
The input is the syllAbles
in the title, count them, as one counts
(q) what other poem, programs can be writ
(a) anything a Turing
machine-machine-machine
would do
re/cur
sion works too, in poems, programs, and this
a lovely.
poem or a calculator or nothing
how lovely can it be?
Using this library, you can run it with a program that looked like this:
extern crate ashpaper;
use std::fs;
pub fn main() {
let fname = "lovely-poem.eso";
let contents = fs::read_to_string(fname).expect("Something went wrong reading input file!");
match ashpaper::program::execute(&contents) {
Ok(res) => print!("{}", res),
Err(e) => eprintln!("{}", e),
}
}
And it will produce the following String:
24
When RUST_LOG=info
is set and the caller initializes logging, you can get at program evaluation info. Here's what lovely-poem.eso
looks like.
instruction | r0 | r1 | stack
--------------------------------------------------- | ---- | ---- | -------
lovely poem | 4 | 0 | []
| 4 | 0 | []
it is a calculator, like a | 4 | 4 | []
poem, is a poem, and finds | 4 | 4 | []
factori- | 4 | 4 | [4]
als | 4 | 1 | [4]
The input is the syllAbles | 4 | -1 | [4]
in the title, count them, as one counts | 3 | -1 | [4]
(q) what other poem, programs can be writ | 3 | 4 | []
(a) anything a Turing | 3 | 12 | []
machine-machine-machine | 3 | 12 | [12]
would do | 3 | 2 | [12]
it is a calculator, like a | 3 | 5 | [12]
poem, is a poem, and finds | 3 | 12 | []
factori- | 3 | 12 | [12]
als | 3 | 1 | [12]
The input is the syllAbles | 3 | -1 | [12]
in the title, count them, as one counts | 2 | -1 | [12]
(q) what other poem, programs can be writ | 2 | 12 | []
(a) anything a Turing | 2 | 24 | []
machine-machine-machine | 2 | 24 | [24]
would do | 2 | 2 | [24]
re/cur | 2 | 2 | [24]
sion works too, in poems, programs, and this | 2 | 24 | []
a lovely. | 2 | 24 | []
poem or a calculator or nothing | 10 | 24 | []
how lovely can it be? | 10 | 24 | []