Intermediate Language Compilation

Tags:

#battle turing #compiling #custom programming language

By: Aaron Jencks

Views: 168
Posted on:

March 17, 2023, 12:48 a.m.

0 👍 0 👎

I've been contemplating how to implement labels and short circuiting into Battle Turing's custom language, and I've come to the determination, that an intermediate pass from the compiler will be necessary. This intermediate language basically consists of all of the existing custom language, converted to a stack compatible form. This consists of:

  • Read: reads a value from the tape and puts it onto the stack
  • Write: pops a value off of the stack and writes it onto the tape
  • Value: pushes a value onto the stack
  • Move: moves the machine left or right
  • Pop: pops a value off of the stack
  • Dup: duplicates the value on the top of the stack
  • Jump: jumps to a label
  • CondJump: jumps if the top of the stack is true to a label
  • Label: Marks a jump point in the program
  • Return: returns to a previous location
  • Break: breaks out of a loop by jumping to the ending label
  • Continue: breaks out of a loop by jumping back to the condition statement

Some of these might change, I think that there should be a specific function call command, to eliminate the need to keep track of all jumps.

I'm not sure if I'd like to keep a boolean type on the stack, this would affect CondJump and other arithmetic operations as well as how I would implement short circuiting.

Comments

You are not logged in, please log in here to comment

Current Comments