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

Implements the OP_CLAMP opcode for value clamping in the VM. More...

Go to the source code of this file.

Functions

 if (x.type !=VAL_INT||lo.type !=VAL_INT||hi.type !=VAL_INT)
 if (v< lo.i) v
 if (v > hi.i) v
 push_value (vm, make_int(v))
 free_value (x)
 free_value (lo)
 free_value (hi)

Variables

case OP_CLAMP
Value lo = pop_value(vm)
Value x = pop_value(vm)
int64_t v = x.i
 break

Detailed Description

Implements the OP_CLAMP opcode for value clamping in the VM.

This file handles the OP_CLAMP instruction, which clamps a value between a minimum and maximum.

Behavior:

  • Pops x, lo, hi from stack
  • Pushes x clamped to [lo,hi]

Error Handling:

  • Exits if arguments wrong types
  • Handles hi < lo case
Author
Johannes Findeisen
Date
2025-10-16

Definition in file clamp.c.

Function Documentation

◆ free_value() [1/3]

free_value(hi)

◆ free_value() [2/3]

free_value(lo)

◆ free_value() [3/3]

free_value(x)

◆ if() [1/3]

if(v,
hi.i )

◆ if() [2/3]

if()

Definition at line 42 of file insert.c.

Here is the call graph for this function:

◆ if() [3/3]

if(x.type ! = VAL_INT || lo.type != VAL_INT || hi.type != VAL_INT)

Definition at line 33 of file clamp.c.

◆ push_value()

push_value(vm,
make_int(v) )

Variable Documentation

◆ break

break

Definition at line 44 of file clamp.c.

◆ lo

Value lo = pop_value(vm)

Definition at line 31 of file clamp.c.

◆ OP_CLAMP

case OP_CLAMP

Definition at line 29 of file clamp.c.

◆ v

int64_t v = x.i

Definition at line 37 of file clamp.c.

◆ x

Value x = pop_value(vm)

Definition at line 32 of file clamp.c.