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

VM opcode snippet for converting a Fun Value to a JSON string. More...

Go to the source code of this file.

Functions

 free_value (vpretty)
 free_value (any)
 push_value (vm, make_string("null"))

Variables

case OP_JSON_STRINGIFY
Value any = pop_value(vm)
 break

Detailed Description

VM opcode snippet for converting a Fun Value to a JSON string.

Implements the OP_JSON_STRINGIFY instruction. Expects a boolean/integer flag indicating pretty-printing and a Value to serialize. Uses json-c to build a json_object from the Value and then renders it to a string, which is pushed back to the stack.

Build gating: compiled only when FUN_WITH_JSON is enabled. Otherwise the opcode consumes its two arguments and pushes the string "null".

Stack effect (with FUN_WITH_JSON):

  • Pops: pretty (bool/int), value (any)
  • Pushes: string (JSON representation)

Errors and edge cases:

  • If conversion to json_object fails, an empty string is pushed.
  • Pretty printing selects JSON_C_TO_STRING_PRETTY; otherwise plain output.

Definition in file stringify.c.

Function Documentation

◆ free_value() [1/2]

free_value(any)

◆ free_value() [2/2]

free_value(vpretty)

◆ push_value()

push_value(vm,
make_string("null") )

Variable Documentation

◆ any

Value any = pop_value(vm)

Definition at line 48 of file stringify.c.

◆ break

break

Definition at line 52 of file stringify.c.

◆ OP_JSON_STRINGIFY

case OP_JSON_STRINGIFY

Definition at line 32 of file stringify.c.