Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
store_global.c File Reference

Implements the OP_STORE_GLOBAL opcode for storing global variables 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 (idx< 0||idx >=MAX_GLOBALS)
 fprintf (stderr, "DEBUG STORE_GLOBAL[%d]: new.type=%d\n", idx, v.type)
 free_value (vm->globals[idx])

Variables

case OP_STORE_GLOBAL
Value v = pop_value(vm)
vm globals [idx] = v
 break

Detailed Description

Implements the OP_STORE_GLOBAL opcode for storing global variables in the VM.

This file handles the OP_STORE_GLOBAL instruction, which stores a value into a global variable using its index.

Behavior:

  • Pops the value from the stack.
  • Stores the value into the global variable at the specified index.

Error Handling:

  • Exits with an error if the index is out of bounds.

Example:

  • Bytecode: OP_STORE_GLOBAL 0
  • Stack before: [42]
  • Stack after: []

Definition in file store_global.c.

Function Documentation

◆ fprintf()

fprintf ( stderr )

◆ free_value()

free_value ( vm-> globals[idx])

◆ if()

if ( idx< 0||idx > = MAX_GLOBALS)

Definition at line 32 of file store_global.c.

Variable Documentation

◆ break

break

Definition at line 42 of file store_global.c.

◆ globals

vm globals[idx] = v

Definition at line 41 of file store_global.c.

◆ OP_STORE_GLOBAL

case OP_STORE_GLOBAL

Definition at line 30 of file store_global.c.

◆ v

Value v = pop_value(vm)

Definition at line 36 of file store_global.c.