Skip to content

Commit

Permalink
fix environment error to get value from function
Browse files Browse the repository at this point in the history
  • Loading branch information
ysw421 committed Jan 31, 2024
1 parent b6dadc4 commit 0baa51e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/test2.or
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ a := -3+21+(-23)

x:=2+2.1
print("hello\n")
y:=((2+3)x+3/2)/3+f(3+2)
y:=((2+3)x+3/2)/3+f(3)

print("variable a: ", a, "\n")
print("variable x: ", x, "\n")
Expand Down
10 changes: 6 additions & 4 deletions src/Visitor/visitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ AST_value_stack* visitor_get_value_from_function
}
AST_value_stack* new_value_stack;

// Set New Environment: new_envs
Envs* new_envs = visitor_merge_envs(envs);

// Get value from arguments...
for (int i = 0; i < env_function->args_size; i ++)
{
AST* ast = ast_function->args[i];
Expand Down Expand Up @@ -356,7 +358,7 @@ AST_value_stack* visitor_get_value_from_function
else
{
AST_value_stack* new_value =
visitor_get_value(envs, ast->value.value_v);
visitor_get_value(new_envs, ast->value.value_v);

orora_value_type* p = value_type_list;
do
Expand All @@ -383,7 +385,7 @@ AST_value_stack* visitor_get_value_from_function
{
case AST_VARIABLE_VALUE:
Env_variable* value_variable =
visitor_get_variable(envs,
visitor_get_variable(new_envs,
ast->value.variable_v);
if (!value_variable)
{
Expand All @@ -397,7 +399,7 @@ AST_value_stack* visitor_get_value_from_function

case AST_VARIABLE_DEFINE:
value_variable =
visitor_variable_define(envs,
visitor_variable_define(new_envs,
ast->value.variable_v);
env_variable->type = value_variable->type;
env_variable->value = value_variable->value;
Expand Down Expand Up @@ -432,7 +434,7 @@ AST_value_stack* visitor_get_value_from_function
}
}

printf("!!!\n");
printf("!!! %s %ld\n", env_function->name, new_envs->local->variable_size);
return (void*) 0;
}

Expand Down

0 comments on commit 0baa51e

Please sign in to comment.