From 8c08996f49ea7b557091b18fee942532e0462360 Mon Sep 17 00:00:00 2001
From: Kenny <70860732+KennyOliver@users.noreply.github.com>
Date: Thu, 9 Jan 2025 22:28:44 +0000
Subject: [PATCH 1/5] Fix: Prevent Redefinition of Built-in Functions in Child
Environments (like `rescue` (`catch`))
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Addressed issue where child environments reinitialized built-in functions, causing duplication errors like “Function string is already defined.”
- Updated interpret_try to use init_environment_with_parent(&catch_env, env) instead of reinitializing built-ins.
- Removed manual copying of functions from the parent environment to the child environment.
- Ensures built-in functions are defined only once in the global environment and are accessible in child environments without duplication.
- Verified that scripts using try-catch blocks execute without triggering function redefinition errors.
#190
---
src/interpreter/interpreter.c | 13 +------------
src/main.c | 11 -----------
2 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/src/interpreter/interpreter.c b/src/interpreter/interpreter.c
index ffb9412..f885bee 100644
--- a/src/interpreter/interpreter.c
+++ b/src/interpreter/interpreter.c
@@ -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) {
diff --git a/src/main.c b/src/main.c
index 6c76605..008714f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
From 8c37a9f1bf9c7414fbb5507fb8494eed4ebb6510 Mon Sep 17 00:00:00 2001
From: Kenny <70860732+KennyOliver@users.noreply.github.com>
Date: Thu, 9 Jan 2025 22:29:38 +0000
Subject: [PATCH 2/5] Update README.md
#190
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 00e5814..42800d4 100644
--- a/README.md
+++ b/README.md
@@ -196,7 +196,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
From 1c75e00d730139fe5cbba2a12e0c6d32bbd0c2aa Mon Sep 17 00:00:00 2001
From: Kenny <70860732+KennyOliver@users.noreply.github.com>
Date: Thu, 9 Jan 2025 22:30:33 +0000
Subject: [PATCH 3/5] Update README.md
#190
---
README.md | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 42800d4..10a5aab 100644
--- a/README.md
+++ b/README.md
@@ -171,9 +171,7 @@ $ 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
From d75423aa178a700ef70659dcb9f10ff268d549b4 Mon Sep 17 00:00:00 2001
From: Kenny <70860732+KennyOliver@users.noreply.github.com>
Date: Thu, 9 Jan 2025 22:31:03 +0000
Subject: [PATCH 4/5] Update README.md
#190
---
README.md | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 10a5aab..3530679 100644
--- a/README.md
+++ b/README.md
@@ -177,9 +177,7 @@ $ flavor --about # About FlavorLang
#### 3. Click the ... Menu and Select Install from VSIX...
-#### 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
From d875ac6d1373ccad14b06ca26406f911d44eaccb Mon Sep 17 00:00:00 2001
From: Kenny <70860732+KennyOliver@users.noreply.github.com>
Date: Thu, 9 Jan 2025 22:32:29 +0000
Subject: [PATCH 5/5] Fix: Unhandled error: Error: Cannot reassign to constant
`a`. in `tests/all.flv`
#190
---
src/interpreter/interpreter.c | 2 +-
src/tests/all.flv | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/interpreter/interpreter.c b/src/interpreter/interpreter.c
index f885bee..ac01ff8 100644
--- a/src/interpreter/interpreter.c
+++ b/src/interpreter/interpreter.c
@@ -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);
}
diff --git a/src/tests/all.flv b/src/tests/all.flv
index 4ec2bd7..564c630 100644
--- a/src/tests/all.flv
+++ b/src/tests/all.flv
@@ -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