Verbose Mode

In GoMelan when running a compiled .gom program you can print its compiled instructions before execution.

Run verbose

If you use -v or --verbose option, you can run the debug mode.

fn factorial(n: Int) -> Int
{
    if (n <= 1) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}

fn main() -> Int
{
    return factorial(5);
}

The debug mode command:

> ./glados run --verbose out.gomc

Output:

Understanding the output

Procedures or functions

The representation of a procedure will be a label followed by instructions in this format

Instructions

A procedure is defined by multiple successive instructions.

Each line of the output corresponds to an internal instruction executed by the GoMelan Virtual Machine.

The GoMelan Virtual Machine (VM) executes programs by interpreting a set of instructions. Here are the details of various VM instructions.

Push

Detailed Information:

  • Description: Pushes the value onto the stack.

  • Usage: Example: Push 5 pushes the value 5 onto the stack.

JumpIfFalse

Detailed Information:

  • Description: Jumps forward in the instruction sequence by the specified number of instructions if the top of the stack is false (the top of the stack is popped).

  • Usage: Example: If false 3 jumps forward by 3 instructions if the top of the stack is false.

Jump

Detailed Information:

  • Description: Jumps forward or backward in the instruction sequence by the specified number of instructions.

  • Usage: Example: Jump 3 instructions jumps forward by 3 instructions, and Jump back 2 instructions jumps back by 2 instructions.

PushArg

Detailed Information:

  • Description: Pushes the value of the specified argument onto the stack.

  • Usage: Example: Push to stack, arg 0 pushes the value of the first argument onto the stack.

PushEnv

Detailed Information:

  • Description: Pushes the value of the specified environment variable onto the stack.

  • Usage: Example: Push to stack, env key "n" pushes the value of the environment variable named "n" onto the stack.

AddEnv

Detailed Information:

  • Description: Adds a variable to the environment.

  • Usage: Example: Add to env "n" adds a variable named "n" to the environment.

Call

Detailed Information:

  • Description: Calls the function with the specified number of arguments.

  • Usage: Example: Call with 2 args calls a function with two arguments.

BuildList

Detailed Information:

  • Description: Builds a list with the specified number of elements.

  • Usage: Example: Build list with 3 args builds a list with three elements.

AccessList

Detailed Information:

  • Description: Accesses the list at index popped from top of the stack.

  • Usage: Example: Access list accesses the list.

Return

Detailed Information:

  • Description: Returns from the current function, popping the current frame from the call stack.

  • Usage: Example: Return is used to exit from a function and return to the calling function.

Last updated

Was this helpful?