// File: /workspace/github_c_makefile_star2_O0/atomlang[P]atomlang/src/pk_var.c
// Function: newScript
Script* newScript(PKVM* vm, String* name, bool is_core) {
  Script* script = ALLOCATE(vm, Script);
  varInitObject(&script->_super, vm, OBJ_SCRIPT);

  ASSERT(name != NULL && name->length > 0, OOPS);

  script->path = name;
  script->module = NULL;
  script->initialized = is_core;
  script->body = NULL;

  // Core modules has its name as the module name.
  if (is_core) script->module = name;

  pkVarBufferInit(&script->globals);
  pkUintBufferInit(&script->global_names);
  pkVarBufferInit(&script->literals);
  pkFunctionBufferInit(&script->functions);
  pkClassBufferInit(&script->classes);
  pkStringBufferInit(&script->names);

  // Add a implicit main function and the '__file__' global to the module, only
  // if it's not a core module.
  if (!is_core) {
    vmPushTempRef(vm, &script->_super);
    scriptAddMain(vm, script);

    // Add '__file__' variable with it's path as value. If the path starts with
    // '$' It's a special file ($(REPL) or $(TRY)) and don't define __file__.
    if (script->path->data[0] != '$') {
      scriptAddGlobal(vm, script, "__file__", 8, VAR_OBJ(script->path));
    }

    // TODO: Add ARGV as a global.

    vmPopTempRef(vm); // script.
  }

  return script;
}

// Assembly:
subq $0x28, %rsp
movb %dl, %al
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
andb $0x1, %al
movb %al, 0x17(%rsp)
movq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x90, %ecx
movq %rdx, %rsi
callq 0x8f90
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl $0x4, %edx
callq 0x3d00
cmpq $0x0, 0x18(%rsp)
je 0x4728
movq 0x18(%rsp), %rax
cmpl $0x0, 0x14(%rax)
ja 0x4762
movq 0x2e8c9(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x25a17(%rip), %rsi     # 0x2a150
leaq 0x25b24(%rip), %rdx     # 0x2a264
leaq 0x25b39(%rip), %rcx     # 0x2a280
leaq 0x25a4e(%rip), %r8      # 0x2a19c
movl $0x176, %r9d            # imm = 0x176
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x4764
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x10(%rax)
movb 0x17(%rsp), %cl
movq 0x8(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x88(%rax)
movq 0x8(%rsp), %rax
movq $0x0, 0x80(%rax)
testb $0x1, 0x17(%rsp)
je 0x47b6
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x8(%rsp), %rdi
addq $0x20, %rdi
callq 0x3330
movq 0x8(%rsp), %rdi
addq $0x30, %rdi
callq 0x2e80
movq 0x8(%rsp), %rdi
addq $0x70, %rdi
callq 0x3330
movq 0x8(%rsp), %rdi
addq $0x40, %rdi
callq 0x37d0
movq 0x8(%rsp), %rdi
addq $0x50, %rdi
callq 0x3a20
movq 0x8(%rsp), %rdi
addq $0x60, %rdi
callq 0x3580
testb $0x1, 0x17(%rsp)
jne 0x487c
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x9420
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x4890
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movsbl 0x1c(%rax), %eax
cmpl $0x24, %eax
je 0x4872
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x8(%rsp), %rax
movq 0x18(%rax), %r8
movabsq $-0x4000000000000, %rax # imm = 0xFFFC000000000000
orq %rax, %r8
leaq 0x25a22(%rip), %rdx     # 0x2a28a
movl $0x8, %ecx
callq 0x4970
movq 0x20(%rsp), %rdi
callq 0x95c0
movq 0x8(%rsp), %rax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)