Skip to content

Conversation

@Rafael-Sapienza
Copy link

Este pull request implementa melhorias significativas no sistema de tipos e na representação de funções. As principais mudanças incluem:

✅ Suporte para funções recursivas
Permite que uma função invoque a si mesma dentro de seu próprio corpo.

✅ Funções como argumentos
Agora é possível passar funções como parâmetros de outras funções, permitindo maior expressividade funcional.

✅ Polimorfismo de funções
Agora permite que funções com mesmos nomes e assinaturas diferentes sejam declaradas

✅ Suporte para expressões lambda
Inclusão de expressões lambda, sendo seu uso permitido tanto em assignments quanto dentro de chamadas de função.

Essas alterações aumentam significativamente a expressividade da linguagem e a flexibilidade do sistema de tipos.

Rafael-Sapienza and others added 13 commits July 6, 2025 16:44
Previously, new_env was not receiving functions from the outer environment,
which caused external functions to be inaccessible inside function bodies.
This also broke recursion, since the function itself wasn't visible in its own scope.

This commit ensures that external functions are copied into new_env,
allowing function bodies to reference both external and self-defined functions.
…nal block execution

Fixes a scoping bug in execute_block where pop() was applied to the wrong environment.

Previously, in function `exec`:
- The environment `env` was cloned into a variable `new_env`.
- In the `Statement::Block` match arm, the returned environment was actually wrapped inside
  the variable `result`, of type `Computation`.
- However, `pop()` was mistakenly called on `new_env`, which was discarded afterward.
- As a result, the environment inside `result` — the one that was actually returned —
  remained unmodified, and the pushed scope was never popped.

This commit fixes the issue by:
- Moving the push/pop operations into the `execute_block` function itself,
  so that scope management is handled consistently before wrapping the result in a `Computation`.

Additionally, it introduces the `exec_if_block` function:
- A simplified version of `execute_block` that executes a list of statements without
  pushing or popping a new scope.
- Intended for use in the body of `if` clauses

These changes improve correctness and modularity in the interpreter's handling of scope and control flow.
…e return and function definition

- Created `check_block_stmt` to handle scoped type checking of block statements
- Created `check_func_call` to validate function call expressions
- Updated `check_return_stmt` to ensure return type matches declared function type
- Improved `check_func_def_stmt` to handle duplicate declarations and parameter validation

These changes improve the accuracy and robustness of the type checker.
…uments

Functions are now stored in the environment using their full
signatures rather than just their names. This allows support for
polymorphic functions and multiple overloads with different type
parameters.

Additionally, when evaluating a FuncCall whose target is an
Expression::Var, the resolution process has changed. Instead of
directly evaluating the variable and assuming it holds a value, we now
perform a scoped lookup. In each environment scope, we first look for
a variable with the given name; if not found, we then look for a
function. This behavior ensures variables shadow functions of the same
name in the same scope.

This change allows function values to be passed as arguments and gives
priority to local variables when both a function and variable share
the same identifier, enabling more flexible and predictable behavior
in higher-order and polymorphic scenarios
…_as_param

Feat/polymorphism and func as param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants