// File: /workspace/github_c_makefile_star2_O1/tabemann[P]attoforth/src/runtime/prim.c
// Function: af_prim_base_interpreter
void af_prim_base_interpreter(af_task_t* task) {
  af_global_t* global = task->global;
  task->interpreter_pointer = &global->base_interpreter_code[0];
  if(af_parse_name_available(global, task)) {
    af_cell_t length;
    af_byte_t* text = af_parse_name(global, task, &length);
    /* char* print_text = malloc(length + 1); */
    /* memcpy(print_text, text, length); */
    /* print_text[length] = '\0'; */
    /* if(task->is_compiling) { */
    /*   printf("Compiling name: %s\n", print_text) */
    /* } else { */
    /*   printf("Evaluating name: %s\n", print_text); */
    /* } */
    af_word_t* word = af_lookup(global, task, text, length);
    if(word) {
      if(task->is_compiling && !(word->flags & AF_WORD_IMMEDIATE)) {
	af_compiled_t* slot = af_allot(global, task,
				       sizeof(af_compiled_t));
	if(slot) {
	  slot->compiled_call = word;
	}
      } else if(!task->is_compiling && (word->flags & AF_WORD_COMPILE_ONLY)) {
	char* buffer = malloc(length + 1);
	memcpy(buffer, text, length);
	buffer[length] = 0;
	printf("%s: ", buffer);
	free(buffer);
	af_handle_compile_only(global, task);
      } else {
	AF_WORD_EXECUTE(task, word);
      }
    } else {
      af_sign_cell_t result;
      if(af_parse_number(global, task->base, text, (size_t)length, &result)) {
	if(task->is_compiling) {
	  af_compiled_t* slot = af_allot(global, task,
					 sizeof(af_compiled_t) * 2);
	  if(slot) {
	    slot->compiled_call = global->builtin_literal_runtime;
	    (slot + 1)->compiled_sign_cell = result;
	  }
	} else {
	  if(--task->data_stack_current >= task->data_stack_top) {
	    *task->data_stack_current = (af_cell_t)result;
	  } else {
	    af_handle_data_stack_overflow(global, task);
	  }
	}
      } else {
	af_float_t float_result;
	if(af_parse_float(global, text, (size_t)length, &float_result)) {
	  if(task->is_compiling) {
	    af_compiled_t* slot = af_allot(global, task,
					   sizeof(af_compiled_t) +
					   sizeof(af_float_t));
	    if(slot) {
	      slot->compiled_call = global->builtin_f_literal_runtime;
	      *(af_float_t*)(&(slot + 1)->compiled_cell) = float_result;
	    }
	  } else {
	    if(--task->float_stack_current >= task->float_stack_top) {
	      *task->float_stack_current = float_result;
	    } else {
	      af_handle_float_stack_overflow(global, task);
	    }
	  }
	} else {
	  af_2cell_t result2;
	  if(af_parse_2number(global, task->base, text, (size_t)length,
			      &result2)) {
	    if(task->is_compiling) {
	      af_compiled_t* slot = af_allot(global, task,
					     sizeof(af_compiled_t) * 4);
	      if(slot) {
		slot->compiled_call = global->builtin_literal_runtime;
		(slot + 1)->compiled_cell =
		  (af_cell_t)(result2 &
			      ((~(af_2cell_t)0) >> (sizeof(af_cell_t) << 3)));
		(slot + 2)->compiled_call = global->builtin_literal_runtime;
		(slot + 3)->compiled_cell =
		  (af_cell_t)(result2 >> (sizeof(af_cell_t) << 3));
	      }
	    } else {
	      if((task->data_stack_current - 2) >= task->data_stack_top) {
		*(--task->data_stack_current) =
		  (af_cell_t)(result2 &
			      ((~(af_2cell_t)0) >> (sizeof(af_cell_t) << 3)));
		*(--task->data_stack_current) =
		  (af_cell_t)(result2 >> (sizeof(af_cell_t) << 3));
	      } else {
		af_handle_data_stack_overflow(global, task);
	      }
	    }
	  } else {
	    char* buffer = malloc(length + 1);
	    memcpy(buffer, text, length);
	    buffer[length] = 0;
	    printf("%s: ", buffer);
	    free(buffer);
	    af_handle_parse_error(global, task);
	  }
	}
      }
    }
  } else {
    af_kill(global, task);
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %r14
movq (%rdi), %rbx
leaq 0x1f0(%rbx), %rax
movq %rax, 0x58(%rdi)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3db7
testq %rax, %rax
je 0xb97d
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3e65
movq %rax, %r15
movq (%r12), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x383a
testq %rax, %rax
je 0xb995
movq %rax, %r12
movq 0x40(%r14), %rax
testq %rax, %rax
je 0xb9fb
testb $0x1, 0x18(%r12)
jne 0xb9f6
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3759
testq %rax, %rax
je 0xbc12
movq %r12, (%rax)
jmp 0xbc12
movq %rbx, %rdi
movq %r14, %rsi
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x3130
movq 0xf0(%r14), %rsi
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3892
testq %rax, %rax
je 0xba65
cmpq $0x0, 0x40(%r14)
je 0xbabd
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3759
testq %rax, %rax
je 0xbc12
movq 0x180(%rbx), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
jmp 0xbc12
testq %rax, %rax
jne 0xba03
testb $0x4, 0x18(%r12)
jne 0xba16
movq %r12, 0xf8(%r14)
movq %r14, %rdi
callq *(%r12)
jmp 0xbc12
movq 0x8(%rsp), %r12
leaq 0x1(%r12), %rdi
callq 0x2220
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x21f0
movb $0x0, (%r13,%r12)
leaq 0x306d(%rip), %rdi      # 0xeab0
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x35e2
jmp 0xbc12
movq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x39ef
testq %rax, %rax
je 0xbae3
cmpq $0x0, 0x40(%r14)
je 0xbb65
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3759
testq %rax, %rax
je 0xbc12
movq 0x188(%rbx), %rcx
movq %rcx, (%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
jmp 0xbc12
movq 0x60(%r14), %rax
addq $-0x8, %rax
movq %rax, 0x60(%r14)
cmpq 0x78(%r14), %rax
jae 0xbb58
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3402
jmp 0xbc12
movq 0xf0(%r14), %rsi
movq 0x8(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3ab9
testq %rax, %rax
je 0xbb8a
cmpq $0x0, 0x40(%r14)
je 0xbbe2
movl $0x20, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3759
testq %rax, %rax
je 0xbc12
movq 0x180(%rbx), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x180(%rbx), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
jmp 0xbc12
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xbc12
movq 0x68(%r14), %rax
addq $-0x8, %rax
movq %rax, 0x68(%r14)
cmpq 0x80(%r14), %rax
jae 0xbbd6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x342a
jmp 0xbc12
movq 0x8(%rsp), %r12
leaq 0x1(%r12), %rdi
callq 0x2220
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x21f0
movb $0x0, (%r13,%r12)
leaq 0x2ef9(%rip), %rdi      # 0xeab0
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3542
jmp 0xbc12
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0xbc12
movq 0x60(%r14), %rax
leaq -0x10(%rax), %rcx
cmpq 0x78(%r14), %rcx
jb 0xbad3
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rsi
leaq -0x8(%rax), %rdi
movq %rdi, 0x60(%r14)
movq %rdx, -0x8(%rax)
movq %rcx, 0x60(%r14)
movq %rsi, -0x10(%rax)
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq