Skip to content

Add require statement#658

Draft
igrvlhlb wants to merge 12 commits intomasterfrom
add-require-statement
Draft

Add require statement#658
igrvlhlb wants to merge 12 commits intomasterfrom
add-require-statement

Conversation

@igrvlhlb
Copy link
Copy Markdown
Contributor

@igrvlhlb igrvlhlb commented Dec 2, 2025

-- Draft PR --

This PR adds partial support for the require command in the compiler's frontend

@igrvlhlb igrvlhlb force-pushed the parse-pallene-types-file branch from 7868a52 to c04903a Compare December 2, 2025 22:20
@igrvlhlb igrvlhlb force-pushed the add-require-statement branch 6 times, most recently from 8ca35cf to ead119c Compare December 4, 2025 04:22
@igrvlhlb igrvlhlb force-pushed the add-require-statement branch 4 times, most recently from e6adf79 to 9df6b6d Compare March 3, 2026 03:16
Base automatically changed from parse-pallene-types-file to master March 31, 2026 01:06
@igrvlhlb igrvlhlb force-pushed the add-require-statement branch from 9df6b6d to b84d2d8 Compare March 31, 2026 01:15

elseif tag == "ast.Stat.Break" then
-- empty
elseif tag == "ast.Stat.Require" then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to remind that Require only accepts string literals, and thus there are no "exp" children to visit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/pallene/ast.lua
Array = {"loc", "subtype"},
Table = {"loc", "fields"},
Function = {"loc", "arg_types", "ret_types"},
QualifiedName = {"loc", "module", "name"},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: would it be better or would it be worse if we had a single constructor for both names and qualified names?

E.g. setting the module as nil for unqualified names, or representing qualified names as a dotted string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't clearly see any disadvantages neither on having a QualifiedName constructor, nor adding a new field "module" to the Name constructor. I'd say I prefere the new constructor as it provides more explicit handling of that particular case and clearly distinguishes it from simple names. Do you have an opinion/preference on that?

or representing qualified names as a dotted string.

While that could also work, I'd avoid due to this drawback: although we could recognize and store the dotted string as the Name identifier with no problem, there would be no straightforward way to verify if the name is qualified or not other than looking for a dot in the string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference. Let's go ahead with QualifiedName then.

One possible advantage is that this way it is is probably more difficult to accidentally treat a qualified name as if it were not qualified, because we don't have to do another if statement inside the branch that handles the Name constructor.

Comment thread src/pallene/to_ir.lua Outdated
end
elseif def._tag == "typechecker.Def.Import" then
-- TODO: Handle module imported fields
return ir.Value.Nil -- added just so the compiler don't break while this case is not implemented
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's OK to break it? There is already a flag to generate the module file without running the to_ir

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@igrvlhlb igrvlhlb force-pushed the add-require-statement branch from a4d8713 to b9b25b4 Compare April 28, 2026 03:07
@igrvlhlb igrvlhlb force-pushed the add-require-statement branch from b9b25b4 to 168329b Compare May 1, 2026 05:29
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