AGI Interpreter

From AGI Wiki
Jump to navigationJump to search

The interpreter reads the logic resources that are a part of an AGI game and uses them to run the game. Logic resources are compiled into a bytecode which has meaning to the interpreter.

For example, the logic commands:

v202 = 35;
set(f98);

translate into the sequence of numbers 3 202 35 12 98, or (for those who like hexadecimal notation) 03 CA 23 0C 62. The assignn command has a bytecode of 3, the command is working with variable number 202, and the variable is being assigned the number 35. The set command, with bytecode 12, is going to set flag number 98. When the interpreter reads these codes, it performs the actions that it knows correspond to those codes – this is the part that is called "interpreting."

As this example shows, the AGI bytecode is not especially complicated, and is for the most part a simple translation of commands to numbers. Having the bytecode allows the interpreter to avoid translating the textual logic code every interpreter cycle. It also allows AGI compilers to use their own syntax, which means that the C-style syntax is not the only possible syntax. There is nothing preventing the command set(f98) from being written as f98.set() other than the need for a compiler to be written that translates f98.set() into the bytecode 12 98.

The interpreter runs in cycles, which means that a game is essentially one giant loop that keeps running until the player quits, the game is completed, or an error occurs. See interpreter cycle for more details on what occurs during a cycle.

Related links