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

Support builtin functions #469

Merged
merged 7 commits into from
Apr 11, 2022
Merged

Support builtin functions #469

merged 7 commits into from
Apr 11, 2022

Conversation

ghaith
Copy link
Collaborator

@ghaith ghaith commented Feb 21, 2022

Add information of builtin to the index
Builtins are hardcoded in the builtin module
Implented REF and ADR

@ghaith ghaith requested a review from riederm February 21, 2022 09:54
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2022

Codecov Report

Merging #469 (a4cbbe4) into master (fd520d7) will increase coverage by 92.76%.
The diff coverage is 91.30%.

❗ Current head a4cbbe4 differs from pull request most recent head f207776. Consider uploading reports for the commit f207776 to get more accurate results

@@             Coverage Diff             @@
##           master     #469       +/-   ##
===========================================
+ Coverage        0   92.76%   +92.76%     
===========================================
  Files           0       37       +37     
  Lines           0    13330    +13330     
===========================================
+ Hits            0    12366    +12366     
- Misses          0      964      +964     
Impacted Files Coverage Δ
src/ast.rs 92.82% <ø> (ø)
src/codegen.rs 100.00% <ø> (ø)
src/index/const_expressions.rs 87.50% <70.00%> (ø)
src/builtins.rs 78.37% <78.37%> (ø)
src/codegen/generators/expression_generator.rs 86.54% <95.00%> (ø)
src/index.rs 98.13% <100.00%> (ø)
src/index/visitor.rs 96.35% <100.00%> (ø)
src/lib.rs 74.78% <100.00%> (ø)
src/resolver.rs 96.45% <100.00%> (ø)
src/test_utils.rs 100.00% <100.00%> (ø)
... and 37 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd520d7...f207776. Read the comment docs.

@@ -449,6 +450,19 @@ impl<'a, 'b> ExpressionCodeGenerator<'a, 'b> {
)
})?;

//If the function is builtin, generate a basic value enum for it
if self.index.is_builtin(implementation.get_call_name()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find it clearer, if the index would return you an Option that you call ...

src/index.rs Outdated
@@ -426,6 +428,11 @@ pub struct Index {
}

impl Index {
pub fn create_with_builtins(id_provider: IdProvider) -> Index {
Copy link
Collaborator

Choose a reason for hiding this comment

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

explain in documentation what this means

pub fn visit(unit: &CompilationUnit, mut id_provider: IdProvider) -> Index {
let mut index = Index::default();

pub fn visit_index(mut index: Index, unit: &CompilationUnit, mut id_provider: IdProvider) -> Index {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the index passed here is always Index::default so we could remove it again

@ghaith ghaith force-pushed the builtin_functions branch 3 times, most recently from 50c2874 to 99e8179 Compare February 24, 2022 07:54
The builtinin index is now created first in the lib, and not always by
visiting an ast.
Also fixed the index import to use not skip enum and hardware constants.
As a side effect of the index being imported, some index numbers changed
in some tests
Copy link
Collaborator

@riederm riederm left a comment

Choose a reason for hiding this comment

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

it feels that you merged two issues here together?
is this whole import-code related to #469?
do you think you can get this out into it's own commit?

}

pub struct BuiltIn {
decl: &'static str,
Copy link
Collaborator

Choose a reason for hiding this comment

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

so far we avoided &'static str
is there a benefit over String?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly, I don't remember, it feels like less code (not having .to_string() in each entry)
I think initially this came when I was using a static array of declarations instead of the lazy_static map

src/index.rs Outdated
//enmu_variables use the qualified variables since name conflicts will be overriden in the enum_global
for (qualified_name, e) in other.enum_qualified_variables.drain(..) {
let e = self.transfer_constants(e, &mut other.constant_expressions);
dbg!(&e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove dbg!
btw. is this code for another issue? or is it related to builtins?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we agreed to not have the builtins sneaked into the index when it's created but have them be parsed independently the import issue has to be solved for the builtins to work.
I could still split the issue in 2 but the import has to come first

@@ -513,7 +544,7 @@ impl Index {
) -> Option<ConstId> {
initializer_id
.as_ref()
.and_then(|it| import_from.remove(it))
.and_then(|it| import_from.clone(it))
Copy link
Collaborator

Choose a reason for hiding this comment

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

was this a test? or is this really required for builtins?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAIK it is required, the problem is that we reused IDs for different types, and if we delete one when importing it is lost to the others who used it.
Since we own the other index, it will be dropped/deleted anyway

@@ -504,6 +503,38 @@ impl Index {
// self.constant_expressions.import(other.constant_expressions)
}

fn transfer_constants(
Copy link
Collaborator

Choose a reason for hiding this comment

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

related to builtins?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, see above

self.expressions.remove(*id).map(|it| match it.expr {
ConstExpression::Unresolved { statement, scope } => {
(statement, it.target_type_name, scope)
// /// removes the expression from the ConstExpressions and returns all of its elements
Copy link
Collaborator

Choose a reason for hiding this comment

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

this whole code is probably related to a different issue?

src/lib.rs Outdated
let mut units = Vec::new();

//parse the builtins into the index
let (builtins, _) = builtins::parse_built_ins(id_provider.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the second element of the tuple is not used here, do we ever use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I don't assume our own code will return diagnostics, I can make the method return only the compilation unit

@ghaith ghaith requested a review from riederm March 9, 2022 07:56
Copy link
Collaborator

@riederm riederm left a comment

Choose a reason for hiding this comment

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

i think this can find its way into master

@ghaith ghaith merged commit 2e3ebff into master Apr 11, 2022
@ghaith ghaith deleted the builtin_functions branch April 11, 2022 09:10
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.

None yet

3 participants