void Autoload::load() { Thread * const thread = current_thread(); void * last_special_binding = thread->last_special_binding(); thread->bind_special(S_current_readtable, thread->symbol_value(S_standard_readtable)); thread->bind_special(S_current_package, make_value(PACKAGE_SYS)); thread->bind_special(S_read_base, FIXNUM_TEN); if (thread->symbol_value(S_autoload_verbose) != NIL) { String * prefix = new String(xcl_home()); prefix->append_char('/'); if (_filename == NULL) prefix->append("lisp/"); Pathname * defaults = check_pathname(parse_namestring(prefix)); Value device = defaults->device(); Value directory = defaults->directory(); Value name; if (_filename) name = make_value(new_simple_string(_filename)); else name = make_value(the_symbol(operator_name())->name()->downcase()); Value type = make_simple_string("xcl"); Pathname * pathname = new Pathname(NIL, device, directory, name, type, NIL); if (CL_probe_file(make_value(pathname)) == NIL) { type = make_simple_string("lisp"); pathname = new Pathname(NIL, device, directory, name, type, NIL); } AbstractString * namestring = pathname->namestring(); AnsiStream * out = check_ansi_stream(thread->symbol_value(S_standard_output)); String * message = new String("; Autoloading "); message->append(::prin1_to_string(operator_name())->as_c_string()); message->append(" from "); message->append(namestring); message->append(" ...\n"); out->fresh_line(); out->write_string(message); CL_load(make_value(namestring)); message = new String("; Autoloaded "); message->append(namestring); message->append("\n"); out->fresh_line(); out->write_string(message); } else if (_filename) { SYS_load_system_file(make_value(_filename)); } else { String * namestring = new String("lisp/"); namestring->append(the_symbol(operator_name())->name()->downcase()); SYS_load_system_file(make_value(namestring)); } thread->set_last_special_binding(last_special_binding); }
AbstractString * Function::write_to_string() { Value name = operator_name(); Thread * thread = current_thread(); if (thread->symbol_value(S_print_readably) != NIL) { if (symbolp(name) || is_valid_setf_function_name(name)) { String * s = new String(); s->append("#.("); s->append(the_symbol(S_coerce_to_function)->prin1_to_string()); s->append(" '"); s->append(::prin1_to_string(name)); s->append_char(')'); return s; } signal_lisp_error(new PrintNotReadable(make_value(this))); // not reached return NULL; } String * s = new String(); s->append(the_symbol(S_function)->write_to_string()); if (name != NULL_VALUE) { s->append_char(' '); void* last_special_binding = thread->last_special_binding(); thread->bind_special(S_print_length, NIL); thread->bind_special(S_print_level, NIL); s->append(::prin1_to_string(name)); thread->set_last_special_binding(last_special_binding); } return unreadable_string(s); }
Value Autoload::execute(Value arg1, Value arg2, Value arg3, Value arg4, Value arg5, Value arg6) { load(); return the_symbol(operator_name())->function()->execute(arg1, arg2, arg3, arg4, arg5, arg6); }
Value Primitive::execute(unsigned int numargs, Value args[]) { if (_minargs <= numargs && numargs <= _maxargs) { Value (*code) (unsigned int, Value *) = (Value (*) (unsigned int, Value *)) _code; return (*code)(numargs, args); } return wrong_number_of_arguments(operator_name(), numargs, _minargs, _maxargs); }
AbstractString * Autoload::prin1_to_string() { String * string = new String("#<"); string->append(the_symbol(S_autoload)->prin1_to_string()); if (operator_name() != NULL_VALUE) { string->append_char(' '); string->append(::prin1_to_string(operator_name())); } if (_filename != NULL) { string->append(" \""); string->append(_filename); string->append_char('"'); } char buf[256]; SNPRINTF(buf, sizeof(buf), " {%lX}>", (unsigned long) this); string->append(buf); return string; }
virtual String * write_to_string() { String * string = new String("#<"); string->append(the_symbol(S_macro)->prin1_to_string()); Value name = operator_name(); if (name != NULL_VALUE) { string->append_char(' '); string->append(::prin1_to_string(name)); } char buf[256]; SNPRINTF(buf, sizeof(buf), " {%lX}>", (unsigned long) this); string->append(buf); return string; }
Value Primitive::execute() { if (_arity == 0) { Value (*code) () = (Value (*) ()) _code; return (*code)(); } if (_arity < 0) { if (_minargs <= 0 && 0 <= _maxargs) { Value args[0]; Value (*code) (unsigned int, Value *) = (Value (*) (unsigned int, Value *)) _code; return (*code)(0, args); } } return wrong_number_of_arguments(operator_name(), 0, _minargs, _maxargs); }
Value Primitive::execute(Value arg) { if (_arity == 1) { Value (*code) (Value) = (Value (*) (Value)) _code; return (*code)(arg); } if (_arity < 0) { if (_minargs <= 1 && 1 <= _maxargs) { Value args[1]; args[0] = arg; Value (*code) (unsigned int, Value *) = (Value (*) (unsigned int, Value *)) _code; return (*code)(1, args); } } return wrong_number_of_arguments(operator_name(), 1, _minargs, _maxargs); }
Value Function::parts() { String * description = new String(prin1_to_string()); description->append_char('\n'); Value elements = NIL; Value name = operator_name(); elements = make_cons(make_cons(make_simple_string("NAME"), name != NULL_VALUE ? name : NIL), elements); elements = make_cons(make_cons(make_simple_string("ARITY"), make_fixnum(arity())), elements); elements = make_cons(make_cons(make_simple_string("MINARGS"), make_fixnum(minargs())), elements); elements = make_cons(make_cons(make_simple_string("MAXARGS"), make_fixnum(maxargs())), elements); return current_thread()->set_values(make_value(description), T, CL_nreverse(elements)); }
Value Primitive::execute(Value arg1, Value arg2) { if (_arity == 2) { Value (*code) (Value, Value) = (Value (*) (Value, Value)) _code; return (*code)(arg1, arg2); } if (_arity < 0) { if (_minargs <= 2 && 2 <= _maxargs) { Value args[2]; args[0] = arg1; args[1] = arg2; Value (*code) (unsigned int, Value *) = (Value (*) (unsigned int, Value *)) _code; return (*code)(2, args); } } return wrong_number_of_arguments(operator_name(), 2, _minargs, _maxargs); }
Value Primitive::execute(Value arg1, Value arg2, Value arg3, Value arg4) { if (_arity == 4) { Value (*code) (Value, Value, Value, Value) = (Value (*) (Value, Value, Value, Value)) _code; return (*code)(arg1, arg2, arg3, arg4); } if (_arity < 0) { if (_minargs <= 4 && 4 <= _maxargs) { Value args[4]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; Value (*code) (unsigned int, Value *) = (Value (*) (unsigned int, Value *)) _code; return (*code)(4, args); } } return wrong_number_of_arguments(operator_name(), 4, _minargs, _maxargs); }
Value Primitive::execute(Value arg1, Value arg2, Value arg3, Value arg4, Value arg5, Value arg6) { if (_arity == 6) { Value (*code) (Value, Value, Value, Value, Value, Value) = (Value (*) (Value, Value, Value, Value, Value, Value)) _code; return (*code)(arg1, arg2, arg3, arg4, arg5, arg6); } if (_arity < 0) { if (_minargs <= 6 && 6 <= _maxargs) { Value args[6]; args[0] = arg1; args[1] = arg2; args[2] = arg3; args[3] = arg4; args[4] = arg5; args[5] = arg6; Value (*code) (unsigned int, Value *) = (Value (*) (unsigned int, Value *)) _code; return (*code)(6, args); } } return wrong_number_of_arguments(operator_name(), 6, _minargs, _maxargs); }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { pixman_image_t *src_img = NULL; pixman_image_t *dst_img = NULL; pixman_image_t *mask_img = NULL; int src_width, src_height; int dst_width, dst_height; int src_stride, dst_stride; int src_x, src_y; int dst_x, dst_y; int mask_x, mask_y; int w, h; pixman_op_t op; pixman_format_code_t src_fmt, dst_fmt, mask_fmt; uint32_t *srcbuf, *maskbuf; uint32_t crc32; int max_width, max_height, max_extra_stride; FLOAT_REGS_CORRUPTION_DETECTOR_START (); max_width = max_height = 24 + testnum / 10000; max_extra_stride = 4 + testnum / 1000000; if (max_width > 256) max_width = 256; if (max_height > 16) max_height = 16; if (max_extra_stride > 8) max_extra_stride = 8; prng_srand (testnum); op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))]; if (prng_rand_n (8)) { /* normal image */ src_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &src_fmt); } else { /* solid case */ src_img = create_random_image (img_fmt_list, 1, 1, max_extra_stride, &src_fmt); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); } dst_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &dst_fmt); src_width = pixman_image_get_width (src_img); src_height = pixman_image_get_height (src_img); src_stride = pixman_image_get_stride (src_img); dst_width = pixman_image_get_width (dst_img); dst_height = pixman_image_get_height (dst_img); dst_stride = pixman_image_get_stride (dst_img); srcbuf = pixman_image_get_data (src_img); src_x = prng_rand_n (src_width); src_y = prng_rand_n (src_height); dst_x = prng_rand_n (dst_width); dst_y = prng_rand_n (dst_height); mask_img = NULL; mask_fmt = PIXMAN_null; mask_x = 0; mask_y = 0; maskbuf = NULL; if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) && (prng_rand_n (4) == 0)) { /* PIXBUF */ mask_fmt = prng_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8; mask_img = pixman_image_create_bits (mask_fmt, src_width, src_height, srcbuf, src_stride); mask_x = src_x; mask_y = src_y; maskbuf = srcbuf; } else if (prng_rand_n (2)) { if (prng_rand_n (2)) { mask_img = create_random_image (mask_fmt_list, max_width, max_height, max_extra_stride, &mask_fmt); } else { /* solid case */ mask_img = create_random_image (mask_fmt_list, 1, 1, max_extra_stride, &mask_fmt); pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL); } if (prng_rand_n (2)) pixman_image_set_component_alpha (mask_img, 1); mask_x = prng_rand_n (pixman_image_get_width (mask_img)); mask_y = prng_rand_n (pixman_image_get_height (mask_img)); } w = prng_rand_n (dst_width - dst_x + 1); h = prng_rand_n (dst_height - dst_y + 1); if (verbose) { printf ("op=%s\n", operator_name (op)); printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n", format_name (src_fmt), format_name (dst_fmt), format_name (mask_fmt)); printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n", src_width, src_height, dst_width, dst_height); printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n", src_x, src_y, dst_x, dst_y); printf ("src_stride=%d, dst_stride=%d\n", src_stride, dst_stride); printf ("w=%d, h=%d\n", w, h); } pixman_image_composite (op, src_img, mask_img, dst_img, src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h); if (verbose) print_image (dst_img); free_random_image (0, src_img, PIXMAN_null); crc32 = free_random_image (0, dst_img, dst_fmt); if (mask_img) { if (srcbuf == maskbuf) pixman_image_unref(mask_img); else free_random_image (0, mask_img, PIXMAN_null); } FLOAT_REGS_CORRUPTION_DETECTOR_FINISH (); return crc32; }
Value Autoload::execute(Value arg) { load(); return the_symbol(operator_name())->function()->execute(arg); }
static pixman_bool_t verify (int test_no, pixman_op_t op, pixman_image_t *source, pixman_image_t *mask, pixman_image_t *dest, pixman_image_t *orig_dest, int x, int y, int width, int height, pixman_bool_t component_alpha) { pixel_checker_t dest_checker, src_checker, mask_checker; int i, j; pixel_checker_init (&src_checker, source->bits.format); pixel_checker_init (&dest_checker, dest->bits.format); pixel_checker_init (&mask_checker, mask->bits.format); assert (dest->bits.format == orig_dest->bits.format); for (j = y; j < y + height; ++j) { for (i = x; i < x + width; ++i) { color_t src_color, mask_color, orig_dest_color, result; uint32_t dest_pixel, orig_dest_pixel, src_pixel, mask_pixel; access (dest, i, j, &dest_pixel); get_color (&src_checker, source, i - x, j - y, &src_color, &src_pixel); get_color (&mask_checker, mask, i - x, j - y, &mask_color, &mask_pixel); get_color (&dest_checker, orig_dest, i, j, &orig_dest_color, &orig_dest_pixel); do_composite (op, &src_color, &mask_color, &orig_dest_color, &result, component_alpha); if (!pixel_checker_check (&dest_checker, dest_pixel, &result)) { int a, r, g, b; printf ("--------- Test 0x%x failed ---------\n", test_no); printf (" operator: %s (%s alpha)\n", operator_name (op), component_alpha? "component" : "unified"); printf (" dest_x, dest_y: %d %d\n", x, y); printf (" width, height: %d %d\n", width, height); printf (" source: format: %-14s size: %2d x %2d\n", format_name (source->bits.format), source->bits.width, source->bits.height); printf (" mask: format: %-14s size: %2d x %2d\n", format_name (mask->bits.format), mask->bits.width, mask->bits.height); printf (" dest: format: %-14s size: %2d x %2d\n", format_name (dest->bits.format), dest->bits.width, dest->bits.height); printf (" -- Failed pixel: (%d, %d) --\n", i, j); printf (" source ARGB: %f %f %f %f (pixel: %x)\n", src_color.a, src_color.r, src_color.g, src_color.b, src_pixel); printf (" mask ARGB: %f %f %f %f (pixel: %x)\n", mask_color.a, mask_color.r, mask_color.g, mask_color.b, mask_pixel); printf (" dest ARGB: %f %f %f %f (pixel: %x)\n", orig_dest_color.a, orig_dest_color.r, orig_dest_color.g, orig_dest_color.b, orig_dest_pixel); printf (" expected ARGB: %f %f %f %f\n", result.a, result.r, result.g, result.b); pixel_checker_get_min (&dest_checker, &result, &a, &r, &g, &b); printf (" min acceptable: %8d %8d %8d %8d\n", a, r, g, b); pixel_checker_split_pixel (&dest_checker, dest_pixel, &a, &r, &g, &b); printf (" got: %8d %8d %8d %8d (pixel: %x)\n", a, r, g, b, dest_pixel); pixel_checker_get_max (&dest_checker, &result, &a, &r, &g, &b); printf (" max acceptable: %8d %8d %8d %8d\n", a, r, g, b); printf ("\n"); printf (" { %s,\n", operator_name (op)); printf (" PIXMAN_%s,\t0x%x,\n", format_name (source->bits.format), src_pixel); printf (" PIXMAN_%s,\t0x%x,\n", format_name (mask->bits.format), mask_pixel); printf (" PIXMAN_%s,\t0x%x\n", format_name (dest->bits.format), orig_dest_pixel); printf (" },\n"); return FALSE; } } } return TRUE; }
static pixman_bool_t verify (int test_no, const pixel_combination_t *combination, int size) { pixman_image_t *src, *dest; pixel_checker_t src_checker, dest_checker; color_t source_color, dest_color, reference_color; pixman_bool_t result = TRUE; int i, j; /* Compute reference color */ pixel_checker_init (&src_checker, combination->src_format); pixel_checker_init (&dest_checker, combination->dest_format); pixel_checker_convert_pixel_to_color ( &src_checker, combination->src_pixel, &source_color); pixel_checker_convert_pixel_to_color ( &dest_checker, combination->dest_pixel, &dest_color); do_composite (combination->op, &source_color, NULL, &dest_color, &reference_color, FALSE); src = pixman_image_create_bits ( combination->src_format, size, size, NULL, -1); dest = pixman_image_create_bits ( combination->dest_format, size, size, NULL, -1); fill (src, combination->src_pixel); fill (dest, combination->dest_pixel); pixman_image_composite32 ( combination->op, src, NULL, dest, 0, 0, 0, 0, 0, 0, size, size); for (j = 0; j < size; ++j) { for (i = 0; i < size; ++i) { uint32_t computed = access (dest, i, j); int32_t a, r, g, b; if (!pixel_checker_check (&dest_checker, computed, &reference_color)) { printf ("----------- Test %d failed ----------\n", test_no); printf (" operator: %s\n", operator_name (combination->op)); printf (" src format: %s\n", format_name (combination->src_format)); printf (" dest format: %s\n", format_name (combination->dest_format)); printf (" - source ARGB: %f %f %f %f (pixel: %8x)\n", source_color.a, source_color.r, source_color.g, source_color.b, combination->src_pixel); pixel_checker_split_pixel (&src_checker, combination->src_pixel, &a, &r, &g, &b); printf (" %8d %8d %8d %8d\n", a, r, g, b); printf (" - dest ARGB: %f %f %f %f (pixel: %8x)\n", dest_color.a, dest_color.r, dest_color.g, dest_color.b, combination->dest_pixel); pixel_checker_split_pixel (&dest_checker, combination->dest_pixel, &a, &r, &g, &b); printf (" %8d %8d %8d %8d\n", a, r, g, b); pixel_checker_split_pixel (&dest_checker, computed, &a, &r, &g, &b); printf (" - expected ARGB: %f %f %f %f\n", reference_color.a, reference_color.r, reference_color.g, reference_color.b); pixel_checker_get_min (&dest_checker, &reference_color, &a, &r, &g, &b); printf (" min acceptable: %8d %8d %8d %8d\n", a, r, g, b); pixel_checker_split_pixel (&dest_checker, computed, &a, &r, &g, &b); printf (" got: %8d %8d %8d %8d (pixel: %8x)\n", a, r, g, b, computed); pixel_checker_get_max (&dest_checker, &reference_color, &a, &r, &g, &b); printf (" max acceptable: %8d %8d %8d %8d\n", a, r, g, b); result = FALSE; goto done; } } } done: pixman_image_unref (src); pixman_image_unref (dest); return result; }
Value Autoload::execute(unsigned int numargs, Value args[]) { load(); return the_symbol(operator_name())->function()->execute(numargs, args); }