MrSmith33 / vox

Vox language compiler. AOT / JIT / Linker. Zero dependencies
Boost Software License 1.0
338 stars 18 forks source link

$alias of global var #20

Closed MANKEYYENAME closed 2 years ago

MANKEYYENAME commented 2 years ago
u32 hey;

$alias getHey(){
    return $alias(hey);
}

void main(){
    ExitProcess(getHey());
}

noreturn ExitProcess(u32 uExitCode);

Compiler crashes

MrSmith33 commented 2 years ago

Currently T(args) syntax is only implemented for structs, for other types it is still on TODO list.

You cannot pass $alias directly to ExitProcess(getHey());, first you need to assign it to the alias declaration.

u32 hey;
$alias getHey(){
    return hey; // this doesn't work atm
}
void main(){
    alias var = getHey();
    ExitProcess(var);
}
noreturn ExitProcess(u32 uExitCode);

But taking alias implicitly in return statement is not yet implemented for non-types. Will fix this soon.

MrSmith33 commented 2 years ago

Now for this code:

u32 hey;
$alias getHey() {
    return $alias(hey);
}
void foo(u32 a){}
void main() {
    foo(getHey());
}

you will get:

test.vx:3:18: Error: Cannot call basic type
test.vx:7:15: Error: Argument 1, must have type u32, not $alias

and this one will work as you want:

u32 hey;
$alias getHey() {
    return hey;
}
void foo(u32 a){}
void main() {
    alias var = getHey();
    foo(var);
}