Codegen does not support true globals
I found an issue it seems to be a compiler bug. A typing error is raised from the compiler for the following code.
Environment
- os: debian
- ante: 0.1.1 (commit: 139cf8c)
Code
s : u32 = 8
g () =
Range 0 s
g ()
Error
$ ante main.an
thread 'main' panicked at '- inst1 (v2, v3 = call fn0(v1, v0)): arg 1 (v0) has type i8, expected i32
', src/cranelift_backend/context.rs:193:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
~~Thank you, looks like this is a codegen error translating an incorrect type for Range : i32 - i8 -> Range rather than i32 - i32 -> Range. Interestingly, it only fails in the cranelift pass (running with --backend llvm works) so it may be local to there.~~
Nevermind - this is from the lack of globals in the current codegen pass. In the future ante may need another design pass on how top-down evaluation is performed as a script and yet still allows use-before-declaration for functions/globals which may depend on other globals, but for now adding non-extern globals to codegen should alleviate most concerns. Llvm only compiles this code because it inlines the constant value without checking that it was actually local to a different function (main).