static void push_function(struct thread *thread, int arg) { struct variable *var = (struct variable *)COMPONENT(thread->component)->constant[arg]; obj_t value = var->value; switch (var->function) { case func_No: type_error(value, obj_FunctionClass); case func_Yes: case func_Always: break; case func_Maybe: if (instancep(value, obj_FunctionClass)) { var->function = func_Yes; break; } else if (value == obj_Unbound) error("Unbound variable: %s", var->name); else { var->function = func_No; type_error(value, obj_FunctionClass); } } *thread->sp++ = value; }
/* Look for an object with the given name in the named file and return a callable "<c-function>" object for it. */ obj_t find_c_function(obj_t /* <string> */ symbol, obj_t lookup) { const char *string = string_chars(symbol); struct symtab *syms; int sym_count, i; obj_t retval = obj_False; if (lookup == obj_Unbound) { if (mindy_dynamic_syms == NULL) mindy_dynamic_syms = load_program_file(); return find_c_function(symbol, mindy_dynamic_syms); } else if (lookup == obj_False) return obj_False; else if (!instancep(lookup, obj_ForeignFileClass)) { error("Keyword file: is not a <foreign-file>: %=", lookup); return retval; /* make lint happy */ } else if (instancep(lookup, obj_SharedFileClass)) { shl_t *files = obj_ptr(struct shared_file *, lookup)->handles; int file_count = obj_ptr(struct shared_file *, lookup)->file_count; void *ptr; for (i = 0; i < file_count; i++) if (shl_findsym(&files[i], string, &ptr) == 0) return(make_c_function(make_byte_string(string), ptr)); return retval; } else {
obj_t check_type(obj_t thing, obj_t type) { if (!instancep(thing, type)) { type_error(thing, type); /* Never reached, but keeps the compiler happy. */ return 0; } else return thing; }
static void op_check_type(int byte, struct thread *thread) { obj_t *sp = thread->sp; obj_t value = sp[-2]; obj_t type = sp[-1]; if (!instancep(value, type)) type_error(value, type); thread->sp = sp - 1; }
static void pop_value(struct thread *thread, int arg) { struct variable *var = (struct variable *)COMPONENT(thread->component)->constant[arg]; obj_t value = *--thread->sp; if (var->type != obj_False && !instancep(value, var->type)) type_error(value, var->type); if (var->function != func_Always) var->function = func_Maybe; var->value = value; }
static void op_check_type_function(int byte, struct thread *thread) { if (!instancep(thread->sp[-1], obj_FunctionClass)) type_error(thread->sp[-1], obj_FunctionClass); }