Initial commit

This commit is contained in:
2026-06-13 19:45:36 +10:00
commit 284b08b12a
56 changed files with 1546 additions and 0 deletions

24
src/New/Arg/DirectRef.c Normal file
View File

@@ -0,0 +1,24 @@
#include "../../../include/ground.h"
#include <string.h>
#include <stdlib.h>
GroundArg _GroundNewArgDirectRef(const char* ref) {
size_t len = strlen(ref);
char* copy = malloc(len + 1);
if (copy == NULL) {
Ground.Flags.error = true;
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = ""
};
}
strcpy(copy, ref);
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = copy
};
}

24
src/New/Arg/FunctionRef.c Normal file
View File

@@ -0,0 +1,24 @@
#include "../../../include/ground.h"
#include <string.h>
#include <stdlib.h>
GroundArg _GroundNewArgFunctionRef(const char* ref) {
size_t len = strlen(ref);
char* copy = malloc(len + 1);
if (copy == NULL) {
Ground.Flags.error = true;
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = ""
};
}
strcpy(copy, ref);
return (GroundArg) {
.type = GroundArg_FunctionRef,
.as.ref = copy
};
}

25
src/New/Arg/LabelRef.c Normal file
View File

@@ -0,0 +1,25 @@
#include "../../../include/ground.h"
#include <string.h>
#include <stdlib.h>
GroundArg _GroundNewArgLabelRef(const char* ref) {
size_t len = strlen(ref);
char* copy = malloc(len + 1);
if (copy == NULL) {
Ground.Flags.error = true;
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = ""
};
}
strcpy(copy, ref);
return (GroundArg) {
.type = GroundArg_Label,
.as.ref = copy
};
}

24
src/New/Arg/LineRef.c Normal file
View File

@@ -0,0 +1,24 @@
#include "../../../include/ground.h"
#include <string.h>
#include <stdlib.h>
GroundArg _GroundNewArgLineRef(const char* ref) {
size_t len = strlen(ref);
char* copy = malloc(len + 1);
if (copy == NULL) {
Ground.Flags.error = true;
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = ""
};
}
strcpy(copy, ref);
return (GroundArg) {
.type = GroundArg_LineRef,
.as.ref = copy
};
}

25
src/New/Arg/TypeRef.c Normal file
View File

@@ -0,0 +1,25 @@
#include "../../../include/ground.h"
#include <string.h>
#include <stdlib.h>
GroundArg _GroundNewArgTypeRef(const char* ref) {
size_t len = strlen(ref);
char* copy = malloc(len + 1);
if (copy == NULL) {
Ground.Flags.error = true;
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = ""
};
}
strcpy(copy, ref);
return (GroundArg) {
.type = GroundArg_TypeRef,
.as.ref = copy
};
}

8
src/New/Arg/Value.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundArg _GroundNewArgValue(GroundValue value) {
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.value = Ground.Copy.Value(&value)
};
}

25
src/New/Arg/ValueRef.c Normal file
View File

@@ -0,0 +1,25 @@
#include "../../../include/ground.h"
#include <string.h>
#include <stdlib.h>
GroundArg _GroundNewArgValueRef(const char* ref) {
size_t len = strlen(ref);
char* copy = malloc(len + 1);
if (copy == NULL) {
Ground.Flags.error = true;
return (GroundArg) {
.type = GroundArg_DirectRef,
.as.ref = ""
};
}
strcpy(copy, ref);
return (GroundArg) {
.type = GroundArg_ValueRef,
.as.ref = copy
};
}

15
src/New/Error.c Normal file
View File

@@ -0,0 +1,15 @@
#include "../../include/ground.h"
GroundError _GroundNewError(GroundValue* in) {
GroundError error = {
.value = malloc(sizeof(GroundValue))
};
if (error.value == NULL) {
Ground.Flags.error = true;
return error;
}
*error.value = Ground.Copy.Value(in);
return error;
}

23
src/New/Function.c Normal file
View File

@@ -0,0 +1,23 @@
#include "../../include/ground.h"
GroundFunction _GroundNewFunction(GroundState* state) {
GroundFunction function = {
.args.at = malloc(sizeof(char*) * 16),
.args.count = 0,
.args.capacity = 0,
.closure = malloc(sizeof(GroundState)),
.isNativeFunction = false,
.program.ground = malloc(sizeof(GroundProgram)),
};
if (function.closure == NULL || function.program.ground == NULL) {
Ground.Flags.error = true;
return function;
}
*function.closure = Ground.Copy.State(state);
*function.program.ground = Ground.New.Program();
return function;
}

17
src/New/Instruction.c Normal file
View File

@@ -0,0 +1,17 @@
#include "../../include/ground.h"
GroundInstruction _GroundNewInstruction(enum GroundInstructionType type) {
GroundInstruction instruction = {
.type = type,
.args = {
.capacity = 8,
.len = 0,
.at = malloc(sizeof(GroundArg) * 8)
}
};
if (instruction.args.at == NULL) {
Ground.Flags.error = true;
}
return instruction;
}

15
src/New/List.c Normal file
View File

@@ -0,0 +1,15 @@
#include "../../include/ground.h"
GroundList _GroundNewList(size_t len, GroundValue* contents) {
GroundList list = {
.capacity = 16,
.count = 0,
.at = malloc(sizeof(GroundValue) * 16)
};
if (list.at == NULL) {
Ground.Flags.error = true;
}
return list;
}

49
src/New/NativeFunction.c Normal file
View File

@@ -0,0 +1,49 @@
#include "../../include/ground.h"
#include <ffi.h>
#include <stdarg.h>
GroundFunction _GroundNewNativeFunction(void* function, size_t argc, ...) {
GroundState state = {NULL, NULL, NULL};
GroundFunction gf = Ground.New.Function(&state);
gf.isNativeFunction = true;
gf.program.native = function;
va_list args;
va_start(args, argc);
for (size_t i = 0; i < argc; i++) {
GroundType type = va_arg(args, GroundType);
if (type.type == GroundType_Struct) {
Ground.Flags.error = true;
return gf;
}
if (type.type == GroundType_Object) {
// WIP
Ground.Flags.error = true;
return gf;
}
if (gf.args.count + 1 >= gf.args.capacity) {
GroundFunctionArg* tmp = realloc(gf.args.at, sizeof(GroundFunctionArg) * gf.args.capacity * 2);
if (tmp == NULL) {
Ground.Flags.error = true;
return gf;
}
gf.args.at = tmp;
gf.args.capacity *= 2;
}
gf.args.at[gf.args.count].as.type = va_arg(args, GroundType);
gf.args.count++;
}
return gf;
}

34
src/New/Object.c Normal file
View File

@@ -0,0 +1,34 @@
#include "../../include/ground.h"
GroundObject _GroundNewObject(GroundStruct* in) {
GroundObject object = {
.fields = NULL,
.type = in
};
GroundObjectField* src = in->fields;
GroundObjectField *s, *tmp, *item;
HASH_ITER(hh, src, s, tmp) {
item = malloc(sizeof(GroundObjectField));
if (item == NULL) {
Ground.Flags.error = true;
return object;
}
strncpy(item->name, s->name, 2047);
*item->value = Ground.Copy.Value(s->value);
if (Ground.Flags.error) {
return object;
}
HASH_ADD_STR(object.fields, name, item);
}
return object;
}

14
src/New/Program.c Normal file
View File

@@ -0,0 +1,14 @@
#include "../../include/ground.h"
GroundProgram _GroundNewProgram() {
GroundProgram newProgram = {
.capacity = 16,
.len = 0,
.at = malloc(sizeof(GroundInstruction) * 16)
};
if (newProgram.at == NULL) {
Ground.Flags.error = true;
}
return newProgram;
}

20
src/New/String.c Normal file
View File

@@ -0,0 +1,20 @@
#include "../../include/ground.h"
GroundString _GroundNewString(const char* in) {
size_t len = strlen(in);
GroundString string = {
.len = len,
.cstr = malloc(sizeof(len) + 1)
};
if (string.cstr == NULL) {
Ground.Flags.error = true;
string.len = 0;
return string;
}
strcpy(string.cstr, in);
return string;
}

7
src/New/Struct.c Normal file
View File

@@ -0,0 +1,7 @@
#include "../../include/ground.h"
GroundStruct _GroundNewStruct() {
return (GroundStruct) {
.fields = NULL
};
}

17
src/New/Type.c Normal file
View File

@@ -0,0 +1,17 @@
#include "../../include/ground.h"
#include <stdarg.h>
GroundType _GroundNewType(enum GroundTypeType type, ...) {
va_list args;
GroundType gt = {
.type = type
};
if (type == GroundType_Object) {
va_start(args, type);
gt.complexType = va_arg(args, GroundStruct);
};
return gt;
}

8
src/New/Value/Bool.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueBool(GroundBool in) {
return (GroundValue) {
.as.Bool = in,
.type = Ground.New.Type(GroundType_Bool)
};
}

8
src/New/Value/Char.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueChar(GroundChar in) {
return (GroundValue) {
.as.Char = in,
.type = Ground.New.Type(GroundType_Char)
};
}

8
src/New/Value/Double.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueDouble(GroundDouble in) {
return (GroundValue) {
.as.Double = in,
.type = Ground.New.Type(GroundType_Double)
};
}

8
src/New/Value/Function.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueFunction(GroundFunction in) {
return (GroundValue) {
.as.Function = in,
.type = Ground.New.Type(GroundType_Function)
};
}

8
src/New/Value/Int.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueInt(GroundInt in) {
return (GroundValue) {
.as.Int = in,
.type = Ground.New.Type(GroundType_Int)
};
}

8
src/New/Value/List.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueList(GroundList in) {
return (GroundValue) {
.as.List = in,
.type = Ground.New.Type(GroundType_List)
};
}

8
src/New/Value/Object.c Normal file
View File

@@ -0,0 +1,8 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueObject(GroundObject in) {
return (GroundValue) {
.as.Object = in,
.type = Ground.New.Type(GroundType_Object, *in.type)
};
}

9
src/New/Value/String.c Normal file
View File

@@ -0,0 +1,9 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueString(GroundString in) {
return (GroundValue) {
.as.String = in,
.type = Ground.New.Type(GroundType_String)
};
}

9
src/New/Value/Struct.c Normal file
View File

@@ -0,0 +1,9 @@
#include "../../../include/ground.h"
GroundValue _GroundNewValueStruct(GroundStruct in) {
return (GroundValue) {
.as.Struct = in,
.type = Ground.New.Type(GroundType_Struct)
};
}