// File: /workspace/github_c_makefile_star2_O3/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 0x3db4
testq %rax, %rax
je 0xb80c
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3e63
movq %rax, %r15
movq (%r12), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x383e
testq %rax, %rax
je 0xb824
movq %rax, %r12
cmpq $0x0, 0x40(%r14)
movq 0x18(%rax), %rax
je 0xb881
testb $0x1, %al
jne 0xb885
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x377a
testq %rax, %rax
je 0xba90
movq %r12, (%rax)
jmp 0xba90
movq %rbx, %rdi
movq %r14, %rsi
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x315d
movq 0xf0(%r14), %rsi
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3892
testq %rax, %rax
je 0xb898
cmpq $0x0, 0x40(%r14)
je 0xb943
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x377a
testq %rax, %rax
je 0xba90
movq 0x180(%rbx), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
jmp 0xba90
testb $0x4, %al
jne 0xb8f4
movq %r12, 0xf8(%r14)
movq %r14, %rdi
callq *(%r12)
jmp 0xba90
movq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x39f3
testq %rax, %rax
je 0xb969
cmpq $0x0, 0x40(%r14)
je 0xb9eb
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x377a
testq %rax, %rax
je 0xba90
movq 0x188(%rbx), %rcx
movq %rcx, (%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
jmp 0xba90
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 0x318f(%rip), %rdi      # 0xeab0
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3605
jmp 0xba90
movq 0x60(%r14), %rax
addq $-0x8, %rax
movq %rax, 0x60(%r14)
cmpq 0x78(%r14), %rax
jae 0xb9de
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3425
jmp 0xba90
movq 0xf0(%r14), %rsi
movq 0x8(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
callq 0x3aa7
testq %rax, %rax
je 0xba10
cmpq $0x0, 0x40(%r14)
je 0xba68
movl $0x20, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x377a
testq %rax, %rax
je 0xba90
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 0xba90
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xba90
movq 0x68(%r14), %rax
addq $-0x8, %rax
movq %rax, 0x68(%r14)
cmpq 0x80(%r14), %rax
jae 0xba5c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x344d
jmp 0xba90
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 0x3073(%rip), %rdi      # 0xeab0
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3565
jmp 0xba90
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0xba90
movq 0x60(%r14), %rax
leaq -0x10(%rax), %rcx
cmpq 0x78(%r14), %rcx
jb 0xb959
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rsi
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