[Question]
  [
[Sandbox](https://codegolf.meta.stackexchange.com/a/20666/80214), [Codidact](https://codegolf.codidact.com/posts/280612)
*A rewrite of [this question](https://codegolf.stackexchange.com/questions/16124/write-an-interactive-deadfish-interpreter) with a simpler input format and guidelines.*
## Challenge
Deadfish uses a single accumulator, on which all commands are to be performed.
It has the following commands:
| Command | Description |
| --- | --- |
| `i` | increment the accumulator |
| `d` | decrement the accumulator |
| `s` | square the value of the accumulator |
| `o` | output the value of the accumulator as a number |
The accumulator starts with a value of zero. If, after executing a command, the accumulator is equal to -1 or equal to 256, the accumulator must be reset to zero.
## I/O
Input can be taken as a single string, list of codepoints, or any other reasonable format. It is guaranteed that the input will only consist of deadfish commands.
Output can be given as an array of numbers, or just the numbers printed with separators between them.
## Testcases
(some are borrowed from the [Esolangs wiki](https://esolangs.org/wiki/Deadfish#Mandatory_test_cases))
```
iissso -> 0
diissisdo -> 288
iissisdddddddddddddddddddddddddddddddddo -> 0
isssoisoisoisoiso -> 1,4,25,676,458329
ooooosioiiisooo -> 0,0,0,0,0,1,16,16,16
iiii -> nothing
iiiiiiiissdiiiiiiiiiiiiiiiiio -> 4112
o -> 0
```
[Without Outputs](https://dzaima.github.io/paste#0y8wsLi7O50rJBNKZxSn5XFAGIQBUCNKYiYS48kGgODM/E2gGkAUA)
  
[Answer]
# [flex](https://www.gnu.org/software/bash/), ~~86~~ \$\cdots\$ ~~83~~ 82 bytes
Saved 2 bytes and got moved into TIO thanks to [Mukundan314](https://codegolf.stackexchange.com/users/91267/mukundan314)!!!
```
%{
a;m(){a*=a!=256;}
%}
%%
i m(++a);
d m(a&&--a);
s m(a*=a);
o printf("%d ",a);
%%
```
[Try it online!](https://tio.run/##hY3BTsNADETP@CuGik1TyqZSpXJJyw2ufMOS3TSW0hjVSG1V@PbgLSAhLoys9Xhkv30J2o1tn45Yrx@fn0Z3plDvytk53G7C9Wa5uq8/yFk5YuzK@TzMaormQlF4nwfNgy2bFbzueXhry4mLmNzlyLnRsETbpoH9Up1OVQMviCnElrWD79ue6NBxn7C30BCyrRGFrlLTCfyAmxxh6h8wRVHgEn9l76gWPySKMqSRWVWFYu6sRvk2/8kW8yH/KpIsZWFjmDMU8@XJUo38V3ZCnw "Bash – Try It Online")
[flex](https://en.wikipedia.org/wiki/Flex_(lexical_analyser_generator)) stands for fast lexical analyser generator. It takes input as above and generates a lexer in C.
The input comprises of a C declaration section:
```
%{
a;m(){a*=a!=256;}
%}
```
where here we simply declare the accumulator `a` (implicitly as an `int`) and a function to set the accumulator to \$0\$ if it's \$256\$ after a computation.
This is followed by the rules section comprised of all the regexes that need to be parsed along with their actions (in C):
```
%%
i m(++a);
d m(a&&--a);
s m(a*=a);
o printf("%d ",a);
%%   
```
here we have our 4 characters along with the code to run when each is encountered. Decrement will only happen if the accumulator is non-zero.
There's a program section that follows this but it will simply default to a `main` that runs the parser if left out (as in this case).
You can generate the C-source code lexer from the above (in file `deadfish.l`) and compile it with the following:
```
flex deadfish.l
gcc lex.yy.c -o deadfish -lfl  
```
After compiling, running the following:
```
echo iissso | ./deadfish
echo diissisdo | ./deadfish
echo iissisdddddddddddddddddddddddddddddddddo | ./deadfish
echo isssoisoisoisoiso | ./deadfish
echo ooooosioiiisooo | ./deadfish
echo iiiiiiiissdiiiiiiiiiiiiiiiiio | ./deadfish  
```
outputs:
```
0
288
0
1 4 25 676 458329
0 0 0 0 0 1 16 16 16
4112   
```
You can also just run it as `./deadfish` and have an interactive deadfish environment to play with to your heart's content!
[Answer]
# JavaScript (ES10), 66 bytes
Expects a list of codepoints.
```
a=>a.flatMap(n=>n%5?p:(p=(p=[p-!!p,p+1,,p*p][n&3])-256&&p,[]),p=0)
```
[Try it online!](https://tio.run/##jZHdaoMwFMfvfYpUmMTtmDapOrcRxxi93BOIF0HrmuFM8Mhe3yUVYRS27pdzcSD8P@B8qC@FzajtlAymPc6dnJUsFet6Nb0pSwdZDjfZs32kVrqpbLLZWLB3HMDe2roaon0dJyLLo8hCVcdg5S6en6qAkFBrRDQhkOtst2TnJa3XaGz/oXISURRrjtNcw3uuOedm@sf8nuckHFIQGeT3OaRZsRcP3sJ4UBvt4t32V2GfCuvjwPNllu4LiK2@xISXLinnIqgD1pnxoJoTRSJL0pgBTX9kvXmnHa0YY1izT3e75vzLmpMaX91tXyYae@Zv "JavaScript (Node.js) – Try It Online")
### How?
`o` is the only command whose codepoint (\$111\$) modulo \$5\$ is not equal to \$0\$. This is also the only command that requires a special operation that doesn't update the accumulator. That's why we first test that.
If the first modulo is \$0\$, we apply a modulo \$4\$ to distinguish between the other commands and update the accumulator accordingly.
```
 char. | code | mod 5 | mod 4
-------+------+-------+-------
  'd'  |  100 |   0   |   0
  'i'  |  105 |   0   |   1
  'o'  |  111 |   1   |  (3)
  's'  |  115 |   0   |   3
```
[Answer]
# [convey](http://xn--wxa.land/convey/), ~~90~~ 76 bytes
```
 {"='i'
0+#<
^v"='d'
^-#<
^v"='s'
^*#+1
^.=<'o'
^>@`
^}",
*<<"=256
.="*.
0-1
```
[Try it online!](https://xn--wxa.land/convey/run.html#eyJjIjoiIHtcIj0naSdcbjArIzxcbl52XCI9J2QnXG5eLSM8XG5edlwiPSdzJ1xuXiojKzFcbl4uPTwnbydcbl4+QGBcbl59XCIsXG4qPDxcIj0yNTZcbi49XCIqLlxuMC0xIiwidiI6MSwiaSI6IidkaWlzc2lzZG8nIn0=)
On the top right side, the input gets compared with `idso`. The result (0 or 1) then gets combined with the accumulator: `a += c == 'i'`, `a -= c == 'd'`, `a = pow(a, (c == 's') + 1)` (pow = `*.`), and `o` pushes a copy into the output `@"}`. At the bottom are the checks for `-1/256`, by calculating `a *= a != 256` and `a *= a != -1`. Then the accumulator loops back to start the next round.
One iteration of the accumulator loop:
[![one iteration](https://i.stack.imgur.com/T324j.gif)](https://i.stack.imgur.com/T324j.gif)
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~60~~ 58 bytes
*Saved 2 bytes thanks to @Sisyphus*
```
a=0;$<.bytes{|b|a=0if(a=eval'~-~p a*'[b%20/3,2]+?a)^256<1}
```
[Try it online](https://tio.run/##KypNqvz/P9HWwFrFRi@psiS1uLomqQbIz0zTSLRNLUvMUa/TrStQSNRSj05SNTLQN9YxitW2T9SMMzI1szGs/f8/s7i4OD8TCQEA "Ruby – Try It Online") or [verify all test cases](https://tio.run/##hVDBbsIwDL3nKyxgA7asawN0jIF22mGnfQBiUkrMaqk0VZOyIQq/3iWjSNMue7Hy7Cc/y3JZJfsGvwpcW1SwgGXIQUynHBwvIz7mYsLjh5iPJ9OReFxx33B5EY/iczg9p4zDOIqEs65Ybx5sZTG4nq1TvS2GAcp1CkpDTTUrKmug85o7nkH3QMdOK71V1mudpgu9OZCBEqUCnWd7MBo2ugSLxlL@AZ8IqdwhWA2VQZC5timWsJMlySRDGLgKOdCQyUX4REGyd85DndSupM1ALnAns/7p7lSAvOkvkysR3o@4WN0@y@G7mMTz6Nicd3ppT@M3vZwpMCltbLs2w1w1RMYYzZRnMkqzNvkPrtEb6Vcw7WFIk5vhMjeK6OfzMEbRXzjLNw "Ruby – Try It Online").
Full program that reads a string from STDIN and outputs to STDOUT, one number per line.
Each operation on the accumulator `a` is carried out by `eval`ing a 3-byte string. The third byte is always `a`. The first two bytes are extracted from the string `~-~p a*` starting at index `b%20/3`:
| Op | \$b\$ | \$\left\lfloor\frac{b\bmod20}{3}\right\rfloor\$ | `eval` |
| --- | --- | --- | --- |
| `d` | \$100\$ | \$0\$ | `~-a` |
| `i` | \$105\$ | \$1\$ | `-~a` |
| `o` | \$111\$ | \$3\$ | `p a` |
| `s` | \$115\$ | \$5\$ | `a*a` |
The reset conditions on the accumulator, which might be written `a==-1||a==256` in ungolfed form, are replaced by the single condition `a^256<1` (`^` is bitwise XOR) because negative accumulator values other than \$-1\$ are not possible.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~83~~ ~~82~~ ~~76~~ 74 bytes
Thanks to [dingledooper](https://codegolf.stackexchange.com/users/88546/dingledooper) for spotting a bug and -6 bytes!  
-2 bytes thanks to [Mukundan](https://codegolf.stackexchange.com/users/91267/mukundan314)!
Takes input as a list of codepoints.
```
a=0
for x in input():
 a=[a-1,a+1,a,a*a][x/6%4];a*=a^256>0
 if x%5:print a
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P9HWgCstv0ihQiEzD4gKSks0NK24FBJtoxN1DXUStYFYJ1ErMTa6Qt9M1STWOlHLNjHOyNTMzoBLITNNoULV1KqgKDOvRCHx//9oQwNTHQVDQzTCEEgYkMuNBQA "Python 2 – Try It Online")
[Answer]
# [Nim](http://nim-lang.org/), 104 bytes
```
var r=0
for c in stdin.readAll:
 r=[r*r,r,r+1,r-1][28-c.ord div 4];r*=int (r xor 256)>0;if c=='o':echo r
```
[Try it online!](https://tio.run/##TYxBCoMwFAX3nuLtbK2KSluKkkLPIS4kUfrB5sOLSG@fZllmdgPj5RPjMRM0TbYqYSEeYXfiay6ze21bn6U4smCZuLQlq3Yau0dla6WDkwPXaWBhxO84Ed806W7387MZZIU1Jte8X@xbwRglhKDy5w8 "Nim – Try It Online")
Based on @ovs's amazing Python answer.
# [Nim](http://nim-lang.org/), 120 114 109 bytes
```
var r=0
for c in stdin.readAll:
 case c
 of'i':r+=1
 of'd':r-=1
 of's':r*=r
 else:r.echo
 if r in[-1,256]:r=0
```
[Try it online!](https://tio.run/##Tc2xCgIxEIThfp9iugP1Dk/QIpDC5ziuCMkGF2ICu@LrxyAWwhRfNX@VZ@/voFB/ptwUEVJhryR1UQ7pXoojxGCMSGh5ksnp0a9fp@H5Zxs@eCVwMXa6cHw0gmToONzm9XS53nY3Kr2LmTX52wc "Nim – Try It Online")
This is embarassingly readable.
*-5 bytes by taking inspiration from @Gotoro's Python answer*
[Answer]
# [Python 3](https://docs.python.org/3/), ~~120~~ 95 bytes
```
n=0
for x in input():
	if n in(-1,256):n=0
	if"o"==x:print(n)
	else:n=[n+1,n-1,n*n][ord(x)%4^1]
```
[Try it online!](https://tio.run/##FYrLCsMgFAXX8SskUNAkhdrXQvBLQroyoRfKuaIG7NcbA7M5cyb885fxqBXuJjaOskhCI@xZaSs62uQ51dVM99db2zNrsufeuWJDJGQFLbr1l9Z2zhjNhBZjwDJz9Kroy/Njllo9UUqUPB8 "Python 3 – Try It Online")
Brought it down by 25 bytes thanks to [Danis](https://codegolf.stackexchange.com/users/99104/danis) suggestion!
Using bit manipulation `^` we choose from the list of possible operations.
[Original suggestion](https://tio.run/##FYrLCsMgEEX3fsUQKGhrIUkfC8EvCenKhA6UO6IW7NdbA2dzzz3xV96CW2vwo9olUSVGJ36LNk4R73RMfZ3s/Hgad2RdDjJ4X11MjKJhFG2fvPVzGS3OsOg5LtO6SAq6mtP9Na@tBeacOQf5Aw) used `ord(x)%4^2` which yielded `0,1,2,3` for indexes and required the use of an additional 0 in the list at the index `0`;
using `^1` instead yields `0,1,2`, which allows to save 2 bytes in comparison.
Maybe it is possible to account for that additional 0 and use it as a condition to print `o` instead.(?)
[Answer]
# [><>](http://esolangs.org/wiki/Fish), 81 bytes
Not the dead one :)
```
0v~$?$0+{="Ā":}=-10<
l<n:oav?="i"{v?="d"}:{v?="s"}:{;?=1
{~:*1->  2+0}>{~1-:v  >
```
[Try it online!](https://tio.run/##HcZBCsMgEEDRvacYBlcNgnY5jXqWQggdKHUx4EaUHC73msT@zX87y0fV12Gz9UuLeB5IPbrgV/Ndf1TeNUdkbHMbdvpDJl45BtMGPYJLAM/F99RGcFQBkqo6gTITLswsty4 "><> – Try It Online")
Branching is the kryptonite of ><> terseness, so the golfiness here was creating a branchless -1 and 256 check `~$?$0+{="Ā":}=-10` backwards on the first line to get rid of whitespace. The `s`, `i` and `d` commands also feed into each other to make the layout manageable.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~92~~ 91 bytes
Thanks to ceilingcat for the -1.
Converts each operation into the range `[0,3]` to simplify the decoding process.
```
a,b;f(char*s){for(a=0;b=*s++/2;a*=a-256&&~a)(b&=3)?--b?--b?printf("%i ",a):a--:(a*=a):a++;}
```
[Try it online!](https://tio.run/##hVFdT8MgFH3vr7ip2QK06NptdQ6rf2DxzSfnA4V2I5llGfiRLPOnW4Fmc/ri4RJOzr33XAKCroToOp5WrEFizXfE4H2jd4iXI1aVxCTJVc44KTnNp8Vw@MkxqoblGN9TWoW93anWNigeKIhTjuec0jnyDY4mCTt0F6oVm1dZw62xUunL9V0UuRZ44apFb1pJDPsIwA8HYmtjzdNz6RWAWCljjI5TiEdx2kvSa8rIoOazmTt@ap3@H367BX91Fj6bwQTyKRTXBUyms3F@c6zWHkZp5WY5FpygXxlkRR8nawdfgVpt16pd4fOEhzFS/UXwnGRZfhp5ft2Hx8XCkUMKhFgWOeq/ypbh1Zh7PQbH71ja@mNbC1vLOQzMsnU2xCYJxtCgQFh06L5Es@Er09H3bw "C (gcc) – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 60 bytes
```
Fold[<|i->#+1,d->#-1,s->#^2,o:>Echo@#|>@#2/.-1|256->0&,0,#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73y0/JyXapiZT105Z21AnBUjpGuoUA6k4I518KzvX5Ix8B@UaOwdlI309XcMaI1MzXTsDNR0DHeVYtf9p0QFFmXklDsrWQF5dcHJiXl01V3WmTqZOMRjm1@pwVafowARAZApEEFWIUgg1Emop2FAsJEhRvg4MguzOBzsNoiQf4TBkWAx2YCZBmF/LVfsfAA "Wolfram Language (Mathematica) – Try It Online")
Input a list of symbols.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), ~~55~~ ~~53~~ ~~52~~ 51 bytes
Thanks to [user41805](https://codegolf.stackexchange.com/users/41805/user41805) for removing awk flags
Expects each operation to be on a separate line
```
{a*=a!=256}/i/{a++}/d/{a&&a--}/s/{a*=a}/o/{print+a}
```
[Try it online!](https://tio.run/##SyzP/v@/OlHLNlHR1sjUrFY/U786UVu7Vj8FSKupJerq1uoX64MV1Orn61cXFGXmlWgn1v7/n8mVAoT5/wE "AWK – Try It Online")
## Explanation
```
{a*=a!=256}    # Before each operation multiply a by 0 if it equals 256
/i/{a++}       # If line contains 'i' increase a by 1
/d/{a&&a--}    # If line contains 'd' and a is non-zero decrement a by 1
/s/{a*=a}      # If line contains 's' square a
/o/{print+a}   # If line contains 'o' output a
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 23 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
0ÿ)²(o▒ê½§"_♠bαm¡╓*"u~╘
```
Input as a list of codepoint integers.
[Try it online.](https://tio.run/##y00syUjPz0n7/9/g8H7NQ5s08h9Nm3R41aG9h5YrxT@auSDp3MbcQwsfTZ2spVRa92jqjP//DQ1MdcDYEBkbchkaGOhgyMHYIDmwGjzyA41h7kP1F5J7iWJzgfkYGOZXQ0QYIeuHYC4UOQNTdD4mNkQOP1PKMcT9AA)
**Explanation:**
```
0                       # Start with 0
 ÿ)²(o                  # Push 4-char string ")²(o"
      ▒                 # Convert it to a list of characters: [")","²","(","o"]
       ê                # Push the input-list of codepoint integers
        ½               # Integer-divide each by 2
         §              # Index (modulair 0-based) them into the list of characters
          "_♠bαm¡╓*"u   # Join these characters with "_♠bαm¡╓*" delimiter
                     ~  # Execute the entire string as MathGolf code
                      ╘ # Discard everything left on the stack (which otherwise would be
                        # output implicitly)
  )                     # Increase by 1
   ²                    # Square
    (                   # Decrease by 1
     o                  # Print without popping
           _            # Duplicate the top of the stack
            ♠bα         # Push 256, push -1, wrap them in a list: [256,-1]
               m        # Map over both of them:
                ¡       #  And check that they're NOT equal to the value we've duplicated
                        #  (0 if the duplicated value is -1 or 256; 1 otherwise)
                 ╓      # Pop and get the minimum of this list
                  *     # Multiply it to the value
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~23~~ ~~22~~ 21 bytes
~~-1~~ -2 bytes thanks to [Command Master](https://codegolf.stackexchange.com/users/92727/command-master)!
Takes input as a list of codepoints.
```
õ?Îv">n<="y;è.VD₁^0›*
```
[Try it online!](https://tio.run/##yy9OTMpM/f//8Fb7w31lSnZ5NrZKldaHV@iFuTxqaowzeNSwS@v//2hDA1MdBUNDNMIQSBiQy40FAA "05AB1E – Try It Online")
**Commented**:
```
õ?                  # print the empty string without a trailing newline
                    # this is necessary to disable implicit output if no 'o' is in the code
  Î                 # push 0 and the input
   v                # iterate over the instructions y in the input:
">n<="              # push string literal ">n<="
                    # These are the instructions in 05AB1E equivalent to "isdo"
      y             # push the current instruction
       ;            # halve the instruction
        è           # modular index into the instruction string
          .V        # execute the instruction
            D       # duplicate the current value
             ₁^     # XOR with 256
               0›   # is this larger than 0?
                 *  # multiply the result with the current value
                    # x*(x^256>0) maps negative numbers and 256 to 0
```
[Answer]
# [Rust](https://www.rust-lang.org/), 119 bytes
Closure with a single parameter of type `Iterator<Item = u8>` with ASCII bytes
```
|s|{let mut a=0;for c in s{a=match c{105=>a+1,100=>a-1,115=>a*a,111=>{println!("{}",a);a},_=>a};if a==-1||a==256{a=0}}}
```
[Try it online!](https://tio.run/##NY5BCoMwEEX3nmLqKmltSQqWQohXKUNacUCjmLhKcnY7Fvo38/gMn7duIe5772FC8kJCqoAzfiK8P/juKQxgIYecjmraIqBVpp9XcEAeQkI7YXQDuKRVazu86EYrxXBl0EdzRgZtu7Ss5OPoT6JOpW5QGizNix@KoZ5n7VXnzOfePnhVlVLMz@XvIer5SKCZiAJTfXMDrkHI24SLyC6zEwbYnlKaqlT7/gU "Rust – Try It Online") (with caller function)
Ungolfed version
```
|s|{
    let mut a = 0;
    for c in s {
        a = match c {
            105 => a + 1,
            100 => a - 1,
            115 => a * a,
            111 => { println!("{}", a); a },
            _ => a
        };
        if a == -1 || a == 256 { a = 0 }
    }
}
```
[Answer]
# x86-16 machine code, ~~45~~ 43 bytes
Source-compatible with x86 and x86\_64.
Fails one test due to integer overflow, but instructions are given to switch it to 64-bit arithmetic in the demo.
```
00000000: 31 d2 ac 3c 64 72 23 74 0d 3c 69 74 0c 3c 6f 92  1..<dr#t.<it.<o.
00000010: 74 0a f7 e0 eb 07 4a eb 05 42 eb 02 ab 92 85 d2  t.....J..B......
00000020: 78 de 81 fa 00 01 74 d8 eb d8 c3                 x.....t....
```
```
        // "//" comments are solely for syntax highlighting
        // sed -i -e 's#//#;#g' deadfish.asm
        // nasm compatible
        [bits 16]
        [cpu 8086]
        global deadfish
        // Input:
        //    si: input, null terminated string
        //    di: output, uint16_t array
        // Output:
        //
        //    di: points past the last value in the array
deadfish:
.Lzero:
        // Set accumulator to 0
        xor     dx, dx
.Lloop:
        // Load byte
        lodsb
        // Check for null terminator and for 'd'
        cmp     al, 'd'
        // Below means null terminator, return
        jb      .Lret
        // equal means 'd'
        je      .Lop_d
        // check for 'i'
        cmp     al, 'i'
        je      .Lop_i
        // check for 'o'
        cmp     al, 'o'
        // Since O and S both need AX instead of DX, xchg here.
        xchg    dx, ax
        je      .Lop_o
        // assume 's'
.Lop_s:
        // Square
        mul     ax
        // Jump to the end of the o code to swap AX to DX.
        jmp     .Lnext_xchg
.Lop_d:
        // Decrement
        dec     dx
        jmp     .Lnext
.Lop_i:
        // Increment
        inc     dx
        jmp     .Lnext
.Lop_o:
        // Output
        // *di++ = ax
        stosw
        // Swap dx and ax again for o and s
.Lnext_xchg:
        xchg    dx, ax
.Lnext:
        // Check for -1 (less than zero) and 256
        // If equal, jump to the xor dx, dx conveniently placed before the loop
        test    dx, dx
        js      .Lzero
        // Literally the only reason I am using 16-bit is this instruction :P
        cmp     dx, 256
        je      .Lzero
        // Otherwise, jump to the top of the loop
        jmp     .Lloop
.Lret:
        // Return
        ret
```
The input is a null terminated string in `si`, and the output is stored to the `uint16_t` array in `di`.
`di` will point to the end of the array to indicate the length (C++ `<algorithm>` style)
[Try it online!](https://tio.run/##jVbhTiM3EP6/TzEKOiWBEMopjU7hikTv0N1JqK2AVpUoipy1N/Gd1155vJAU8ex0xpvNLiGIWpDdtWfGM9/MfHZaFIfzNH3a0zY1pVTwMcUgtTtNtmZsOE2SoyP4rDJtFQQHJSoYjw5nOoDwOixyFXTKC@lCpT/ACD9XnlVsmc@UxwGo4XwImfMQFgpGYQFBYYBUoBrSdplUGfx5dT4eJSVqO4dLNdcYlL9eFQp@gZJ8GI@m4YRtamvYDYGo8plRHjTaboDCq8K7VNG0BHRwr6KbrPHl7AqE0bQZDpPpVGA@nfYuO70E1mOIKsDl@Zfp578H77xcvlw44wWxTPqd/kmypwyq1z09HrOnb@7z2jbNLlbqLCL/VRSFssgI93KHwaz6BKYx7h5whXcgZhpmK0gdJU5LZVOGh14g8y6PkHsVSm/pUXkLkz8StaQXC51PneRZEPtSCZlpXPS2pjEMaAvLeVsID/voU3KzFSg57DIdhDG9p01oc@NmBmqbm5D3wLqgJuScRsog@NJaxtNZWH4YT8cjmJUBuMDSgC0tDgZFzgHyqnQK1zqHx@OkJXhNghXURxWykIvUOwS1LISVjKWi0qU6bXTk8kgsgaqUauCI0k1uF5yFyq/7hWL5qlDJ57ZibA3ZJJTKQJkprmwgK9ZRcWZ6mdQoTJLhxb/Ku6lcTjY6S9qXx7o@1k@SNM4VjZhxEvkpzABuPOrbzUqaF1CvdGV3M/99tnbqgqqgmVX1rCumcrcR3d0trneLu0Z8mS7mdTBnTTA7rbkWkNTVJSW3i90krmETeF4aaEw2ptYeDC94z0pLNlpSpS1Ud2hZ6oNKSzda1Ef/V8s1WhhcTM2Nl/p2UDtaOTZ5C5rKZiMWCfJlOWxcwRrBdSG9SEmt@P7n8Q7ct7Wa0Ljcklgrk1ZivpfkDvVMLn4obrzU5YUImggY7jXz@UK1pK9WxBs5/AVnv35jMv5GVG/p3xjWZVZqCX86OBg2WXZ38UndN6A2bCqNa7fpLxFC3V1Vbz31G/Zh9kwwCD6U7pyWEcveM@oKvp88RHPPSG5WZjfH7z/cEpM//PR48lJgn3ahxQ1FksIA2FolW3hq/KzXeYdweAqd9hIffluMqskSGTgBDR@BDNPLwUEfHjZhbswZU7K1XmlRz4loiAWIk/inv6/XGzw@8@Afyyg8Jgl9UtK07dUBRzA6WiOi66x1qznJkxrl1vR69q0Rtegst81hHh0qA/Y6v/1@fT6JnKy8d3xmU1kYZVYgy3ilOB7H6wTzJt0dwN0pn9H5NqxdqcywAWHmLl462EjqvFcpHUxM6StXVnW2EHYeq/TVuwqdlpGzmdqjr8PWkdsKnUHSrb/nyDgeqJ0miOhtGzat40zzyQNR6u2xbbb@pPw9/Qc) Uses GAS Intel syntax because I want to use libc with it, and uses macros for registers to make it possible to switch to 64-bit arithmetic.
[Answer]
# [J](http://jsoftware.com/), 64 58 bytes
```
g=:]e.&256 _1|]
i=:g>:
d=:g<:
s=:g*:
o=:1!:2&2
f=:'0'".@|.@,]
```
[Try it online!](https://tio.run/##hU7BasMwDL37K7QeYjYUE7tJ1oq5hH3AfmCEHZY01Q51QbkM@u@Zzdok7LIngYSk956@pmnw1PYmc1UNH/baKvY0HEh1sbyQklieSAVP9oFc5tTRky70xjRX02A7jb2M3myBCgUgF2/gnVCDznCTJsdGLvAdm/7zFEDnea7Vo0ok0MwiEjS8vRooVjOW7j/cWPlhISYtXuV8YbFEV2H9XGNZ7bZuf2OEBOHA0TN2iyLew6Ktf3P@jnm@O4fxxOdhtUoQ6fgvFu3SWne3XwynHw "J – Try It Online")
*-6 thanks to FrownyFrog!*
Note: -3 off TIO count for `f=:`
This stores each Deadfish command in a variable of the same name, followed by the -1/256 check. Then we just prepend 0, reverse, and eval.
Takes input with spaces between the letters.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 61 bytes
```
\bi()|#?\bd|^(#*)s
$#1*#$.2*$2
^#{256}\b
m}`^(#*)o
$.1¶$1
#
```
[Try it online!](https://tio.run/##K0otycxLNPyvqqHhnvA/JilTQ7NG2T4mKaUmTkNZS7OYS0XZUEtZRc9IS8WIK0652sjUrDYmiYsrtzYBrCCfS0XP8NA2FUMuZa7//zMzi4uL87lSQHRmcUo@F5RBCAAVgjRmIiGufBAozszPBJoBZAGNgoDi4pRMdJAPAA "Retina – Try It Online") Link includes test cases, although they can be a bit slow (I think `#?\bd` is the slow case, but I'm not sure). Explanation:
```
\bi()|#?\bd|^(#*)s
$#1*#$.2*$2
```
Handle the `i`, `d` and `s` cases by inserting a `#` (for the `i` case), deleting an optional `#` (for the `d` case, also handling a `d` of 0) or squaring the number of `#`s (for the `s` case).
```
^#{256}\b
```
But if the value is exactly 256, then set it back to 0 (assuming that there's another operation, otherwise the remaining `#`s are ignored anyway).
```
^(#*)o
$.1¶$1
```
Handle the `o` case by prepending a decimal copy of the current number of `#`s on a previous line.
```
m}`
```
Evaluate the above stages until there are no more letters to process; also turn on multiline matching for all of the stages.
```
#
```
Delete any remaining accumulated unary value.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 37 bytes
```
≔⁰θＦＳ«Ｆ№⟦²⁵⁶±¹⟧θ≔⁰θ≡ιi≦⊕θd≦⊖θs≧Ｘ²θ⟦Ｉθ
```
[Try it online!](https://tio.run/##bc@xCsJADAbg2T5F6HQHFVTQQSepSwdFdBSH4xrbg3rXXlIdxGc/be2gIGRKvj8kulReO1WFsCYyhRWTBBq5ii7Og8hs3fKRvbGFkBIe0ahvp661LE6z@SKBHRaKUUzluctJ@N0yorthXYIwfVorQohNvIStqgeZWe3xipYxHzIflf@oDf5X9K0OpihZ7N0dfQKzweV4UW3FS9i/33hfnSpi0chzN3tGzxAMETnzVWF8q14 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔⁰θ
```
Initialise the accumulator to 0.
```
ＦＳ«
```
Loop over the commands.
```
Ｆ№⟦²⁵⁶±¹⟧θ
```
If the list (256, -1) includes the accumulator...
```
≔⁰θ
```
... then set the accumulator to 0. (This is done before the operation because it's golfier, and doesn't change the result, since it still always happens between two operations, and whether it happens after the last operation isn't observable.)
```
≡ι
```
Switch on the current operation: ...
```
i≦⊕θ
```
... `i` means increment the accumulator; ...
```
d≦⊖θ
```
... `d` means decrement the accumulator; ...
```
s≧Ｘ²θ
```
... `s` means square the accumulator; ...
```
⟦Ｉθ
```
... otherwise print the accumulator on its own line.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 25 24 bytes
```
:4ị⁾’‘;⁾Ṅ²¤j“-,⁹¤i¬×Ʋ”VZ
```
[Try it online!](https://tio.run/##y0rNyan8/9/K5OHu7keN@x41zHzUMMMayHq4s@XQpkNLsh41zNHVedS489CSzENrDk8/tulRw9ywqP///0cbGpjqKBgaohGGQMKAXG4sAA "Jelly – Try It Online")
Interprets a Deadfish program given as a list of codepoints in a command-line argument, printing newlines between the numbers, then crashes with a TypeError.
Without the last two characters, it's a Deadfish to Jelly transpiler.
## Explanation
```
:4ị⁾’‘;⁾Ṅ²¤j“-,⁹¤i¬×Ʋ”VZ   Main monadic link
:4                         Integer divide by 4
  ị                        Index into
   ⁾’‘;⁾Ṅ²¤                  "’‘Ṅ²"
    ’                          Decrement
     ‘                         Increment
        Ṅ                      Print with newline
         ²                     Square
           j               Join with separator
            “-,⁹¤i¬×Ʋ”       "-,⁹¤i¬×Ʋ"
             -,⁹¤              [-1, 256]
                 i             Find 1-based index
                  ¬            Negate
                   ×           Multiply by the number
                    Ʋ          Group this into one instruction
                      V    Evaluate (implicitly starting with 0)
                       Z   Zip — a number can't be zipped,
                           so this crashes the program in order to
                           suppress the implicit output
```
[Answer]
# [Arturo](https://github.com/arturo-lang/arturo), 80 bytes
```
$[p][r:0loop p'c[do[[r:r*r][print r][r:r+1][r:r-1]]\28-c/4if or? r<0r=256[r:0]]]
```
A function that takes an array of codepoints and prints numbers separated by newlines.
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~26~~ 25 bytes
```
tGF₅0hx'o
S&≠256!ë→a□?←0c
```
[Try it online!](https://tio.run/##yygtzv6vkBus4aWkoGunoJSqqVH8qKlR89C2/yXubo@aWg0yKtTzuYLVHnUuMDI1Uzy8@lHbpMRH0xbaP2qbYJD8////zMzi4uJ8rhQQnVmcks8FZRACQIUgjZlIiCsfBIoz8zOBZgBZQKMyM8EECBQXp2SiA6AWAA "Husk – Try It Online")
### Explanation
The first line is the main program, the second line an helper function that computes the output of a Deadfish command that could be 'i', 'd' or 's'.
Let's start from the first line:
```
tGF₅0hx'o
      x'o    Split the string on each 'o'
     h       and discard the last part 
              (we don't care what happens after the last 'o')
 G  0        Scan this list of strings using 0 as initial value
  F₅          computing the result of each Deadfish subprogram
t            Discard the first value (0)
```
What we are doing here is splitting the Deadfish code into the subprograms preceding each output 'o', and then computing the result of each subprogram.
The result of a subprogram is computed by folding the helper function over the commands: the fold will start with the value of the accumulator coming from the previous subprogram (initially 0), and will apply the helper function to the next command and the accumulator to generate the new value for the accumulator.
Lines in a Husk program are zero-indexed and modular: referring to line `₅` here is effectively the same as referring to line `₁`, but the number of times we "loop around" back to the first line determines how the called function should be modified (in order `argdup`,`flip`,`map`,`zip`,`hook`); in this case we loop around 2 times, so we `flip` the helper function, passing the command ('i','d',or 's') first, and the accumulator second.
We chain together the interpretations of the subprograms by scanning over the list of subprograms. A scan `G` is the same thing as a fold `F`, except it returns all partial results instead of only the final one. We explicitly set 0 as the initial value, but then the result of each subprogram will be passed as the accumulator to the next subprogram. The initial value is always part of the output for a scan, so we have to discard it at the end (`t`).
So, how does the helper function compute the result of a Deadfish command?
```
S&≠256!ë→a□?←0c     Takes a character (one of "ids") and an accumulator,
                     returns the new value for the accumulator
              c     Convert the character to its codepoint value
      !ë            and use it to index into this list of four functions:
        →            Increment
         a           Absolute value (dummy)
          □          Square
           ?←0       If nonzero then decrement else return 0
S&≠256              Return the result if ≠256, else 0
```
The trick here is that ord(c)%4 will return a different value for each c in "ids" (respectively 1,0,3). List indexing in Husk is modular so by indexing with this value into the list of functions we will get the function we need. `a` is there only to pad the list to 4 elements (because otherwise 's' and 'd' would have the same value modulo 3).
We check for -1 by only decreasing the accumulator if its value is not 0, and we check for 256 explicitly after any command.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), ~~83~~ 81 bytes
*Thanks to Dominic van Essen for shaving off 2 bytes...*
```
{for(;c=$++b%9;)printf c-3?(d=(x=c-6?c-1?d*d:--d:++d)<1?0:x==256?0:x)?f:f:+d"\n"}
```
This is pretty brute force, but it's ugly enough that I wanted to submit it. :) It's mostly abusing ternaries to save characters.
The input is code points separated by spaces as commandline arguments. The code converts them to modulo-9 to shorten the comparisons to the specific command values.
There's a minor trick on the `printf` line that might be worth highlighting.
```
printf c-3?..not-a-print-command..:d"\n"
```
prints the accumulator value when a `o` command is found.
The logic in the "truthy" part updates the accumulator, but always returns a value of `f`. Since that's a uninitialized variables, AWK picks a value based on the content where it's used. In this context it turns into a null string, so `printf` doesn't produce any output for non-`o` commands.
The code to update the accumulator is bundled into the print statement, so it's only called for `a`, `d`, `i`, and `s` commands. As result it doesn't have to check for `o`.
[Try it online!](https://tio.run/##SyzP/v@/Oi2/SMM62VZFWztJ1dJas6AoM68kTSFZ19heI8VWo8I2WdfMPlnX0D5FK8VKVzfFSls7RdPG0N7AqsLW1sjUDMTQtE@zSrPSTlGKyVOq/f/f0MBUwdAQGRsqIMSIYv8HAA "AWK – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 98 bytes
```
s->{int a=0;for(var c:s){if((c%=7)>5)System.out.println(a);a=c%5<3?1-c%5+a:a*a;a=a<0|a==256?0:a;}}
```
[Try it online!](https://tio.run/##hU/fa8IwEH73rziEQupmcRtu0Fpl@LwnH8XBLW3duTYpubQgrn97lhaZmwz25cddLt/3XXLAFqeH7MNRVWtj4eDPUWOpjIpGSUtaRZNkJEtkhhckBacRQN28lSSBLVofWk0ZVP5ObKwhtd/uAM2ew4EKsNaKmyo3C/mOZrtbQpE6ni5PpCxgOksKbUSLBmTM4YkKIWSQPoXLebg5ss2rSDc2qr2vLZXAMMFUBvPFw@pu6uMNxjhBX8PF7BPT9H7@uJrFmHSdS4bm3hwGd5uzjX@9C@C6QSHGAQeqvSBQ49tBGiZnTRGhlHltRV@NrF77Tz0bg0cRfnP@8H29IFD9GJ/Z3ahfnXNEzKxd1kfiTLtz8h88sRfSj@l0DyZN3sNn3opo2HowZ3QNL/kC "Java (JDK) – Try It Online")
[Answer]
# [Ohm v2](https://github.com/nickbclifford/Ohm), 30 bytes
```
ÝL}`7%5%›0s:_ΦD256â0>*
›
=
‹
²
```
[Try it online!](https://tio.run/##y8/INfr///Bcn9oEc1VT1UcNuwyKreLPLXMxMjU7vMjATosLKMRlCyR3ch3a9P9/ZnFxcX4mEgIA "Ohm v2 – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-F -E`, ~~96~~ ~~91~~ ~~90~~ ~~79~~ 74 bytes
*(+4 bytes for switches included)*
*Saved 5 bytes by using a built-in variable that defaults to 0 (`$-` / `$FORMAT_LINES_LEFT`) instead of $a*  
*Saved 1 byte by using print and `$/` instead of `CORE::say`*  
*Saved 11 bytes by using `-F` and `-E` switches*  
*Saved 4 bytes by (ab)using regex match return value coercion. Saved 0 bytes but improved readability by changing $- to $% (`$FORMAT_PAGE_NUMBER`)*
```
for(@F){$%+=/i/;$%-=/d/;$%*=$%if/s/;say$%if/o/;$%=0if$%=~/^(-1|256)$/}
```
[Try it online!](https://tio.run/##K0gtyjH9/z8tv0jDwU2zWkVV21Y/U99aRVXXVj8FRGvZqqhmpukX61sXJ1aCmfkgYVuDzDQgWacfp6FrWGNkaqapol/7/39mcXFxfiYS@pdfUJKZn1f8X9dNQdfXVM/A0AAA "Perl 5 – Try It Online")
More-readable version:
```
for (@F) {
    $% += /i/;
    $% -= /d/;
    $% *= $% if /s/;
    say($%) if /o/;
    $% = 0 if $% =~ /^(-1|256)$/;
}
```
[Answer]
# Knight, 57 bytes
```
;=a 0W=cP I?c"o"Oa=a*=a I?c"d"-a 1I?c"i"+1a^a 2!|?256a>0a
```
Takes in each character on a separate input line.
## Explanation
Here's the code with generous whitespace and comments added:
```
;=a 0       #set a to 0
W=cP        #  while the next input character `c` is not null:
 I?c"o"     #    if c is "o": 
  Oa        #      output a
  =a        #    else...
   *=a      #      set a to the following:
   I?c"d"   #      (if a is "d": 
    -a 1    #         a-1
    I?c"i"  #       else if a is "i":
     +1a    #         a+1
     ^a 2   #       else a^2)
   !|?256a>0a   #    multiply a by (not (a is 256) or (0>a)), which is 1 when a is within bounds and 0 otherwise
```
An earlier version where I tried to use some more clever tricks which ended up being longer (66 bytes):
```
;=a 0W =cP I?c"o"Oa=a*=aE S G"^2-1+1"/%Ac 23 3 2 1 0"a "!|?256a>0a
```
[Answer]
# PHP, 136 bytes
```
<?php $w=0;foreach(str_split($argv[1])as$v){if($v=='o'){echo$w.' ';}else{$w=$v=='s'?$w**2:($v=='i'?++$w:--$w);}if($w==256||$w<0){$w=0;}}
```
Example explained:
```
$w=0;                                   #declare w var, is accumulator
foreach(str_split($argv[1])as$v){       # for each char of first CLI argument
if($v=='o'){                            #if output
echo$w.' ';                             #output w
}else{                                  #otherwise
$w=                                     #set w to
$v=='s'?                                #if input is s
$w**2                                   #squared
:($v=='i'?                              #otherwise if incremented
++$w:                                   #add one
--$w);}                                 #otherwise subtract one
if($w==256||$w<0){$w=0;}}               #if -1 or 256 set 0
```
PHP is annoying for this.
Is run `php deadfish.php <program>`
Note: run on CLI so no online example.
[Answer]
# [Red](http://www.red-lang.org), 106 bytes
```
func[s][a: 0 parse s[any[(if a xor 256 < 1[a: 0])"i"(a: a + 1)|"d"(a: a - 1)|"s"(a: a * a)|"o"(print a)]]]
```
[Try it online!](https://tio.run/##hY/BCsIwEETv/YphT61SsIIeRPwIr2EPwTS4l6ZkFRT895rUWsWLjxz2hWFgYuuGY@sMF36HwV@7k1E2docVehu1hRrb3U0pHha3ELHebLFHM0a4IqEyXRZLNNWD3GT1aDrZAjZZoLKP0l2SMPPgQ2zt6YwepkCCRFQ10EtcNlH39kn/McdzlXy96T9kVIKkvnTN5SKEz51RdfLL3EIFm3GL6UH1gcDwachrHtUJ4pwcng "Red – Try It Online")
Pretty simple solution :
```
f: func[s][
    a: 0
    parse s[
       any[
           (if a xor 256 < 1[a: 0]) 
            "i"(a: a + 1)
           |"d"(a: a - 1)
           |"s"(a: a * a)
           |"o"(print a)
       ]
    ]
]
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 68 bytes
```
switch -r($args){i{$a++}d{$a--}s{$a*=$a}o{+$a}.{$a*=$a-notin-1,256}}
```
[Try it online!](https://tio.run/##hU7bTsMwDH3vV1hTYC1LEClbGZomTdoHgOARIVTajAW1y6g7DSnk24uzXkC84Fixj3187L05qgq3qigatlnaBo@6zrYgqpCl1RtGVluWTiYupyCEQwoXS5Y6Yyf0X3ZQ7Eytd0LyeJY417hgFQYBD8daI6IZc7iKPMw91pj7SjyfRz2FSv/Zj8hJUv9y6kg@pdU8uUn4dDa/jm9PTOMNtdG0gzKvwPsnuUxa767Qejxk3hBz/de8xFTKuFVvLwoi@IIzsAEAy0xZprscOTD1uVdZrXJYAnvxvUrhoagJnrMNrHomdZ7ucX3A2pR3r@808ryy8HjIMoVI5FE3NwKhPgj1sqMFPPSCA2cB607Wbx1yF7jmGw "PowerShell – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 59 bytes
```
FNz=T%CN4IqN"o"Z=tT)IqT1=hZ)IqT0=tZ)IqT3=*ZZ)I}hZ[0 257)=Z0
```
[Try it online!](https://tio.run/##K6gsyfj/382vyjZE1dnPxLPQTylfKcq2JETTszDE0DYjCkQb2JaAaWNbrSggozYjKtpAwcjUXNM2yuD//8zi4uL8TCQEAA "Pyth – Try It Online")
Bit out of practice. :)
]