Function calling

This commit is contained in:
2025-12-06 11:50:42 +11:00
parent 571d3bcc34
commit 9553934db5
6 changed files with 100 additions and 39 deletions

View File

@@ -12,7 +12,7 @@ typedef enum GroundInstType {
} GroundInstType;
typedef enum GroundValueType {
INT, DOUBLE, STRING, CHAR, BOOL, LIST, CUSTOM, NONE
INT, DOUBLE, STRING, CHAR, BOOL, LIST, FUNCTION, CUSTOM, NONE
} GroundValueType;
typedef enum GroundArgType {
@@ -24,6 +24,7 @@ typedef enum ListAccessStatus {
} ListAccessStatus;
struct GroundValue;
struct GroundFunction;
struct List;
@@ -52,6 +53,7 @@ typedef struct GroundValue {
char charVal;
bool boolVal;
List listVal;
struct GroundFunction* fnVal;
void* customVal;
} data;
} GroundValue;
@@ -92,6 +94,33 @@ typedef struct GroundInstruction {
} args;
} GroundInstruction;
/*
* Represents a Ground program or function.
*/
typedef struct GroundProgram {
GroundInstruction* instructions;
size_t size;
} GroundProgram;
/*
* Represents the argument typing for a GroundFunction.
*/
typedef struct GroundFunctionArgs {
GroundValueType type;
char* name;
} GroundFunctionArgs;
/*
* Represents a Ground function.
*/
typedef struct GroundFunction {
GroundFunctionArgs* args;
size_t argSize;
GroundValueType returnType;
GroundProgram program;
} GroundFunction;
// Creates a GroundValue containing (in), with type INT.
GroundValue createIntGroundValue(int64_t in);
@@ -110,6 +139,9 @@ GroundValue createBoolGroundValue(bool in);
// Creates a GroundValue containing (in), with type LIST.
GroundValue createListGroundValue(List in);
// Creates a GroundValue conatining (in), with type FUNCTION.
GroundValue createFunctionGroundValue(GroundFunction* in);
// Creates a deep copy of a GroundValue
GroundValue copyGroundValue(const GroundValue* gv);