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

Implements the OP_DUP opcode for duplicating the top stack value in the VM. More...

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

Go to the source code of this file.

Functions

 exit (1)
 push_value (vm, copy_value(&top))

Variables

case OP_DUP
case Runtime error
Value top = vm->stack[vm->sp]
 break

Detailed Description

Implements the OP_DUP opcode for duplicating the top stack value in the VM.

This file handles the OP_DUP instruction, which duplicates the top value on the stack. The duplicated value is pushed back onto the stack.

Behavior:

  • Duplicates the top value on the stack.
  • Pushes the duplicated value onto the stack.

Error Handling:

  • Exits with an error if the stack is empty.

Example: // Bytecode: OP_DUP // Stack before: [42] // Stack after: [42, 42]

Definition in file dup.c.

Function Documentation

◆ exit()

exit(1)

◆ push_value()

push_value(vm,
copy_value &top )

Variable Documentation

◆ break

break

Definition at line 37 of file dup.c.

◆ error

case Runtime error

Definition at line 32 of file dup.c.

◆ OP_DUP

case OP_DUP

Definition at line 30 of file dup.c.

◆ top

Value top = vm->stack[vm->sp]

Definition at line 35 of file dup.c.