aboutsummaryrefslogtreecommitdiff
path: root/src/vm/runner
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2024-09-25 19:47:29 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2024-09-25 19:47:29 +0330
commitc409b8aaf6b6f63bd68a3356e146ab80b2ec8c4b (patch)
tree65ea5801fd910fc6bcff3f2e8f06b5fd7d249c78 /src/vm/runner
parentf79290084948f3cf140395c270c07cf29ca58e8d (diff)
fixed multiple variable definition bug
tried to implement import
Diffstat (limited to 'src/vm/runner')
-rw-r--r--src/vm/runner/runner.c13
-rw-r--r--src/vm/runner/runner.h2
2 files changed, 8 insertions, 7 deletions
diff --git a/src/vm/runner/runner.c b/src/vm/runner/runner.c
index 4fcea52..3dcab9b 100644
--- a/src/vm/runner/runner.c
+++ b/src/vm/runner/runner.c
@@ -16,8 +16,8 @@ const char *BUILTIN_FUNCTION_NAMES[] = {
const size_t BUILTIN_FUNCTIONS_SIZE =
sizeof(BUILTIN_FUNCTIONS) / sizeof(BuiltinFunction);
-bool runner(SourceCode code) {
- Instructions instructions = codeGenerator(code);
+bool runner(SourceCode *sourceCode) {
+ Instructions instructions = codeGenerator(sourceCode);
if (instructions.size != ERROR_SIZE) {
bool ranSuccess = _runner(instructions);
deleteInstructions(instructions);
@@ -44,7 +44,7 @@ bool _runner(Instructions instructions) {
}
}
- for(size_t i = 0;i < variables_size;++i){
+ for (size_t i = 0; i < variables_inserted; ++i) {
free(variables[i]);
}
@@ -88,8 +88,9 @@ bool runInstruction(Instruction instruction, void ***restrict stack,
switch (instruction.command) {
case COMMAND_PUSH_IDENTIFIER: {
const CommandPushIdentifierOperand *operand = instruction.operand;
- pushToStack(getRunnerVariable(operand, variables, variables_inserted)->value,
- stack, stack_size, stack_inserted);
+ pushToStack(
+ getRunnerVariable(operand, variables, variables_inserted)->value,
+ stack, stack_size, stack_inserted);
return true;
}
case COMMAND_PUSH_STRING: {
@@ -123,7 +124,7 @@ bool runInstruction(Instruction instruction, void ***restrict stack,
RunnerVariable *getRunnerVariable(const SizedString *varName,
RunnerVariable ***restrict variables,
size_t *restrict variables_inserted) {
- for (size_t i = *variables_inserted - 1; i != (typeof(i))-1; ++i) {
+ for (size_t i = *variables_inserted - 1; i != (typeof(i))-1; --i) {
RunnerVariable *variable = (*variables)[i];
if (variable->name->size == varName->size &&
strncmp(varName->str, variable->name->str, varName->size) == 0) {
diff --git a/src/vm/runner/runner.h b/src/vm/runner/runner.h
index d2df5d7..80ef571 100644
--- a/src/vm/runner/runner.h
+++ b/src/vm/runner/runner.h
@@ -14,7 +14,7 @@ extern const BuiltinFunction BUILTIN_FUNCTIONS[];
extern const char *BUILTIN_FUNCTION_NAMES[];
extern const size_t BUILTIN_FUNCTIONS_SIZE;
-extern bool runner(SourceCode code);
+extern bool runner(SourceCode *code);
extern bool _runner(Instructions instructions);
extern bool runInstruction(Instruction instruction, void ***restrict stack,