Skip to content
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

Types #9

Merged
merged 7 commits into from
Jun 23, 2024
Merged

Types #9

merged 7 commits into from
Jun 23, 2024

Conversation

andy-byers
Copy link
Owner

No description provided.

Switch to 2-phase compilation: 1 phase to build an AST, and another to
check types and generate code. Support type annotations, as well as type
inference: require annotations on function parameters, and let them be
optional on variable definitions and return types. Infer variable types
from the initializer expression and return types from the type of the
first returned expression. Breaks pretty much every API feature: just
working on compilation for now.
Phase 1 builds an AST from the source code. Phase 2 resolves the types and allocates the symbol tables. Phase 3 allocates runtime objects and emits
bytecode. Makes 'int' and 'BigInt' separate types. Most everything is
broken: as it turns out, designs that work well for a dynamic language
are unsuitable for one that is statically-typed.
Start working on classes
At this point, variables with generic types must be treated completely
generically. This will allow abstract data types, like 'Vec' and 'Map',
but doesn't allow creating, for example, a polymorphic function that
sums a list of numbers (either 'int' or 'float'). That behavior will be
implemented later, when the codebase becomes stable. Also using the
Boehm–Demers–Weiser garbage collector for now (using FetchContent from an unofficial git repo). At some point, paw will
get its own garbage collector. At first, it will be a simple tracing GC,
like the one we had before static typing was added, except that it needs
to coordinate with a custom allocator so it can find pointers (or
maintain a lookup table).
Use an AstFolder pass to turn each InstanceDecl into a FuncDecl (the
'stenciler'). Uses the base template, which is fully type checked, along
with the concrete types that the instance was instantiated with.
Structures are not monomorphied right now. We have a uniform value
representation, so it isn't strictly necessary.
Requires that we use extra metadata to distinguish tombstones from
vacant/occupied slots (no more type tag that we can use for
this purpose). Get more tests to work.
@andy-byers andy-byers merged commit 2704362 into main Jun 23, 2024
32 of 40 checks passed
@andy-byers andy-byers deleted the types branch July 1, 2024 19:15
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