MrSmith33 / vox

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

vox.context:574: ICE: getAst(FunctionDeclNode) got decl_struct #42

Closed rempas closed 2 years ago

rempas commented 2 years ago

Expected behavior I was expecting to not get the exception

Describe the bug I'm trying to create a templated struct and it doesn't work. It gives me the following error message:

vox.context:574: ICE: getAst(FunctionDeclNode) got decl_struct
Stack:
> test.vox:27:36: node.1297 type_check expr_call Vector[i32]
  test.vox:27:15: node.1311 type_check decl_var numbers
  test.vox:26:13: node.1353 type_check stmt_block stmt_block
  test.vox:26:6: node.1194 type_check decl_function main
  test.vox:1:1: node.485 type_check decl_module test
vox.context.CompilationException@vox.context(574)
----------------
??:? [0x5640eeec169c]
??:? [0x5640eeea316d]
??:? [0x5640eecf11ad]
??:? [0x5640eecf0d59]
??:? [0x5640eedac4e9]
??:? [0x5640eeda7d9a]
??:? [0x5640eeda774a]
??:? [0x5640eeda766e]
??:? [0x5640eeda7bac]
??:? [0x5640eedcb2df]
??:? [0x5640eee7548f]
??:? [0x5640eee7c708]
??:? [0x5640eeea2dfe]
??:? [0x5640eeea2c80]
??:? [0x5640eeea2add]
??:? __libc_start_main [0x7fc47c3f40b2]
??:? [0x5640eedeecbd]

To Reproduce Trying to compile the following source code:

@extern(syscall, 60)
void exit(i32 error_code);

@extern(syscall, 1)
void sys_write(u32 fd, u8* buf, u64 count);

void print(u8[] data) {
  sys_write(1, data.ptr, data.length);
}

struct Vector[T] {
  T* ptr;
  u64 capacity;
  u64 length;

  void add(T element) {
    if (capacity <= length) {
      /* ptr = malloc(); */
      print("Allocating more memory!");
    }

    ptr[length++] = element;
  }
}

void main() {
  Vector[i32] numbers = Vector[i32](null, 10, 0);
  exit(0);
}

.har file

Additional context

rempas commented 2 years ago

As always, I can guarantee that it works! Thank you!