-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: implement generic functions #16
Conversation
PTAL @xujuntwt95329 |
@@ -521,6 +531,7 @@ export class Scope { | |||
scope.localIndex = this.localIndex; | |||
scope.mangledName = this.mangledName; | |||
scope.modifiers = this.modifiers; | |||
if (this.genericOwner) scope.setGenericOwner(this.genericOwner); |
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.
copy
and clone
, which is used for generic specialization?
According to the function name, I would expect the result scope is the same as the original one (e.g. the genericOwner field should be the same), but this line breaks this assumption.
I would suggest to use specialize
as the method name used to process generic specialization.
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.
done.
The name of method was changed to specialize.
src/scope.ts
Outdated
|
||
constructor(parent: Scope) { | ||
constructor(parent: Scope | null) { |
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.
Why would it be possible to have a null parent scope?
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.
done.
This does seem redundant and wrong.
src/semantics/expression_builder.ts
Outdated
@@ -921,6 +923,14 @@ function buildArrayLiteralExpression( | |||
|
|||
// return new NewLiteralArrayValue(array_type!, init_values); | |||
const elem_type = (array_type as ArrayType).element; | |||
// Workaround: solve the case that the return value of a generic function is a generic array |
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.
Why this only work for return value of a generic function
? Seems it should also work for assignment statement?
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.
done.
In buildArrayLiteralExpression, I made common logic to process generic arrays.It does not only work for return value of a generic function.
src/semantics/expression_builder.ts
Outdated
@@ -1276,6 +1286,14 @@ export function newCastValue( | |||
return value; | |||
} | |||
|
|||
// Workaround: solve the case that the return value of a generic function is a generic array |
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.
Same as above
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.
done.
This code has been deleted
newParam.setIsLocalVar(v.isLocalVar()); | ||
newParam.needReBinding = v.needReBinding; | ||
newParam.tsNode = v.tsNode; | ||
f.addParameter(newParam); |
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 the specialized function scope is created in frontend, and the parameters are added in semantic tree, and it is same as class specialization too?
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,the same goes for generic member functions in generic class.
src/utils.ts
Outdated
* @returns a new specialized ClassScope | ||
*/ | ||
export function createClassScopeByClassType( | ||
originalClassScope: ClassScope, | ||
parent: Scope, | ||
parent: Scope | null, |
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.
In which situation, parent
will be null
?
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.
done.
This does seem redundant and wrong.
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.
LGTM
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.
LGTM
Signed-off-by: ganjing <[email protected]>
@Shanks0224 Thanks for the great work! |
No description provided.