jeandrek / do-it

Toy compiled language
GNU General Public License v3.0
2 stars 1 forks source link

Lexical scoping/global variables are broken #3

Closed jeandrek closed 8 years ago

jeandrek commented 8 years ago
(var i 0)
(proc foo ()
  (printf "%d\n" i))
(foo)

won't work because i is not defined in foo's environment. Environments should be a list of frames

jeandrek commented 8 years ago

Oh, I guess by fixing this I'm also making lexically scoped nested procedures.

jeandrek commented 8 years ago

Oh, I guess by fixing this I'm also making lexically scoped nested procedures.

Wait, no, I'm not, the compiler may accept something like

(proc foo ()
  (var x 0)
  (proc bar ()
    (printf "%d\n" x))
  (bar))
(foo)

but it'll segfault or print nonsense values and bar isn't local to foo anyway in the sense that you could put a call to bar anywhere.