// File: /workspace/github_c_makefile_star2_O0/atomlang[P]atomlang/src/pk_compiler.c
// Function: compileRegularImport
static void compileRegularImport(Compiler* compiler) {
  ASSERT(compiler->scope_depth == DEPTH_GLOBAL, OOPS);

  do {

    // Import the library and push it on the stack. If it cannot import,
    // the lib would be null, but we're not terminating here, just continue
    // parsing for cascaded errors.
    Script* lib = compilerImport(compiler);

    // variable to bind the imported script.
    int var_index = -1;

    // Check if it has an alias, if so bind the variable with that name.
    if (match(compiler, TK_AS)) {
      // Consuming it'll update the previous token which would be the name of
      // the binding variable.
      consume(compiler, TK_NAME, "Expected a name after 'as'.");

      // Get the variable to bind the imported symbol, if we already have a
      // variable with that name override it, otherwise use a new variable.
      const char* name = compiler->previous.start;
      int length = compiler->previous.length, line = compiler->previous.line;
      var_index = compilerImportName(compiler, line, name, length);

    } else {
      // If it has a module name use it as binding variable.
      // Core libs names are it's module name but for local libs it's optional
      // to define a module name for a script.
      if (lib && lib->module != NULL) {

        // Get the variable to bind the imported symbol, if we already have a
        // variable with that name override it, otherwise use a new variable.
        const char* name = lib->module->data;
        uint32_t length = lib->module->length;
        int line = compiler->previous.line;
        var_index = compilerImportName(compiler, line, name, length);

      } else {
        // -- Nothing to do here --
        // Importing from path which doesn't have a module name. Import
        // everything of it. and bind to a variables.
      }
    }

    if (var_index != -1) {
      emitStoreVariable(compiler, var_index, true);
      emitOpcode(compiler, OP_POP);

    } else {
      if (lib) compilerImportAll(compiler, lib);
      // Done importing everything from lib now pop the lib.
      emitOpcode(compiler, OP_POP);
    }

  } while (match(compiler, TK_COMMA) && (skipNewLines(compiler), true));

  consumeEndStatement(compiler);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpl $-0x1, 0xa0(%rax)
je 0x19bb1
movq 0x1947a(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x105c8(%rip), %rsi     # 0x2a150
leaq 0x106d5(%rip), %rdx     # 0x2a264
leaq 0x11dfb(%rip), %rcx     # 0x2b991
leaq 0x1143a(%rip), %r8      # 0x2afd7
movl $0x989, %r9d            # imm = 0x989
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x19bb3
jmp 0x19bb5
movq 0x40(%rsp), %rdi
callq 0x19d40
movq %rax, 0x38(%rsp)
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
movq 0x40(%rsp), %rdi
movl $0x31, %esi
callq 0x15f50
testb $0x1, %al
jne 0x19be1
jmp 0x19c3a
movq 0x40(%rsp), %rdi
movl $0x47, %esi
leaq 0x11c33(%rip), %rdx     # 0x2b825
callq 0x160a0
movq 0x40(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rax
movl 0x40(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x40(%rsp), %rax
movl 0x44(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x40(%rsp), %rdi
movl 0x20(%rsp), %esi
movq 0x28(%rsp), %rdx
movl 0x24(%rsp), %ecx
callq 0x1a140
movl %eax, 0x34(%rsp)
jmp 0x19c9d
cmpq $0x0, 0x38(%rsp)
je 0x19c99
movq 0x38(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x19c99
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
addq $0x1c, %rax
movq %rax, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x14(%rax), %eax
movl %eax, 0x14(%rsp)
movq 0x40(%rsp), %rax
movl 0x44(%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rdx
movl 0x14(%rsp), %ecx
callq 0x1a140
movl %eax, 0x34(%rsp)
jmp 0x19c9b
jmp 0x19c9b
jmp 0x19c9d
cmpl $-0x1, 0x34(%rsp)
je 0x19cc8
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %esi
movl $0x1, %edx
callq 0x18350
movq 0x40(%rsp), %rdi
movl $0x25, %esi
callq 0x16650
jmp 0x19cee
cmpq $0x0, 0x38(%rsp)
je 0x19cdf
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x19ec0
movq 0x40(%rsp), %rdi
movl $0x25, %esi
callq 0x16650
jmp 0x19cf0
movq 0x40(%rsp), %rdi
movl $0x5, %esi
callq 0x15f50
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xf(%rsp)
jne 0x19d0e
jmp 0x19d1e
movq 0x40(%rsp), %rdi
callq 0x15f40
movb $0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x19bb5
movq 0x40(%rsp), %rdi
callq 0x16110
addq $0x48, %rsp
retq
nopl (%rax)