aboutsummaryrefslogtreecommitdiffstats
path: root/write.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'write.cpp')
-rw-r--r--write.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/write.cpp b/write.cpp
index b5784ab..7cad2c5 100644
--- a/write.cpp
+++ b/write.cpp
@@ -20,14 +20,17 @@
ostream&
operator<<(ostream& out, const AST* ast)
{
-#define TRY_WRITE_LITERAL(T) \
- const ASTLiteral<T>* lit ## T = dynamic_cast<const ASTLiteral<T>*>(ast); \
- if (lit ## T) \
- return out << (lit ## T)->val;
-
- TRY_WRITE_LITERAL(int32_t);
- TRY_WRITE_LITERAL(float);
- TRY_WRITE_LITERAL(bool);
+ const ASTLiteral<float>* flit = dynamic_cast<const ASTLiteral<float>*>(ast);
+ if (flit)
+ return out << showpoint << flit->val;
+
+ const ASTLiteral<int32_t>* ilit = dynamic_cast<const ASTLiteral<int32_t>*>(ast);
+ if (ilit)
+ return out << ilit->val;
+
+ const ASTLiteral<bool>* blit = dynamic_cast<const ASTLiteral<bool>*>(ast);
+ if (blit)
+ return out << (blit->val ? "#t" : "#f");
const ASTSymbol* sym = dynamic_cast<const ASTSymbol*>(ast);
if (sym)
@@ -40,7 +43,7 @@ operator<<(ostream& out, const AST* ast)
case AType::PRIM: return out << type->at(0);
case AType::EXPR: break; // will catch Tuple case below
}
- }
+ }
const ASTTuple* tup = dynamic_cast<const ASTTuple*>(ast);
if (tup) {