Permalink
Browse files

new builtin __ASSERT__ in stage 0

Not very informative but the zero means something
  • Loading branch information...
NotFound committed Sep 8, 2011
1 parent 20bcd02 commit 3374e4f9525dad99087fbede9d3758bbb0e8ee68
Showing with 52 additions and 2 deletions.
  1. +12 −1 emit.cpp
  2. +4 −1 emit.h
  3. +36 −0 winxedst0.cpp
View
@@ -1,16 +1,27 @@
// emit.cpp
-// Revision 8-nov-2009
+// Revision 8-sep-2011
#include "emit.h"
Emit::Emit (std::ostream &out) :
o(out),
+ debug(false),
with_an(true),
pendingf(false),
pendingl(false),
line(0)
{ }
+void Emit::setDebug()
+{
+ debug = true;
+}
+
+bool Emit::getDebug() const
+{
+ return debug;
+}
+
void Emit::omit_annotations()
{
with_an= false;
View
5 emit.h
@@ -2,7 +2,7 @@
#define INCLUDE_EMIT_H
// emit.h
-// Revision 8-nov-2009
+// Revision 8-sep-2011
#include "token.h"
@@ -19,9 +19,12 @@ class Emit
std::ostream & get() { return o; }
template <typename T>
friend Emit & operator << (Emit &e, const T &t);
+ void setDebug();
+ bool getDebug() const;
private:
void preemit();
std::ostream &o;
+ bool debug;
bool with_an;
bool pendingf;
bool pendingl;
View
@@ -369,7 +369,26 @@ class Predef_cry : public PredefFunctionVarargs
}
};
+class Predef_ASSERT : public PredefFunction
+{
+public:
+ Predef_ASSERT() : PredefFunction("__ASSERT__", REGnone, 1)
+ { }
+ char paramtype(size_t n) const { return REGint; }
+ void emit(Emit &e, const std::string &,
+ const std::vector<std::string> args) const
+ {
+ if (e.getDebug())
+ {
+ e <<
+ INDENT ".const 'Sub' __WINXED_ASSERT_check ='__WINXED_ASSERT_check'\n"
+ INDENT "__WINXED_ASSERT_check(" << args[0] << ")\n";
+ }
+ }
+};
+
const PredefFunction *PredefFunction::predefs[]= {
+ new Predef_ASSERT(),
new Predef_print(),
new Predef_say(),
new Predef_cry(),
@@ -7393,6 +7412,7 @@ class Winxed
{
public:
Winxed(bool debug) :
+ assertions(debug),
root_ns(debug),
cur_nsblock(&root_ns)
{
@@ -7402,6 +7422,7 @@ class Winxed
void optimize ();
void emit (Emit &e);
private:
+ bool assertions;
RootNamespaceBlock root_ns;
NamespaceBlockBase *cur_nsblock;
NamespaceKey cur_namespace;
@@ -7514,6 +7535,19 @@ void Winxed::emit (Emit &e)
e <<
".end\n";
+
+ if (assertions)
+ {
+ e <<
+ ".sub WinxedAssertCheck :anon :subid('__WINXED_ASSERT_check')\n"
+ " .param int check\n"
+ " if check goto done\n"
+ " die 'Assertion failed!'\n"
+ " done:\n"
+ " .return()\n"
+ ".end\n";
+ }
+
e.comment("End of initializations");
e << "\n\n";
@@ -7613,6 +7647,8 @@ void winxed_main (int argc, char **argv)
}
Emit e(*output);
+ if (debug)
+ e.setDebug();
if (noan)
e.omit_annotations();
winxed.emit(e);

0 comments on commit 3374e4f

Please sign in to comment.