Skip to content

Commit

Permalink
Merge pull request #191 from KennyOliver/issue-190
Browse files Browse the repository at this point in the history
Issue 190: Built-In Function Redefinition Errors in Child Environments (Specifically `rescue`)
  • Loading branch information
KennyOliver authored Jan 9, 2025
2 parents ec60be7 + d875ac6 commit 23e9cb8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 33 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,13 @@ $ flavor --about # About FlavorLang

### Installation Instructions

#### 1. Download & Extract the ZIP

[FlavorLang Releases](https://github.com/KennyOliver/FlavorLang/releases)
#### 1. Download & Extract the ZIP ([FlavorLang Releases](https://github.com/KennyOliver/FlavorLang/releases))

#### 2. Open VS Code and Navigate to the Extensions Tab

#### 3. Click the <kbd>...</kbd> Menu and Select <kbd>Install from VSIX...</kbd>

#### 4. Select the File in Finder or your File Explorer

#### 5. Restart your Extensions via the Popup Notification
#### 4. Restart your Extensions via the Popup Notification

### Make it Yourself

Expand All @@ -196,7 +192,7 @@ $ npm install

#### 2. Package the Extension

Use vsce (Visual Studio Code Extension Manager) to build the `.vsix` package:
Use `vsce` (Visual Studio Code Extension Manager) to build the `.vsix` package:

```bash
$ npx vsce package
Expand Down
15 changes: 2 additions & 13 deletions src/interpreter/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ InterpretResult add_variable(Environment *env, Variable var) {
if (env->variables[i].is_constant) {
debug_print_int("Attempted to reassign to constant `%s`\n",
var.variable_name);
return raise_error("Error: Cannot reassign to constant `%s`.\n",
return raise_error("Cannot reassign to constant `%s`.\n",
var.variable_name);
}

Expand Down Expand Up @@ -1606,18 +1606,7 @@ InterpretResult interpret_try(ASTNode *node, Environment *env) {

while (catch && !handled) {
Environment catch_env;
init_environment(&catch_env);

// Copy global functions to rescue environment
for (size_t i = 0; i < env->function_count; i++) {
Function *global_func = &env->functions[i];
Function func_copy = {.name = strdup(global_func->name),
.parameters = copy_function_parameters(
global_func->parameters),
.body = copy_ast_node(global_func->body),
.is_builtin = global_func->is_builtin};
add_function(&catch_env, func_copy);
}
init_environment_with_parent(&catch_env, env);

// If there's an error variable, bind the exception to it
if (catch->error_variable) {
Expand Down
11 changes: 0 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,6 @@ int main(int argc, char **argv) {
debug_print_basic("Execution complete!\n");
}

// Minify if flag is set (This check is redundant now since we already
// handled minify above)
/*
if (options.minify) {
char *minified_filename = generate_minified_filename(options.filename);
minify_tokens(tokens, minified_filename);
printf("Minified script written to '%s'\n", minified_filename);
free(minified_filename);
}
*/

// Clean up memory
free(tokens);
free(source);
Expand Down
4 changes: 2 additions & 2 deletions src/tests/all.flv
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ create test(num, func_a, func_b) {
deliver func_b(func_a(func_b(num)));
}

let a = test(10, times_2, times_3); # 180
serve(a);
let calc17_result = test(10, times_2, times_3); # 180
serve(calc17_result);

# ==================================================
# 18
Expand Down

0 comments on commit 23e9cb8

Please sign in to comment.