-
Notifications
You must be signed in to change notification settings - Fork 55
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@@ -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()) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
src/index/visitor.rs
Outdated
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 { |
There was a problem hiding this comment.
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
50c2874
to
99e8179
Compare
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
99e8179
to
f9b9dc4
Compare
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related to builtins?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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
Add information of builtin to the index
Builtins are hardcoded in the builtin module
Implented REF and ADR