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

VM opcode snippet for writing a Fun Value as JSON to a file. More...

Go to the source code of this file.

Functions

 free_value (vpretty)
 free_value (any)
 free_value (vpath)
 push_value (vm, make_int(0))

Variables

case OP_JSON_TO_FILE
Value any = pop_value(vm)
Value vpath = pop_value(vm)
 break

Detailed Description

VM opcode snippet for writing a Fun Value as JSON to a file.

Implements the OP_JSON_TO_FILE instruction. Expects a pretty-print flag, a Value to serialize, and a path. Serializes the Value via json-c and writes it to the specified file path.

Build gating: compiled only when FUN_WITH_JSON is enabled. Otherwise the opcode consumes three arguments and pushes 0 (failure).

Stack effect (with FUN_WITH_JSON):

  • Pops: pretty (bool/int), value (any), path (any; converted to string)
  • Pushes: int (1 on success, 0 on failure)

Errors and edge cases:

  • If the path cannot be converted to a C string or file writing fails, the opcode pushes 0.
  • Pretty printing selects JSON_C_TO_STRING_PRETTY; otherwise plain output.

Definition in file to_file.c.

Function Documentation

◆ free_value() [1/3]

free_value(any)

◆ free_value() [2/3]

free_value(vpath)

◆ free_value() [3/3]

free_value(vpretty)

◆ push_value()

push_value(vm,
make_int(0) )

Variable Documentation

◆ any

Value any = pop_value(vm)

Definition at line 56 of file to_file.c.

◆ break

break

Definition at line 62 of file to_file.c.

◆ OP_JSON_TO_FILE

case OP_JSON_TO_FILE

Definition at line 32 of file to_file.c.

◆ vpath

Value vpath = pop_value(vm)

Definition at line 58 of file to_file.c.