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

Implements the OP_MOD opcode for modulo operation in the VM. More...

Go to the source code of this file.

Functions

 if (a.type !=VAL_INT||b.type !=VAL_INT)
 if (b.i==0)
 free_value (a)
 free_value (b)
 push_value (vm, res)

Variables

case OP_MOD
Value a = pop_value(vm)
Value res = make_int(a.i % b.i)
 break

Detailed Description

Implements the OP_MOD opcode for modulo operation in the VM.

This file handles the OP_MOD instruction, which computes the modulo of two integer values. The values are popped from the stack, and the result is pushed back.

Behavior:

  • Pops two integer values from the stack.
  • Computes the modulo of the first value by the second.
  • Pushes the result onto the stack.

Error Handling:

  • Exits with an error if the operands are not integers.
  • Exits with an error if the second operand is zero.

Example: // Bytecode: OP_MOD // Stack before: [10, 3] // Stack after: [1]

Definition in file mod.c.

Function Documentation

◆ free_value() [1/2]

free_value(a)

◆ free_value() [2/2]

free_value(b)

◆ if() [1/2]

if(a.type ! = VAL_INT || b.type != VAL_INT)

Definition at line 35 of file mod.c.

◆ if() [2/2]

if(b.i = = 0)

Definition at line 40 of file mod.c.

◆ push_value()

push_value(vm,
res )

Variable Documentation

◆ a

Value a = pop_value(vm)

Definition at line 34 of file mod.c.

◆ break

break

Definition at line 48 of file mod.c.

◆ OP_MOD

case OP_MOD

Definition at line 32 of file mod.c.

◆ res

Value res = make_int(a.i % b.i)

Definition at line 44 of file mod.c.