diff --git a/src/interpreter.c b/src/interpreter.c index 7e675c5..1680c2f 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -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); } diff --git a/src/parser.c b/src/parser.c index 3408340..d956934 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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); diff --git a/src/types.c b/src/types.c index f22d478..017e551 100644 --- a/src/types.c +++ b/src/types.c @@ -371,6 +371,9 @@ void printGroundInstruction(GroundInstruction* gi) { case EXTERN: printf("extern"); break; + case DROP: + printf("drop"); + break; case CREATELABEL: break; default: diff --git a/src/types.h b/src/types.h index 3b561e5..28c4979 100644 --- a/src/types.h +++ b/src/types.h @@ -8,7 +8,7 @@ #include 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 { diff --git a/tests/drop.grnd b/tests/drop.grnd new file mode 100644 index 0000000..f4186d4 --- /dev/null +++ b/tests/drop.grnd @@ -0,0 +1,4 @@ +set &x "dingus" +PAUSE +drop &x +PAUSE