blech-lang / blech

Blech is a language for developing reactive, real-time critical embedded software.
Apache License 2.0
64 stars 5 forks source link

Params initialized with params leads to an error in generated code #13

Open schorg opened 1 year ago

schorg commented 1 year ago

If you try to initialize a param with another param the type-checker does not complain. But, the generated code cannot be compiled by a C-compiler

To Reproduce The following program in file typing.blc

param x: int32 = 42

param y: int32 = x * 2

@[EntryPoint]
activity Test() returns int32
    await true
    return y
end

compiles without errors

blechc --app  typing.blc

A C compiler cannot compile the generated code

cd blech
clang -Iinclude blech.c

and shows the following error message

In file included from blech.c:21:
./typing.c:42:54: error: initializer element is not a compile-time constant
static blc_int32 blc_01typing01_y = blc_01typing01_x * 2;
                                    ~~~~~~~~~~~~~~~~~^~~
1 error generated.

Expected behaviour Either a typing error in the Blech compiler, Or even better - but much more effort and a big change - a different code generation for parameter initialization, maybe as a function, called from the initialiser.