One-pass Compiler
keleshev.com
One-pass Compiler
1–10 of 44 posts
Re: One-pass Compiler
#2> This limited both the language features that were possible and the quality of the produced code.
What are the limitations ?
Re: One-pass Compiler
#3That was a short and epic read. > This limited both the language features that were possible and the quality of the produced code. What are the limitations ?
Maybe more exotically, here is a legal Haskell program:
compute = f x y
x = 3
y = 4
f = (+)
Using typed identifiers before they are declared would not be possible in a single-pass compiler. You wouldn't know what code to emit for compute since you wouldn't even know its type until you have seen the definitions of x, y, and f.Interestingly, this restriction does not apply to goto labels, which you can use first and define later: The compiler can just emit the label as written into the assembly code and let the assembler worry about patching up the jump target.
Re: One-pass Compiler
#4https://compilers.iecc.com/crenshaw/ circa 1995
And a new C version https://github.com/lotabout/Let-s-build-a-compiler
Re: One-pass Compiler
#5That was a short and epic read. > This limited both the language features that were possible and the quality of the produced code. What are the limitations ?
Older versions of C had the restriction that variables could only be declared at the start of a block. Supposedly this was due to the original C compiler being one-pass. It's easier to keep track of the size of the stack frame if you see all declarations in one place. Though I think with a frame pointer you could make it work anyway. You have essentially the same complications if you allow programmers to open a block…
A one-pass compiler can manage this by maintaining a mapping of undefined labels to a list of goto statements that refer to them. Once the definition is located, unwind the list and fill in the jump values. Types are trickier because the size is unknown.
Re: One-pass Compiler
#6>"An optimizing compiler would constant-fold our expression into a single number ahead of time."
Could someone say what is meant by constant-folding here?
Re: One-pass Compiler
#7Re: One-pass Compiler
#8Earlier quoted context omitted.
Older versions of C had the restriction that variables could only be declared at the start of a block. Supposedly this was due to the original C compiler being one-pass. It's easier to keep track of the size of the stack frame if you see all declarations in one place. Though I think with a frame pointer you could make it work anyway. You have essentially the same complications if you allow programmers to open a block…
> Interestingly, this restriction does not apply to goto labels, which you can use first and define later: The compiler can just emit the label as written into the assembly code and let the assembler worry about patching up the jump target. A one-pass compiler can manage this by maintaining a mapping of undefined labels to a list of goto statements that refer to them. Once the definition is located, unwind the list a…
Re: One-pass Compiler
#9The author states: >"An optimizing compiler would constant-fold our expression into a single number ahead of time." Could someone say what is meant by constant-folding here?
Ex: 4 + 4 would be condensed down to just 8 at compile time rather than writing the code to get 4 and 4 both into registers and add them at execution time.
Re: One-pass Compiler
#10The author states: >"An optimizing compiler would constant-fold our expression into a single number ahead of time." Could someone say what is meant by constant-folding here?
i = 320 * 200 * 32;
Most compilers would not actually generate two multiply instructions and a store for this statement. Instead, they identify constructs such as these and substitute the computed values at compile time (in this case, 2,048,000)."