Debian Codegraph @

src/c/printer/write_code.d

raw
1 /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
3
4 /*
5 * write_list.d - ugly printer for bytecodes and functions
6 *
7 * Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya
8 * Copyright (c) 1990 Giuseppe Attardi
9 * Copyright (c) 2001 Juan Jose Garcia Ripoll
10 *
11 * See file 'LICENSE' for the copyright details.
12 *
13 */
14
15 #include <ecl/ecl.h>
16 #include <ecl/internal.h>
17 #include <ecl/bytecodes.h>
18
19 void
20 _ecl_write_bytecodes_readably(cl_object x, cl_object stream, cl_object lex)
21 {
22 cl_index i;
23 cl_object code_l = ECL_NIL;
24 for ( i=x->bytecodes.code_size-1 ; i<(cl_index)(-1l) ; i-- )
25 code_l = ecl_cons(ecl_make_fixnum(((cl_opcode*)(x->bytecodes.code))[i]), code_l);
26 writestr_stream("#Y", stream);
27 /* We don't write the definition because is not guaranteed to be readable. */
28 si_write_ugly_object(cl_list(7, x->bytecodes.name, lex,
29 ECL_NIL /* x->bytecodes.definition */,
30 code_l,
31 x->bytecodes.data,
32 x->bytecodes.flex,
33 x->bytecodes.nlcl,
34 x->bytecodes.file,
35 x->bytecodes.file_position),
36 stream);
37 }
38
39 void
40 _ecl_write_bytecodes(cl_object x, cl_object stream)
41 {
42 if (ecl_print_readably()) {
43 _ecl_write_bytecodes_readably(x, stream, ECL_NIL);
44 } else {
45 _ecl_write_unreadable(x, "bytecompiled-function", x->bytecodes.name, stream);
46 }
47 }
48
49 void
50 _ecl_write_bclosure(cl_object x, cl_object stream)
51 {
52 if (ecl_print_readably()) {
53 _ecl_write_bytecodes_readably(x->bclosure.code, stream, x->bclosure.lex);
54 } else {
55 cl_object name = x->bclosure.code->bytecodes.name;
56 writestr_stream("#<bytecompiled-closure ", stream);
57 if (name != ECL_NIL) {
58 si_write_ugly_object(name, stream);
59 writestr_stream(" ", stream);
60 }
61 _ecl_write_addr((void *)x, stream);
62 ecl_write_char('>', stream);
63 }
64 }