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