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

'new' keyword #97

Open
liuhenry4428 opened this issue Apr 17, 2020 · 2 comments
Open

'new' keyword #97

liuhenry4428 opened this issue Apr 17, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@liuhenry4428
Copy link
Collaborator

TypeScript use case: img[i] = new Image();

@liuhenry4428 liuhenry4428 added the enhancement New feature or request label Apr 17, 2020
@sampsyo
Copy link
Contributor

sampsyo commented Apr 17, 2020

Hey, @liuhenry4428—I was just having a few thoughts while reading over these new issues about language features to promote parity with TypeScript. It occurs to me that, while some of these would undoubtedly be convenient, it should certainly be a non-goal to completely replicate the entirety of TypeScript within Gator. That's way too much work! And the focus should be on making interesting geometric code expressible, not on writing any old random library interaction code.

Of course, we need a way to support the kind of code we want to write, and things like new Image() might be critical for some relevant examples. So allow me to suggest a workaround that might reduce the level of effort while providing a shortcut to writing realistic programs:

Put stuff like this in a runtime library. That is, make the TS backend produce code that import a custom library that you hand-write in TypeScript. The spirit could be similar to this glrt library I once wrote for a different compiler:
https://github.com/cucapra/braid/blob/master/glrt/glrt.ts

Then the Gator code that needs to do things like this can just call simple functions that do the TypeScript dirty work underneath. Or use simple type names to refer to complex TypeScript types, declared as type x = y type aliases in TS.

For example, there could be a function called new_image specifically for this. Or if you find yourself needing to write lots of class instantiation expressions, you could create a new_ function that takes the prototype as an argument. And for union types (#99) you could declare a type NullableTexture that is aliased to WebGLTexture | null under the hood.

I'd be interested in @Checkmate50's opinion on this stuff!

@Checkmate50
Copy link
Contributor

I like this idea a lot! I think this principle should also be used for TypeScript features that haven't been implemented yet but should be (such as #96, cause duh), since it centralizes the uses of each feature so they can be replaced as Gator supports them.

I do think it's still important to create issues for these features and support some of them; otherwise I could imagine this sort of design getting out of hand. This issue in particular seems to provide an example of a potential metaprogramming/design explosion. With Gator slated to support structs (see #63), being able to create objects/classes in some way seems important to avoid type-checking complexity around internal variables and functions. Graphics in general just has so much need for object structure (such as when bundling light information), that it seems way too complicated to not support.

I do agree with something like #99 not getting explicit support; however, I think I'll keep them as an issue (I'll tag those with wontfix), since they document cases where we intend to use internal "hacks" without compiler implementation.

@sampsyo sampsyo mentioned this issue Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants