]> www.ginac.de Git - cln.git/blob - src/base/cl_debug.cc
- Compatibility was not really broken, so: C=0, R=1, A=0.
[cln.git] / src / base / cl_debug.cc
1 // Debugging support for dynamic typing.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_object.h"
8
9
10 // Implementation.
11
12 #include "cl_io.h"
13 #include "cl_abort.h"
14
15 // The default printer function.
16 void cl_dprint_unknown (cl_heap* pointer)
17 {
18         fprint(cl_debugout, "<unknown @0x");
19         fprinthexadecimal(cl_debugout, (unsigned long) pointer);
20         fprint(cl_debugout, " refcount=");
21         fprintdecimal(cl_debugout, pointer->refcount);
22         fprint(cl_debugout, " type=");
23         fprinthexadecimal(cl_debugout, (unsigned long) pointer->type);
24         fprint(cl_debugout, ">");
25 }
26
27 static void cl_dprint_unknown_immediate (cl_heap* pointer)
28 {
29         fprint(cl_debugout, "<unknown @0x");
30         fprinthexadecimal(cl_debugout, (unsigned long) pointer);
31         fprint(cl_debugout, ">");
32 }
33
34 // Print an object. This function is callable from the debugger.
35 extern "C" void* cl_print (cl_uint word);
36 void* cl_print (cl_uint word)
37 {
38         var cl_heap* pointer = (cl_heap*)word;
39         if (cl_pointer_p(word)) {
40                 var const cl_class* type = pointer->type;
41                 if (type->dprint)
42                         type->dprint(pointer);
43                 else
44                         cl_dprint_unknown(pointer);
45         } else {
46                 var const cl_class* type = cl_immediate_classes[cl_tag(word)];
47                 if (type && type->dprint)
48                         type->dprint(pointer);
49                 else
50                         cl_dprint_unknown_immediate(pointer);
51         }
52         #ifdef CL_IO_IOSTREAM
53         cl_debugout << endl; // newline and flush output
54         #else
55         fprint(cl_debugout, "\n");
56         #endif
57         return pointer;
58 }
59
60 void cl_gcobject::debug_print () const
61 {
62         cl_print(word);
63 }
64
65 void cl_gcpointer::debug_print () const
66 {
67         cl_print(word);
68 }
69
70 void cl_rcobject::debug_print () const
71 {
72         cl_print(word);
73 }
74
75 void cl_rcpointer::debug_print () const
76 {
77         cl_print(word);
78 }