Skip to content

Commit

Permalink
tiny fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ImShyMike committed Jan 21, 2025
1 parent 1a8a91a commit 3c5f687
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/docs/language-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class Maths {
print(Maths.sum(10, 5)); # Output: 15
```

!!! note "Own property access"
Currently, there is no way to access properties from the class from within its own functions (like `self` (python) or `this` (javascript))

## Enums

Enums can be created using `enum`:
Expand Down
5 changes: 2 additions & 3 deletions eryx/runtime/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ def declare_variable(
) -> RuntimeValue:
"""Declare a variable in the current scope."""
# Raise an exception if the variable is already declared
if variable_name in self.variables:
if not overwrite:
raise RuntimeError(f'Variable "{variable_name}" already declared')
if variable_name in self.variables and not overwrite:
raise RuntimeError(f'Variable "{variable_name}" already declared')

self.variables[variable_name] = value

Expand Down
7 changes: 5 additions & 2 deletions eryx/runtime/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ def eval_class_declaration(
)

if isinstance(method, FunctionDeclaration):
env = Environment(
parent_env=environment, disable_file_io=environment.disable_file_io
)
func = FunctionValue(
name=method.name,
arguments=method.arguments,
environment=environment,
environment=env,
body=method.body,
)
class_obj.methods[method.name] = func
Expand Down Expand Up @@ -468,7 +471,7 @@ def eval_member_expression(
member: MemberExpression, environment: Environment
) -> RuntimeValue:
"""Evaluate a member expression."""
object_value = evaluate(member.object, environment)
object_value = evaluate(member.object, environment) # if ur reading this, you are silly :3

if isinstance(object_value, (ObjectValue, ClassValue, EnumValue)):
if member.computed:
Expand Down

0 comments on commit 3c5f687

Please sign in to comment.