#include "fold.h"
//#include "parser.h"
+#include "algo.h"
+
#define ast_instantiate(T, ctx, destroyfn) \
T* self = (T*)mem_a(sizeof(T)); \
if (!self) { \
}
ast_expression_delete((ast_expression*)self);
+ self->~ast_value();
mem_d(self);
}
}
for (auto &it : self->static_names)
mem_d(it);
- for (auto &it : self->blocks)
- ast_delete(it);
+ // FIXME::DELME:: unique_ptr used on ast_block
+ //for (auto &it : self->blocks)
+ // ast_delete(it);
if (self->varargs)
ast_delete(self->varargs);
if (self->argc)
for (auto &it : self->blocks) {
cgen = it->codegen;
- if (!(*cgen)((ast_expression*)it, self, false, &dummy))
+ if (!(*cgen)(it.get(), self, false, &dummy))
return false;
}
if (!ir_block_create_jump(func->curblock, ast_ctx(self), merge))
return false;
- func->ir_func->blocks.erase(func->ir_func->blocks.begin() + merge_id);
- func->ir_func->blocks.emplace_back(merge);
+ algo::shiftback(func->ir_func->blocks.begin() + merge_id,
+ func->ir_func->blocks.end());
+ // FIXME::DELME::
+ //func->ir_func->blocks[merge_id].release();
+ //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + merge_id);
+ //func->ir_func->blocks.emplace_back(merge);
func->curblock = merge;
phi = ir_block_create_phi(func->curblock, ast_ctx(self),
}
/* Move 'bout' to the end */
- func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
- func->ir_func->blocks.emplace_back(bout);
+ algo::shiftback(func->ir_func->blocks.begin() + bout_id,
+ func->ir_func->blocks.end());
+ // FIXME::DELME::
+ //func->ir_func->blocks[bout_id].release(); // it's a vector<unique_ptr<>>
+ //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
+ //func->ir_func->blocks.emplace_back(bout);
return true;
}
/* enter the else and move it down */
func->curblock = bnot;
- func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bnot_id);
- func->ir_func->blocks.emplace_back(bnot);
+ algo::shiftback(func->ir_func->blocks.begin() + bnot_id,
+ func->ir_func->blocks.end());
+ // FIXME::DELME::
+ //func->ir_func->blocks[bnot_id].release();
+ //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bnot_id);
+ //func->ir_func->blocks.emplace_back(bnot);
} else {
/* The default case */
/* Remember where to fall through from: */
func->breakblocks.pop_back();
/* Move 'bout' to the end, it's nicer */
- func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
- func->ir_func->blocks.emplace_back(bout);
+ algo::shiftback(func->ir_func->blocks.begin() + bout_id,
+ func->ir_func->blocks.end());
+ // FIXME::DELME::
+ //func->ir_func->blocks[bout_id].release();
+ //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
+ //func->ir_func->blocks.emplace_back(bout);
return true;
}