diff options
Diffstat (limited to 'Build/source/utils/asymptote/program.cc')
-rw-r--r-- | Build/source/utils/asymptote/program.cc | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/Build/source/utils/asymptote/program.cc b/Build/source/utils/asymptote/program.cc index fd7b14bfe0e..4459362e9b5 100644 --- a/Build/source/utils/asymptote/program.cc +++ b/Build/source/utils/asymptote/program.cc @@ -6,8 +6,11 @@ *****/ #include <iostream> +#include "util.h" +#include "callable.h" #include "program.h" + namespace vm { static const char* opnames[] = { @@ -19,6 +22,44 @@ static const char* opnames[] = { }; static const Int numOps = (Int)(sizeof(opnames)/sizeof(char *)); +#ifdef DEBUG_BLTIN +mem::map<bltin,string> bltinRegistry; + +void registerBltin(bltin b, string s) { + bltinRegistry[b] = s; +} +string lookupBltin(bltin b) { + return bltinRegistry[b]; +} +#endif + + +ostream& operator<< (ostream& out, const item& i) +{ + // TODO: Make a data structure mapping typeids to print functions. + if (i.empty()) + out << "empty"; + else if (isdefault(i)) + out << "default"; + else if (i.type() == typeid(Int)) + out << "Int, value = " << get<Int>(i); + else if (i.type() == typeid(double)) + out << "real, value = " << get<double>(i); + else if (i.type() == typeid(string)) + out << "string, value = " << get<string>(i); + else if (i.type() == typeid(callable)) + out << *(get<callable *>(i)); + else if (i.type() == typeid(frame)) { + out << "frame"; +#ifdef DEBUG_FRAME + out << " " << (get<frame *>(i))->getName(); +#endif + } + else + out << "type " << demangle(i.type().name()); + return out; +} + void printInst(ostream& out, const program::label& code, const program::label& base) { @@ -44,11 +85,21 @@ void printInst(ostream& out, const program::label& code, break; } + case inst::constpush: + { + item c = code->ref; + out << " " << c; + break; + } + +#ifdef DEBUG_BLTIN case inst::builtin: - { - out << " " << get<bltin>(*code) << " "; + { + string s=lookupBltin(get<bltin>(*code)); + out << " " << (!s.empty() ? s : "<unnamed>") << " "; break; } +#endif case inst::jmp: case inst::cjmp: @@ -62,11 +113,13 @@ void printInst(ostream& out, const program::label& code, break; } +#ifdef DEBUG_FRAME case inst::makefunc: { - out << " " << get<lambda*>(*code) << " "; + out << " " << get<lambda*>(*code)->name << " "; break; } +#endif default: { /* nothing else to do */ |