More debug features, update README, new makefile
This commit is contained in:
81
src/interface.c
Normal file
81
src/interface.c
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
#include "interpreter.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
GroundProgram groundCreateProgram() {
|
||||
return (GroundProgram) {
|
||||
.instructions = malloc(sizeof(GroundInstruction)),
|
||||
.size = 0
|
||||
};
|
||||
}
|
||||
void groundAddInstructionToProgram(GroundProgram* program, GroundInstruction instruction) {
|
||||
addInstructionToProgram(program, instruction);
|
||||
}
|
||||
|
||||
GroundInstruction groundCreateInstruction(GroundInstType type) {
|
||||
return (GroundInstruction) {
|
||||
.type = type,
|
||||
.args.args = malloc(sizeof(GroundArg)),
|
||||
.args.length = 0
|
||||
};
|
||||
}
|
||||
|
||||
void groundAddValueToInstruction(GroundInstruction* inst, GroundValue value) {
|
||||
addArgToInstruction(inst, createValueGroundArg(value));
|
||||
}
|
||||
|
||||
void groundAddReferenceToInstruction(GroundInstruction* inst, GroundArg value) {
|
||||
addArgToInstruction(inst, value);
|
||||
}
|
||||
|
||||
GroundArg groundCreateReference(GroundArgType type, char* ref) {
|
||||
return (GroundArg) {
|
||||
.type = type,
|
||||
.value.refName = ref
|
||||
};
|
||||
}
|
||||
|
||||
GroundValue groundCreateValue(GroundValueType type, ...) {
|
||||
va_list args;
|
||||
va_start(args, type);
|
||||
|
||||
switch (type) {
|
||||
case INT: {
|
||||
return createIntGroundValue(va_arg(args, int));
|
||||
break;
|
||||
}
|
||||
case DOUBLE: {
|
||||
return createDoubleGroundValue(va_arg(args, double));
|
||||
break;
|
||||
}
|
||||
case STRING: {
|
||||
return createStringGroundValue(va_arg(args, char*));
|
||||
break;
|
||||
}
|
||||
case CHAR: {
|
||||
return createCharGroundValue((char)va_arg(args, int));
|
||||
break;
|
||||
}
|
||||
case BOOL: {
|
||||
return createBoolGroundValue((bool)va_arg(args, int));
|
||||
break;
|
||||
}
|
||||
case LIST: {
|
||||
return createListGroundValue(va_arg(args, List));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return createNoneGroundValue();
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
GroundValue groundRunProgram(GroundProgram* program) {
|
||||
return interpretGroundProgram(program, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user