edwadli / note-hashtag

3 stars 0 forks source link

Add global variables to symbol table #101

Closed kevin1 closed 8 years ago

kevin1 commented 8 years ago

@el2724 pointed out while looking at #100

edwadli commented 8 years ago

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:

kevin1 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

meant to say first, not second option lol

edwadli commented 8 years ago

closed by #109