forked from ground/cground
extlibs can now add variables and structs!
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
#include "lexer.h"
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -68,11 +67,34 @@ GroundValue groundCreateValue(GroundValueType type, ...) {
|
|||||||
return createListGroundValue(va_arg(args, List));
|
return createListGroundValue(va_arg(args, List));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
case FUNCTION: {
|
||||||
|
return createFunctionGroundValue(va_arg(args, GroundFunction*));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case STRUCTVAL: {
|
||||||
|
GroundValue gv;
|
||||||
|
gv.type = STRUCTVAL;
|
||||||
|
gv.data.structVal = malloc(sizeof(GroundStruct));
|
||||||
|
*gv.data.structVal = va_arg(args, GroundStruct);
|
||||||
|
return gv;
|
||||||
|
}
|
||||||
|
case CUSTOM: {
|
||||||
|
// FIXME do this later lmao
|
||||||
return createNoneGroundValue();
|
return createNoneGroundValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ERROR: {
|
||||||
|
return createErrorGroundValue(va_arg(args, GroundError));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NONE: {
|
||||||
|
return createNoneGroundValue();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return createNoneGroundValue();
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,3 +112,18 @@ void groundPrintProgram(GroundProgram* program) {
|
|||||||
GroundProgram groundParseFile(const char* code) {
|
GroundProgram groundParseFile(const char* code) {
|
||||||
return parseFile(code);
|
return parseFile(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GroundStruct groundCreateStruct() {
|
||||||
|
GroundStruct gs;
|
||||||
|
gs.size = 0;
|
||||||
|
gs.fields = malloc(sizeof(GroundStructField));
|
||||||
|
return gs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void groundAddValueToScope(GroundScope* gs, const char* name, GroundValue value) {
|
||||||
|
addVariable(gs->variables, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void groundAddFieldToStruct(GroundStruct* gstruct, char* name, GroundValue field) {
|
||||||
|
addFieldToStruct(gstruct, name, field);
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ GroundFunction* parseFunction(GroundProgram* in, size_t errorOffset);
|
|||||||
GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope);
|
GroundValue interpretGroundProgram(GroundProgram* in, GroundScope* inScope);
|
||||||
GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scope);
|
GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scope);
|
||||||
|
|
||||||
|
void addVariable(GroundVariable **head, const char *id, GroundValue data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user