Gotohell
Jump to navigation
Jump to search
Gotohell is a variation of C that disallows any flow control or function definitions (besides main
), and focuses on defining labels and using the goto
statement. switch
statements are not allowed.
if
statements can only be used in the following way:
if(condition) goto label;
Turing Completeness
Gotohell is a bounded-storage machine as it is a subset of C, which has a limited amount of memory.
Examples
Brainfuck interpreter with limited memory
#include <stdio.h> int cs[255]; int csp = 0; int tape[1024]; int tp = 0; #define PUSH(x) cs[++csp] = x #define POP cs[csp--] #define PROG_MAX 4096 int main(int argc, char** argv){ char* program = malloc(PROG_MAX); gets(program); int idx = 0; loop: if(program[idx] == '>') goto tr; if(program[idx] == '<') goto tl; if(program[idx] == '+') goto plus; if(program[idx] == '-') goto minus; if(program[idx] == '[') goto bloop; if(program[idx] == ']') goto endbloop; if(program[idx] == '.') goto print; if(program[idx] == ',') goto input; goto exit; tr: tp++; goto endl; tl: tp--; goto endl; plus: tape[tp]++; goto endl; minus: tape[tp]--; goto endl; bloop: if(tape[tp] > 0) goto t; int loopP = 1; s: if(loopP == 0) goto endl; if(program[++idx] == '[') goto i; if(program[++idx] == ']') goto d; goto s; i: loopP++; goto s; d: loopP--; goto s; t: PUSH(idx); goto endl; endbloop: int lindex = POP; if(tape[tp] > 0) goto j; goto endl; j: idx = lindex; PUSH(lindex); goto endl; print: putchar(tape[tp]); goto endl; input: tape[tp] = getchar(); goto endl; endl: idx++; goto loop; exit: }
Input is taken through stdin.