blob: 1ac0cf281de409d3cf8f9c797391e213b4ea6bdc (
plain) (
tree)
|
|
#include "builtin.h"
#include <cstdio>
#include <sstream>
using std::stringstream;
extern EmptyList *empty_list;
BoolObj::BoolObj(bool _val) : EvalObj(), val(_val) {}
bool BoolObj::is_true() { return val; }
string BoolObj::ext_repr() { return string(val ? "#t" : "#f"); }
#ifdef DEBUG
string BoolObj::_debug_repr() { return ext_repr(); }
#endif
IntObj::IntObj(int _val) : NumberObj(), val(_val) {}
string IntObj::ext_repr() {
stringstream ss;
ss << val;
return ss.str();
}
#ifdef DEBUG
string IntObj::_debug_repr() { return ext_repr(); }
#endif
FloatObj::FloatObj(double _val) : NumberObj(), val(_val) {}
string FloatObj::ext_repr() {
stringstream ss;
ss << val;
return ss.str();
}
#ifdef DEBUG
string FloatObj::_debug_repr() { return ext_repr(); }
#endif
SpecialOptIf::SpecialOptIf() : SpecialOptObj() {}
void SpecialOptIf::prepare(Cons *pc) {
state = 0; // Prepared
pc = pc->cdr;
pc->skip = false;
pc->cdr->skip = true;
if (pc->cdr->cdr != empty_list)
pc->cdr->cdr->skip = true;
}
void SpecialOptIf::pre_call(ArgList *args, Cons *pc,
Environment *envt) {
// static_cast because it's a call invocation
pc = static_cast<Cons*>(pc->car);
// Condition evaluated and the decision is made
state = 1;
if (args->cdr->car->is_true())
{
pc = pc->cdr;
pc->skip = true;
pc->cdr->skip
|