feat: Add pointer support #107
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.