Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
from_file.c File Reference

VM opcode snippet for loading a JSON document from a file. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 free_value (vpath)
 if (!path)
 free (path)
 push_value (vm, v)
 json_object_put (root)

Variables

case OP_JSON_FROM_FILE
char * path = value_to_string_alloc(&vpath)
json_object * root = json_object_from_file(path)
Value v = json_to_fun(root)
 break

Detailed Description

VM opcode snippet for loading a JSON document from a file.

This snippet is included by vm.c and implements the OP_JSON_FROM_FILE instruction. It expects a path on the VM stack, reads the file using json-c, converts the resulting json_object tree into a Fun Value, and pushes that Value back on the VM stack.

Build gating: compiled only when FUN_WITH_JSON is enabled (json-c available). When disabled, the opcode consumes its argument (if any) and pushes Nil.

Stack effect (with FUN_WITH_JSON):

  • Pops: path (any; converted to string)
  • Pushes: Value converted from JSON, or Nil on error

Errors and edge cases:

  • If the path cannot be converted to a C string or json_object_from_file fails (e.g., missing file, invalid JSON), the opcode pushes Nil.
  • The created json_object is released after conversion; ownership of the pushed Fun Value follows normal VM semantics.

Definition in file from_file.c.

Function Documentation

◆ free()

free ( path )

◆ free_value()

free_value ( vpath )

◆ if()

if ( ! path)

Definition at line 40 of file from_file.c.

◆ json_object_put()

json_object_put ( root )

◆ push_value()

push_value ( vm ,
v  )

Variable Documentation

◆ break

break

Definition at line 58 of file from_file.c.

◆ OP_JSON_FROM_FILE

case OP_JSON_FROM_FILE

Definition at line 35 of file from_file.c.

◆ path

char* path = value_to_string_alloc(&vpath)

Definition at line 38 of file from_file.c.

◆ root

json_object* root = json_object_from_file(path)

Definition at line 44 of file from_file.c.

◆ v

Definition at line 50 of file from_file.c.