Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rust Inpterpreter for Esopo language AshPaper conceived by William Hicks

License

NotificationsYou must be signed in to change notification settings

shnewto/ashpaper

Repository files navigation

.github/workflows/ci.ymlcodecovCrates.io VersionCrates.io

AshPaper

An inpterpreter for the Esopo language AshPaper conceived byWilliam Hicks. You can read about it and the Esopo project in Willian Hick's own wordshere. Daniel Temkin also wrote about it on esoteric.codes, you can read thathere. And of course the spec! Checkout that outhere.

How it works

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 ofVec<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 thenon-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 calledlovely-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 syllAblesin the title, count them, as one counts  (q) what other poem, programs can be writ  (a) anything a Turing    machine-machine-machine    would dore/cur    sion works too, in poems, programs, and this       a lovely.poem or a calculator or nothinghow lovely can it be?

Using this library, you can run it with a program that looked like this:

externcrate ashpaper;use std::fs;pubfnmain(){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

WhenRUST_LOG=info is set and the caller initializes logging, you can get at program evaluation info. Here's whatlovely-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  | []

Some caveats about compliance with the informal spec

  • It is possible at this point that my implementation deviates from the spec in unintended ways. If you spot anything like that, please raise an issue ❤️ ❤️
  • The alliteration and rhyming rules are still unimplemented.

[8]ページ先頭

©2009-2025 Movatter.jp