// File: /workspace/github_c_makefile_star2_O2/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 0x3c38
testq %rax, %rax
je 0xb582
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3cc1
movq %rax, %r15
movq (%r12), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x36c6
testq %rax, %rax
je 0xb59a
movq %rax, %r12
cmpq $0x0, 0x40(%r14)
movq 0x18(%rax), %rax
je 0xb5f5
testb $0x1, %al
jne 0xb5f9
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3621
testq %rax, %rax
je 0xb800
movq %r12, (%rax)
jmp 0xb800
movq %rbx, %rdi
movq %r14, %rsi
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x3096
movq 0xf0(%r14), %rsi
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
callq 0x371a
testq %rax, %rax
je 0xb60c
cmpq $0x0, 0x40(%r14)
je 0xb6b5
pushq $0x10
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3621
testq %rax, %rax
je 0xb800
movq 0x180(%rbx), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
jmp 0xb800
testb $0x4, %al
jne 0xb666
movq %r12, 0xf8(%r14)
movq %r14, %rdi
callq *(%r12)
jmp 0xb800
movq 0x8(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x388a
testq %rax, %rax
je 0xb6db
cmpq $0x0, 0x40(%r14)
je 0xb75b
pushq $0x10
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3621
testq %rax, %rax
je 0xb800
movq 0x188(%rbx), %rcx
movq %rcx, (%rax)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
jmp 0xb800
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 0x341d(%rip), %rdi      # 0xeab0
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x34be
jmp 0xb800
movq 0x60(%r14), %rax
addq $-0x8, %rax
movq %rax, 0x60(%r14)
cmpq 0x78(%r14), %rax
jae 0xb74e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32de
jmp 0xb800
movq 0xf0(%r14), %rsi
movq 0x8(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
callq 0x392e
testq %rax, %rax
je 0xb780
cmpq $0x0, 0x40(%r14)
je 0xb7d8
pushq $0x20
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3621
testq %rax, %rax
je 0xb800
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 0xb800
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xb800
movq 0x68(%r14), %rax
addq $-0x8, %rax
movq %rax, 0x68(%r14)
cmpq 0x80(%r14), %rax
jae 0xb7cc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3306
jmp 0xb800
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 0x3303(%rip), %rdi      # 0xeab0
movq %r13, %rsi
xorl %eax, %eax
callq 0x2130
movq %r13, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r14, %rsi
callq 0x341e
jmp 0xb800
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0xb800
movq 0x60(%r14), %rax
leaq -0x10(%rax), %rcx
cmpq 0x78(%r14), %rcx
jb 0xb6cb
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