progress
This commit is contained in:
@@ -31,7 +31,7 @@ GroundFunction _GroundCopyFunction(GroundFunction* in) {
|
||||
Ground.Flags.error = true;
|
||||
return newFunction;
|
||||
}
|
||||
for (size_t i = 0; i < in->args.count; i++) {
|
||||
for (GroundSize i = 0; i < in->args.count; i++) {
|
||||
if (newFunction.args.at == NULL) {
|
||||
Ground.Log.Error("malloc failed in Ground.Copy.Function()");
|
||||
Ground.Flags.error = true;
|
||||
|
||||
@@ -12,7 +12,7 @@ GroundInstruction _GroundCopyInstruction(GroundInstruction* in) {
|
||||
return instruction;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < in->args.len; i++) {
|
||||
for (GroundSize i = 0; i < in->args.len; i++) {
|
||||
instruction.args.at[i] = Ground.Copy.Arg(&in->args.at[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ GroundList _GroundCopyList(GroundList* in) {
|
||||
return list;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < in->count; i++) {
|
||||
for (GroundSize i = 0; i < in->count; i++) {
|
||||
list.at[i] = Ground.Copy.Value(&in->at[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ GroundProgram _GroundCopyProgram(GroundProgram* in) {
|
||||
return program;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < in->len; i++) {
|
||||
for (GroundSize i = 0; i < in->len; i++) {
|
||||
program.at[i] = Ground.Copy.Instruction(&in->at[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ void _GroundFreeFunction(GroundFunction* in) {
|
||||
Ground.Free.Program(in->program.ground);
|
||||
free(in->program.ground);
|
||||
|
||||
for (size_t i = 0; i < in->args.count; i++) {
|
||||
for (GroundSize i = 0; i < in->args.count; i++) {
|
||||
free(in->args.at[i].as.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../../include/ground.h"
|
||||
|
||||
void _GroundFreeInstruction(GroundInstruction* in) {
|
||||
for (size_t i = 0; i < in->args.len; i++) {
|
||||
for (GroundSize i = 0; i < in->args.len; i++) {
|
||||
Ground.Free.Arg(&in->args.at[i]);
|
||||
}
|
||||
free(in->args.at);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "../../include/ground.h"
|
||||
|
||||
void _GroundFreeProgram(GroundProgram* in) {
|
||||
for (size_t i = 0; i < in->len; i++) {
|
||||
for (GroundSize i = 0; i < in->len; i++) {
|
||||
Ground.Free.Instruction(&in->at[i]);
|
||||
}
|
||||
free(in->at);
|
||||
|
||||
@@ -29,9 +29,9 @@ int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* h
|
||||
};
|
||||
|
||||
// Preprocess any ValueRefs
|
||||
for (size_t i = 0; i < instruction->args.len; i++) {
|
||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||
if (instruction->args.at[i].type == GroundArg_ValueRef) {
|
||||
size_t offset = instruction->args.at[i]._offset;
|
||||
GroundSize offset = instruction->args.at[i]._offset;
|
||||
instruction->args.at[i] = Ground.New.Arg.Value(heap[offset]);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* h
|
||||
return -1;
|
||||
}
|
||||
PRINT: {
|
||||
for (size_t i = 0; i < instruction->args.len; i++) {
|
||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||
GroundValue* val = &instruction->args.at[i].as.value;
|
||||
switch (val->type.type) {
|
||||
case GroundType_Int:
|
||||
@@ -93,7 +93,7 @@ int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* h
|
||||
return -1;
|
||||
}
|
||||
PRINTLN: {
|
||||
for (size_t i = 0; i < instruction->args.len; i++) {
|
||||
for (GroundSize i = 0; i < instruction->args.len; i++) {
|
||||
GroundValue* val = &instruction->args.at[i].as.value;
|
||||
switch (val->type.type) {
|
||||
case GroundType_Int:
|
||||
@@ -125,7 +125,7 @@ int64_t _GroundInstructionExecute(GroundInstruction* instruction, GroundValue* h
|
||||
return -1;
|
||||
}
|
||||
SET: {
|
||||
size_t offset = instruction->args.at[0]._offset;
|
||||
GroundSize offset = instruction->args.at[0]._offset;
|
||||
heap[offset] = instruction->args.at[1].as.value;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
|
||||
for (size_t i = 0; i < program->len; i++) {
|
||||
for (GroundSize i = 0; i < program->len; i++) {
|
||||
GroundInstruction* instruction = &program->at[i];
|
||||
if (instruction->type == GroundInstruction_CREATELABEL) {
|
||||
if (instruction->args.len > 0) {
|
||||
@@ -30,11 +30,11 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < program->len; i++) {
|
||||
for (GroundSize i = 0; i < program->len; i++) {
|
||||
GroundInstruction* instruction = &program->at[i];
|
||||
if (instruction->type == GroundInstruction_JUMP) {
|
||||
GroundArg* arg = &instruction->args.at[0];
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
GroundSize* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
if (line == NULL) {
|
||||
char buf[2048];
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction JUMP at %zu) in Ground.Internal.Run()", arg->as.ref->string, i);
|
||||
@@ -47,7 +47,7 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
|
||||
} else if (instruction->type == GroundInstruction_IF) {
|
||||
GroundArg* arg = &instruction->args.at[1];
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
GroundSize* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
if (line == NULL) {
|
||||
char buf[2048];
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction IF at %zu) in Ground.Internal.Run()", arg->as.ref->string, i);
|
||||
@@ -60,7 +60,7 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
|
||||
} else if (instruction->type == GroundInstruction_CATCH) {
|
||||
GroundArg* arg = &instruction->args.at[1];
|
||||
size_t* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
GroundSize* line = Ground.State.findLabel(state, arg->as.ref->string);
|
||||
if (line == NULL) {
|
||||
char buf[2048];
|
||||
snprintf(buf, 2047, "couldn't find label '%s' (instruction CATCH at %zu) in Ground.Internal.Run()", arg->as.ref->string, i);
|
||||
@@ -79,10 +79,10 @@ static inline void doLabels(GroundProgram* program, GroundState* state) {
|
||||
/*
|
||||
* Assigns an offset to each variable referenced.
|
||||
*/
|
||||
static inline size_t doOffsets(GroundProgram* program, GroundState* state) {
|
||||
size_t size = 0;
|
||||
for (size_t i = 0; i < program->len; i++) {
|
||||
for (size_t j = 0; j < program->at[i].args.len; j++) {
|
||||
static inline GroundSize doOffsets(GroundProgram* program, GroundState* state) {
|
||||
GroundSize size = 0;
|
||||
for (GroundSize i = 0; i < program->len; i++) {
|
||||
for (GroundSize j = 0; j < program->at[i].args.len; j++) {
|
||||
GroundArg* arg = &program->at[i].args.at[j];
|
||||
|
||||
if (
|
||||
@@ -120,12 +120,12 @@ void _GroundInternalRun(GroundProgram* program, GroundState* state) {
|
||||
doLabels(program, state);
|
||||
if (Ground.Flags.error) return;
|
||||
|
||||
size_t size = doOffsets(program, state);
|
||||
GroundSize size = doOffsets(program, state);
|
||||
if (Ground.Flags.error) return;
|
||||
|
||||
GroundValue* heap = malloc(sizeof(GroundValue) * size);
|
||||
|
||||
for (size_t i = 0; i < program->len; i++) {
|
||||
for (GroundSize i = 0; i < program->len; i++) {
|
||||
GroundInstruction instruction = Ground.Copy.Instruction(&program->at[i]);
|
||||
int64_t status = Ground.Instruction.execute(&instruction, heap);
|
||||
switch (status) {
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
void _GroundLogPrintErrors() {
|
||||
if (Ground.Log.errorCount != 0) {
|
||||
printf("%zu errors:\n", Ground.Log.errorCount);
|
||||
for (size_t i = 0; i < Ground.Log.errorCount; i++) {
|
||||
for (GroundSize i = 0; i < Ground.Log.errorCount; i++) {
|
||||
printf(" \e[0;31m%zu: %s\n\e[0m", Ground.Log.errorCount, Ground.Log.errors[i]);
|
||||
}
|
||||
}
|
||||
if (Ground.Log.warningCount != 0) {
|
||||
printf("%zu warnings:\n", Ground.Log.warningCount);
|
||||
for (size_t i = 0; i < Ground.Log.warningCount; i++) {
|
||||
for (GroundSize i = 0; i < Ground.Log.warningCount; i++) {
|
||||
printf(" \e[0;33m%zu: %s\n\e[0m", Ground.Log.warningCount, Ground.Log.warnings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "../../include/ground.h"
|
||||
|
||||
GroundList _GroundNewList(size_t len, GroundValue* contents) {
|
||||
GroundList _GroundNewList(GroundSize len, GroundValue* contents) {
|
||||
GroundList list = {
|
||||
.capacity = 16,
|
||||
.count = 0,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <ffi.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
GroundFunction _GroundNewNativeFunction(void* function, size_t argc, ...) {
|
||||
GroundFunction _GroundNewNativeFunction(void* function, GroundSize argc, ...) {
|
||||
|
||||
GroundState state = {NULL, NULL, NULL};
|
||||
GroundFunction gf = Ground.New.Function(&state);
|
||||
@@ -13,7 +13,7 @@ GroundFunction _GroundNewNativeFunction(void* function, size_t argc, ...) {
|
||||
va_list args;
|
||||
va_start(args, argc);
|
||||
|
||||
for (size_t i = 0; i < argc; i++) {
|
||||
for (GroundSize i = 0; i < argc; i++) {
|
||||
GroundType type = va_arg(args, GroundType);
|
||||
if (type.type == GroundType_Struct) {
|
||||
Ground.Log.Error("Cannot pass struct to native function in Ground.New.NativeFunction()");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
GroundString _GroundNewString(const char* in) {
|
||||
|
||||
size_t len = strlen(in);
|
||||
GroundSize len = strlen(in);
|
||||
|
||||
GroundString string = {
|
||||
.len = len,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "../../include/ground.h"
|
||||
|
||||
size_t* _GroundStateFindLabel(GroundState* state, char* id) {
|
||||
GroundSize* _GroundStateFindLabel(GroundState* state, char* id) {
|
||||
GroundLabel* item = NULL;
|
||||
HASH_FIND_STR(state->labels, id, item);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ GroundArg _GroundNewArgTypeRef(GroundIdentifier* ref);
|
||||
GroundList _GroundNewList();
|
||||
GroundString _GroundNewString(const char* in);
|
||||
GroundFunction _GroundNewFunction(GroundState* state);
|
||||
GroundFunction _GroundNewNativeFunction(void* function, size_t argc, ...);
|
||||
GroundFunction _GroundNewNativeFunction(void* function, GroundSize argc, ...);
|
||||
GroundStruct _GroundNewStruct();
|
||||
GroundObject _GroundNewObject(GroundStruct* in);
|
||||
GroundError _GroundNewError(GroundValue* in);
|
||||
@@ -81,7 +81,7 @@ void _GroundStructAddField(GroundStruct* gs, const char* id, GroundValue value);
|
||||
|
||||
|
||||
GroundValue* _GroundStateFindVariable(GroundState* state, const char* id);
|
||||
size_t* _GroundStateFindLabel(GroundState* state, const char* id);
|
||||
GroundSize* _GroundStateFindLabel(GroundState* state, const char* id);
|
||||
GroundCatch* _GroundStateFindCatch(GroundState* state, const char* id);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user