1.1 --- a/jitcraft/Stack.cpp Wed Jul 11 01:12:54 2012 -0700
1.2 +++ b/jitcraft/Stack.cpp Thu Jul 12 00:38:00 2012 -0700
1.3 @@ -20,8 +20,9 @@
1.4 #include <stdlib.h>
1.5 #include "Stack.h"
1.6 #include "Zone.h"
1.7 +#include "Strings.h"
1.8 +#include "Modules.h"
1.9 #include "Heap-inl.h"
1.10 -#include "Strings.h"
1.11
1.12 using namespace ke;
1.13
1.14 @@ -245,42 +246,50 @@
1.15 return false;
1.16 }
1.17
1.18 -StackIter::StackIter(Zone *zone)
1.19 - : pc_(zone->stack().top()->pc),
1.20 - fp_(zone->stack().top()->fp)
1.21 -{
1.22 -}
1.23 -
1.24 -bool
1.25 -StackIter::done() const
1.26 -{
1.27 - return !fp_;
1.28 -}
1.29 -
1.30 -const char *
1.31 -StackIter::function() const
1.32 -{
1.33 - if (fp_->isNative())
1.34 - return fp_->native()->name()->chars();
1.35 - if (Function *fun = fp_->maybeFun())
1.36 - return fun->name()->chars();
1.37 - return "<toplevel>";
1.38 -}
1.39 -
1.40 -unsigned
1.41 -StackIter::lineNumber() const
1.42 -{
1.43 - return 0;
1.44 -}
1.45 -
1.46 -const char *
1.47 -StackIter::source() const
1.48 -{
1.49 - if (fp_->isNative())
1.50 - return "<native>";
1.51 - return "unknown";
1.52 -}
1.53 -
1.54 +StackIter::StackIter(Zone *zone)
1.55 + : pc_(zone->stack().top()->pc),
1.56 + fp_(zone->stack().top()->fp)
1.57 +{
1.58 +}
1.59 +
1.60 +bool
1.61 +StackIter::done() const
1.62 +{
1.63 + return !fp_;
1.64 +}
1.65 +
1.66 +const char *
1.67 +StackIter::function() const
1.68 +{
1.69 + if (fp_->isNative())
1.70 + return fp_->native()->name()->chars();
1.71 + if (Function *fun = fp_->maybeFun())
1.72 + return fun->name()->chars();
1.73 + return "<toplevel>";
1.74 +}
1.75 +
1.76 +unsigned
1.77 +StackIter::lineNumber() const
1.78 +{
1.79 + if (fp_->isNative())
1.80 + return 0;
1.81 + if (fp_->maybeFun()) {
1.82 + unsigned offs = fp_->code()->pcToOffset(pc_);
1.83 + return fp_->code()->pcToSource(offs).line;
1.84 + }
1.85 + return fp_->code()->lineNumber();
1.86 +}
1.87 +
1.88 +const char *
1.89 +StackIter::source() const
1.90 +{
1.91 + if (fp_->isNative())
1.92 + return "<native>";
1.93 + return fp_->code()->module()->file()
1.94 + ? fp_->code()->module()->file()->chars()
1.95 + : "(anonymous)";
1.96 +}
1.97 +
1.98 void
1.99 StackIter::prev()
1.100 {