Skip to content

Commit

Permalink
Fix a bug in variable definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-develop committed Sep 14, 2024
1 parent 4e30014 commit 129d03f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/runtime/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from src.runtime.runtime_result import RTResult
from src.runtime.context import Context
from src.runtime.symbol_table import SymbolTable
from src.misc import clear_screen, RunFunction
from src.misc import clear_screen, RunFunction, print_in_red
from src.noug_version import LIB_VERSION
import src.conffiles
# built-in python imports
Expand Down Expand Up @@ -800,6 +800,10 @@ def visit_VarAssignNode(self, node: VarAssignNode, ctx: Context, methods_instead
value.attributes[var_name[-1].value] = final_value
else:
assert final_value is not None
if final_var_name == "javascript":
print_in_red(
"DEPRECATION WARNING: naming a variable 'javascript' is deprecated and will be removed in 2.0.0."
)
ctx.symbol_table.set(final_var_name, final_value)

final_values.append(final_value)
Expand Down
7 changes: 2 additions & 5 deletions src/runtime/values/functions/builtin_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,11 @@ def execute_print_in_red_ret(self, exec_ctx: Context):
# * value
assert exec_ctx.symbol_table is not None
value = exec_ctx.symbol_table.getf('value')
easter_egg = exec_ctx.symbol_table.getf('easteregg?')
if value is not None: # if the value is defined
try:
print_in_red(value.to_python_str())
easter_egg_trigger = "Is there an easter egg in this program? That would be so cool!"
if easter_egg is not None and value.to_python_str() == easter_egg_trigger:
if isinstance(easter_egg, String) and easter_egg.value == "thanks":
print("You’re welcome :)")
if value.to_python_str() == easter_egg_trigger:
return RTResult().success(String("Here you go!", self.pos_start, self.pos_end))
return RTResult().success(String(value.to_python_str(), self.pos_start, self.pos_end))
except UnicodeEncodeError as e:
Expand All @@ -322,7 +319,7 @@ def execute_print_in_red_ret(self, exec_ctx: Context):
builtin_functions["print_in_red_ret"] = {
"function": execute_print_in_red_ret,
"param_names": [],
"optional_params": ["value", "easteregg?"],
"optional_params": ["value"],
"should_respect_args_number": True,
"run_noug_dir": False,
"noug_dir": False
Expand Down

0 comments on commit 129d03f

Please sign in to comment.