FuckPutin
Jump to navigation
Jump to search
FuckPutin is stack based esoteric programming language invented in 2022 by user PoetLuchnik. Stack - 65536 cells. Cell - 32 bit integer. Two stacks (A and B). Program is a sequence of digits and notes. Each digit it is offset for operation-accumulator. Operation-accumulator can be from 0 to 9. After offset operation-accumulator, program interpret operation-accumulator. At the beginning operation-accumulator is zero.
Operations
operation-accumulator value | operation description |
---|---|
0 | A.pop()
|
1 | A.push(1)
|
2 | A.push(A.pop() + A.pop())
|
3 | A.push(~(A.pop() | A.pop()))
|
4 | A.push(A.pop() >> 1)
|
5 | A.push(B.pop())
|
6 | B.push(A.peek())
|
7 | tmp = B.pop(); if A.pop() != 0 then go to tmp
|
8 | output(A.pop())
|
9 | A.push(input())
|
Examples
print A
1597497497497497497916
Description: push_1 dup add dup add dup add dup add dup add dup add push_1 add out
C implementation
#include<stdlib.h> #include<stdio.h> #include<stdint.h> FILE* fp = 0, * fi = 0, * fo = 0; struct stk { long _[0x10000]; uint16_t i; } A = { .i = 0 }, B = { .i = 0 }; long fp_len = 0; void push(struct stk* s, long d) { s->_[(s->i)++] = d; } long poop(struct stk* s) { return s->_[--(s->i)]; } long peek(struct stk* s) { return s->_[(s->i) - 1]; } void jump() { long t = poop(&B); if (poop(&A)) fseek(fp, t % fp_len, SEEK_SET); } int main(int argc, char** argv) { // open if (argc > 1) fp = fopen(argv[1], "r"); if (fp == 0) return 1; fseek(fp, 0, SEEK_END); fp_len = ftell(fp); fseek(fp, 0, SEEK_SET); if (argc > 2) fi = fopen(argv[2], "r"); if (fi == 0) fi = stdin; if (argc > 3) fo = fopen(argv[3], "w"); if (fo == 0) fo = stdout; // run uint8_t op = 0; for (int c = fgetc(fp); c != EOF; c = fgetc(fp)) { if ('0' > c || c > '9') continue; // ignore op = (op + c - '0') % 10; // op += c (WARNING: NOT op = c) switch (op) { case 0: poop(&A); break; // pop case 1: push(&A, 1); break; // one case 2: push(&A, poop(&A) + poop(&A)); break; // add case 3: push(&A, ~(poop(&A) | poop(&A))); break; // nor case 4: push(&A, poop(&A) >> 1); break; // shr case 5: push(&A, poop(&B)); break; // bta case 6: push(&B, peek(&A)); break; // atb case 7: jump(); break; // jmp case 8: fputc(poop(&A), fo); break; // put case 9: push(&A, fgetc(fi)); break; // get } } // close fclose(fp); if (fi != stdin) fclose(fi); if (fo != stdout) fclose(fo); return 0; }