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,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 read_file.c
* @brief Implements the OP_READ_FILE opcode for reading file contents in the VM.
*
* This file handles the OP_READ_FILE instruction, which reads the contents of a file
* and pushes the result as a string onto the stack.
*
* Behavior:
* - Pops the file path from the stack.
* - Reads the file contents.
* - Pushes the contents as a string onto the stack.
*
* Error Handling:
* - Exits with an error if the file path is invalid or the file cannot be read.
*
* Example:
* // Bytecode: OP_READ_FILE
* // Stack before: ["file.txt"]
* // Stack after: ["file contents"]
*
* @author Johannes Findeisen
* @date 2025-10-16
*/
case OP_READ_FILE: {
Value path = pop_value(vm);
if (path.type != VAL_STRING) { fprintf(stderr, "READ_FILE expects string\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 write_file.c
* @brief Implements the OP_WRITE_FILE opcode for writing to a file in the VM.
*
* This file handles the OP_WRITE_FILE instruction, which writes data to a file.
* The file path and data are popped from the stack, and a success/failure flag is pushed back.
*
* Behavior:
* - Pops the file path and data from the stack.
* - Writes the data to the file.
* - Pushes 1 (success) or 0 (failure) onto the stack.
*
* Error Handling:
* - Exits with an error if the file path is invalid or the file cannot be written.
*
* Example:
* // Bytecode: OP_WRITE_FILE
* // Stack before: ["file.txt", "data"]
* // Stack after: [1]
*
* @author Johannes Findeisen
* @date 2025-10-16
*/
case OP_WRITE_FILE: {
Value data = pop_value(vm);
Value path = pop_value(vm);