User:Tpaefawzen/Notes

From Esolang
Jump to navigation Jump to search

Dis step function

#pragma once

typedef unsigned short DisInt;
static void assertIsDis(DisInt x) {
   if (x >= 59049)
      __builtin_trap();
}

typedef enum {
   DisStepOk,
   DisStepOkWritten,
   DisStepOkRead,
   DisStepHalt,
   DisStepWantRead,
   DisStepWantWrite,
} StepResult;

static DisInt rot(DisInt);
static DisInt opr(DisInt, DisInt);

static StepResult dis_step(DisInt *a, DisInt *c, DisInt *d, DisInt mem[59049],
      _Bool can_write, unsigned char *outc,
      _Bool is_eof, _Bool can_read, unsigned char in_ch)
{
   StepResult r = DisStepOk;

   assertIsDis(*a); assertIsDis(*c); assertIsDis(*d);
   assertIsDis(mem[*c]);
   assertIsDis(mem[*d]);

   DisInt x = mem[*c];
   if (x == 33) {
      return DisStepHalt;
   } else if (x == 42) {
      *d = mem[*d];
   } else if (x == 62) {
      *a = mem[*d] = rot(mem[*d]);
   } else if (x == 94) {
      *c = mem[*d];
   } else if (x == 123) {
      if (*a == 59048) {
         return DisStepHalt;
      }
      if (can_write) {
         *outc = (unsigned char)*a;
         r = DisStepOkWritten;
      } else {
         return DisStepWantWrite;
      }
   } else if (x == 124) {
      *a = mem[*d] = opr(*a, mem[*d]);
   } else if (x == 125) {
      if (is_eof) {
         *a = 59048;
      } else if (can_read) {
         *a = (unsigned char)in_ch;
         r = DisStepOkRead;
      } else {
         return DisStepWantRead;
      }
   }

   *c = (*c + 1) % 59049;
   *d = (*d + 1) % 59049;

   return DisStepOk;
}

Grass is procedural language

Output double u sixteen times

ww
  WWw
  WWWw
v
w
  WWww
  Wwww
  Wwwwww
  Wwwwwwwww

Styled
f1 = read
f2 = 119
f3 = next
f4 = out
f5 v5 v6 =
  let v7 = v5 v6 in
  let v8 = v5 v7 in
  v8
f6 v6 =
  let v7 = f5 f5 in
  let v8 = v7 f5 in
  let v9 = v8 f4 in
  let v10 = v9 v2 in
  v10
main = f6 f6

f x y =
  let v = x y in
  x v

main' x =
  let v = f f in
  let v2 = v f in
  let v3 = v2 out in
  v3 119

THEREFORE

f x y = x (x y)
main' _ = ((f f) f) out 119
main = main' main'