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

Implements the OP_ZIP opcode for array zipping 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 (a.type !=VAL_ARRAY||b.type !=VAL_ARRAY)
 free_value (a)
 free_value (b)
 push_value (vm, out)

Variables

case OP_ZIP
Value a = pop_value(vm)
Value out = bi_zip(&a, &b)
 break

Detailed Description

Implements the OP_ZIP opcode for array zipping in the VM.

This file handles the OP_ZIP instruction, which combines two arrays into an array of pairs (subarrays with two elements).

Behavior:

  • Pops two arrays from the stack
  • Creates new array of [a[i],b[i]] pairs
  • Length is minimum of input array lengths
  • Pushes resulting array onto stack

Error Handling:

  • Exits with error if arguments aren't arrays

Example: // Bytecode: OP_ZIP // Stack before: [[1,2], ['a','b']] // Stack after: [[[1,'a'], [2,'b']]]

Definition in file zip.c.

Function Documentation

◆ free_value() [1/2]

free_value(a)

◆ free_value() [2/2]

free_value(b)

◆ if()

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

Definition at line 35 of file zip.c.

◆ push_value()

push_value(vm,
out )

Variable Documentation

◆ a

Value a = pop_value(vm)

Definition at line 34 of file zip.c.

◆ break

break

Definition at line 43 of file zip.c.

◆ OP_ZIP

case OP_ZIP

Definition at line 32 of file zip.c.

◆ out

Value out = bi_zip(&a, &b)

Definition at line 39 of file zip.c.