titzer / virgil

A fast and lightweight native programming language
1.24k stars 50 forks source link

compile-time initialization System.puts error #42

Closed diakopter closed 3 years ago

diakopter commented 3 years ago

is it supposed to still work?

image

titzer commented 3 years ago

Ah, you are calling System.puts during compile-time initialization.

That's a problem (right now) because the compiler will resolve System.puts to the implementation in the Linux platform code and it tries to do things with pointers which are not allowed at compile time.

Do you want to do this a lot? If so, I can think about how to support one version of System at compile time and one version at runtime.

diakopter commented 3 years ago

Not really. Just trying things out and copied the example from the tutorial (and wiki) docs. :)

Multiple stages is nice. Side effects not necessary. Curious about how nested data structures cross over from initialization to run-time.

titzer commented 3 years ago

Ah, thanks for pointing this out. I should update the wiki example.

titzer commented 3 years ago

By nested, you just mean an object graph? The compiler serializes everything reachable from the (used) component fields of the program after init. It traces the code starting from main and does tree shaking to toss everything not used.