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

A modest proposal #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

A modest proposal #113

wants to merge 1 commit into from

Conversation

laelath
Copy link

@laelath laelath commented Oct 28, 2022

Restructure compiler to use objects to avoid so much copying between languages.
There's a significant catch in that extracting a full compiler to give to students for assignments is now non-trivial.

@dvanhorn
Copy link
Member

I was talking to Pierce about this... did you chat with him? Overall, I like this, although I think it may break down when we get to things like Fraud since the methods for earlier languages would need to be replaced with ones that accept (and pass along) the static environment. I also want to be able to generate stand-alone compilers and I don't see how to do this. I think what's needed is something that's more like a meta-language for writing incrementally extensible programs. Maybe something like that exists, or maybe we should think about making our own.

@pdarragh
Copy link
Contributor

Yeah, after our meeting yesterday I walked out of the building with @laelath and we talked about this. Turns out I accidentally nerdsniped him haha.

Definitely see your point about a metalanguage for generating this stuff. Although @laelath's implementation would probably be fine to maintain for one individual, I could imagine it being difficult for students to come in and see a late-stage language definition and understand everything that's going on. We talked a bit about possible metalanguage implementations, but I think having a starting point for an OO approach will be helpful in deciding how the final thing ought to look.

@dvanhorn
Copy link
Member

Also, it seems a bit weird not to use the AST for the class hierarchy. Being object-oriented means never have to say cond (or match in this case). So I think you could do something like (in psuedo-Java):

interface Expr {
  Asm compile();
}
class Int implements Expr {
  Integer i;
  Asm compile() { return [ Mov rax this.i ] }
}
class Add1 implements Expr {
  Expr e;
  Asm compile() { return this.e.compile() ++ [ Add rax 1 ] }
}

etc.

This helps with the stand-alone thing because you can get earlier langs by simply omitting some class definitions, at least for the simple cases. You still have the problem of the signatures changing over time with variables, tail calls, etc.

@dvanhorn
Copy link
Member

OK, one more note about this: either you give up on bootstrapping, or you have to implement the class system ;)

@laelath
Copy link
Author

laelath commented Oct 29, 2022

I think that all the problems can be addressed (though the extra args in fraud probably requires restarting the inheritance chain) except for needing to extract a compiler for each stage, which definitely needs a metalanguage to specify. As for making exprs objects too... I have no good reason other than that that just feels wrong™️.

For implementing the class system, I would simply introduce macros, and then classes are easy :)

@laelath
Copy link
Author

laelath commented Oct 29, 2022

I want to make some handwavy argument about language specifications being positive constructs and so more naturally represented as positive sum types rather than negative objects

@laelath
Copy link
Author

laelath commented Oct 29, 2022

Okay okay, when you define AST nodes as objects, you're saying that the meaning of the AST nodes is the result of making the 'compile' observation on it, when I would argue that morally, ASTs are just some data to be interpreted in whatever way is needed. This can be seen by how Ints are compiled to plain words in Abscond through Con, but by Dupe they need tags, so the definition needs to become something like TaggedInt, requiring compiler implementations to be leaked to parsing. But it wasn't the "meaning" of Int that changed, just the requirements of its encoding in the target language.

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.

3 participants