forked from ground/cground
drop instruction for saving memory and time
This commit is contained in:
@@ -1468,6 +1468,24 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
|
||||
currentInstruction = currentCurrentInstruction;
|
||||
break;
|
||||
}
|
||||
|
||||
case DROP: {
|
||||
if (in->args.length < 1) {
|
||||
runtimeError(TOO_FEW_ARGS, "Expecting 1 arg", in, currentInstruction);
|
||||
}
|
||||
if (in->args.length > 1) {
|
||||
runtimeError(TOO_MANY_ARGS, "Expecting 1 arg", in, currentInstruction);
|
||||
}
|
||||
if (in->args.args[0].type != DIRREF) {
|
||||
runtimeError(ARG_TYPE_MISMATCH, "Expecting a DirectRef for arg 1", in, currentInstruction);
|
||||
}
|
||||
GroundVariable* var = findVariable(*scope->variables, in->args.args[0].value.refName);
|
||||
if (!var) {
|
||||
runtimeError(UNKNOWN_VARIABLE, NULL, in, currentInstruction);
|
||||
}
|
||||
deleteVariable(scope->variables, var);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
runtimeError(FIXME, "Currently unimplemented instruction", in, currentInstruction);
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ static GroundInstType getInstructionType(const char* inst) {
|
||||
if (strcmp(inst, "init") == 0) return INIT;
|
||||
if (strcmp(inst, "use") == 0) return USE;
|
||||
if (strcmp(inst, "extern") == 0) return EXTERN;
|
||||
if (strcmp(inst, "drop") == 0) return DROP;
|
||||
if (strcmp(inst, "PAUSE") == 0) return PAUSE;
|
||||
|
||||
fprintf(stderr, "Error: Unknown instruction: %s\n", inst);
|
||||
|
||||
@@ -371,6 +371,9 @@ void printGroundInstruction(GroundInstruction* gi) {
|
||||
case EXTERN:
|
||||
printf("extern");
|
||||
break;
|
||||
case DROP:
|
||||
printf("drop");
|
||||
break;
|
||||
case CREATELABEL:
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <string.h>
|
||||
|
||||
typedef enum GroundInstType {
|
||||
IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, USE, EXTERN, CREATELABEL, PAUSE
|
||||
IF, JUMP, END, INPUT, PRINT, PRINTLN, SET, GETTYPE, EXISTS, SETLIST, SETLISTAT, GETLISTAT, GETLISTSIZE, LISTAPPEND, GETSTRSIZE, GETSTRCHARAT, ADD, SUBTRACT, MULTIPLY, DIVIDE, EQUAL, INEQUAL, NOT, GREATER, LESSER, STOI, STOD, TOSTRING, FUN, RETURN, ENDFUN, PUSHARG, CALL, STRUCT, ENDSTRUCT, INIT, USE, EXTERN, CREATELABEL, PAUSE, DROP
|
||||
} GroundInstType;
|
||||
|
||||
typedef enum GroundValueType {
|
||||
|
||||
4
tests/drop.grnd
Normal file
4
tests/drop.grnd
Normal file
@@ -0,0 +1,4 @@
|
||||
set &x "dingus"
|
||||
PAUSE
|
||||
drop &x
|
||||
PAUSE
|
||||
Reference in New Issue
Block a user