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

Add global variables to symbol table #101

Closed
kevin1 opened this issue Dec 1, 2015 · 5 comments
Closed

Add global variables to symbol table #101

kevin1 opened this issue Dec 1, 2015 · 5 comments

Comments

@kevin1
Copy link
Collaborator

kevin1 commented Dec 1, 2015

@el2724 pointed out while looking at #100

@edwadli
Copy link
Owner

edwadli commented Dec 1, 2015

typedefs should happen before top level expressions (globals) are evaluated (because our ast separates typedefs from expressions so we don't know whether a particular expr came before a typedef). However, function calls are allowed to reference these globals as long as the globals happen before the function is called.
Consequently, we have to choose:

  • dont allow function calls in typedefs
  • allow function calls in typedefs, but fail if the function references a global

@kevin1
Copy link
Collaborator Author

kevin1 commented Dec 1, 2015

I think we should go with the first one — don't allow function calls in typedefs. If we do 2nd one, it becomes pretty non-obvious why this code is wrong:

fun F = 1
type t = { m = F () }

Also there's no way to enforce "no global variables" (aka "pure functions only") if you can call out to C++ — for example, F could be rand() or some arbitrary C++. Then F could return something different every time you init t! And we have a way to make constructors.

Implementation: it may be easier to enforce this at the grammar level rather than in the type/semantic checker.

@edwadli edwadli self-assigned this Dec 1, 2015
@edwadli
Copy link
Owner

edwadli commented Dec 2, 2015

ok we will go with the second first option. note that our sast may still generate function calls in typedefs because some of our expressions internally call stdlib functions.

@edwadli
Copy link
Owner

edwadli commented Dec 2, 2015

meant to say first, not second option lol

@edwadli
Copy link
Owner

edwadli commented Dec 6, 2015

closed by #109

@edwadli edwadli closed this as completed Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants