Files
ground-rewrite/src/libmain.c

277 lines
8.8 KiB
C
Raw Normal View History

2026-06-13 19:45:36 +10:00
#include "../include/ground.h"
GroundValue _GroundNewValueInt(GroundInt in);
GroundValue _GroundNewValueDouble(GroundDouble in);
GroundValue _GroundNewValueChar(GroundChar in);
GroundValue _GroundNewValueBool(GroundBool in);
GroundValue _GroundNewValueList(GroundList in);
GroundValue _GroundNewValueString(GroundString in);
GroundValue _GroundNewValueFunction(GroundFunction in);
GroundValue _GroundNewValueStruct(GroundStruct in);
GroundValue _GroundNewValueObject(GroundObject in);
GroundArg _GroundNewArgValue(GroundValue value);
2026-06-17 10:11:15 +10:00
GroundArg _GroundNewArgValueRef(GroundIdentifier* ref);
GroundArg _GroundNewArgDirectRef(GroundIdentifier* ref);
GroundArg _GroundNewArgLineRef(GroundIdentifier* ref);
GroundArg _GroundNewArgLabelRef(GroundIdentifier* ref);
GroundArg _GroundNewArgFunctionRef(GroundIdentifier* ref);
GroundArg _GroundNewArgTypeRef(GroundIdentifier* ref);
2026-06-13 19:45:36 +10:00
GroundList _GroundNewList();
GroundString _GroundNewString(const char* in);
GroundFunction _GroundNewFunction(GroundState* state);
2026-06-20 19:45:52 +10:00
GroundFunction _GroundNewNativeFunction(void* function, GroundSize argc, ...);
2026-06-13 19:45:36 +10:00
GroundStruct _GroundNewStruct();
GroundObject _GroundNewObject(GroundStruct* in);
GroundError _GroundNewError(GroundValue* in);
GroundInstruction _GroundNewInstruction(enum GroundInstructionType type);
GroundProgram _GroundNewProgram();
GroundType _GroundNewType(enum GroundTypeType type, ...);
2026-06-17 10:11:15 +10:00
GroundIdentifier* _GroundNewIdentifier(const char* id);
2026-06-13 19:45:36 +10:00
2026-06-21 14:35:48 +10:00
GroundBytecode _GroundNewBytecode (GroundProgram* program, GroundState* state);
2026-07-02 11:35:56 +10:00
GroundBytecodeValue _GroundNewBytecodeValue(GroundValue value);
2026-06-21 14:35:48 +10:00
2026-06-13 19:45:36 +10:00
void _GroundFreeValue(GroundValue* in);
void _GroundFreeList(GroundList* in);
void _GroundFreeString(GroundString* in);
void _GroundFreeFunction(GroundFunction* in);
void _GroundFreeStruct(GroundStruct* in);
void _GroundFreeObject(GroundObject* in);
2026-06-16 20:01:42 +10:00
void _GroundFreeArg(GroundArg* in);
void _GroundFreeInstruction(GroundInstruction* in);
void _GroundFreeProgram(GroundProgram* in);
void _GroundFreeState(GroundState* in);
2026-06-17 10:11:15 +10:00
void _GroundFreeIdentifier(GroundIdentifier* identifier);
2026-07-02 11:35:56 +10:00
void _GroundFreeBytecodeValue(GroundBytecodeValue* in);
2026-06-13 19:45:36 +10:00
GroundValue _GroundCopyValue(GroundValue* in);
GroundList _GroundCopyList(GroundList* in);
GroundString _GroundCopyString(GroundString* in);
GroundFunction _GroundCopyFunction(GroundFunction* in);
GroundStruct _GroundCopyStruct(GroundStruct* in);
GroundObject _GroundCopyObject(GroundObject* in);
GroundArg _GroundCopyArg(GroundArg* in);
GroundInstruction _GroundCopyInstruction(GroundInstruction* in);
GroundProgram _GroundCopyProgram(GroundProgram* in);
GroundState _GroundCopyState(GroundState* in);
2026-06-17 10:11:15 +10:00
GroundIdentifier* _GroundCopyIdentifier(GroundIdentifier* identifier);
GroundBytecodeValue _GroundCopyBytecodeValue(GroundBytecodeValue* value);
2026-06-13 19:45:36 +10:00
void _GroundListAppend(GroundList* list, GroundValue value);
void _GroundInstructionAppend(GroundInstruction* instruction, GroundArg arg);
2026-06-15 21:33:58 +10:00
int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* heap);
2026-06-13 19:45:36 +10:00
void _GroundProgramAppend(GroundProgram* program, GroundInstruction instruction);
void _GroundProgramExecute(GroundProgram* program, GroundState* state);
2026-07-02 11:35:56 +10:00
GroundProgram _GroundProgramPreprocess(GroundProgram* program, GroundState* state);
2026-06-13 19:45:36 +10:00
void _GroundFunctionAppendInstruction(GroundFunction* function, GroundInstruction instruction);
void _GroundFunctionAppendArg(GroundFunction* function, const char* argName);
void _GroundStructAddField(GroundStruct* gs, const char* id, GroundValue value);
2026-06-15 20:27:50 +10:00
GroundValue* _GroundStateFindVariable(GroundState* state, const char* id);
2026-06-20 19:45:52 +10:00
GroundSize* _GroundStateFindLabel(GroundState* state, const char* id);
2026-06-15 20:27:50 +10:00
GroundCatch* _GroundStateFindCatch(GroundState* state, const char* id);
void _GroundInternalRun(GroundProgram* program, GroundState* state);
void _GroundLogError(const char* message);
void _GroundLogWarning(const char* message);
void _GroundLogPrintErrors();
GroundBytecodeValue _GroundBytecodeProgramExecute(GroundBytecodeProgram* program, GroundBytecodeHeap* heap);
2026-06-21 14:35:48 +10:00
void _GroundBytecodeProgramOptimise(GroundBytecodeProgram* program);
struct GroundExecutionResult _GroundBytecodeInstructionExecute(GroundBytecodeInstruction* instruction, GroundBytecodeHeap* heap);
2026-06-21 14:35:48 +10:00
2026-06-21 16:13:00 +10:00
void _GroundBytecodeSave(GroundBytecode* bytecode, const char* path);
GroundBytecode _GroundBytecodeLoad(const char* path);
2026-06-21 14:35:48 +10:00
void _GroundBytecodeHeapSet(GroundBytecodeHeap* heap, GroundSize idx, GroundValue value);
GroundValue* _GroundBytecodeHeapGet(GroundBytecodeHeap* heap, GroundSize idx);
2026-06-15 20:27:50 +10:00
2026-06-25 18:57:53 +10:00
char* _GroundStringifyArg(GroundArg* arg);
char* _GroundStringifyHeap(GroundBytecodeHeap* heap);
char* _GroundStringifyInstruction(GroundInstruction* instruction);
char* _GroundStringifyProgram(GroundProgram* program);
char* _GroundStringifyString(GroundString* string);
char* _GroundStringifyValue(GroundValue* value);
2026-07-02 11:35:56 +10:00
char* _GroundStringifyBytecodeValue(GroundBytecodeValue* value);
2026-06-25 18:57:53 +10:00
2026-06-13 19:45:36 +10:00
struct _Ground Ground = {
.Flags = {
.error = false
},
.New = {
.Value = {
.Int = _GroundNewValueInt,
.Double = _GroundNewValueDouble,
.Char = _GroundNewValueChar,
.Bool = _GroundNewValueBool,
.List = _GroundNewValueList,
.String = _GroundNewValueString,
.Function = _GroundNewValueFunction,
.Struct = _GroundNewValueStruct,
.Object = _GroundNewValueObject,
},
.Arg = {
.Value = _GroundNewArgValue,
.ValueRef = _GroundNewArgValueRef,
.DirectRef = _GroundNewArgDirectRef,
.LineRef = _GroundNewArgLineRef,
.LabelRef = _GroundNewArgLabelRef,
.FunctionRef = _GroundNewArgFunctionRef,
.TypeRef = _GroundNewArgTypeRef,
},
.List = _GroundNewList,
.String = _GroundNewString,
.Function = _GroundNewFunction,
.Struct = _GroundNewStruct,
.Object = _GroundNewObject,
.Error = _GroundNewError,
.NativeFunction = _GroundNewNativeFunction,
.Instruction = _GroundNewInstruction,
.Program = _GroundNewProgram,
.Type = _GroundNewType,
2026-06-17 10:11:15 +10:00
.Identifier = _GroundNewIdentifier,
2026-06-21 14:35:48 +10:00
.Bytecode = _GroundNewBytecode,
2026-07-02 11:35:56 +10:00
.BytecodeValue = _GroundNewBytecodeValue,
2026-06-13 19:45:36 +10:00
},
.Free = {
.Value = _GroundFreeValue,
.List = _GroundFreeList,
.String = _GroundFreeString,
.Function = _GroundFreeFunction,
.Struct = _GroundFreeStruct,
.Object = _GroundFreeObject,
2026-06-16 20:01:42 +10:00
.Arg = _GroundFreeArg,
.Instruction = _GroundFreeInstruction,
.Program = _GroundFreeProgram,
.State = _GroundFreeState,
2026-06-17 10:11:15 +10:00
.Identifier = _GroundFreeIdentifier,
2026-07-02 11:35:56 +10:00
.BytecodeValue = _GroundFreeBytecodeValue,
2026-06-13 19:45:36 +10:00
},
.Copy = {
.Value = _GroundCopyValue,
.List = _GroundCopyList,
.String = _GroundCopyString,
.Function = _GroundCopyFunction,
.Struct = _GroundCopyStruct,
.Object = _GroundCopyObject,
.Arg = _GroundCopyArg,
.Instruction = _GroundCopyInstruction,
.Program = _GroundCopyProgram,
.State = _GroundCopyState,
2026-06-17 10:11:15 +10:00
.Identifier = _GroundCopyIdentifier,
2026-07-03 19:06:40 +10:00
.BytecodeValue = _GroundCopyBytecodeValue,
2026-06-13 19:45:36 +10:00
},
.List = {
.append = _GroundListAppend,
},
.Instruction = {
.append = _GroundInstructionAppend,
.execute = _GroundInstructionExecute,
},
.Program = {
.append = _GroundProgramAppend,
.execute = _GroundProgramExecute,
2026-07-02 11:35:56 +10:00
.preprocess = _GroundProgramPreprocess,
2026-06-13 19:45:36 +10:00
},
.Function = {
.appendInstruction = _GroundFunctionAppendInstruction,
.appendArg = _GroundFunctionAppendArg,
},
.Struct = {
.addField = _GroundStructAddField,
},
2026-06-15 20:27:50 +10:00
.State = {
.findCatch = _GroundStateFindCatch,
.findLabel = _GroundStateFindLabel,
.findVariable = _GroundStateFindVariable,
},
.Internal = {
.run = _GroundInternalRun
},
.Log = {
.Error = _GroundLogError,
.Warning = _GroundLogWarning,
.printErrors = _GroundLogPrintErrors,
.errors = NULL,
.warnings = NULL,
},
2026-06-21 14:35:48 +10:00
.Bytecode = {
2026-06-21 16:13:00 +10:00
.save = _GroundBytecodeSave,
.load = _GroundBytecodeLoad,
2026-06-21 14:35:48 +10:00
.Program = {
.execute = _GroundBytecodeProgramExecute,
.optimise = _GroundBytecodeProgramOptimise,
},
.Instruction = {
.execute = _GroundBytecodeInstructionExecute,
},
.Heap = {
.set = _GroundBytecodeHeapSet,
.get = _GroundBytecodeHeapGet,
},
},
2026-06-25 18:57:53 +10:00
.Stringify = {
.Arg = _GroundStringifyArg,
.Heap = _GroundStringifyHeap,
.Instruction = _GroundStringifyInstruction,
.Program = _GroundStringifyProgram,
.String = _GroundStringifyString,
.Value = _GroundStringifyValue,
2026-07-02 11:35:56 +10:00
.BytecodeValue = _GroundStringifyBytecodeValue,
2026-06-25 18:57:53 +10:00
},
2026-06-13 19:45:36 +10:00
};