Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error by assigning an array to inner const #390

Open
yhara opened this issue Sep 6, 2022 · 2 comments
Open

Compile error by assigning an array to inner const #390

yhara opened this issue Sep 6, 2022 · 2 comments
Labels

Comments

@yhara
Copy link
Collaborator

yhara commented Sep 6, 2022

Given

class A
  B = []
end

Expected

no error

Actual

thread 'main' panicked at '[BUG] lvar `ary@0_' not found in ctx.lvars', lib/skc_codegen/src/gen_exprs.rs:464:32

@yhara yhara added the bug label Sep 6, 2022
@moozzi
Copy link
Contributor

moozzi commented Dec 12, 2022

Hi!
I understand that ctx.lvars is missing the key-value pair for name.

fn gen_const_inits(&self, const_inits: &'hir [HirExpression]) -> Result<()> {
for expr in const_inits {
match &expr.node {
HirExpressionBase::HirConstAssign { fullname, .. } => {
let fn_type = self.void_type.fn_type(&[], false);
let function = self.module.add_function(
&const_initialize_func_name(fullname),
fn_type,
None,
);
let basic_block = self.context.append_basic_block(function, "");
self.builder.position_at_end(basic_block);
let (end_block, mut ctx) =
self.new_ctx(FunctionOrigin::Other, function, None, HashMap::new());
self.gen_expr(&mut ctx, expr)?;
self.builder.build_unconditional_branch(*end_block);

Inside gen_const_inits function we call self.new_ctx with empty Hash as lvars param. Should I add a pair somewhere?

@yhara
Copy link
Collaborator Author

yhara commented Dec 13, 2022

Should I add a pair somewhere?

The story is little more complex. The compiler defines LLVM function for each constant (like @"init_A::B") but to support programs like this:

class A
  let x = 1000
  B = x + 10
  C = x * 20
end

the LLVM functions should not be per constant but per class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants