Skip to content

feat: Add pointer support #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tacheraSasi
Copy link
Contributor

This PR introduces basic pointer support to VintLang, allowing for more advanced data manipulation.

Key Features:

Address-of Operator (&): Get a pointer to the value of a variable.
Dereference Operator (*): Access the value a pointer refers to.
Implementation Details:

Lexer: Added AMPERSAND (&) and ASTERISK (*) as tokens. & is now correctly tokenized as a single operator.
Parser: Registered & and * as prefix operators, allowing expressions like &x and p.
Object System: Introduced a new object.Pointer type to represent pointers at runtime.
Evaluator: Implemented logic to handle the creation of pointers (&) and dereferencing (
). Includes defensive checks for nil and non-pointer values.
Documentation: Added docs/pointers.md explaining the new feature, its syntax, and its current limitations (value pointers, not variable references).
Example Usage:

let x = 42
let p = &x // p is a pointer to the value of x

print(p) // Prints the pointer's representation
print(*p) // Prints 42
This feature lays the groundwork for more complex memory management and data structure implementations in the future.

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.

1 participant