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,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 and.c
|
||||
* @brief Implements the OP_AND opcode for logical AND in the VM.
|
||||
*
|
||||
* This file handles the OP_AND instruction, which performs a logical AND operation
|
||||
* on two boolean values. The values are popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two boolean values from the stack.
|
||||
* - Performs a logical AND operation.
|
||||
* - Pushes the result (1 or 0) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are not boolean values.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_AND
|
||||
* // Stack before: [1, 0]
|
||||
* // Stack after: [0]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_AND: {
|
||||
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 eq.c
|
||||
* @brief Implements the OP_EQ opcode for equality comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_EQ instruction, which checks if two values are equal.
|
||||
* The values are popped from the stack, and the result (1 or 0) is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two values from the stack.
|
||||
* - Checks if the values are equal.
|
||||
* - Pushes 1 (true) or 0 (false) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are of incompatible types.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_EQ
|
||||
* // Stack before: [42, 42]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_EQ: {
|
||||
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 gt.c
|
||||
* @brief Implements the OP_GT opcode for greater-than comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_GT instruction, which checks if the first value is greater than the second.
|
||||
* The values are popped from the stack, and the result (1 or 0) is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two values from the stack.
|
||||
* - Checks if the first value is greater than the second.
|
||||
* - Pushes 1 (true) or 0 (false) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are of incompatible types.
|
||||
*
|
||||
* Example:
|
||||
* ```c
|
||||
* // Bytecode: OP_GT
|
||||
* // Stack before: [42, 10]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_GT: {
|
||||
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 gte.c
|
||||
* @brief Implements the OP_GTE opcode for greater-than-or-equal comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_GTE instruction, which checks if the first value is greater than or equal to the second.
|
||||
* The values are popped from the stack, and the result (1 or 0) is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two values from the stack.
|
||||
* - Checks if the first value is greater than or equal to the second.
|
||||
* - Pushes 1 (true) or 0 (false) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are of incompatible types.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_GTE
|
||||
* // Stack before: [42, 42]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_GTE: {
|
||||
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 lt.c
|
||||
* @brief Implements the OP_LT opcode for less-than comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_LT instruction, which checks if the first value is less than the second.
|
||||
* The values are popped from the stack, and the result (1 or 0) is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two values from the stack.
|
||||
* - Checks if the first value is less than the second.
|
||||
* - Pushes 1 (true) or 0 (false) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are of incompatible types.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_LT
|
||||
* // Stack before: [10, 42]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_LT: {
|
||||
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 lte.c
|
||||
* @brief Implements the OP_LTE opcode for less-than-or-equal comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_LTE instruction, which checks if the first value is less than or equal to the second.
|
||||
* The values are popped from the stack, and the result (1 or 0) is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two values from the stack.
|
||||
* - Checks if the first value is less than or equal to the second.
|
||||
* - Pushes 1 (true) or 0 (false) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are of incompatible types.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_LTE
|
||||
* // Stack before: [42, 42]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_LTE: {
|
||||
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 neq.c
|
||||
* @brief Implements the OP_NEQ opcode for inequality comparison in the VM.
|
||||
*
|
||||
* This file handles the OP_NEQ instruction, which checks if two values are not equal.
|
||||
* The values are popped from the stack, and the result (1 or 0) is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two values from the stack.
|
||||
* - Checks if the values are not equal.
|
||||
* - Pushes 1 (true) or 0 (false) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are of incompatible types.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_NEQ
|
||||
* // Stack before: [42, 10]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_NEQ: {
|
||||
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 not.c
|
||||
* @brief Implements the OP_NOT opcode for logical NOT in the VM.
|
||||
*
|
||||
* This file handles the OP_NOT instruction, which performs a logical NOT operation
|
||||
* on a boolean value. The value is popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops a boolean value from the stack.
|
||||
* - Performs a logical NOT operation.
|
||||
* - Pushes the result (1 or 0) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operand is not a boolean value.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_NOT
|
||||
* // Stack before: [0]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_NOT: {
|
||||
Value v = pop_value(vm);
|
||||
int res = !value_is_truthy(&v);
|
||||
|
|
|
|||
|
|
@ -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 or.c
|
||||
* @brief Implements the OP_OR opcode for logical OR in the VM.
|
||||
*
|
||||
* This file handles the OP_OR instruction, which performs a logical OR operation
|
||||
* on two boolean values. The values are popped from the stack, and the result is pushed back.
|
||||
*
|
||||
* Behavior:
|
||||
* - Pops two boolean values from the stack.
|
||||
* - Performs a logical OR operation.
|
||||
* - Pushes the result (1 or 0) onto the stack.
|
||||
*
|
||||
* Error Handling:
|
||||
* - Exits with an error if the operands are not boolean values.
|
||||
*
|
||||
* Example:
|
||||
* // Bytecode: OP_OR
|
||||
* // Stack before: [1, 0]
|
||||
* // Stack after: [1]
|
||||
*
|
||||
* @author Johannes Findeisen
|
||||
* @date 2025-10-16
|
||||
*/
|
||||
|
||||
case OP_OR: {
|
||||
Value b = pop_value(vm);
|
||||
Value a = pop_value(vm);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue