Added tons of opcode documentation, changed license to ISC and a lot of file refactoring.
This commit is contained in:
parent
50a91d0b6f
commit
d7843274ee
111 changed files with 2597 additions and 26 deletions
|
|
@ -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 abs.c
|
||||
* @brief Implements the OP_ABS opcode for absolute value in the VM.
|
||||
*
|
||||
* This file handles the OP_ABS instruction, which computes the absolute value
|
||||
* of an integer.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops value from stack
|
||||
* - Pushes |value|
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits if not integer
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_ABS: {
|
||||
Value x = pop_value(vm);
|
||||
if (x.type != VAL_INT) { fprintf(stderr, "ABS expects int\n"); exit(1); }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,31 @@
|
|||
/**
|
||||
* 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 clamp.c
|
||||
* @brief Implements the OP_CLAMP opcode for value clamping in the VM.
|
||||
*
|
||||
* This file handles the OP_CLAMP instruction, which clamps a value between
|
||||
* a minimum and maximum.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops x, lo, hi from stack
|
||||
* - Pushes x clamped to [lo,hi]
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits if arguments wrong types
|
||||
* - Handles hi < lo case
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_CLAMP: {
|
||||
Value hi = pop_value(vm);
|
||||
Value lo = pop_value(vm);
|
||||
|
|
|
|||
|
|
@ -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 max.c
|
||||
* @brief Implements the OP_MAX opcode for finding the maximum of two values in the VM.
|
||||
*
|
||||
* This file handles the OP_MAX instruction, which finds the maximum of two integer values.
|
||||
* The values are popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two integer values from the stack.
|
||||
* - Finds the maximum of the two values.
|
||||
* - Pushes the result onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are not integers.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_MAX
|
||||
* // Stack before: [10, 42]
|
||||
* // Stack after: [42]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_MAX: {
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
|
|
|
|||
|
|
@ -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 min.c
|
||||
* @brief Implements the OP_MIN opcode for finding the minimum of two values in the VM.
|
||||
*
|
||||
* This file handles the OP_MIN instruction, which finds the minimum of two integer values.
|
||||
* The values are popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two integer values from the stack.
|
||||
* - Finds the minimum of the two values.
|
||||
* - Pushes the result onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are not integers.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_MIN
|
||||
* // Stack before: [10, 42]
|
||||
* // Stack after: [10]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_MIN: {
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,37 @@
|
|||
/**
|
||||
* 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 mod.c
|
||||
* @brief Implements the OP_MOD opcode for modulo operation in the VM.
|
||||
*
|
||||
* This file handles the OP_MOD instruction, which computes the modulo of two integer values.
|
||||
* The values are popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two integer values from the stack.
|
||||
* - Computes the modulo of the first value by the second.
|
||||
* - Pushes the result onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are not integers.
|
||||
* - Exits with an error if the second operand is zero.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_MOD
|
||||
* // Stack before: [10, 3]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_MOD: {
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
|
|
|
|||
|
|
@ -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 pow.c
|
||||
* @brief Implements the OP_POW opcode for exponentiation in the VM.
|
||||
*
|
||||
* This file handles the OP_POW instruction, which computes the power of two integer values.
|
||||
* The values are popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two integer values from the stack.
|
||||
* - Computes the power of the first value raised to the second.
|
||||
* - Pushes the result onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are not integers.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_POW
|
||||
* // Stack before: [2, 3]
|
||||
* // Stack after: [8]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_POW: {
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,38 @@
|
|||
/**
|
||||
* 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 random_int.c
|
||||
* @brief Implements the OP_RANDOM_INT opcode for generating random integers in the VM.
|
||||
*
|
||||
* This file handles the OP_RANDOM_INT instruction, which generates a random integer
|
||||
* within a specified range. The range bounds are popped from the stack, and the result
|
||||
* is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops the upper and lower bounds from the stack.
|
||||
* - Generates a random integer within the range.
|
||||
* - Pushes the result onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the bounds are not integers.
|
||||
* - Exits with an error if the lower bound is greater than the upper bound.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_RANDOM_INT
|
||||
* // Stack before: [10, 1]
|
||||
* // Stack after: [7]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_RANDOM_INT: {
|
||||
Value hi = pop_value(vm);
|
||||
Value lo = pop_value(vm);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,35 @@
|
|||
/**
|
||||
* 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 random_seed.c
|
||||
* @brief Implements the OP_RANDOM_SEED opcode for seeding the random number generator in the VM.
|
||||
*
|
||||
* This file handles the OP_RANDOM_SEED instruction, which seeds the random number generator
|
||||
* with a specified value. The seed is popped from the stack.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops the seed value from the stack.
|
||||
* - Seeds the random number generator with the value.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the seed is not an integer.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_RANDOM_SEED
|
||||
* // Stack before: [42]
|
||||
* // Stack after: []
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_RANDOM_SEED: {
|
||||
Value seed = pop_value(vm);
|
||||
if (seed.type != VAL_INT) { fprintf(stderr, "RANDOM_SEED expects int\n"); exit(1); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue