1
0
Fork 0
forked from fun/fun

Added tons of opcode documentation, changed license to ISC and a lot of file refactoring.

This commit is contained in:
Johannes Findeisen 2025-09-16 02:11:22 +02:00
commit d7843274ee
111 changed files with 2597 additions and 26 deletions

View file

@ -1,3 +1,30 @@
/**
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the ISC license.
* https://opensource.org/license/isc-license-txt
*/
/**
* @file has_key.c
* @brief Implements the OP_HAS_KEY opcode for map key checking in the VM.
*
* This file handles the OP_HAS_KEY instruction, which checks if a map contains
* a specific key.
*
* Behavior:
* - Pops key and map from stack
* - Pushes 1 if key exists, 0 otherwise
*
* Error Handling:
* - Exits if arguments wrong types
*
* @author Johannes Findeisen
* @date 2025-10-16
*/
case OP_HAS_KEY: {
Value key = pop_value(vm);
Value m = pop_value(vm);

View file

@ -1,3 +1,36 @@
/**
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the ISC license.
* https://opensource.org/license/isc-license-txt
*/
/**
* @file keys.c
* @brief Implements the OP_KEYS opcode for retrieving map keys in the VM.
*
* This file handles the OP_KEYS instruction, which retrieves the keys of a map
* and pushes them as an array onto the stack.
*
* Behavior:
* - Pops the map from the stack.
* - Retrieves the keys of the map.
* - Pushes the keys as an array onto the stack.
*
* Error Handling:
* - Exits with an error if the map is of the wrong type.
*
* Example:
* // Bytecode: OP_KEYS
* // Stack before: [{"a": 1, "b": 2}]
* // Stack after: [["a", "b"]]
*
* @author Johannes Findeisen
* @date 2025-10-16
*/
case OP_KEYS: {
Value m = pop_value(vm);
if (m.type != VAL_MAP) { fprintf(stderr, "KEYS expects map\n"); exit(1); }

View file

@ -1,3 +1,39 @@
/**
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the ISC license.
* https://opensource.org/license/isc-license-txt
*/
/**
* @file make_map.c
* @brief Implements the OP_MAKE_MAP opcode for creating maps in the VM.
*
* This file handles the OP_MAKE_MAP instruction, which pops `pairs` key-value pairs
* from the stack, creates a map from them, and pushes the resulting map back onto the stack.
*
* Behavior:
* - Validates the number of pairs to ensure it is non-negative.
* - Ensures that map keys are strings.
* - Constructs the map using `make_map_empty` and `map_set`.
* - Pushes the map onto the stack.
*
* Error Handling:
* - Exits with an error if the number of pairs is invalid, if keys are not strings,
* or if map construction fails.
*
* Example:
* // Bytecode: OP_MAKE_MAP 2
* // Stack before: ["key1", 1, "key2", 2]
* // Stack after: [{"key1": 1, "key2": 2}]
*
* @author Johannes Findeisen
* @date 2025-10-16
*/
case OP_MAKE_MAP: {
int pairs = inst.operand;
if (pairs < 0) { fprintf(stderr, "MAKE_MAP invalid pair count\n"); exit(1); }

View file

@ -1,3 +1,36 @@
/**
* This file is part of the Fun programming language.
* https://hanez.org/project/fun/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the ISC license.
* https://opensource.org/license/isc-license-txt
*/
/**
* @file values.c
* @brief Implements the OP_VALUES opcode for retrieving map values in the VM.
*
* This file handles the OP_VALUES instruction, which retrieves the values of a map
* and pushes them as an array onto the stack.
*
* Behavior:
* - Pops the map from the stack.
* - Retrieves the values of the map.
* - Pushes the values as an array onto the stack.
*
* Error Handling:
* - Exits with an error if the map is of the wrong type.
*
* Example:
* // Bytecode: OP_VALUES
* // Stack before: [{"a": 1, "b": 2}]
* // Stack after: [[1, 2]]
*
* @author Johannes Findeisen
* @date 2025-10-16
*/
case OP_VALUES: {
Value m = pop_value(vm);
if (m.type != VAL_MAP) { fprintf(stderr, "VALUES expects map\n"); exit(1); }