IUCompilerCourse / Essentials-of-Compilation

A book about compiling Racket and Python to x86-64 assembly
1.27k stars 137 forks source link

Chapter 6 Functions does not cover the situation of SetBang to a top-level defined function #128

Open wine99 opened 2 years ago

wine99 commented 2 years ago

I am having trouble compiling programs like the below:

(define (f) : Integer 1)

(define (g) : Integer 42)

(begin (set! f g)
       (f))
(define (f) : Integer
  (begin (set! f g)
         (f)))

(define (g) : Integer 42)

(f)

I am following the course videos of 2020 but doing the assignments in the order that's presented in the book. The book introduces WhileLoop before Tuple and Function, which I think is nice since I can use Begin for the translation of Tuple. But when I come to Functions, the above examples upsets me. How can I compile the (set! f g)? Or should I just modify the type checker to forbid assignments to top-level defined functions?

jsiek commented 1 year ago

Good question! I hadn't thought about that. Let's forbid assignments to top-level defined functions.