-
Notifications
You must be signed in to change notification settings - Fork 1
All the emitter framework changes I made to get the COI demo working #49
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
base: feature/model-interface
Are you sure you want to change the base?
Conversation
| ? getExtendsType($, props.type) | ||
| : undefined; | ||
| let basesType = props.bases ? props.bases : (globalBasesType ?? undefined); | ||
| function createBasesType( |
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 changes in this function are aimed at allowing us to specify additional bases for the purpose of adding Generic.
Those bases are generated in ClassDeclaration.
| if ( | ||
| !props.type.isFinished && | ||
| (props.type.node as TemplateDeclarationNode)?.templateParameters | ||
| ) { | ||
| const templateParameters = (props.type.node as TemplateDeclarationNode)?.templateParameters; | ||
| typeVars = ( | ||
| <> | ||
| <For each={templateParameters} hardline> | ||
| {(node) => { | ||
| const typeVar = ( | ||
| <py.FunctionCallExpression | ||
| target={typingModule["."].TypeVar} | ||
| args={[<py.Atom jsValue={node.id.sv} />]} | ||
| /> | ||
| ); | ||
| return <py.VariableDeclaration name={node.id.sv} initializer={typeVar} />; | ||
|
|
||
| // ("${node.id.sv}")`; | ||
| // return <py.Declaration name={String(node.id.sv)}></py.Declaration>; | ||
| }} | ||
| </For> | ||
| </> | ||
| ); | ||
| for (const templateParamter of templateParameters) { | ||
| typeArgs.push(templateParamter.id.sv); | ||
| } | ||
| } |
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 part is all aimed at determining if there are template parameters that are unfulfilled and, if so, adding them as type arguments to a Generic base.
| </> | ||
| ); | ||
| for (const templateParamter of templateParameters) { | ||
| typeArgs.push(templateParamter.id.sv); |
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 isn't great, we're just making a list of strings. These should probably be references but I didn't have time to figure out how to make that work.
| const output = ( | ||
| <Output | ||
| program={context.program} | ||
| externals={[ef.abcModule, ef.dataclassesModule, ef.typingModule, py.enumModule]} |
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 part was critical, as the stdlib references didn't work without it.
I'm not sure if it's expected that we'll always need to do this in emitters? Or if something should be happening with references or scopes or what have you so it happens automatically.
| </For> | ||
| <For each={type.models}> | ||
| {(name, type) => { | ||
| return <ef.ClassDeclaration type={type} abstract={!type.isFinished} />; |
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.
tbf I don't understand what isFinished actually means.
| } | ||
|
|
||
| function isTemplateVar(type: Type): boolean { | ||
| return (type as TemplatedTypeBase).templateMapper !== undefined; |
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.
¯_(ツ)_/¯
| reportPythonDiagnostic($.program, { code: "python-unsupported-type", target: type }); | ||
| break; | ||
| case "TemplateParameter": | ||
| return code`${String((type.node as TemplateParameterDeclarationNode).id.sv)}`; |
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.
Probably can do a lot better than a string! Should be a reference.
| if (isTemplateVar(type)) { | ||
| return <TypeExpression type={type.templateMapper?.args[0] as Type} />; | ||
| } |
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 weird thing is that models used as template arguments are treated as models here.
| const typeNode = isOptional ? ( | ||
| <py.TypeReference | ||
| refkey={typingModule["."].Optional} | ||
| typeArgs={[unpackedTypeNode]} | ||
| ></py.TypeReference> | ||
| ) : ( | ||
| unpackedTypeNode | ||
| ); |
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.
Adds support for wrapping types in Optional[] if the model property is optional.
| <Show when={!!typeVars}> | ||
| {typeVars} | ||
| <hbr /> | ||
| <line /> | ||
| </Show> |
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 typeVars should probably go at the top of the module, but I didn't want to figure out how to do that.
Even then, I'm not sure there is a defined style for where TypeVars should go.
| if ( | ||
| !props.type.isFinished && | ||
| (props.type.node as TemplateDeclarationNode)?.templateParameters | ||
| ) { |
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.
@mauriciogardini this is what I was referring to here #45 (comment)
No description provided.