Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
throw.c File Reference

Implements the OP_THROW opcode for raising exceptions in the VM. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 if (f->try_sp >=0)
 if (s)
 free_value (err)

Variables

case OP_THROW
char * s = value_to_string_alloc(&err)
 else
vm fp = -1
 break

Detailed Description

Implements the OP_THROW opcode for raising exceptions in the VM.

This file handles the OP_THROW instruction, which raises an exception. If a matching TRY handler exists in the current frame (pushed via OP_TRY_PUSH), control flow jumps to the handler location and the error value is made available to the catch block via the stack. If no handler is present in the current frame, the error is printed and the VM terminates execution by clearing the frame stack.

Behavior:

  • Pops the error Value from the stack.
  • If the current frame has a pending TRY handler (f->try_sp >= 0):
    • Retrieves the handler target IP from the TRY instruction's operand.
    • Pushes the error back on the stack for the catch block to consume.
    • Sets the instruction pointer (IP) to the handler target.
  • Otherwise (no handler):
    • Prints the error in a human-readable form.
    • Frees the error value and clears all frames (vm->fp = -1) to stop the VM.

Errors:

  • None explicitly thrown here; if unhandled, the VM stops after printing the error message.

Definition in file throw.c.

Function Documentation

◆ free_value()

free_value(err)

◆ if() [1/2]

if(f->try_sp >=0)

Definition at line 39 of file throw.c.

◆ if() [2/2]

if(s)

Definition at line 49 of file throw.c.

Here is the call graph for this function:

Variable Documentation

◆ break

break

Definition at line 58 of file throw.c.

◆ else

else
Initial value:
{
fprintf(stdout, "<error>\n")
#define fprintf
Definition vm.c:200

Definition at line 52 of file throw.c.

◆ fp

vm fp = -1

Definition at line 57 of file throw.c.

◆ OP_THROW

case OP_THROW

Definition at line 36 of file throw.c.

◆ s

char* s = value_to_string_alloc(&err)

Definition at line 48 of file throw.c.