Merge branch 'cleanup' of github.com:graphitemaster/gmqcc into cleanup
authorDale Weiler <weilercdale@gmail.com>
Fri, 30 Jan 2015 05:20:41 +0000 (00:20 -0500)
committerDale Weiler <weilercdale@gmail.com>
Fri, 30 Jan 2015 05:20:41 +0000 (00:20 -0500)
18 files changed:
algo.h [new file with mode: 0644]
ast.cpp
ast.h
code.cpp
fold.cpp
gmqcc.h
intrin.cpp
intrin.h
ir.cpp
ir.h
lexer.cpp
lexer.h
parser.cpp
test.cpp
tests/fieldfuncs.qc [new file with mode: 0644]
tests/fieldfuncs.tmpl [new file with mode: 0644]
tests/forloop.qc [new file with mode: 0644]
tests/forloop.tmpl [new file with mode: 0644]

diff --git a/algo.h b/algo.h
new file mode 100644 (file)
index 0000000..3218b1b
--- /dev/null
+++ b/algo.h
@@ -0,0 +1,18 @@
+#ifndef GMQCC_ALGO_HDR
+#define GMQCC_ALGO_HDR
+
+namespace algo {
+
+template<typename ITER>
+void shiftback(ITER element, ITER end) {
+    //typename ITER::value_type backup(move(*element)); // hold the element
+    typename std::remove_reference<decltype(*element)>::type backup(move(*element)); // hold the element
+    ITER p = element++;
+    for (; element != end; p = element++)
+        *p = move(*element);
+    *p = move(backup);
+}
+
+} // ::algo
+
+#endif
diff --git a/ast.cpp b/ast.cpp
index 4768e6e5bb9db83be59b9415cb73733d66d829b9..df2d6769ccafbfb75c3e568400a9c5f73bf355f5 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -8,14 +8,13 @@
 #include "fold.h"
 //#include "parser.h"
 
-#define ast_instantiate(T, ctx, destroyfn)                          \
-    T* self = (T*)mem_a(sizeof(T));                                 \
-    if (!self) {                                                    \
-        return nullptr;                                                \
-    }                                                               \
-    new (self) T();                                                 \
-    ast_node_init((ast_node*)self, ctx, TYPE_##T);                  \
-    ( (ast_node*)self )->destroy = (ast_node_delete*)destroyfn
+#include "algo.h"
+
+#define ast_instantiate(T, ctx, destroyfn) \
+    T* self = new T;                       \
+    if (!self) return nullptr;             \
+    ast_node_init(self, ctx, TYPE_##T);    \
+    self->m_destroy = (ast_node_delete*)destroyfn
 
 /*
  * forward declarations, these need not be in ast.h for obvious
@@ -58,176 +57,162 @@ static void ast_binary_delete(ast_binary*);
 static bool ast_binary_codegen(ast_binary*, ast_function*, bool lvalue, ir_value**);
 static bool ast_state_codegen(ast_state*, ast_function*, bool lvalue, ir_value**);
 
-/* It must not be possible to get here. */
-static GMQCC_NORETURN void _ast_node_destroy(ast_node *self)
+/* Initialize main ast node aprts */
+ast_node::ast_node(lex_ctx_t ctx, int node_type)
+    : m_context(ctx)
+    , m_node_type(node_type)
+    , m_keep_node(false)
+    , m_side_effects(false)
 {
-    (void)self;
-    con_err("ast node missing destroy()\n");
-    exit(EXIT_FAILURE);
 }
 
-/* Initialize main ast node aprts */
-static void ast_node_init(ast_node *self, lex_ctx_t ctx, int nodetype)
+ast_node::~ast_node()
 {
-    self->context = ctx;
-    self->destroy = &_ast_node_destroy;
-    self->keep    = false;
-    self->nodetype = nodetype;
-    self->side_effects = false;
 }
 
 /* weight and side effects */
-static void _ast_propagate_effects(ast_node *self, ast_node *other)
+void ast_node::propagate_side_effects(ast_node *other) const
 {
-    if (ast_side_effects(other))
-        ast_side_effects(self) = true;
+    other->m_side_effects = m_side_effects;
 }
-#define ast_propagate_effects(s,o) _ast_propagate_effects(((ast_node*)(s)), ((ast_node*)(o)))
 
 /* General expression initialization */
-static void ast_expression_init(ast_expression *self,
-                                ast_expression_codegen *codegen)
-{
-    self->codegen  = codegen;
-    self->vtype    = TYPE_VOID;
-    self->next     = nullptr;
-    self->outl     = nullptr;
-    self->outr     = nullptr;
-    self->count    = 0;
-    self->varparam = nullptr;
-    self->flags    = 0;
+ast_expression::ast_expression(lex_ctx_t ctx, int nodetype, qc_type type)
+    : ast_node(ctx, nodetype)
+    , m_vtype(type)
+{
     if (OPTS_OPTION_BOOL(OPTION_COVERAGE))
-        self->flags |= AST_FLAG_BLOCK_COVERAGE;
+        m_flags |= AST_FLAG_BLOCK_COVERAGE;
 }
+ast_expression::ast_expression(lex_ctx_t ctx, int nodetype)
+    : ast_expression(ctx, nodetype, TYPE_VOID)
+{}
 
-static void ast_expression_delete(ast_expression *self)
+ast_expression::~ast_expression()
 {
-    if (self->next)
-        ast_delete(self->next);
-    for (auto &it : self->params)
-        ast_delete(it);
-    if (self->varparam)
-        ast_delete(self->varparam);
+    if (m_next)
+        delete m_next;
+    if (m_varparam)
+        delete m_varparam;
 }
 
-static void ast_expression_delete_full(ast_expression *self)
+ast_expression::ast_expression(ast_copy_type_t, int nodetype, const ast_expression &other)
+    : ast_expression(other.m_context, nodetype)
 {
-    ast_expression_delete(self);
-    mem_d(self);
+    m_vtype = other.m_vtype;
+    m_count = other.m_count;
+    m_flags = other.m_flags;
+    if (other.m_next)
+        m_next = new ast_expression(ast_copy_type, TYPE_ast_expression, *other.m_next);
+    m_type_params.reserve(other.m_type_params.size());
+    for (auto &it : other.m_type_params)
+        m_type_params.emplace_back(new ast_value(ast_copy_type, *it));
 }
 
-ast_value* ast_value_copy(const ast_value *self)
-{
-    const ast_expression *fromex;
-    ast_expression *selfex;
-    ast_value *cp = ast_value_new(self->expression.node.context, self->name, self->expression.vtype);
-    if (self->expression.next) {
-        cp->expression.next = ast_type_copy(self->expression.node.context, self->expression.next);
-    }
-    fromex = &self->expression;
-    selfex = &cp->expression;
-    selfex->count = fromex->count;
-    selfex->flags = fromex->flags;
-    for (auto &it : fromex->params) {
-        ast_value *v = ast_value_copy(it);
-        selfex->params.push_back(v);
-    }
-    return cp;
-}
+ast_expression::ast_expression(ast_copy_type_t, const ast_expression &other)
+    : ast_expression(other.m_context, TYPE_ast_expression)
+{}
 
-void ast_type_adopt_impl(ast_expression *self, const ast_expression *other)
-{
-    const ast_expression *fromex;
-    ast_expression *selfex;
-    self->vtype = other->vtype;
-    if (other->next) {
-        self->next = (ast_expression*)ast_type_copy(ast_ctx(self), other->next);
-    }
-    fromex = other;
-    selfex = self;
-    selfex->count = fromex->count;
-    selfex->flags = fromex->flags;
-    for (auto &it : fromex->params) {
-        ast_value *v = ast_value_copy(it);
-        selfex->params.push_back(v);
-    }
+ast_expression *ast_expression::shallow_type(lex_ctx_t ctx, qc_type vtype) {
+    auto expr = new ast_expression(ctx, TYPE_ast_expression);
+    expr->m_vtype = vtype;
+    return expr;
 }
 
-static ast_expression* ast_shallow_type(lex_ctx_t ctx, int vtype)
+void ast_expression::adopt_type(const ast_expression &other)
 {
-    ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
-    ast_expression_init(self, nullptr);
-    self->codegen = nullptr;
-    self->next    = nullptr;
-    self->vtype   = vtype;
-    return self;
-}
-
-ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex)
-{
-    const ast_expression *fromex;
-    ast_expression       *selfex;
-
-    if (!ex)
-        return nullptr;
-    else
-    {
-        ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
-        ast_expression_init(self, nullptr);
-
-        fromex = ex;
-        selfex = self;
-
-        /* This may never be codegen()d */
-        selfex->codegen = nullptr;
-
-        selfex->vtype = fromex->vtype;
-        if (fromex->next)
-            selfex->next = ast_type_copy(ctx, fromex->next);
-        else
-            selfex->next = nullptr;
-
-        selfex->count = fromex->count;
-        selfex->flags = fromex->flags;
-        for (auto &it : fromex->params) {
-            ast_value *v = ast_value_copy(it);
-            selfex->params.push_back(v);
-        }
-
-        return self;
-    }
+    m_vtype = other.m_vtype;
+    if (other.m_next)
+        m_next = new ast_expression(ast_copy_type, TYPE_ast_expression, *other.m_next);
+    m_count = other.m_count;
+    m_flags = other.m_flags;
+    m_type_params.clear();
+    m_type_params.reserve(other.m_type_params.size());
+    for (auto &it : other.m_type_params)
+        m_type_params.emplace_back(new ast_value(ast_copy_type, *it));
 }
 
-bool ast_compare_type(ast_expression *a, ast_expression *b)
+bool ast_expression::compare_type(const ast_expression &other) const
 {
-    if (a->vtype == TYPE_NIL ||
-        b->vtype == TYPE_NIL)
+    if (m_vtype == TYPE_NIL ||
+        other.m_vtype == TYPE_NIL)
         return true;
-    if (a->vtype != b->vtype)
+    if (m_vtype != other.m_vtype)
         return false;
-    if (!a->next != !b->next)
+    if (!m_next != !other.m_next)
         return false;
-    if (a->params.size() != b->params.size())
+    if (m_type_params.size() != other.m_type_params.size())
         return false;
-    if ((a->flags & AST_FLAG_TYPE_MASK) !=
-        (b->flags & AST_FLAG_TYPE_MASK) )
+    if ((m_flags & AST_FLAG_TYPE_MASK) !=
+        (other.m_flags & AST_FLAG_TYPE_MASK) )
     {
         return false;
     }
-    if (a->params.size()) {
+    if (m_type_params.size()) {
         size_t i;
-        for (i = 0; i < a->params.size(); ++i) {
-            if (!ast_compare_type((ast_expression*)a->params[i],
-                                  (ast_expression*)b->params[i]))
+        for (i = 0; i < m_type_params.size(); ++i) {
+            if (!m_type_params[i]->compare_type(*other.m_type_params[i]))
                 return false;
         }
     }
-    if (a->next)
-        return ast_compare_type(a->next, b->next);
+    if (m_next)
+        return m_next->compare_type(*other.m_next);
     return true;
 }
 
-static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsize, size_t pos)
+ast_value::ast_value(ast_copy_type_t, const ast_value &other, const std::string &name)
+    : ast_value(ast_copy_type, static_cast<const ast_expression&>(other), name)
+{}
+
+ast_value::ast_value(ast_copy_type_t, const ast_value &other)
+    : ast_value(ast_copy_type, static_cast<const ast_expression&>(other), other.m_name)
+{}
+
+ast_value::ast_value(ast_copy_type_t, const ast_expression &other, const std::string &name)
+    : ast_expression(ast_copy_type, other)
+    , m_name(name)
+{}
+
+ast_value::ast_value(lex_ctx_t ctx, const std::string &name, qc_type t)
+    : ast_expression(ctx, TYPE_ast_value, t)
+    , m_name(name)
+{
+    m_keep_node = true; // keep values, always
+    memset(&m_constval, 0, sizeof(m_constval));
+}
+
+ast_value::~ast_value()
+{
+    if (m_argcounter)
+        mem_d((void*)m_argcounter);
+    if (m_hasvalue) {
+        switch (m_vtype)
+        {
+        case TYPE_STRING:
+            mem_d((void*)m_constval.vstring);
+            break;
+        case TYPE_FUNCTION:
+            // unlink us from the function node
+            m_constval.vfunc->m_function_type = nullptr;
+            break;
+        // NOTE: delete function? currently collected in
+        // the parser structure
+        default:
+            break;
+        }
+    }
+    if (m_ir_values)
+        mem_d(m_ir_values);
+
+    // initlist imples an array which implies .next in the expression exists.
+    if (m_initlist.size() && m_next->m_vtype == TYPE_STRING) {
+        for (auto &it : m_initlist)
+            if (it.vstring)
+                mem_d(it.vstring);
+    }
+}
+
+static size_t ast_type_to_string_impl(const ast_expression *e, char *buf, size_t bufsize, size_t pos)
 {
     const char *typestr;
     size_t typelen;
@@ -243,43 +228,43 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi
     if (pos + 1 >= bufsize)
         goto full;
 
-    switch (e->vtype) {
+    switch (e->m_vtype) {
         case TYPE_VARIANT:
             util_strncpy(buf + pos, "(variant)", 9);
             return pos + 9;
 
         case TYPE_FIELD:
             buf[pos++] = '.';
-            return ast_type_to_string_impl(e->next, buf, bufsize, pos);
+            return ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
 
         case TYPE_POINTER:
             if (pos + 3 >= bufsize)
                 goto full;
             buf[pos++] = '*';
             buf[pos++] = '(';
-            pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
+            pos = ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
             if (pos + 1 >= bufsize)
                 goto full;
             buf[pos++] = ')';
             return pos;
 
         case TYPE_FUNCTION:
-            pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
+            pos = ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
             if (pos + 2 >= bufsize)
                 goto full;
-            if (e->params.empty()) {
+            if (e->m_type_params.empty()) {
                 buf[pos++] = '(';
                 buf[pos++] = ')';
                 return pos;
             }
             buf[pos++] = '(';
-            pos = ast_type_to_string_impl((ast_expression*)(e->params[0]), buf, bufsize, pos);
-            for (i = 1; i < e->params.size(); ++i) {
+            pos = ast_type_to_string_impl(e->m_type_params[0].get(), buf, bufsize, pos);
+            for (i = 1; i < e->m_type_params.size(); ++i) {
                 if (pos + 2 >= bufsize)
                     goto full;
                 buf[pos++] = ',';
                 buf[pos++] = ' ';
-                pos = ast_type_to_string_impl((ast_expression*)(e->params[i]), buf, bufsize, pos);
+                pos = ast_type_to_string_impl(e->m_type_params[i].get(), buf, bufsize, pos);
             }
             if (pos + 1 >= bufsize)
                 goto full;
@@ -287,18 +272,18 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi
             return pos;
 
         case TYPE_ARRAY:
-            pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
+            pos = ast_type_to_string_impl(e->m_next, buf, bufsize, pos);
             if (pos + 1 >= bufsize)
                 goto full;
             buf[pos++] = '[';
-            pos += util_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->count);
+            pos += util_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->m_count);
             if (pos + 1 >= bufsize)
                 goto full;
             buf[pos++] = ']';
             return pos;
 
         default:
-            typestr = type_name[e->vtype];
+            typestr = type_name[e->m_vtype];
             typelen = strlen(typestr);
             if (pos + typelen >= bufsize)
                 goto full;
@@ -313,110 +298,30 @@ full:
     return bufsize;
 }
 
-void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize)
+void ast_type_to_string(const ast_expression *e, char *buf, size_t bufsize)
 {
     size_t pos = ast_type_to_string_impl(e, buf, bufsize-1, 0);
     buf[pos] = 0;
 }
 
-static bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out);
-ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
+void ast_value::add_param(ast_value *p)
 {
-    ast_instantiate(ast_value, ctx, ast_value_delete);
-    ast_expression_init((ast_expression*)self,
-                        (ast_expression_codegen*)&ast_value_codegen);
-    self->expression.node.keep = true; /* keep */
-
-    self->name = name ? util_strdup(name) : nullptr;
-    self->expression.vtype = t;
-    self->expression.next  = nullptr;
-    self->isfield  = false;
-    self->cvq      = CV_NONE;
-    self->hasvalue = false;
-    self->isimm    = false;
-    self->inexact  = false;
-    self->uses     = 0;
-    memset(&self->constval, 0, sizeof(self->constval));
-
-    self->ir_v           = nullptr;
-    self->ir_values      = nullptr;
-    self->ir_value_count = 0;
-
-    self->setter = nullptr;
-    self->getter = nullptr;
-    self->desc   = nullptr;
-
-    self->argcounter = nullptr;
-    self->intrinsic = false;
-
-    return self;
+    m_type_params.emplace_back(p);
 }
 
-void ast_value_delete(ast_value* self)
+ast_binary::ast_binary(lex_ctx_t ctx, int op,
+                       ast_expression* left, ast_expression* right)
+    : ast_expression(ctx, TYPE_ast_binary)
+    , m_op(op)
+    // m_left/m_right happen after the peephole step right below
+    , m_right_first(false)
 {
-    if (self->name)
-        mem_d((void*)self->name);
-    if (self->argcounter)
-        mem_d((void*)self->argcounter);
-    if (self->hasvalue) {
-        switch (self->expression.vtype)
-        {
-        case TYPE_STRING:
-            mem_d((void*)self->constval.vstring);
-            break;
-        case TYPE_FUNCTION:
-            /* unlink us from the function node */
-            self->constval.vfunc->vtype = nullptr;
-            break;
-        /* NOTE: delete function? currently collected in
-         * the parser structure
-         */
-        default:
-            break;
-        }
-    }
-    if (self->ir_values)
-        mem_d(self->ir_values);
-
-    if (self->desc)
-        mem_d(self->desc);
-
-    // initlist imples an array which implies .next in the expression exists.
-    if (self->initlist.size() && self->expression.next->vtype == TYPE_STRING) {
-        for (auto &it : self->initlist)
-            if (it.vstring)
-                mem_d(it.vstring);
-    }
-
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
-}
-
-void ast_value_params_add(ast_value *self, ast_value *p)
-{
-    self->expression.params.push_back(p);
-}
-
-bool ast_value_set_name(ast_value *self, const char *name)
-{
-    if (self->name)
-        mem_d((void*)self->name);
-    self->name = util_strdup(name);
-    return !!self->name;
-}
-
-ast_binary* ast_binary_new(lex_ctx_t ctx, int op,
-                           ast_expression* left, ast_expression* right)
-{
-    ast_instantiate(ast_binary, ctx, ast_binary_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binary_codegen);
-
     if (ast_istype(right, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
         ast_unary      *unary  = ((ast_unary*)right);
-        ast_expression *normal = unary->operand;
+        ast_expression *normal = unary->m_operand;
 
         /* make a-(-b) => a + b */
-        if (unary->op == VINSTR_NEG_F || unary->op == VINSTR_NEG_V) {
+        if (unary->m_op == VINSTR_NEG_F || unary->m_op == VINSTR_NEG_V) {
             if (op == INSTR_SUB_F) {
                 op = INSTR_ADD_F;
                 right = normal;
@@ -429,417 +334,346 @@ ast_binary* ast_binary_new(lex_ctx_t ctx, int op,
         }
     }
 
-    self->op = op;
-    self->left = left;
-    self->right = right;
-    self->right_first = false;
+    m_left = left;
+    m_right = right;
 
-    ast_propagate_effects(self, left);
-    ast_propagate_effects(self, right);
+    propagate_side_effects(left);
+    propagate_side_effects(right);
 
     if (op >= INSTR_EQ_F && op <= INSTR_GT)
-        self->expression.vtype = TYPE_FLOAT;
+        m_vtype = TYPE_FLOAT;
     else if (op == INSTR_AND || op == INSTR_OR) {
         if (OPTS_FLAG(PERL_LOGIC))
-            ast_type_adopt(self, right);
+            adopt_type(*right);
         else
-            self->expression.vtype = TYPE_FLOAT;
+            m_vtype = TYPE_FLOAT;
     }
     else if (op == INSTR_BITAND || op == INSTR_BITOR)
-        self->expression.vtype = TYPE_FLOAT;
+        m_vtype = TYPE_FLOAT;
     else if (op == INSTR_MUL_VF || op == INSTR_MUL_FV)
-        self->expression.vtype = TYPE_VECTOR;
+        m_vtype = TYPE_VECTOR;
     else if (op == INSTR_MUL_V)
-        self->expression.vtype = TYPE_FLOAT;
+        m_vtype = TYPE_FLOAT;
     else
-        self->expression.vtype = left->vtype;
-
-    /* references all */
-    self->refs = AST_REF_ALL;
+        m_vtype = left->m_vtype;
 
-    return self;
+    // references all
+    m_refs = AST_REF_ALL;
 }
 
-void ast_binary_delete(ast_binary *self)
+ast_binary::~ast_binary()
 {
-    if (self->refs & AST_REF_LEFT)  ast_unref(self->left);
-    if (self->refs & AST_REF_RIGHT) ast_unref(self->right);
-
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    if (m_refs & AST_REF_LEFT)  ast_unref(m_left);
+    if (m_refs & AST_REF_RIGHT) ast_unref(m_right);
 }
 
-ast_binstore* ast_binstore_new(lex_ctx_t ctx, int storop, int op,
-                               ast_expression* left, ast_expression* right)
+ast_binstore::ast_binstore(lex_ctx_t ctx, int storop, int mathop,
+                           ast_expression* left, ast_expression* right)
+    : ast_expression(ctx, TYPE_ast_binstore)
+    , m_opstore(storop)
+    , m_opbin(mathop)
+    , m_dest(left)
+    , m_source(right)
+    , m_keep_dest(false)
 {
-    ast_instantiate(ast_binstore, ctx, ast_binstore_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_binstore_codegen);
-
-    ast_side_effects(self) = true;
-
-    self->opstore = storop;
-    self->opbin   = op;
-    self->dest    = left;
-    self->source  = right;
-
-    self->keep_dest = false;
-
-    ast_type_adopt(self, left);
-    return self;
+    m_side_effects = true;
+    adopt_type(*left);
 }
 
-void ast_binstore_delete(ast_binstore *self)
+ast_binstore::~ast_binstore()
 {
-    if (!self->keep_dest)
-        ast_unref(self->dest);
-    ast_unref(self->source);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    if (!m_keep_dest)
+        ast_unref(m_dest);
+    ast_unref(m_source);
 }
 
-ast_unary* ast_unary_new(lex_ctx_t ctx, int op,
-                         ast_expression *expr)
+ast_unary* ast_unary::make(lex_ctx_t ctx, int op, ast_expression *expr)
 {
-    ast_instantiate(ast_unary, ctx, ast_unary_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_unary_codegen);
-
-    self->op      = op;
-    self->operand = expr;
-
-
     if (ast_istype(expr, ast_unary) && OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
-        ast_unary *prev = (ast_unary*)((ast_unary*)expr)->operand;
+        ast_unary *prev = (ast_unary*)((ast_unary*)expr)->m_operand;
 
         /* Handle for double negation */
-        if (((ast_unary*)expr)->op == op)
-            prev = (ast_unary*)((ast_unary*)expr)->operand;
+        if (((ast_unary*)expr)->m_op == op)
+            prev = (ast_unary*)((ast_unary*)expr)->m_operand;
 
         if (ast_istype(prev, ast_unary)) {
-            ast_expression_delete((ast_expression*)self);
-            mem_d(self);
             ++opts_optimizationcount[OPTIM_PEEPHOLE];
             return prev;
         }
     }
 
-    ast_propagate_effects(self, expr);
+    return new ast_unary(ctx, op, expr);
+}
 
+ast_unary::ast_unary(lex_ctx_t ctx, int op, ast_expression *expr)
+    : ast_expression(ctx, TYPE_ast_unary)
+    , m_op(op)
+    , m_operand(expr)
+{
+    propagate_side_effects(expr);
     if ((op >= INSTR_NOT_F && op <= INSTR_NOT_FNC) || op == VINSTR_NEG_F) {
-        self->expression.vtype = TYPE_FLOAT;
+        m_vtype = TYPE_FLOAT;
     } else if (op == VINSTR_NEG_V) {
-        self->expression.vtype = TYPE_VECTOR;
+        m_vtype = TYPE_VECTOR;
     } else {
         compile_error(ctx, "cannot determine type of unary operation %s", util_instr_str[op]);
     }
-
-    return self;
 }
 
-void ast_unary_delete(ast_unary *self)
+ast_unary::~ast_unary()
 {
-    if (self->operand) ast_unref(self->operand);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    if (m_operand)
+        ast_unref(m_operand);
 }
 
-ast_return* ast_return_new(lex_ctx_t ctx, ast_expression *expr)
+ast_return::ast_return(lex_ctx_t ctx, ast_expression *expr)
+    : ast_expression(ctx, TYPE_ast_return)
+    , m_operand(expr)
 {
-    ast_instantiate(ast_return, ctx, ast_return_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_return_codegen);
-
-    self->operand = expr;
-
     if (expr)
-        ast_propagate_effects(self, expr);
-
-    return self;
+        propagate_side_effects(expr);
 }
 
-void ast_return_delete(ast_return *self)
+ast_return::~ast_return()
 {
-    if (self->operand)
-        ast_unref(self->operand);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    if (m_operand)
+        ast_unref(m_operand);
 }
 
-ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expression *field)
+ast_entfield::ast_entfield(lex_ctx_t ctx, ast_expression *entity, ast_expression *field)
+    : ast_entfield(ctx, entity, field, field->m_next)
 {
-    if (field->vtype != TYPE_FIELD) {
-        compile_error(ctx, "ast_entfield_new with expression not of type field");
-        return nullptr;
-    }
-    return ast_entfield_new_force(ctx, entity, field, field->next);
+    if (field->m_vtype != TYPE_FIELD)
+        compile_error(ctx, "ast_entfield with expression not of type field");
 }
 
-ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype)
+ast_entfield::ast_entfield(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype)
+    : ast_expression(ctx, TYPE_ast_entfield)
+    , m_entity(entity)
+    , m_field(field)
 {
-    ast_instantiate(ast_entfield, ctx, ast_entfield_delete);
+    propagate_side_effects(m_entity);
+    propagate_side_effects(m_field);
 
     if (!outtype) {
-        mem_d(self);
-        /* Error: field has no type... */
-        return nullptr;
+        compile_error(ctx, "ast_entfield: field has no type");
+        m_vtype = TYPE_VOID;
     }
-
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_entfield_codegen);
-
-    self->entity = entity;
-    self->field  = field;
-    ast_propagate_effects(self, entity);
-    ast_propagate_effects(self, field);
-
-    ast_type_adopt(self, outtype);
-    return self;
+    else
+        adopt_type(*outtype);
 }
 
-void ast_entfield_delete(ast_entfield *self)
+ast_entfield::~ast_entfield()
 {
-    ast_unref(self->entity);
-    ast_unref(self->field);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    ast_unref(m_entity);
+    ast_unref(m_field);
 }
 
-ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const char *name)
+ast_member *ast_member::make(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const std::string &name)
 {
-    ast_instantiate(ast_member, ctx, ast_member_delete);
     if (field >= 3) {
-        mem_d(self);
+        compile_error(ctx, "ast_member: invalid field (>=3): %u", field);
         return nullptr;
     }
-
-    if (owner->vtype != TYPE_VECTOR &&
-        owner->vtype != TYPE_FIELD) {
-        compile_error(ctx, "member-access on an invalid owner of type %s", type_name[owner->vtype]);
-        mem_d(self);
+    if (owner->m_vtype != TYPE_VECTOR &&
+        owner->m_vtype != TYPE_FIELD)
+    {
+        compile_error(ctx, "member-access on an invalid owner of type %s", type_name[owner->m_vtype]);
         return nullptr;
     }
+    return new ast_member(ctx, owner, field, name);
+}
 
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen);
-    self->expression.node.keep = true; /* keep */
+ast_member::ast_member(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const std::string &name)
+    : ast_expression(ctx, TYPE_ast_member)
+    , m_owner(owner)
+    , m_field(field)
+    , m_name(name)
+    , m_rvalue(false)
+{
+    m_keep_node = true;
 
-    if (owner->vtype == TYPE_VECTOR) {
-        self->expression.vtype = TYPE_FLOAT;
-        self->expression.next  = nullptr;
+    if (m_owner->m_vtype == TYPE_VECTOR) {
+        m_vtype = TYPE_FLOAT;
+        m_next  = nullptr;
     } else {
-        self->expression.vtype = TYPE_FIELD;
-        self->expression.next = ast_shallow_type(ctx, TYPE_FLOAT);
+        m_vtype = TYPE_FIELD;
+        m_next = ast_shallow_type(ctx, TYPE_FLOAT);
     }
 
-    self->rvalue = false;
-    self->owner  = owner;
-    ast_propagate_effects(self, owner);
-
-    self->field = field;
-    if (name)
-        self->name = util_strdup(name);
-    else
-        self->name = nullptr;
-
-    return self;
-}
-
-void ast_member_delete(ast_member *self)
-{
-    /* The owner is always an ast_value, which has .keep=true,
-     * also: ast_members are usually deleted after the owner, thus
-     * this will cause invalid access
-    ast_unref(self->owner);
-     * once we allow (expression).x to access a vector-member, we need
-     * to change this: preferably by creating an alternate ast node for this
-     * purpose that is not garbage-collected.
-    */
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self->name);
-    mem_d(self);
+    propagate_side_effects(owner);
 }
 
-bool ast_member_set_name(ast_member *self, const char *name)
+ast_member::~ast_member()
 {
-    if (self->name)
-        mem_d((void*)self->name);
-    self->name = util_strdup(name);
-    return !!self->name;
+    // The owner is always an ast_value, which has .keep_node=true,
+    // also: ast_members are usually deleted after the owner, thus
+    // this will cause invalid access
+        //ast_unref(self->m_owner);
+    // once we allow (expression).x to access a vector-member, we need
+    // to change this: preferably by creating an alternate ast node for this
+    // purpose that is not garbage-collected.
 }
 
-ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_expression *index)
+ast_array_index* ast_array_index::make(lex_ctx_t ctx, ast_expression *array, ast_expression *index)
 {
-    ast_expression *outtype;
-    ast_instantiate(ast_array_index, ctx, ast_array_index_delete);
-
-    outtype = array->next;
+    ast_expression *outtype = array->m_next;
     if (!outtype) {
-        mem_d(self);
-        /* Error: field has no type... */
+        // field has no type
         return nullptr;
     }
 
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_array_index_codegen);
+    return new ast_array_index(ctx, array, index);
+}
 
-    self->array = array;
-    self->index = index;
-    ast_propagate_effects(self, array);
-    ast_propagate_effects(self, index);
+ast_array_index::ast_array_index(lex_ctx_t ctx, ast_expression *array, ast_expression *index)
+    : ast_expression(ctx, TYPE_ast_array_index)
+    , m_array(array)
+    , m_index(index)
+{
+    propagate_side_effects(array);
+    propagate_side_effects(index);
 
-    ast_type_adopt(self, outtype);
-    if (array->vtype == TYPE_FIELD && outtype->vtype == TYPE_ARRAY) {
-        if (self->expression.vtype != TYPE_ARRAY) {
-            compile_error(ast_ctx(self), "array_index node on type");
-            ast_array_index_delete(self);
-            return nullptr;
-        }
-        self->array = outtype;
-        self->expression.vtype = TYPE_FIELD;
+    ast_expression *outtype = m_array->m_next;
+    adopt_type(*outtype);
+
+    if (array->m_vtype == TYPE_FIELD && outtype->m_vtype == TYPE_ARRAY) {
+        // FIXME: investigate - this is not possible after adopt_type
+        //if (m_vtype != TYPE_ARRAY) {
+        //    compile_error(self->m_context, "array_index node on type");
+        //    ast_array_index_delete(self);
+        //    return nullptr;
+        //}
+
+        m_array = outtype;
+        m_vtype = TYPE_FIELD;
     }
+}
 
-    return self;
+ast_array_index::~ast_array_index()
+{
+    if (m_array)
+        ast_unref(m_array);
+    if (m_index)
+        ast_unref(m_index);
 }
 
-void ast_array_index_delete(ast_array_index *self)
+ast_argpipe::ast_argpipe(lex_ctx_t ctx, ast_expression *index)
+    : ast_expression(ctx, TYPE_ast_argpipe)
+    , m_index(index)
 {
-    if (self->array)
-        ast_unref(self->array);
-    if (self->index)
-        ast_unref(self->index);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    m_vtype = TYPE_NOEXPR;
 }
 
-ast_argpipe* ast_argpipe_new(lex_ctx_t ctx, ast_expression *index)
+ast_argpipe::~ast_argpipe()
 {
-    ast_instantiate(ast_argpipe, ctx, ast_argpipe_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_argpipe_codegen);
-    self->index = index;
-    self->expression.vtype = TYPE_NOEXPR;
-    return self;
+    if (m_index)
+        ast_unref(m_index);
 }
 
-void ast_argpipe_delete(ast_argpipe *self)
+ast_store::ast_store(lex_ctx_t ctx, int op, ast_expression *dest, ast_expression *source)
+    : ast_expression(ctx, TYPE_ast_store)
+    , m_op(op)
+    , m_dest(dest)
+    , m_source(source)
 {
-    if (self->index)
-        ast_unref(self->index);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    m_side_effects = true;
+    adopt_type(*dest);
 }
 
-ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
+ast_store::~ast_store()
 {
-    ast_instantiate(ast_ifthen, ctx, ast_ifthen_delete);
-    if (!ontrue && !onfalse) {
-        /* because it is invalid */
-        mem_d(self);
-        return nullptr;
-    }
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_ifthen_codegen);
+    ast_unref(m_dest);
+    ast_unref(m_source);
+}
 
-    self->cond     = cond;
-    self->on_true  = ontrue;
-    self->on_false = onfalse;
-    ast_propagate_effects(self, cond);
+ast_ifthen::ast_ifthen(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
+    : ast_expression(ctx, TYPE_ast_ifthen)
+    , m_cond(cond)
+    , m_on_true(ontrue)
+    , m_on_false(onfalse)
+{
+    propagate_side_effects(cond);
     if (ontrue)
-        ast_propagate_effects(self, ontrue);
+        propagate_side_effects(ontrue);
     if (onfalse)
-        ast_propagate_effects(self, onfalse);
-
-    return self;
+        propagate_side_effects(onfalse);
 }
 
-void ast_ifthen_delete(ast_ifthen *self)
+ast_ifthen::~ast_ifthen()
 {
-    ast_unref(self->cond);
-    if (self->on_true)
-        ast_unref(self->on_true);
-    if (self->on_false)
-        ast_unref(self->on_false);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    ast_unref(m_cond);
+    if (m_on_true)
+        ast_unref(m_on_true);
+    if (m_on_false)
+        ast_unref(m_on_false);
 }
 
-ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
+ast_ternary::ast_ternary(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse)
+    : ast_expression(ctx, TYPE_ast_ternary)
+    , m_cond(cond)
+    , m_on_true(ontrue)
+    , m_on_false(onfalse)
 {
-    ast_expression *exprtype = ontrue;
-    ast_instantiate(ast_ternary, ctx, ast_ternary_delete);
-    /* This time NEITHER must be nullptr */
-    if (!ontrue || !onfalse) {
-        mem_d(self);
-        return nullptr;
-    }
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_ternary_codegen);
+    propagate_side_effects(cond);
+    propagate_side_effects(ontrue);
+    propagate_side_effects(onfalse);
 
-    self->cond     = cond;
-    self->on_true  = ontrue;
-    self->on_false = onfalse;
-    ast_propagate_effects(self, cond);
-    ast_propagate_effects(self, ontrue);
-    ast_propagate_effects(self, onfalse);
-
-    if (ontrue->vtype == TYPE_NIL)
-        exprtype = onfalse;
-    ast_type_adopt(self, exprtype);
-
-    return self;
+    if (ontrue->m_vtype == TYPE_NIL)
+        adopt_type(onfalse);
+    else
+        adopt_type(ontrue);
 }
 
-void ast_ternary_delete(ast_ternary *self)
+ast_ternary::~ast_ternary()
 {
     /* the if()s are only there because computed-gotos can set them
      * to nullptr
      */
-    if (self->cond)     ast_unref(self->cond);
-    if (self->on_true)  ast_unref(self->on_true);
-    if (self->on_false) ast_unref(self->on_false);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
-}
-
-ast_loop* ast_loop_new(lex_ctx_t ctx,
-                       ast_expression *initexpr,
-                       ast_expression *precond, bool pre_not,
-                       ast_expression *postcond, bool post_not,
-                       ast_expression *increment,
-                       ast_expression *body)
+    if (m_cond)     ast_unref(m_cond);
+    if (m_on_true)  ast_unref(m_on_true);
+    if (m_on_false) ast_unref(m_on_false);
+}
+
+ast_loop::ast_loop(lex_ctx_t ctx,
+                   ast_expression *initexpr,
+                   ast_expression *precond, bool pre_not,
+                   ast_expression *postcond, bool post_not,
+                   ast_expression *increment,
+                   ast_expression *body)
+    , ast_expression(ctx, TYPE_ast_loop)
+    , m_initexpr(initexpr)
+    , m_precond(precond)
+    , m_postcond(postcond)
+    , m_increment(increment)
+    , m_body(body)
+    , m_pre_not(pre_not)
+    , m_post_not(post_not)
 {
-    ast_instantiate(ast_loop, ctx, ast_loop_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_loop_codegen);
-
-    self->initexpr  = initexpr;
-    self->precond   = precond;
-    self->postcond  = postcond;
-    self->increment = increment;
-    self->body      = body;
-
-    self->pre_not   = pre_not;
-    self->post_not  = post_not;
-
     if (initexpr)
-        ast_propagate_effects(self, initexpr);
+        propagate_side_effects(initexpr);
     if (precond)
-        ast_propagate_effects(self, precond);
+        propagate_side_effects(precond);
     if (postcond)
-        ast_propagate_effects(self, postcond);
+        propagate_side_effects(postcond);
     if (increment)
-        ast_propagate_effects(self, increment);
+        propagate_side_effects(increment);
     if (body)
-        ast_propagate_effects(self, body);
-
-    return self;
+        propagate_side_effects(body);
 }
 
-void ast_loop_delete(ast_loop *self)
+ast_loop::~ast_loop()
 {
-    if (self->initexpr)
-        ast_unref(self->initexpr);
-    if (self->precond)
-        ast_unref(self->precond);
-    if (self->postcond)
-        ast_unref(self->postcond);
-    if (self->increment)
-        ast_unref(self->increment);
-    if (self->body)
-        ast_unref(self->body);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
+    if (m_initexpr)
+        ast_unref(m_initexpr);
+    if (m_precond)
+        ast_unref(m_precond);
+    if (m_postcond)
+        ast_unref(m_postcond);
+    if (m_increment)
+        ast_unref(m_increment);
+    if (m_body)
+        ast_unref(m_body);
 }
 
 ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels)
@@ -847,8 +681,8 @@ ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels
     ast_instantiate(ast_breakcont, ctx, ast_breakcont_delete);
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_breakcont_codegen);
 
-    self->is_continue = iscont;
-    self->levels      = levels;
+    self->m_is_continue = iscont;
+    self->m_levels      = levels;
 
     return self;
 }
@@ -856,6 +690,7 @@ ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels
 void ast_breakcont_delete(ast_breakcont *self)
 {
     ast_expression_delete((ast_expression*)self);
+    self->~ast_breakcont();
     mem_d(self);
 }
 
@@ -864,24 +699,25 @@ ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op)
     ast_instantiate(ast_switch, ctx, ast_switch_delete);
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_switch_codegen);
 
-    self->operand = op;
+    self->m_operand = op;
 
-    ast_propagate_effects(self, op);
+    self->propagate_side_effects(op);
 
     return self;
 }
 
 void ast_switch_delete(ast_switch *self)
 {
-    ast_unref(self->operand);
+    ast_unref(self->m_operand);
 
-    for (auto &it : self->cases) {
-        if (it.value)
-            ast_unref(it.value);
-        ast_unref(it.code);
+    for (auto &it : self->m_cases) {
+        if (it.m_value)
+            ast_unref(it.m_value);
+        ast_unref(it.m_code);
     }
 
     ast_expression_delete((ast_expression*)self);
+    self->~ast_switch();
     mem_d(self);
 }
 
@@ -890,25 +726,26 @@ ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined)
     ast_instantiate(ast_label, ctx, ast_label_delete);
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_label_codegen);
 
-    self->expression.vtype = TYPE_NOEXPR;
+    self->m_vtype = TYPE_NOEXPR;
 
-    self->name      = util_strdup(name);
-    self->irblock   = nullptr;
-    self->undefined = undefined;
+    self->m_name      = util_strdup(name);
+    self->m_irblock   = nullptr;
+    self->m_undefined = undefined;
 
     return self;
 }
 
 void ast_label_delete(ast_label *self)
 {
-    mem_d((void*)self->name);
+    mem_d((void*)self->m_name);
     ast_expression_delete((ast_expression*)self);
+    self->~ast_label();
     mem_d(self);
 }
 
 static void ast_label_register_goto(ast_label *self, ast_goto *g)
 {
-   self->gotos.push_back(g);
+   self->m_gotos.push_back(g);
 }
 
 ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name)
@@ -916,42 +753,44 @@ ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name)
     ast_instantiate(ast_goto, ctx, ast_goto_delete);
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_goto_codegen);
 
-    self->name    = util_strdup(name);
-    self->target  = nullptr;
-    self->irblock_from = nullptr;
+    self->m_name    = util_strdup(name);
+    self->m_target  = nullptr;
+    self->m_irblock_from = nullptr;
 
     return self;
 }
 
 void ast_goto_delete(ast_goto *self)
 {
-    mem_d((void*)self->name);
+    mem_d((void*)self->m_name);
     ast_expression_delete((ast_expression*)self);
+    self->~ast_goto();
     mem_d(self);
 }
 
 void ast_goto_set_label(ast_goto *self, ast_label *label)
 {
-    self->target = label;
+    self->m_target = label;
 }
 
 ast_state* ast_state_new(lex_ctx_t ctx, ast_expression *frame, ast_expression *think)
 {
     ast_instantiate(ast_state, ctx, ast_state_delete);
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_state_codegen);
-    self->framenum  = frame;
-    self->nextthink = think;
+    self->m_framenum  = frame;
+    self->m_nextthink = think;
     return self;
 }
 
 void ast_state_delete(ast_state *self)
 {
-    if (self->framenum)
-        ast_unref(self->framenum);
-    if (self->nextthink)
-        ast_unref(self->nextthink);
+    if (self->m_framenum)
+        ast_unref(self->m_framenum);
+    if (self->m_nextthink)
+        ast_unref(self->m_nextthink);
 
     ast_expression_delete((ast_expression*)self);
+    self->~ast_state();
     mem_d(self);
 }
 
@@ -959,35 +798,36 @@ ast_call* ast_call_new(lex_ctx_t ctx,
                        ast_expression *funcexpr)
 {
     ast_instantiate(ast_call, ctx, ast_call_delete);
-    if (!funcexpr->next) {
+    if (!funcexpr->m_next) {
         compile_error(ctx, "not a function");
         mem_d(self);
         return nullptr;
     }
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_call_codegen);
 
-    ast_side_effects(self) = true;
+    self->m_side_effects = true;
 
-    self->func     = funcexpr;
-    self->va_count = nullptr;
+    self->m_func     = funcexpr;
+    self->m_va_count = nullptr;
 
-    ast_type_adopt(self, funcexpr->next);
+    ast_type_adopt(self, funcexpr->m_next);
 
     return self;
 }
 
 void ast_call_delete(ast_call *self)
 {
-    for (auto &it : self->params)
+    for (auto &it : self->m_params)
         ast_unref(it);
 
-    if (self->func)
-        ast_unref(self->func);
+    if (self->m_func)
+        ast_unref(self->m_func);
 
-    if (self->va_count)
-        ast_unref(self->va_count);
+    if (self->m_va_count)
+        ast_unref(self->m_va_count);
 
     ast_expression_delete((ast_expression*)self);
+    self->~ast_call();
     mem_d(self);
 }
 
@@ -1004,12 +844,12 @@ static bool ast_call_check_vararg(ast_call *self, ast_expression *va_type, ast_e
             ast_type_to_string(va_type,  tgot, sizeof(tgot));
             ast_type_to_string(exp_type, texp, sizeof(texp));
             if (OPTS_FLAG(UNSAFE_VARARGS)) {
-                if (compile_warning(ast_ctx(self), WARN_UNSAFE_TYPES,
+                if (compile_warning(self->m_context, WARN_UNSAFE_TYPES,
                                     "piped variadic argument differs in type: constrained to type %s, expected type %s",
                                     tgot, texp))
                     return false;
             } else {
-                compile_error(ast_ctx(self),
+                compile_error(self->m_context,
                               "piped variadic argument differs in type: constrained to type %s, expected type %s",
                               tgot, texp);
                 return false;
@@ -1019,12 +859,12 @@ static bool ast_call_check_vararg(ast_call *self, ast_expression *va_type, ast_e
         {
             ast_type_to_string(exp_type, texp, sizeof(texp));
             if (OPTS_FLAG(UNSAFE_VARARGS)) {
-                if (compile_warning(ast_ctx(self), WARN_UNSAFE_TYPES,
+                if (compile_warning(self->m_context, WARN_UNSAFE_TYPES,
                                     "piped variadic argument may differ in type: expected type %s",
                                     texp))
                     return false;
             } else {
-                compile_error(ast_ctx(self),
+                compile_error(self->m_context,
                               "piped variadic argument may differ in type: expected type %s",
                               texp);
                 return false;
@@ -1040,48 +880,48 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type)
     char tgot[1024];
     size_t i;
     bool retval = true;
-    const ast_expression *func = self->func;
-    size_t count = self->params.size();
-    if (count > func->params.size())
-        count = func->params.size();
+    const ast_expression *func = self->m_func;
+    size_t count = self->m_params.size();
+    if (count > func->m_type_params.size())
+        count = func->m_type_params.size();
 
     for (i = 0; i < count; ++i) {
-        if (ast_istype(self->params[i], ast_argpipe)) {
+        if (ast_istype(self->m_params[i], ast_argpipe)) {
             /* warn about type safety instead */
             if (i+1 != count) {
-                compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call");
+                compile_error(self->m_context, "argpipe must be the last parameter to a function call");
                 return false;
             }
-            if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->params[i]))
+            if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->m_type_params[i]))
                 retval = false;
         }
-        else if (!ast_compare_type(self->params[i], (ast_expression*)(func->params[i])))
+        else if (!ast_compare_type(self->m_params[i], (ast_expression*)(func->m_type_params[i])))
         {
-            ast_type_to_string(self->params[i], tgot, sizeof(tgot));
-            ast_type_to_string((ast_expression*)func->params[i], texp, sizeof(texp));
-            compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s",
+            ast_type_to_string(self->m_params[i], tgot, sizeof(tgot));
+            ast_type_to_string((ast_expression*)func->m_type_params[i], texp, sizeof(texp));
+            compile_error(self->m_context, "invalid type for parameter %u in function call: expected %s, got %s",
                      (unsigned int)(i+1), texp, tgot);
             /* we don't immediately return */
             retval = false;
         }
     }
-    count = self->params.size();
-    if (count > func->params.size() && func->varparam) {
+    count = self->m_params.size();
+    if (count > func->m_type_params.size() && func->m_varparam) {
         for (; i < count; ++i) {
-            if (ast_istype(self->params[i], ast_argpipe)) {
+            if (ast_istype(self->m_params[i], ast_argpipe)) {
                 /* warn about type safety instead */
                 if (i+1 != count) {
-                    compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call");
+                    compile_error(self->m_context, "argpipe must be the last parameter to a function call");
                     return false;
                 }
-                if (!ast_call_check_vararg(self, va_type, func->varparam))
+                if (!ast_call_check_vararg(self, va_type, func->m_varparam))
                     retval = false;
             }
-            else if (!ast_compare_type(self->params[i], func->varparam))
+            else if (!ast_compare_type(self->m_params[i], func->m_varparam))
             {
-                ast_type_to_string(self->params[i], tgot, sizeof(tgot));
-                ast_type_to_string(func->varparam, texp, sizeof(texp));
-                compile_error(ast_ctx(self), "invalid type for variadic parameter %u in function call: expected %s, got %s",
+                ast_type_to_string(self->m_params[i], tgot, sizeof(tgot));
+                ast_type_to_string(func->m_varparam, texp, sizeof(texp));
+                compile_error(self->m_context, "invalid type for variadic parameter %u in function call: expected %s, got %s",
                          (unsigned int)(i+1), texp, tgot);
                 /* we don't immediately return */
                 retval = false;
@@ -1091,31 +931,6 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type)
     return retval;
 }
 
-ast_store* ast_store_new(lex_ctx_t ctx, int op,
-                         ast_expression *dest, ast_expression *source)
-{
-    ast_instantiate(ast_store, ctx, ast_store_delete);
-    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_store_codegen);
-
-    ast_side_effects(self) = true;
-
-    self->op = op;
-    self->dest = dest;
-    self->source = source;
-
-    ast_type_adopt(self, dest);
-
-    return self;
-}
-
-void ast_store_delete(ast_store *self)
-{
-    ast_unref(self->dest);
-    ast_unref(self->source);
-    ast_expression_delete((ast_expression*)self);
-    mem_d(self);
-}
-
 ast_block* ast_block_new(lex_ctx_t ctx)
 {
     ast_instantiate(ast_block, ctx, ast_block_delete);
@@ -1126,11 +941,11 @@ ast_block* ast_block_new(lex_ctx_t ctx)
 
 bool ast_block_add_expr(ast_block *self, ast_expression *e)
 {
-    ast_propagate_effects(self, e);
-    self->exprs.push_back(e);
-    if (self->expression.next) {
-        ast_delete(self->expression.next);
-        self->expression.next = nullptr;
+    self->propagate_side_effects(e);
+    self->m_exprs.push_back(e);
+    if (self->m_next) {
+        ast_delete(self->m_next);
+        self->m_next = nullptr;
     }
     ast_type_adopt(self, e);
     return true;
@@ -1138,23 +953,24 @@ bool ast_block_add_expr(ast_block *self, ast_expression *e)
 
 void ast_block_collect(ast_block *self, ast_expression *expr)
 {
-    self->collect.push_back(expr);
-    expr->node.keep = true;
+    self->m_collect.push_back(expr);
+    expr->m_keep_node = true;
 }
 
 void ast_block_delete(ast_block *self)
 {
-    for (auto &it : self->exprs) ast_unref(it);
-    for (auto &it : self->locals) ast_delete(it);
-    for (auto &it : self->collect) ast_delete(it);
+    for (auto &it : self->m_exprs) ast_unref(it);
+    for (auto &it : self->m_locals) ast_delete(it);
+    for (auto &it : self->m_collect) ast_delete(it);
     ast_expression_delete((ast_expression*)self);
+    self->~ast_block();
     mem_d(self);
 }
 
 void ast_block_set_type(ast_block *self, ast_expression *from)
 {
-    if (self->expression.next)
-        ast_delete(self->expression.next);
+    if (self->m_next)
+        ast_delete(self->m_next);
     ast_type_adopt(self, from);
 }
 
@@ -1163,33 +979,33 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
     ast_instantiate(ast_function, ctx, ast_function_delete);
 
     if (!vtype) {
-        compile_error(ast_ctx(self), "internal error: ast_function_new condition 0");
+        compile_error(self->m_context, "internal error: ast_function_new condition 0");
         goto cleanup;
-    } else if (vtype->hasvalue || vtype->expression.vtype != TYPE_FUNCTION) {
-        compile_error(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)",
+    } else if (vtype->m_hasvalue || vtype->m_vtype != TYPE_FUNCTION) {
+        compile_error(self->m_context, "internal error: ast_function_new condition %i %i type=%i (probably 2 bodies?)",
                  (int)!vtype,
-                 (int)vtype->hasvalue,
-                 vtype->expression.vtype);
+                 (int)vtype->m_hasvalue,
+                 vtype->m_vtype);
         goto cleanup;
     }
 
-    self->vtype  = vtype;
-    self->name   = name ? util_strdup(name) : nullptr;
+    self->m_function_type = vtype;
+    self->m_name          = name ? util_strdup(name) : nullptr;
 
-    self->labelcount = 0;
-    self->builtin = 0;
+    self->m_labelcount = 0;
+    self->m_builtin = 0;
 
-    self->ir_func = nullptr;
-    self->curblock = nullptr;
+    self->m_ir_func = nullptr;
+    self->m_curblock = nullptr;
 
-    vtype->hasvalue = true;
-    vtype->constval.vfunc = self;
+    vtype->m_hasvalue = true;
+    vtype->m_constval.vfunc = self;
 
-    self->varargs          = nullptr;
-    self->argc             = nullptr;
-    self->fixedparams      = nullptr;
-    self->return_value     = nullptr;
-    self->static_count     = 0;
+    self->m_varargs          = nullptr;
+    self->m_argc             = nullptr;
+    self->m_fixedparams      = nullptr;
+    self->m_return_value     = nullptr;
+    self->m_static_count     = 0;
 
     return self;
 
@@ -1200,29 +1016,31 @@ cleanup:
 
 void ast_function_delete(ast_function *self)
 {
-    if (self->name)
-        mem_d((void*)self->name);
-    if (self->vtype) {
-        /* ast_value_delete(self->vtype); */
-        self->vtype->hasvalue = false;
-        self->vtype->constval.vfunc = nullptr;
+    if (self->m_name)
+        mem_d((void*)self->m_name);
+    if (self->m_function_type) {
+        /* ast_value_delete(self->m_function_type); */
+        self->m_function_type->m_hasvalue = false;
+        self->m_function_type->m_constval.vfunc = nullptr;
         /* We use unref - if it was stored in a global table it is supposed
          * to be deleted from *there*
          */
-        ast_unref(self->vtype);
+        ast_unref(self->m_function_type);
     }
-    for (auto &it : self->static_names)
+    for (auto &it : self->m_static_names)
         mem_d(it);
-    for (auto &it : self->blocks)
-        ast_delete(it);
-    if (self->varargs)
-        ast_delete(self->varargs);
-    if (self->argc)
-        ast_delete(self->argc);
-    if (self->fixedparams)
-        ast_unref(self->fixedparams);
-    if (self->return_value)
-        ast_unref(self->return_value);
+    // FIXME::DELME:: unique_ptr used on ast_block
+    //for (auto &it : self->m_blocks)
+    //    ast_delete(it);
+    if (self->m_varargs)
+        ast_delete(self->m_varargs);
+    if (self->m_argc)
+        ast_delete(self->m_argc);
+    if (self->m_fixedparams)
+        ast_unref(self->m_fixedparams);
+    if (self->m_return_value)
+        ast_unref(self->m_return_value);
+    self->~ast_function();
     mem_d(self);
 }
 
@@ -1239,10 +1057,10 @@ const char* ast_function_label(ast_function *self, const char *prefix)
         return nullptr;
     }
 
-    id  = (self->labelcount++);
+    id  = (self->m_labelcount++);
     len = strlen(prefix);
 
-    from = self->labelbuf + sizeof(self->labelbuf)-1;
+    from = self->m_labelbuf + sizeof(self->m_labelbuf)-1;
     *from-- = 0;
     do {
         *from-- = (id%10) + '0';
@@ -1262,90 +1080,90 @@ const char* ast_function_label(ast_function *self, const char *prefix)
 
 static void _ast_codegen_output_type(ast_expression *self, ir_value *out)
 {
-    if (out->vtype == TYPE_FIELD)
-        out->fieldtype = self->next->vtype;
-    if (out->vtype == TYPE_FUNCTION)
-        out->outtype = self->next->vtype;
+    if (out->m_vtype == TYPE_FIELD)
+        out->m_fieldtype = self->m_next->m_vtype;
+    if (out->m_vtype == TYPE_FUNCTION)
+        out->m_outtype = self->m_next->m_vtype;
 }
 
-#define codegen_output_type(a,o) (_ast_codegen_output_type(&((a)->expression),(o)))
+#define codegen_output_type(a,o) (_ast_codegen_output_type(static_cast<ast_expression*>((a)),(o)))
 
 bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out)
 {
     (void)func;
     (void)lvalue;
-    if (self->expression.vtype == TYPE_NIL) {
-        *out = func->ir_func->owner->nil;
+    if (self->m_vtype == TYPE_NIL) {
+        *out = func->m_ir_func->m_owner->m_nil;
         return true;
     }
-    /* NOTE: This is the codegen for a variable used in an expression.
+    /* NOTE: This is the codegen for a variable used in an 
      * It is not the codegen to generate the value. For this purpose,
      * ast_local_codegen and ast_global_codegen are to be used before this
      * is executed. ast_function_codegen should take care of its locals,
      * and the ast-user should take care of ast_global_codegen to be used
      * on all the globals.
      */
-    if (!self->ir_v) {
+    if (!self->m_ir_v) {
         char tname[1024]; /* typename is reserved in C++ */
         ast_type_to_string((ast_expression*)self, tname, sizeof(tname));
-        compile_error(ast_ctx(self), "ast_value used before generated %s %s", tname, self->name);
+        compile_error(self->m_context, "ast_value used before generated %s %s", tname, self->m_name);
         return false;
     }
-    *out = self->ir_v;
+    *out = self->m_ir_v;
     return true;
 }
 
 static bool ast_global_array_set(ast_value *self)
 {
-    size_t count = self->initlist.size();
+    size_t count = self->m_initlist.size();
     size_t i;
 
-    if (count > self->expression.count) {
-        compile_error(ast_ctx(self), "too many elements in initializer");
-        count = self->expression.count;
+    if (count > self->m_count) {
+        compile_error(self->m_context, "too many elements in initializer");
+        count = self->m_count;
     }
-    else if (count < self->expression.count) {
+    else if (count < self->m_count) {
         /* add this?
-        compile_warning(ast_ctx(self), "not all elements are initialized");
+        compile_warning(self->m_context, "not all elements are initialized");
         */
     }
 
     for (i = 0; i != count; ++i) {
-        switch (self->expression.next->vtype) {
+        switch (self->m_next->m_vtype) {
             case TYPE_FLOAT:
-                if (!ir_value_set_float(self->ir_values[i], self->initlist[i].vfloat))
+                if (!ir_value_set_float(self->m_ir_values[i], self->m_initlist[i].vfloat))
                     return false;
                 break;
             case TYPE_VECTOR:
-                if (!ir_value_set_vector(self->ir_values[i], self->initlist[i].vvec))
+                if (!ir_value_set_vector(self->m_ir_values[i], self->m_initlist[i].vvec))
                     return false;
                 break;
             case TYPE_STRING:
-                if (!ir_value_set_string(self->ir_values[i], self->initlist[i].vstring))
+                if (!ir_value_set_string(self->m_ir_values[i], self->m_initlist[i].vstring))
                     return false;
                 break;
             case TYPE_ARRAY:
                 /* we don't support them in any other place yet either */
-                compile_error(ast_ctx(self), "TODO: nested arrays");
+                compile_error(self->m_context, "TODO: nested arrays");
                 return false;
             case TYPE_FUNCTION:
                 /* this requiers a bit more work - similar to the fields I suppose */
-                compile_error(ast_ctx(self), "global of type function not properly generated");
+                compile_error(self->m_context, "global of type function not properly generated");
                 return false;
             case TYPE_FIELD:
-                if (!self->initlist[i].vfield) {
-                    compile_error(ast_ctx(self), "field constant without vfield set");
+                if (!self->m_initlist[i].vfield) {
+                    compile_error(self->m_context, "field constant without vfield set");
                     return false;
                 }
-                if (!self->initlist[i].vfield->ir_v) {
-                    compile_error(ast_ctx(self), "field constant generated before its field");
+                if (!self->m_initlist[i].vfield->m_ir_v) {
+                    compile_error(self->m_context, "field constant generated before its field");
                     return false;
                 }
-                if (!ir_value_set_field(self->ir_values[i], self->initlist[i].vfield->ir_v))
+                if (!ir_value_set_field(self->m_ir_values[i], self->m_initlist[i].vfield->m_ir_v))
                     return false;
                 break;
             default:
-                compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
+                compile_error(self->m_context, "TODO: global constant type %i", self->m_vtype);
                 break;
         }
     }
@@ -1354,13 +1172,13 @@ static bool ast_global_array_set(ast_value *self)
 
 static bool check_array(ast_value *self, ast_value *array)
 {
-    if (array->expression.flags & AST_FLAG_ARRAY_INIT && array->initlist.empty()) {
-        compile_error(ast_ctx(self), "array without size: %s", self->name);
+    if (array->m_flags & AST_FLAG_ARRAY_INIT && array->m_initlist.empty()) {
+        compile_error(self->m_context, "array without size: %s", self->m_name);
         return false;
     }
     /* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
-    if (!array->expression.count || array->expression.count > OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE)) {
-        compile_error(ast_ctx(self), "Invalid array of size %lu", (unsigned long)array->expression.count);
+    if (!array->m_count || array->m_count > OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE)) {
+        compile_error(self->m_context, "Invalid array of size %lu", (unsigned long)array->m_count);
         return false;
     }
     return true;
@@ -1370,122 +1188,122 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
 {
     ir_value *v = nullptr;
 
-    if (self->expression.vtype == TYPE_NIL) {
-        compile_error(ast_ctx(self), "internal error: trying to generate a variable of TYPE_NIL");
+    if (self->m_vtype == TYPE_NIL) {
+        compile_error(self->m_context, "internal error: trying to generate a variable of TYPE_NIL");
         return false;
     }
 
-    if (self->hasvalue && self->expression.vtype == TYPE_FUNCTION)
+    if (self->m_hasvalue && self->m_vtype == TYPE_FUNCTION)
     {
-        ir_function *func = ir_builder_create_function(ir, self->name, self->expression.next->vtype);
+        ir_function *func = ir_builder_create_function(ir, self->m_name, self->m_next->m_vtype);
         if (!func)
             return false;
-        func->context = ast_ctx(self);
-        func->value->context = ast_ctx(self);
-
-        self->constval.vfunc->ir_func = func;
-        self->ir_v = func->value;
-        if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-            self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
-        if (self->expression.flags & AST_FLAG_ERASEABLE)
-            self->ir_v->flags |= IR_FLAG_ERASABLE;
-        if (self->expression.flags & AST_FLAG_BLOCK_COVERAGE)
-            func->flags |= IR_FLAG_BLOCK_COVERAGE;
+        func->m_context = self->m_context;
+        func->m_value->m_context = self->m_context;
+
+        self->m_constval.vfunc->m_ir_func = func;
+        self->m_ir_v = func->m_value;
+        if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+            self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
+        if (self->m_flags & AST_FLAG_ERASEABLE)
+            self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+        if (self->m_flags & AST_FLAG_BLOCK_COVERAGE)
+            func->m_flags |= IR_FLAG_BLOCK_COVERAGE;
         /* The function is filled later on ast_function_codegen... */
         return true;
     }
 
-    if (isfield && self->expression.vtype == TYPE_FIELD) {
-        ast_expression *fieldtype = self->expression.next;
+    if (isfield && self->m_vtype == TYPE_FIELD) {
+        ast_expression *fieldtype = self->m_next;
 
-        if (self->hasvalue) {
-            compile_error(ast_ctx(self), "TODO: constant field pointers with value");
+        if (self->m_hasvalue) {
+            compile_error(self->m_context, "TODO: constant field pointers with value");
             goto error;
         }
 
-        if (fieldtype->vtype == TYPE_ARRAY) {
+        if (fieldtype->m_vtype == TYPE_ARRAY) {
             size_t ai;
             char   *name;
             size_t  namelen;
 
             ast_expression *elemtype;
-            int             vtype;
+            qc_type         vtype;
             ast_value      *array = (ast_value*)fieldtype;
 
             if (!ast_istype(fieldtype, ast_value)) {
-                compile_error(ast_ctx(self), "internal error: ast_value required");
+                compile_error(self->m_context, "internal error: ast_value required");
                 return false;
             }
 
             if (!check_array(self, array))
                 return false;
 
-            elemtype = array->expression.next;
-            vtype = elemtype->vtype;
+            elemtype = array->m_next;
+            vtype = elemtype->m_vtype;
 
-            v = ir_builder_create_field(ir, self->name, vtype);
+            v = ir_builder_create_field(ir, self->m_name, vtype);
             if (!v) {
-                compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", self->name);
+                compile_error(self->m_context, "ir_builder_create_global failed on `%s`", self->m_name);
                 return false;
             }
-            v->context = ast_ctx(self);
-            v->unique_life = true;
-            v->locked      = true;
-            array->ir_v = self->ir_v = v;
+            v->m_context = self->m_context;
+            v->m_unique_life = true;
+            v->m_locked      = true;
+            array->m_ir_v = self->m_ir_v = v;
 
-            if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-                self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
-            if (self->expression.flags & AST_FLAG_ERASEABLE)
-                self->ir_v->flags |= IR_FLAG_ERASABLE;
+            if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+                self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
+            if (self->m_flags & AST_FLAG_ERASEABLE)
+                self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
 
-            namelen = strlen(self->name);
+            namelen = strlen(self->m_name);
             name    = (char*)mem_a(namelen + 16);
-            util_strncpy(name, self->name, namelen);
+            util_strncpy(name, self->m_name, namelen);
 
-            array->ir_values = (ir_value**)mem_a(sizeof(array->ir_values[0]) * array->expression.count);
-            array->ir_values[0] = v;
-            for (ai = 1; ai < array->expression.count; ++ai) {
+            array->m_ir_values = (ir_value**)mem_a(sizeof(array->m_ir_values[0]) * array->m_count);
+            array->m_ir_values[0] = v;
+            for (ai = 1; ai < array->m_count; ++ai) {
                 util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
-                array->ir_values[ai] = ir_builder_create_field(ir, name, vtype);
-                if (!array->ir_values[ai]) {
+                array->m_ir_values[ai] = ir_builder_create_field(ir, name, vtype);
+                if (!array->m_ir_values[ai]) {
                     mem_d(name);
-                    compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", name);
+                    compile_error(self->m_context, "ir_builder_create_global failed on `%s`", name);
                     return false;
                 }
-                array->ir_values[ai]->context = ast_ctx(self);
-                array->ir_values[ai]->unique_life = true;
-                array->ir_values[ai]->locked      = true;
-                if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-                    self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF;
+                array->m_ir_values[ai]->m_context = self->m_context;
+                array->m_ir_values[ai]->m_unique_life = true;
+                array->m_ir_values[ai]->m_locked      = true;
+                if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+                    self->m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
             }
             mem_d(name);
         }
         else
         {
-            v = ir_builder_create_field(ir, self->name, self->expression.next->vtype);
+            v = ir_builder_create_field(ir, self->m_name, self->m_next->m_vtype);
             if (!v)
                 return false;
-            v->context = ast_ctx(self);
-            self->ir_v = v;
-            if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-                self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
+            v->m_context = self->m_context;
+            self->m_ir_v = v;
+            if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+                self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
 
-            if (self->expression.flags & AST_FLAG_ERASEABLE)
-                self->ir_v->flags |= IR_FLAG_ERASABLE;
+            if (self->m_flags & AST_FLAG_ERASEABLE)
+                self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
         }
         return true;
     }
 
-    if (self->expression.vtype == TYPE_ARRAY) {
+    if (self->m_vtype == TYPE_ARRAY) {
         size_t ai;
         char   *name;
         size_t  namelen;
 
-        ast_expression *elemtype = self->expression.next;
-        int vtype = elemtype->vtype;
+        ast_expression *elemtype = self->m_next;
+        qc_type vtype = elemtype->m_vtype;
 
-        if (self->expression.flags & AST_FLAG_ARRAY_INIT && !self->expression.count) {
-            compile_error(ast_ctx(self), "array `%s' has no size", self->name);
+        if (self->m_flags & AST_FLAG_ARRAY_INIT && !self->m_count) {
+            compile_error(self->m_context, "array `%s' has no size", self->m_name);
             return false;
         }
 
@@ -1493,39 +1311,39 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
         if (!check_array(self, self))
             return false;
 
-        v = ir_builder_create_global(ir, self->name, vtype);
+        v = ir_builder_create_global(ir, self->m_name, vtype);
         if (!v) {
-            compile_error(ast_ctx(self), "ir_builder_create_global failed `%s`", self->name);
+            compile_error(self->m_context, "ir_builder_create_global failed `%s`", self->m_name);
             return false;
         }
-        v->context = ast_ctx(self);
-        v->unique_life = true;
-        v->locked      = true;
+        v->m_context = self->m_context;
+        v->m_unique_life = true;
+        v->m_locked      = true;
 
-        if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-            v->flags |= IR_FLAG_INCLUDE_DEF;
-        if (self->expression.flags & AST_FLAG_ERASEABLE)
-            self->ir_v->flags |= IR_FLAG_ERASABLE;
+        if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+            v->m_flags |= IR_FLAG_INCLUDE_DEF;
+        if (self->m_flags & AST_FLAG_ERASEABLE)
+            self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
 
-        namelen = strlen(self->name);
+        namelen = strlen(self->m_name);
         name    = (char*)mem_a(namelen + 16);
-        util_strncpy(name, self->name, namelen);
+        util_strncpy(name, self->m_name, namelen);
 
-        self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->expression.count);
-        self->ir_values[0] = v;
-        for (ai = 1; ai < self->expression.count; ++ai) {
+        self->m_ir_values = (ir_value**)mem_a(sizeof(self->m_ir_values[0]) * self->m_count);
+        self->m_ir_values[0] = v;
+        for (ai = 1; ai < self->m_count; ++ai) {
             util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
-            self->ir_values[ai] = ir_builder_create_global(ir, name, vtype);
-            if (!self->ir_values[ai]) {
+            self->m_ir_values[ai] = ir_builder_create_global(ir, name, vtype);
+            if (!self->m_ir_values[ai]) {
                 mem_d(name);
-                compile_error(ast_ctx(self), "ir_builder_create_global failed `%s`", name);
+                compile_error(self->m_context, "ir_builder_create_global failed `%s`", name);
                 return false;
             }
-            self->ir_values[ai]->context = ast_ctx(self);
-            self->ir_values[ai]->unique_life = true;
-            self->ir_values[ai]->locked      = true;
-            if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-                self->ir_values[ai]->flags |= IR_FLAG_INCLUDE_DEF;
+            self->m_ir_values[ai]->m_context = self->m_context;
+            self->m_ir_values[ai]->m_unique_life = true;
+            self->m_ir_values[ai]->m_locked      = true;
+            if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+                self->m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
         }
         mem_d(name);
     }
@@ -1534,70 +1352,70 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
         /* Arrays don't do this since there's no "array" value which spans across the
          * whole thing.
          */
-        v = ir_builder_create_global(ir, self->name, self->expression.vtype);
+        v = ir_builder_create_global(ir, self->m_name, self->m_vtype);
         if (!v) {
-            compile_error(ast_ctx(self), "ir_builder_create_global failed on `%s`", self->name);
+            compile_error(self->m_context, "ir_builder_create_global failed on `%s`", self->m_name);
             return false;
         }
         codegen_output_type(self, v);
-        v->context = ast_ctx(self);
+        v->m_context = self->m_context;
     }
 
     /* link us to the ir_value */
-    v->cvq = self->cvq;
-    self->ir_v = v;
+    v->m_cvq = self->m_cvq;
+    self->m_ir_v = v;
 
-    if (self->expression.flags & AST_FLAG_INCLUDE_DEF)
-        self->ir_v->flags |= IR_FLAG_INCLUDE_DEF;
-    if (self->expression.flags & AST_FLAG_ERASEABLE)
-        self->ir_v->flags |= IR_FLAG_ERASABLE;
+    if (self->m_flags & AST_FLAG_INCLUDE_DEF)
+        self->m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
+    if (self->m_flags & AST_FLAG_ERASEABLE)
+        self->m_ir_v->m_flags |= IR_FLAG_ERASABLE;
 
     /* initialize */
-    if (self->hasvalue) {
-        switch (self->expression.vtype)
+    if (self->m_hasvalue) {
+        switch (self->m_vtype)
         {
             case TYPE_FLOAT:
-                if (!ir_value_set_float(v, self->constval.vfloat))
+                if (!ir_value_set_float(v, self->m_constval.vfloat))
                     goto error;
                 break;
             case TYPE_VECTOR:
-                if (!ir_value_set_vector(v, self->constval.vvec))
+                if (!ir_value_set_vector(v, self->m_constval.vvec))
                     goto error;
                 break;
             case TYPE_STRING:
-                if (!ir_value_set_string(v, self->constval.vstring))
+                if (!ir_value_set_string(v, self->m_constval.vstring))
                     goto error;
                 break;
             case TYPE_ARRAY:
                 ast_global_array_set(self);
                 break;
             case TYPE_FUNCTION:
-                compile_error(ast_ctx(self), "global of type function not properly generated");
+                compile_error(self->m_context, "global of type function not properly generated");
                 goto error;
                 /* Cannot generate an IR value for a function,
                  * need a pointer pointing to a function rather.
                  */
             case TYPE_FIELD:
-                if (!self->constval.vfield) {
-                    compile_error(ast_ctx(self), "field constant without vfield set");
+                if (!self->m_constval.vfield) {
+                    compile_error(self->m_context, "field constant without vfield set");
                     goto error;
                 }
-                if (!self->constval.vfield->ir_v) {
-                    compile_error(ast_ctx(self), "field constant generated before its field");
+                if (!self->m_constval.vfield->m_ir_v) {
+                    compile_error(self->m_context, "field constant generated before its field");
                     goto error;
                 }
-                if (!ir_value_set_field(v, self->constval.vfield->ir_v))
+                if (!ir_value_set_field(v, self->m_constval.vfield->m_ir_v))
                     goto error;
                 break;
             default:
-                compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
+                compile_error(self->m_context, "TODO: global constant type %i", self->m_vtype);
                 break;
         }
     }
     return true;
 
 error: /* clean up */
-    if(v) ir_value_delete(v);
+    if (v) delete v;
     return false;
 }
 
@@ -1605,12 +1423,12 @@ static bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
 {
     ir_value *v = nullptr;
 
-    if (self->expression.vtype == TYPE_NIL) {
-        compile_error(ast_ctx(self), "internal error: trying to generate a variable of TYPE_NIL");
+    if (self->m_vtype == TYPE_NIL) {
+        compile_error(self->m_context, "internal error: trying to generate a variable of TYPE_NIL");
         return false;
     }
 
-    if (self->hasvalue && self->expression.vtype == TYPE_FUNCTION)
+    if (self->m_hasvalue && self->m_vtype == TYPE_FUNCTION)
     {
         /* Do we allow local functions? I think not...
          * this is NOT a function pointer atm.
@@ -1618,18 +1436,18 @@ static bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
         return false;
     }
 
-    if (self->expression.vtype == TYPE_ARRAY) {
+    if (self->m_vtype == TYPE_ARRAY) {
         size_t ai;
         char   *name;
         size_t  namelen;
 
-        ast_expression *elemtype = self->expression.next;
-        int vtype = elemtype->vtype;
+        ast_expression *elemtype = self->m_next;
+        qc_type vtype = elemtype->m_vtype;
 
-        func->flags |= IR_FLAG_HAS_ARRAYS;
+        func->m_flags |= IR_FLAG_HAS_ARRAYS;
 
-        if (param && !(self->expression.flags & AST_FLAG_IS_VARARG)) {
-            compile_error(ast_ctx(self), "array-parameters are not supported");
+        if (param && !(self->m_flags & AST_FLAG_IS_VARARG)) {
+            compile_error(self->m_context, "array-parameters are not supported");
             return false;
         }
 
@@ -1637,82 +1455,82 @@ static bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
         if (!check_array(self, self))
             return false;
 
-        self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->expression.count);
-        if (!self->ir_values) {
-            compile_error(ast_ctx(self), "failed to allocate array values");
+        self->m_ir_values = (ir_value**)mem_a(sizeof(self->m_ir_values[0]) * self->m_count);
+        if (!self->m_ir_values) {
+            compile_error(self->m_context, "failed to allocate array values");
             return false;
         }
 
-        v = ir_function_create_local(func, self->name, vtype, param);
+        v = ir_function_create_local(func, self->m_name, vtype, param);
         if (!v) {
-            compile_error(ast_ctx(self), "internal error: ir_function_create_local failed");
+            compile_error(self->m_context, "internal error: ir_function_create_local failed");
             return false;
         }
-        v->context = ast_ctx(self);
-        v->unique_life = true;
-        v->locked      = true;
+        v->m_context = self->m_context;
+        v->m_unique_life = true;
+        v->m_locked      = true;
 
-        namelen = strlen(self->name);
+        namelen = strlen(self->m_name);
         name    = (char*)mem_a(namelen + 16);
-        util_strncpy(name, self->name, namelen);
+        util_strncpy(name, self->m_name, namelen);
 
-        self->ir_values[0] = v;
-        for (ai = 1; ai < self->expression.count; ++ai) {
+        self->m_ir_values[0] = v;
+        for (ai = 1; ai < self->m_count; ++ai) {
             util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai);
-            self->ir_values[ai] = ir_function_create_local(func, name, vtype, param);
-            if (!self->ir_values[ai]) {
-                compile_error(ast_ctx(self), "internal_error: ir_builder_create_global failed on `%s`", name);
+            self->m_ir_values[ai] = ir_function_create_local(func, name, vtype, param);
+            if (!self->m_ir_values[ai]) {
+                compile_error(self->m_context, "internal_error: ir_builder_create_global failed on `%s`", name);
                 return false;
             }
-            self->ir_values[ai]->context = ast_ctx(self);
-            self->ir_values[ai]->unique_life = true;
-            self->ir_values[ai]->locked      = true;
+            self->m_ir_values[ai]->m_context = self->m_context;
+            self->m_ir_values[ai]->m_unique_life = true;
+            self->m_ir_values[ai]->m_locked      = true;
         }
         mem_d(name);
     }
     else
     {
-        v = ir_function_create_local(func, self->name, self->expression.vtype, param);
+        v = ir_function_create_local(func, self->m_name, self->m_vtype, param);
         if (!v)
             return false;
         codegen_output_type(self, v);
-        v->context = ast_ctx(self);
+        v->m_context = self->m_context;
     }
 
     /* A constant local... hmmm...
      * I suppose the IR will have to deal with this
      */
-    if (self->hasvalue) {
-        switch (self->expression.vtype)
+    if (self->m_hasvalue) {
+        switch (self->m_vtype)
         {
             case TYPE_FLOAT:
-                if (!ir_value_set_float(v, self->constval.vfloat))
+                if (!ir_value_set_float(v, self->m_constval.vfloat))
                     goto error;
                 break;
             case TYPE_VECTOR:
-                if (!ir_value_set_vector(v, self->constval.vvec))
+                if (!ir_value_set_vector(v, self->m_constval.vvec))
                     goto error;
                 break;
             case TYPE_STRING:
-                if (!ir_value_set_string(v, self->constval.vstring))
+                if (!ir_value_set_string(v, self->m_constval.vstring))
                     goto error;
                 break;
             default:
-                compile_error(ast_ctx(self), "TODO: global constant type %i", self->expression.vtype);
+                compile_error(self->m_context, "TODO: global constant type %i", self->m_vtype);
                 break;
         }
     }
 
     /* link us to the ir_value */
-    v->cvq = self->cvq;
-    self->ir_v = v;
+    v->m_cvq = self->m_cvq;
+    self->m_ir_v = v;
 
-    if (!ast_generate_accessors(self, func->owner))
+    if (!ast_generate_accessors(self, func->m_owner))
         return false;
     return true;
 
 error: /* clean up */
-    ir_value_delete(v);
+    delete v;
     return false;
 }
 
@@ -1720,47 +1538,46 @@ bool ast_generate_accessors(ast_value *self, ir_builder *ir)
 {
     size_t i;
     bool warn = OPTS_WARN(WARN_USED_UNINITIALIZED);
-    if (!self->setter || !self->getter)
+    if (!self->m_setter || !self->m_getter)
         return true;
-    for (i = 0; i < self->expression.count; ++i) {
-        if (!self->ir_values) {
-            compile_error(ast_ctx(self), "internal error: no array values generated for `%s`", self->name);
+    for (i = 0; i < self->m_count; ++i) {
+        if (!self->m_ir_values) {
+            compile_error(self->m_context, "internal error: no array values generated for `%s`", self->m_name);
             return false;
         }
-        if (!self->ir_values[i]) {
-            compile_error(ast_ctx(self), "internal error: not all array values have been generated for `%s`", self->name);
+        if (!self->m_ir_values[i]) {
+            compile_error(self->m_context, "internal error: not all array values have been generated for `%s`", self->m_name);
             return false;
         }
-        if (self->ir_values[i]->life) {
-            compile_error(ast_ctx(self), "internal error: function containing `%s` already generated", self->name);
+        if (!self->m_ir_values[i]->m_life.empty()) {
+            compile_error(self->m_context, "internal error: function containing `%s` already generated", self->m_name);
             return false;
         }
     }
 
     opts_set(opts.warn, WARN_USED_UNINITIALIZED, false);
-    if (self->setter) {
-        if (!ast_global_codegen  (self->setter, ir, false) ||
-            !ast_function_codegen(self->setter->constval.vfunc, ir) ||
-            !ir_function_finalize(self->setter->constval.vfunc->ir_func))
+    if (self->m_setter) {
+        if (!ast_global_codegen  (self->m_setter, ir, false) ||
+            !ast_function_codegen(self->m_setter->m_constval.vfunc, ir) ||
+            !ir_function_finalize(self->m_setter->m_constval.vfunc->m_ir_func))
         {
-            compile_error(ast_ctx(self), "internal error: failed to generate setter for `%s`", self->name);
+            compile_error(self->m_context, "internal error: failed to generate setter for `%s`", self->m_name);
             opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
             return false;
         }
     }
-    if (self->getter) {
-        if (!ast_global_codegen  (self->getter, ir, false) ||
-            !ast_function_codegen(self->getter->constval.vfunc, ir) ||
-            !ir_function_finalize(self->getter->constval.vfunc->ir_func))
+    if (self->m_getter) {
+        if (!ast_global_codegen  (self->m_getter, ir, false) ||
+            !ast_function_codegen(self->m_getter->m_constval.vfunc, ir) ||
+            !ir_function_finalize(self->m_getter->m_constval.vfunc->m_ir_func))
         {
-            compile_error(ast_ctx(self), "internal error: failed to generate getter for `%s`", self->name);
+            compile_error(self->m_context, "internal error: failed to generate getter for `%s`", self->m_name);
             opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
             return false;
         }
     }
-    for (i = 0; i < self->expression.count; ++i) {
-        vec_free(self->ir_values[i]->life);
-    }
+    for (i = 0; i < self->m_count; ++i)
+        self->m_ir_values[i]->m_life.clear();
     opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
     return true;
 }
@@ -1774,106 +1591,106 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
 
     (void)ir;
 
-    irf = self->ir_func;
+    irf = self->m_ir_func;
     if (!irf) {
-        compile_error(ast_ctx(self), "internal error: ast_function's related ast_value was not generated yet");
+        compile_error(self->m_context, "internal error: ast_function's related ast_value was not generated yet");
         return false;
     }
 
     /* fill the parameter list */
-    ec = &self->vtype->expression;
-    for (auto &it : ec->params) {
-        if (it->expression.vtype == TYPE_FIELD)
-            vec_push(irf->params, it->expression.next->vtype);
+    ec = self->m_function_type;
+    for (auto &it : ec->m_type_params) {
+        if (it->m_vtype == TYPE_FIELD)
+            vec_push(irf->m_params, it->m_next->m_vtype);
         else
-            vec_push(irf->params, it->expression.vtype);
-        if (!self->builtin) {
-            if (!ast_local_codegen(it, self->ir_func, true))
+            vec_push(irf->m_params, it->m_vtype);
+        if (!self->m_builtin) {
+            if (!ast_local_codegen(it, self->m_ir_func, true))
                 return false;
         }
     }
 
-    if (self->varargs) {
-        if (!ast_local_codegen(self->varargs, self->ir_func, true))
+    if (self->m_varargs) {
+        if (!ast_local_codegen(self->m_varargs, self->m_ir_func, true))
             return false;
-        irf->max_varargs = self->varargs->expression.count;
+        irf->m_max_varargs = self->m_varargs->m_count;
     }
 
-    if (self->builtin) {
-        irf->builtin = self->builtin;
+    if (self->m_builtin) {
+        irf->m_builtin = self->m_builtin;
         return true;
     }
 
     /* have a local return value variable? */
-    if (self->return_value) {
-        if (!ast_local_codegen(self->return_value, self->ir_func, false))
+    if (self->m_return_value) {
+        if (!ast_local_codegen(self->m_return_value, self->m_ir_func, false))
             return false;
     }
 
-    if (self->blocks.empty()) {
-        compile_error(ast_ctx(self), "function `%s` has no body", self->name);
+    if (self->m_blocks.empty()) {
+        compile_error(self->m_context, "function `%s` has no body", self->m_name);
         return false;
     }
 
-    irf->first = self->curblock = ir_function_create_block(ast_ctx(self), irf, "entry");
-    if (!self->curblock) {
-        compile_error(ast_ctx(self), "failed to allocate entry block for `%s`", self->name);
+    irf->m_first = self->m_curblock = ir_function_create_block(self->m_context, irf, "entry");
+    if (!self->m_curblock) {
+        compile_error(self->m_context, "failed to allocate entry block for `%s`", self->m_name);
         return false;
     }
 
-    if (self->argc) {
+    if (self->m_argc) {
         ir_value *va_count;
         ir_value *fixed;
         ir_value *sub;
-        if (!ast_local_codegen(self->argc, self->ir_func, true))
+        if (!ast_local_codegen(self->m_argc, self->m_ir_func, true))
             return false;
-        cgen = self->argc->expression.codegen;
-        if (!(*cgen)((ast_expression*)(self->argc), self, false, &va_count))
+        cgen = self->m_argc->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_argc), self, false, &va_count))
             return false;
-        cgen = self->fixedparams->expression.codegen;
-        if (!(*cgen)((ast_expression*)(self->fixedparams), self, false, &fixed))
+        cgen = self->m_fixedparams->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_fixedparams), self, false, &fixed))
             return false;
-        sub = ir_block_create_binop(self->curblock, ast_ctx(self),
+        sub = ir_block_create_binop(self->m_curblock, self->m_context,
                                     ast_function_label(self, "va_count"), INSTR_SUB_F,
                                     ir_builder_get_va_count(ir), fixed);
         if (!sub)
             return false;
-        if (!ir_block_create_store_op(self->curblock, ast_ctx(self), INSTR_STORE_F,
+        if (!ir_block_create_store_op(self->m_curblock, self->m_context, INSTR_STORE_F,
                                       va_count, sub))
         {
             return false;
         }
     }
 
-    for (auto &it : self->blocks) {
-        cgen = it->expression.codegen;
-        if (!(*cgen)((ast_expression*)it, self, false, &dummy))
+    for (auto &it : self->m_blocks) {
+        cgen = it->m_codegen;
+        if (!(*cgen)(it.get(), self, false, &dummy))
             return false;
     }
 
     /* TODO: check return types */
-    if (!self->curblock->final)
+    if (!self->m_curblock->m_final)
     {
-        if (!self->vtype->expression.next ||
-            self->vtype->expression.next->vtype == TYPE_VOID)
+        if (!self->m_function_type->m_next ||
+            self->m_function_type->m_next->m_vtype == TYPE_VOID)
         {
-            return ir_block_create_return(self->curblock, ast_ctx(self), nullptr);
+            return ir_block_create_return(self->m_curblock, self->m_context, nullptr);
         }
-        else if (vec_size(self->curblock->entries) || self->curblock == irf->first)
+        else if (vec_size(self->m_curblock->m_entries) || self->m_curblock == irf->m_first)
         {
-            if (self->return_value) {
-                cgen = self->return_value->expression.codegen;
-                if (!(*cgen)((ast_expression*)(self->return_value), self, false, &dummy))
+            if (self->m_return_value) {
+                cgen = self->m_return_value->m_codegen;
+                if (!(*cgen)((ast_expression*)(self->m_return_value), self, false, &dummy))
                     return false;
-                return ir_block_create_return(self->curblock, ast_ctx(self), dummy);
+                return ir_block_create_return(self->m_curblock, self->m_context, dummy);
             }
-            else if (compile_warning(ast_ctx(self), WARN_MISSING_RETURN_VALUES,
+            else if (compile_warning(self->m_context, WARN_MISSING_RETURN_VALUES,
                                 "control reaches end of non-void function (`%s`) via %s",
-                                self->name, self->curblock->label))
+                                self->m_name, self->m_curblock->m_label.c_str()))
             {
                 return false;
             }
-            return ir_block_create_return(self->curblock, ast_ctx(self), nullptr);
+            return ir_block_create_return(self->m_curblock, self->m_context, nullptr);
         }
     }
     return true;
@@ -1883,7 +1700,7 @@ static bool starts_a_label(ast_expression *ex)
 {
     while (ex && ast_istype(ex, ast_block)) {
         ast_block *b = (ast_block*)ex;
-        ex = b->exprs[0];
+        ex = b->m_exprs[0];
     }
     if (!ex)
         return false;
@@ -1903,12 +1720,12 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
      * of the form: (a, b, c) = x should not assign to c...
      */
     if (lvalue) {
-        compile_error(ast_ctx(self), "not an l-value (code-block)");
+        compile_error(self->m_context, "not an l-value (code-block)");
         return false;
     }
 
-    if (self->expression.outr) {
-        *out = self->expression.outr;
+    if (self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
@@ -1921,27 +1738,27 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
     *out = nullptr;
 
     /* generate locals */
-    for (auto &it : self->locals) {
-        if (!ast_local_codegen(it, func->ir_func, false)) {
+    for (auto &it : self->m_locals) {
+        if (!ast_local_codegen(it, func->m_ir_func, false)) {
             if (OPTS_OPTION_BOOL(OPTION_DEBUG))
-                compile_error(ast_ctx(self), "failed to generate local `%s`", it->name);
+                compile_error(self->m_context, "failed to generate local `%s`", it->m_name);
             return false;
         }
     }
 
-    for (auto &it : self->exprs) {
+    for (auto &it : self->m_exprs) {
         ast_expression_codegen *gen;
-        if (func->curblock->final && !starts_a_label(it)) {
-            if (compile_warning(ast_ctx(it), WARN_UNREACHABLE_CODE, "unreachable statement"))
+        if (func->m_curblock->m_final && !starts_a_label(it)) {
+            if (compile_warning(it->m_context, WARN_UNREACHABLE_CODE, "unreachable statement"))
                 return false;
             continue;
         }
-        gen = it->codegen;
+        gen = it->m_codegen;
         if (!(*gen)(it, func, false, out))
             return false;
     }
 
-    self->expression.outr = *out;
+    self->m_outr = *out;
 
     return true;
 }
@@ -1956,23 +1773,23 @@ bool ast_store_codegen(ast_store *self, ast_function *func, bool lvalue, ir_valu
     ast_value       *idx = 0;
     ast_array_index *ai = nullptr;
 
-    if (lvalue && self->expression.outl) {
-        *out = self->expression.outl;
+    if (lvalue && self->m_outl) {
+        *out = self->m_outl;
         return true;
     }
 
-    if (!lvalue && self->expression.outr) {
-        *out = self->expression.outr;
+    if (!lvalue && self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
-    if (ast_istype(self->dest, ast_array_index))
+    if (ast_istype(self->m_dest, ast_array_index))
     {
 
-        ai = (ast_array_index*)self->dest;
-        idx = (ast_value*)ai->index;
+        ai = (ast_array_index*)self->m_dest;
+        idx = (ast_value*)ai->m_index;
 
-        if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
+        if (ast_istype(ai->m_index, ast_value) && idx->m_hasvalue && idx->m_cvq == CV_CONST)
             ai = nullptr;
     }
 
@@ -1982,53 +1799,53 @@ bool ast_store_codegen(ast_store *self, ast_function *func, bool lvalue, ir_valu
         ir_instr  *call;
 
         if (lvalue) {
-            compile_error(ast_ctx(self), "array-subscript assignment cannot produce lvalues");
+            compile_error(self->m_context, "array-subscript assignment cannot produce lvalues");
             return false;
         }
 
-        arr = (ast_value*)ai->array;
-        if (!ast_istype(ai->array, ast_value) || !arr->setter) {
-            compile_error(ast_ctx(self), "value has no setter (%s)", arr->name);
+        arr = (ast_value*)ai->m_array;
+        if (!ast_istype(ai->m_array, ast_value) || !arr->m_setter) {
+            compile_error(self->m_context, "value has no setter (%s)", arr->m_name);
             return false;
         }
 
-        cgen = idx->expression.codegen;
+        cgen = idx->m_codegen;
         if (!(*cgen)((ast_expression*)(idx), func, false, &iridx))
             return false;
 
-        cgen = arr->setter->expression.codegen;
-        if (!(*cgen)((ast_expression*)(arr->setter), func, true, &funval))
+        cgen = arr->m_setter->m_codegen;
+        if (!(*cgen)((ast_expression*)(arr->m_setter), func, true, &funval))
             return false;
 
-        cgen = self->source->codegen;
-        if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+        cgen = self->m_source->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_source), func, false, &right))
             return false;
 
-        call = ir_block_create_call(func->curblock, ast_ctx(self), ast_function_label(func, "store"), funval, false);
+        call = ir_block_create_call(func->m_curblock, self->m_context, ast_function_label(func, "store"), funval, false);
         if (!call)
             return false;
         ir_call_param(call, iridx);
         ir_call_param(call, right);
-        self->expression.outr = right;
+        self->m_outr = right;
     }
     else
     {
         /* regular code */
 
-        cgen = self->dest->codegen;
+        cgen = self->m_dest->m_codegen;
         /* lvalue! */
-        if (!(*cgen)((ast_expression*)(self->dest), func, true, &left))
+        if (!(*cgen)((ast_expression*)(self->m_dest), func, true, &left))
             return false;
-        self->expression.outl = left;
+        self->m_outl = left;
 
-        cgen = self->source->codegen;
+        cgen = self->m_source->m_codegen;
         /* rvalue! */
-        if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+        if (!(*cgen)((ast_expression*)(self->m_source), func, false, &right))
             return false;
 
-        if (!ir_block_create_store_op(func->curblock, ast_ctx(self), self->op, left, right))
+        if (!ir_block_create_store_op(func->m_curblock, self->m_context, self->m_op, left, right))
             return false;
-        self->expression.outr = right;
+        self->m_outr = right;
     }
 
     /* Theoretically, an assinment returns its left side as an
@@ -2050,17 +1867,17 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va
 
     /* A binary operation cannot yield an l-value */
     if (lvalue) {
-        compile_error(ast_ctx(self), "not an l-value (binop)");
+        compile_error(self->m_context, "not an l-value (binop)");
         return false;
     }
 
-    if (self->expression.outr) {
-        *out = self->expression.outr;
+    if (self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
     if ((OPTS_FLAG(SHORT_LOGIC) || OPTS_FLAG(PERL_LOGIC)) &&
-        (self->op == INSTR_AND || self->op == INSTR_OR))
+        (self->m_op == INSTR_AND || self->m_op == INSTR_OR))
     {
         /* NOTE: The short-logic path will ignore right_first */
 
@@ -2071,50 +1888,54 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va
         size_t    merge_id;
 
         /* prepare end-block */
-        merge_id = vec_size(func->ir_func->blocks);
-        merge    = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "sce_merge"));
+        merge_id = func->m_ir_func->m_blocks.size();
+        merge    = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "sce_merge"));
 
         /* generate the left expression */
-        cgen = self->left->codegen;
-        if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+        cgen = self->m_left->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_left), func, false, &left))
             return false;
         /* remember the block */
-        from_left = func->curblock;
+        from_left = func->m_curblock;
 
         /* create a new block for the right expression */
-        other = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "sce_other"));
-        if (self->op == INSTR_AND) {
+        other = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "sce_other"));
+        if (self->m_op == INSTR_AND) {
             /* on AND: left==true -> other */
-            if (!ir_block_create_if(func->curblock, ast_ctx(self), left, other, merge))
+            if (!ir_block_create_if(func->m_curblock, self->m_context, left, other, merge))
                 return false;
         } else {
             /* on OR: left==false -> other */
-            if (!ir_block_create_if(func->curblock, ast_ctx(self), left, merge, other))
+            if (!ir_block_create_if(func->m_curblock, self->m_context, left, merge, other))
                 return false;
         }
         /* use the likely flag */
-        vec_last(func->curblock->instr)->likely = true;
+        vec_last(func->m_curblock->m_instr)->m_likely = true;
 
         /* enter the right-expression's block */
-        func->curblock = other;
+        func->m_curblock = other;
         /* generate */
-        cgen = self->right->codegen;
-        if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+        cgen = self->m_right->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_right), func, false, &right))
             return false;
         /* remember block */
-        from_right = func->curblock;
+        from_right = func->m_curblock;
 
         /* jump to the merge block */
-        if (!ir_block_create_jump(func->curblock, ast_ctx(self), merge))
+        if (!ir_block_create_jump(func->m_curblock, self->m_context, merge))
             return false;
 
-        vec_remove(func->ir_func->blocks, merge_id, 1);
-        vec_push(func->ir_func->blocks, merge);
+        algo::shiftback(func->m_ir_func->m_blocks.begin() + merge_id,
+                        func->m_ir_func->m_blocks.end());
+        // FIXME::DELME::
+        //func->m_ir_func->m_blocks[merge_id].release();
+        //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + merge_id);
+        //func->m_ir_func->m_blocks.emplace_back(merge);
 
-        func->curblock = merge;
-        phi = ir_block_create_phi(func->curblock, ast_ctx(self),
+        func->m_curblock = merge;
+        phi = ir_block_create_phi(func->m_curblock, self->m_context,
                                   ast_function_label(func, "sce_value"),
-                                  self->expression.vtype);
+                                  self->m_vtype);
         ir_phi_add(phi, from_left, left);
         ir_phi_add(phi, from_right, right);
         *out = ir_phi_value(phi);
@@ -2123,32 +1944,32 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va
 
         if (!OPTS_FLAG(PERL_LOGIC)) {
             /* cast-to-bool */
-            if (OPTS_FLAG(CORRECT_LOGIC) && (*out)->vtype == TYPE_VECTOR) {
-                *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+            if (OPTS_FLAG(CORRECT_LOGIC) && (*out)->m_vtype == TYPE_VECTOR) {
+                *out = ir_block_create_unary(func->m_curblock, self->m_context,
                                              ast_function_label(func, "sce_bool_v"),
                                              INSTR_NOT_V, *out);
                 if (!*out)
                     return false;
-                *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+                *out = ir_block_create_unary(func->m_curblock, self->m_context,
                                              ast_function_label(func, "sce_bool"),
                                              INSTR_NOT_F, *out);
                 if (!*out)
                     return false;
             }
-            else if (OPTS_FLAG(FALSE_EMPTY_STRINGS) && (*out)->vtype == TYPE_STRING) {
-                *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+            else if (OPTS_FLAG(FALSE_EMPTY_STRINGS) && (*out)->m_vtype == TYPE_STRING) {
+                *out = ir_block_create_unary(func->m_curblock, self->m_context,
                                              ast_function_label(func, "sce_bool_s"),
                                              INSTR_NOT_S, *out);
                 if (!*out)
                     return false;
-                *out = ir_block_create_unary(func->curblock, ast_ctx(self),
+                *out = ir_block_create_unary(func->m_curblock, self->m_context,
                                              ast_function_label(func, "sce_bool"),
                                              INSTR_NOT_F, *out);
                 if (!*out)
                     return false;
             }
             else {
-                *out = ir_block_create_binop(func->curblock, ast_ctx(self),
+                *out = ir_block_create_binop(func->m_curblock, self->m_context,
                                              ast_function_label(func, "sce_bool"),
                                              INSTR_AND, *out, *out);
                 if (!*out)
@@ -2156,32 +1977,32 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va
             }
         }
 
-        self->expression.outr = *out;
+        self->m_outr = *out;
         codegen_output_type(self, *out);
         return true;
     }
 
-    if (self->right_first) {
-        cgen = self->right->codegen;
-        if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+    if (self->m_right_first) {
+        cgen = self->m_right->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_right), func, false, &right))
             return false;
-        cgen = self->left->codegen;
-        if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+        cgen = self->m_left->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_left), func, false, &left))
             return false;
     } else {
-        cgen = self->left->codegen;
-        if (!(*cgen)((ast_expression*)(self->left), func, false, &left))
+        cgen = self->m_left->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_left), func, false, &left))
             return false;
-        cgen = self->right->codegen;
-        if (!(*cgen)((ast_expression*)(self->right), func, false, &right))
+        cgen = self->m_right->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_right), func, false, &right))
             return false;
     }
 
-    *out = ir_block_create_binop(func->curblock, ast_ctx(self), ast_function_label(func, "bin"),
-                                 self->op, left, right);
+    *out = ir_block_create_binop(func->m_curblock, self->m_context, ast_function_label(func, "bin"),
+                                 self->m_op, left, right);
     if (!*out)
         return false;
-    self->expression.outr = *out;
+    self->m_outr = *out;
     codegen_output_type(self, *out);
 
     return true;
@@ -2197,47 +2018,46 @@ bool ast_binstore_codegen(ast_binstore *self, ast_function *func, bool lvalue, i
     ast_array_index *ai = nullptr;
     ir_value        *iridx = nullptr;
 
-    if (lvalue && self->expression.outl) {
-        *out = self->expression.outl;
+    if (lvalue && self->m_outl) {
+        *out = self->m_outl;
         return true;
     }
 
-    if (!lvalue && self->expression.outr) {
-        *out = self->expression.outr;
+    if (!lvalue && self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
-    if (ast_istype(self->dest, ast_array_index))
+    if (ast_istype(self->m_dest, ast_array_index))
     {
 
-        ai = (ast_array_index*)self->dest;
-        idx = (ast_value*)ai->index;
+        ai = (ast_array_index*)self->m_dest;
+        idx = (ast_value*)ai->m_index;
 
-        if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
+        if (ast_istype(ai->m_index, ast_value) && idx->m_hasvalue && idx->m_cvq == CV_CONST)
             ai = nullptr;
     }
 
     /* for a binstore we need both an lvalue and an rvalue for the left side */
     /* rvalue of destination! */
     if (ai) {
-        cgen = idx->expression.codegen;
+        cgen = idx->m_codegen;
         if (!(*cgen)((ast_expression*)(idx), func, false, &iridx))
             return false;
     }
-    cgen = self->dest->codegen;
-    if (!(*cgen)((ast_expression*)(self->dest), func, false, &leftr))
+    cgen = self->m_dest->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_dest), func, false, &leftr))
         return false;
 
     /* source as rvalue only */
-    cgen = self->source->codegen;
-    if (!(*cgen)((ast_expression*)(self->source), func, false, &right))
+    cgen = self->m_source->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_source), func, false, &right))
         return false;
 
     /* now the binary */
-    bin = ir_block_create_binop(func->curblock, ast_ctx(self), ast_function_label(func, "binst"),
-                                self->opbin, leftr, right);
-    self->expression.outr = bin;
-
+    bin = ir_block_create_binop(func->m_curblock, self->m_context, ast_function_label(func, "binst"),
+                                self->m_opbin, leftr, right);
+    self->m_outr = bin;
 
     if (ai) {
         /* we need to call the setter */
@@ -2245,37 +2065,37 @@ bool ast_binstore_codegen(ast_binstore *self, ast_function *func, bool lvalue, i
         ir_instr  *call;
 
         if (lvalue) {
-            compile_error(ast_ctx(self), "array-subscript assignment cannot produce lvalues");
+            compile_error(self->m_context, "array-subscript assignment cannot produce lvalues");
             return false;
         }
 
-        arr = (ast_value*)ai->array;
-        if (!ast_istype(ai->array, ast_value) || !arr->setter) {
-            compile_error(ast_ctx(self), "value has no setter (%s)", arr->name);
+        arr = (ast_value*)ai->m_array;
+        if (!ast_istype(ai->m_array, ast_value) || !arr->m_setter) {
+            compile_error(self->m_context, "value has no setter (%s)", arr->m_name);
             return false;
         }
 
-        cgen = arr->setter->expression.codegen;
-        if (!(*cgen)((ast_expression*)(arr->setter), func, true, &funval))
+        cgen = arr->m_setter->m_codegen;
+        if (!(*cgen)((ast_expression*)(arr->m_setter), func, true, &funval))
             return false;
 
-        call = ir_block_create_call(func->curblock, ast_ctx(self), ast_function_label(func, "store"), funval, false);
+        call = ir_block_create_call(func->m_curblock, self->m_context, ast_function_label(func, "store"), funval, false);
         if (!call)
             return false;
         ir_call_param(call, iridx);
         ir_call_param(call, bin);
-        self->expression.outr = bin;
+        self->m_outr = bin;
     } else {
         /* now store them */
-        cgen = self->dest->codegen;
+        cgen = self->m_dest->m_codegen;
         /* lvalue of destination */
-        if (!(*cgen)((ast_expression*)(self->dest), func, true, &leftl))
+        if (!(*cgen)((ast_expression*)(self->m_dest), func, true, &leftl))
             return false;
-        self->expression.outl = leftl;
+        self->m_outl = leftl;
 
-        if (!ir_block_create_store_op(func->curblock, ast_ctx(self), self->opstore, leftl, bin))
+        if (!ir_block_create_store_op(func->m_curblock, self->m_context, self->m_opstore, leftl, bin))
             return false;
-        self->expression.outr = bin;
+        self->m_outr = bin;
     }
 
     /* Theoretically, an assinment returns its left side as an
@@ -2297,25 +2117,25 @@ bool ast_unary_codegen(ast_unary *self, ast_function *func, bool lvalue, ir_valu
 
     /* An unary operation cannot yield an l-value */
     if (lvalue) {
-        compile_error(ast_ctx(self), "not an l-value (binop)");
+        compile_error(self->m_context, "not an l-value (binop)");
         return false;
     }
 
-    if (self->expression.outr) {
-        *out = self->expression.outr;
+    if (self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
-    cgen = self->operand->codegen;
+    cgen = self->m_operand->m_codegen;
     /* lvalue! */
-    if (!(*cgen)((ast_expression*)(self->operand), func, false, &operand))
+    if (!(*cgen)((ast_expression*)(self->m_operand), func, false, &operand))
         return false;
 
-    *out = ir_block_create_unary(func->curblock, ast_ctx(self), ast_function_label(func, "unary"),
-                                 self->op, operand);
+    *out = ir_block_create_unary(func->m_curblock, self->m_context, ast_function_label(func, "unary"),
+                                 self->m_op, operand);
     if (!*out)
         return false;
-    self->expression.outr = *out;
+    self->m_outr = *out;
 
     return true;
 }
@@ -2331,26 +2151,26 @@ bool ast_return_codegen(ast_return *self, ast_function *func, bool lvalue, ir_va
      * anything...
      */
     if (lvalue) {
-        compile_error(ast_ctx(self), "return-expression is not an l-value");
+        compile_error(self->m_context, "return-expression is not an l-value");
         return false;
     }
 
-    if (self->expression.outr) {
-        compile_error(ast_ctx(self), "internal error: ast_return cannot be reused, it bears no result!");
+    if (self->m_outr) {
+        compile_error(self->m_context, "internal error: ast_return cannot be reused, it bears no result!");
         return false;
     }
-    self->expression.outr = (ir_value*)1;
+    self->m_outr = (ir_value*)1;
 
-    if (self->operand) {
-        cgen = self->operand->codegen;
+    if (self->m_operand) {
+        cgen = self->m_operand->m_codegen;
         /* lvalue! */
-        if (!(*cgen)((ast_expression*)(self->operand), func, false, &operand))
+        if (!(*cgen)((ast_expression*)(self->m_operand), func, false, &operand))
             return false;
 
-        if (!ir_block_create_return(func->curblock, ast_ctx(self), operand))
+        if (!ir_block_create_return(func->m_curblock, self->m_context, operand))
             return false;
     } else {
-        if (!ir_block_create_return(func->curblock, ast_ctx(self), nullptr))
+        if (!ir_block_create_return(func->m_curblock, self->m_context, nullptr))
             return false;
     }
 
@@ -2367,48 +2187,48 @@ bool ast_entfield_codegen(ast_entfield *self, ast_function *func, bool lvalue, i
      * value in a temp.
      */
 
-    if (lvalue && self->expression.outl) {
-        *out = self->expression.outl;
+    if (lvalue && self->m_outl) {
+        *out = self->m_outl;
         return true;
     }
 
-    if (!lvalue && self->expression.outr) {
-        *out = self->expression.outr;
+    if (!lvalue && self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
-    cgen = self->entity->codegen;
-    if (!(*cgen)((ast_expression*)(self->entity), func, false, &ent))
+    cgen = self->m_entity->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_entity), func, false, &ent))
         return false;
 
-    cgen = self->field->codegen;
-    if (!(*cgen)((ast_expression*)(self->field), func, false, &field))
+    cgen = self->m_field->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_field), func, false, &field))
         return false;
 
     if (lvalue) {
         /* address! */
-        *out = ir_block_create_fieldaddress(func->curblock, ast_ctx(self), ast_function_label(func, "efa"),
+        *out = ir_block_create_fieldaddress(func->m_curblock, self->m_context, ast_function_label(func, "efa"),
                                             ent, field);
     } else {
-        *out = ir_block_create_load_from_ent(func->curblock, ast_ctx(self), ast_function_label(func, "efv"),
-                                             ent, field, self->expression.vtype);
+        *out = ir_block_create_load_from_ent(func->m_curblock, self->m_context, ast_function_label(func, "efv"),
+                                             ent, field, self->m_vtype);
         /* Done AFTER error checking:
         codegen_output_type(self, *out);
         */
     }
     if (!*out) {
-        compile_error(ast_ctx(self), "failed to create %s instruction (output type %s)",
+        compile_error(self->m_context, "failed to create %s instruction (output type %s)",
                  (lvalue ? "ADDRESS" : "FIELD"),
-                 type_name[self->expression.vtype]);
+                 type_name[self->m_vtype]);
         return false;
     }
     if (!lvalue)
         codegen_output_type(self, *out);
 
     if (lvalue)
-        self->expression.outl = *out;
+        self->m_outl = *out;
     else
-        self->expression.outr = *out;
+        self->m_outr = *out;
 
     /* Hm that should be it... */
     return true;
@@ -2420,27 +2240,27 @@ bool ast_member_codegen(ast_member *self, ast_function *func, bool lvalue, ir_va
     ir_value *vec;
 
     /* in QC this is always an lvalue */
-    if (lvalue && self->rvalue) {
-        compile_error(ast_ctx(self), "not an l-value (member access)");
+    if (lvalue && self->m_rvalue) {
+        compile_error(self->m_context, "not an l-value (member access)");
         return false;
     }
-    if (self->expression.outl) {
-        *out = self->expression.outl;
+    if (self->m_outl) {
+        *out = self->m_outl;
         return true;
     }
 
-    cgen = self->owner->codegen;
-    if (!(*cgen)((ast_expression*)(self->owner), func, false, &vec))
+    cgen = self->m_owner->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_owner), func, false, &vec))
         return false;
 
-    if (vec->vtype != TYPE_VECTOR &&
-        !(vec->vtype == TYPE_FIELD && self->owner->next->vtype == TYPE_VECTOR))
+    if (vec->m_vtype != TYPE_VECTOR &&
+        !(vec->m_vtype == TYPE_FIELD && self->m_owner->m_next->m_vtype == TYPE_VECTOR))
     {
         return false;
     }
 
-    *out = ir_value_vector_member(vec, self->field);
-    self->expression.outl = *out;
+    *out = ir_value_vector_member(vec, self->m_field);
+    self->m_outl = *out;
 
     return (*out != nullptr);
 }
@@ -2450,17 +2270,17 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
     ast_value *arr;
     ast_value *idx;
 
-    if (!lvalue && self->expression.outr) {
-        *out = self->expression.outr;
+    if (!lvalue && self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
-    if (lvalue && self->expression.outl) {
-        *out = self->expression.outl;
+    if (lvalue && self->m_outl) {
+        *out = self->m_outl;
         return true;
     }
 
-    if (!ast_istype(self->array, ast_value)) {
-        compile_error(ast_ctx(self), "array indexing this way is not supported");
+    if (!ast_istype(self->m_array, ast_value)) {
+        compile_error(self->m_context, "array indexing this way is not supported");
         /* note this would actually be pointer indexing because the left side is
          * not an actual array but (hopefully) an indexable expression.
          * Once we get integer arithmetic, and GADDRESS/GSTORE/GLOAD instruction
@@ -2469,68 +2289,68 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
         return false;
     }
 
-    arr = (ast_value*)self->array;
-    idx = (ast_value*)self->index;
+    arr = (ast_value*)self->m_array;
+    idx = (ast_value*)self->m_index;
 
-    if (!ast_istype(self->index, ast_value) || !idx->hasvalue || idx->cvq != CV_CONST) {
+    if (!ast_istype(self->m_index, ast_value) || !idx->m_hasvalue || idx->m_cvq != CV_CONST) {
         /* Time to use accessor functions */
         ast_expression_codegen *cgen;
         ir_value               *iridx, *funval;
         ir_instr               *call;
 
         if (lvalue) {
-            compile_error(ast_ctx(self), "(.2) array indexing here needs a compile-time constant");
+            compile_error(self->m_context, "(.2) array indexing here needs a compile-time constant");
             return false;
         }
 
-        if (!arr->getter) {
-            compile_error(ast_ctx(self), "value has no getter, don't know how to index it");
+        if (!arr->m_getter) {
+            compile_error(self->m_context, "value has no getter, don't know how to index it");
             return false;
         }
 
-        cgen = self->index->codegen;
-        if (!(*cgen)((ast_expression*)(self->index), func, false, &iridx))
+        cgen = self->m_index->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_index), func, false, &iridx))
             return false;
 
-        cgen = arr->getter->expression.codegen;
-        if (!(*cgen)((ast_expression*)(arr->getter), func, true, &funval))
+        cgen = arr->m_getter->m_codegen;
+        if (!(*cgen)((ast_expression*)(arr->m_getter), func, true, &funval))
             return false;
 
-        call = ir_block_create_call(func->curblock, ast_ctx(self), ast_function_label(func, "fetch"), funval, false);
+        call = ir_block_create_call(func->m_curblock, self->m_context, ast_function_label(func, "fetch"), funval, false);
         if (!call)
             return false;
         ir_call_param(call, iridx);
 
         *out = ir_call_value(call);
-        self->expression.outr = *out;
-        (*out)->vtype = self->expression.vtype;
+        self->m_outr = *out;
+        (*out)->m_vtype = self->m_vtype;
         codegen_output_type(self, *out);
         return true;
     }
 
-    if (idx->expression.vtype == TYPE_FLOAT) {
-        unsigned int arridx = idx->constval.vfloat;
-        if (arridx >= self->array->count)
+    if (idx->m_vtype == TYPE_FLOAT) {
+        unsigned int arridx = idx->m_constval.vfloat;
+        if (arridx >= self->m_array->m_count)
         {
-            compile_error(ast_ctx(self), "array index out of bounds: %i", arridx);
+            compile_error(self->m_context, "array index out of bounds: %i", arridx);
             return false;
         }
-        *out = arr->ir_values[arridx];
+        *out = arr->m_ir_values[arridx];
     }
-    else if (idx->expression.vtype == TYPE_INTEGER) {
-        unsigned int arridx = idx->constval.vint;
-        if (arridx >= self->array->count)
+    else if (idx->m_vtype == TYPE_INTEGER) {
+        unsigned int arridx = idx->m_constval.vint;
+        if (arridx >= self->m_array->m_count)
         {
-            compile_error(ast_ctx(self), "array index out of bounds: %i", arridx);
+            compile_error(self->m_context, "array index out of bounds: %i", arridx);
             return false;
         }
-        *out = arr->ir_values[arridx];
+        *out = arr->m_ir_values[arridx];
     }
     else {
-        compile_error(ast_ctx(self), "array indexing here needs an integer constant");
+        compile_error(self->m_context, "array indexing here needs an integer constant");
         return false;
     }
-    (*out)->vtype = self->expression.vtype;
+    (*out)->m_vtype = self->m_vtype;
     codegen_output_type(self, *out);
     return true;
 }
@@ -2539,12 +2359,12 @@ bool ast_argpipe_codegen(ast_argpipe *self, ast_function *func, bool lvalue, ir_
 {
     *out = nullptr;
     if (lvalue) {
-        compile_error(ast_ctx(self), "argpipe node: not an lvalue");
+        compile_error(self->m_context, "argpipe node: not an lvalue");
         return false;
     }
     (void)func;
     (void)out;
-    compile_error(ast_ctx(self), "TODO: argpipe codegen not implemented");
+    compile_error(self->m_context, "TODO: argpipe codegen not implemented");
     return false;
 }
 
@@ -2567,81 +2387,81 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     (void)out;
     (void)lvalue;
 
-    if (self->expression.outr) {
-        compile_error(ast_ctx(self), "internal error: ast_ifthen cannot be reused, it bears no result!");
+    if (self->m_outr) {
+        compile_error(self->m_context, "internal error: ast_ifthen cannot be reused, it bears no result!");
         return false;
     }
-    self->expression.outr = (ir_value*)1;
+    self->m_outr = (ir_value*)1;
 
     /* generate the condition */
-    cgen = self->cond->codegen;
-    if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+    cgen = self->m_cond->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_cond), func, false, &condval))
         return false;
     /* update the block which will get the jump - because short-logic or ternaries may have changed this */
-    cond = func->curblock;
+    cond = func->m_curblock;
 
     /* try constant folding away the condition */
     if ((folded = fold::cond_ifthen(condval, func, self)) != -1)
         return folded;
 
-    if (self->on_true) {
+    if (self->m_on_true) {
         /* create on-true block */
-        ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "ontrue"));
+        ontrue = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "ontrue"));
         if (!ontrue)
             return false;
 
         /* enter the block */
-        func->curblock = ontrue;
+        func->m_curblock = ontrue;
 
         /* generate */
-        cgen = self->on_true->codegen;
-        if (!(*cgen)((ast_expression*)(self->on_true), func, false, &dummy))
+        cgen = self->m_on_true->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_on_true), func, false, &dummy))
             return false;
 
         /* we now need to work from the current endpoint */
-        ontrue_endblock = func->curblock;
+        ontrue_endblock = func->m_curblock;
     } else
         ontrue = nullptr;
 
     /* on-false path */
-    if (self->on_false) {
+    if (self->m_on_false) {
         /* create on-false block */
-        onfalse = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "onfalse"));
+        onfalse = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "onfalse"));
         if (!onfalse)
             return false;
 
         /* enter the block */
-        func->curblock = onfalse;
+        func->m_curblock = onfalse;
 
         /* generate */
-        cgen = self->on_false->codegen;
-        if (!(*cgen)((ast_expression*)(self->on_false), func, false, &dummy))
+        cgen = self->m_on_false->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_on_false), func, false, &dummy))
             return false;
 
         /* we now need to work from the current endpoint */
-        onfalse_endblock = func->curblock;
+        onfalse_endblock = func->m_curblock;
     } else
         onfalse = nullptr;
 
     /* Merge block were they all merge in to */
-    if (!ontrue || !onfalse || !ontrue_endblock->final || !onfalse_endblock->final)
+    if (!ontrue || !onfalse || !ontrue_endblock->m_final || !onfalse_endblock->m_final)
     {
-        merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "endif"));
+        merge = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "endif"));
         if (!merge)
             return false;
         /* add jumps ot the merge block */
-        if (ontrue && !ontrue_endblock->final && !ir_block_create_jump(ontrue_endblock, ast_ctx(self), merge))
+        if (ontrue && !ontrue_endblock->m_final && !ir_block_create_jump(ontrue_endblock, self->m_context, merge))
             return false;
-        if (onfalse && !onfalse_endblock->final && !ir_block_create_jump(onfalse_endblock, ast_ctx(self), merge))
+        if (onfalse && !onfalse_endblock->m_final && !ir_block_create_jump(onfalse_endblock, self->m_context, merge))
             return false;
 
         /* Now enter the merge block */
-        func->curblock = merge;
+        func->m_curblock = merge;
     }
 
     /* we create the if here, that way all blocks are ordered :)
      */
-    if (!ir_block_create_if(cond, ast_ctx(self), condval,
+    if (!ir_block_create_if(cond, self->m_context, condval,
                             (ontrue  ? ontrue  : merge),
                             (onfalse ? onfalse : merge)))
     {
@@ -2659,7 +2479,7 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
     ir_value *trueval, *falseval;
     ir_instr *phi;
 
-    ir_block *cond = func->curblock;
+    ir_block *cond = func->m_curblock;
     ir_block *cond_out = nullptr;
     ir_block *ontrue, *ontrue_out = nullptr;
     ir_block *onfalse, *onfalse_out = nullptr;
@@ -2675,95 +2495,95 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
      * may still happen, thus we remember a created ir_value and simply return one
      * if it already exists.
      */
-    if (self->expression.outr) {
-        *out = self->expression.outr;
+    if (self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
     /* In the following, contraty to ast_ifthen, we assume both paths exist. */
 
     /* generate the condition */
-    func->curblock = cond;
-    cgen = self->cond->codegen;
-    if (!(*cgen)((ast_expression*)(self->cond), func, false, &condval))
+    func->m_curblock = cond;
+    cgen = self->m_cond->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_cond), func, false, &condval))
         return false;
-    cond_out = func->curblock;
+    cond_out = func->m_curblock;
 
     /* try constant folding away the condition */
     if ((folded = fold::cond_ternary(condval, func, self)) != -1)
         return folded;
 
     /* create on-true block */
-    ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_T"));
+    ontrue = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "tern_T"));
     if (!ontrue)
         return false;
     else
     {
         /* enter the block */
-        func->curblock = ontrue;
+        func->m_curblock = ontrue;
 
         /* generate */
-        cgen = self->on_true->codegen;
-        if (!(*cgen)((ast_expression*)(self->on_true), func, false, &trueval))
+        cgen = self->m_on_true->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_on_true), func, false, &trueval))
             return false;
 
-        ontrue_out = func->curblock;
+        ontrue_out = func->m_curblock;
     }
 
     /* create on-false block */
-    onfalse = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_F"));
+    onfalse = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "tern_F"));
     if (!onfalse)
         return false;
     else
     {
         /* enter the block */
-        func->curblock = onfalse;
+        func->m_curblock = onfalse;
 
         /* generate */
-        cgen = self->on_false->codegen;
-        if (!(*cgen)((ast_expression*)(self->on_false), func, false, &falseval))
+        cgen = self->m_on_false->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_on_false), func, false, &falseval))
             return false;
 
-        onfalse_out = func->curblock;
+        onfalse_out = func->m_curblock;
     }
 
     /* create merge block */
-    merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_out"));
+    merge = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "tern_out"));
     if (!merge)
         return false;
     /* jump to merge block */
-    if (!ir_block_create_jump(ontrue_out, ast_ctx(self), merge))
+    if (!ir_block_create_jump(ontrue_out, self->m_context, merge))
         return false;
-    if (!ir_block_create_jump(onfalse_out, ast_ctx(self), merge))
+    if (!ir_block_create_jump(onfalse_out, self->m_context, merge))
         return false;
 
     /* create if instruction */
-    if (!ir_block_create_if(cond_out, ast_ctx(self), condval, ontrue, onfalse))
+    if (!ir_block_create_if(cond_out, self->m_context, condval, ontrue, onfalse))
         return false;
 
     /* Now enter the merge block */
-    func->curblock = merge;
+    func->m_curblock = merge;
 
     /* Here, now, we need a PHI node
      * but first some sanity checking...
      */
-    if (trueval->vtype != falseval->vtype && trueval->vtype != TYPE_NIL && falseval->vtype != TYPE_NIL) {
+    if (trueval->m_vtype != falseval->m_vtype && trueval->m_vtype != TYPE_NIL && falseval->m_vtype != TYPE_NIL) {
         /* error("ternary with different types on the two sides"); */
-        compile_error(ast_ctx(self), "internal error: ternary operand types invalid");
+        compile_error(self->m_context, "internal error: ternary operand types invalid");
         return false;
     }
 
     /* create PHI */
-    phi = ir_block_create_phi(merge, ast_ctx(self), ast_function_label(func, "phi"), self->expression.vtype);
+    phi = ir_block_create_phi(merge, self->m_context, ast_function_label(func, "phi"), self->m_vtype);
     if (!phi) {
-        compile_error(ast_ctx(self), "internal error: failed to generate phi node");
+        compile_error(self->m_context, "internal error: failed to generate phi node");
         return false;
     }
     ir_phi_add(phi, ontrue_out,  trueval);
     ir_phi_add(phi, onfalse_out, falseval);
 
-    self->expression.outr = ir_phi_value(phi);
-    *out = self->expression.outr;
+    self->m_outr = ir_phi_value(phi);
+    *out = self->m_outr;
 
     codegen_output_type(self, *out);
 
@@ -2800,11 +2620,11 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
     (void)lvalue;
     (void)out;
 
-    if (self->expression.outr) {
-        compile_error(ast_ctx(self), "internal error: ast_loop cannot be reused, it bears no result!");
+    if (self->m_outr) {
+        compile_error(self->m_context, "internal error: ast_loop cannot be reused, it bears no result!");
         return false;
     }
-    self->expression.outr = (ir_value*)1;
+    self->m_outr = (ir_value*)1;
 
     /* NOTE:
      * Should we ever need some kind of block ordering, better make this function
@@ -2815,22 +2635,22 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
     /* initexpr doesn't get its own block, it's pointless, it could create more blocks
      * anyway if for example it contains a ternary.
      */
-    if (self->initexpr)
+    if (self->m_initexpr)
     {
-        cgen = self->initexpr->codegen;
-        if (!(*cgen)((ast_expression*)(self->initexpr), func, false, &dummy))
+        cgen = self->m_initexpr->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_initexpr), func, false, &dummy))
             return false;
     }
 
     /* Store the block from which we enter this chaos */
-    bin = func->curblock;
+    bin = func->m_curblock;
 
     /* The pre-loop condition needs its own block since we
      * need to be able to jump to the start of that expression.
      */
-    if (self->precond)
+    if (self->m_precond)
     {
-        bprecond = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "pre_loop_cond"));
+        bprecond = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "pre_loop_cond"));
         if (!bprecond)
             return false;
 
@@ -2838,14 +2658,14 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         bcontinue = bprecond;
 
         /* enter */
-        func->curblock = bprecond;
+        func->m_curblock = bprecond;
 
         /* generate */
-        cgen = self->precond->codegen;
-        if (!(*cgen)((ast_expression*)(self->precond), func, false, &precond))
+        cgen = self->m_precond->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_precond), func, false, &precond))
             return false;
 
-        end_bprecond = func->curblock;
+        end_bprecond = func->m_curblock;
     } else {
         bprecond = end_bprecond = nullptr;
     }
@@ -2853,8 +2673,8 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
     /* Now the next blocks won't be ordered nicely, but we need to
      * generate them this early for 'break' and 'continue'.
      */
-    if (self->increment) {
-        bincrement = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "loop_increment"));
+    if (self->m_increment) {
+        bincrement = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "loop_increment"));
         if (!bincrement)
             return false;
         bcontinue = bincrement; /* increment comes before the pre-loop-condition */
@@ -2862,8 +2682,8 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         bincrement = end_bincrement = nullptr;
     }
 
-    if (self->postcond) {
-        bpostcond = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "post_loop_cond"));
+    if (self->m_postcond) {
+        bpostcond = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "post_loop_cond"));
         if (!bpostcond)
             return false;
         bcontinue = bpostcond; /* postcond comes before the increment */
@@ -2871,70 +2691,70 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         bpostcond = end_bpostcond = nullptr;
     }
 
-    bout_id = vec_size(func->ir_func->blocks);
-    bout = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "after_loop"));
+    bout_id = func->m_ir_func->m_blocks.size();
+    bout = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "after_loop"));
     if (!bout)
         return false;
     bbreak = bout;
 
     /* The loop body... */
-    /* if (self->body) */
+    /* if (self->m_body) */
     {
-        bbody = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "loop_body"));
+        bbody = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "loop_body"));
         if (!bbody)
             return false;
 
         /* enter */
-        func->curblock = bbody;
+        func->m_curblock = bbody;
 
-        func->breakblocks.push_back(bbreak);
+        func->m_breakblocks.push_back(bbreak);
         if (bcontinue)
-            func->continueblocks.push_back(bcontinue);
+            func->m_continueblocks.push_back(bcontinue);
         else
-            func->continueblocks.push_back(bbody);
+            func->m_continueblocks.push_back(bbody);
 
         /* generate */
-        if (self->body) {
-            cgen = self->body->codegen;
-            if (!(*cgen)((ast_expression*)(self->body), func, false, &dummy))
+        if (self->m_body) {
+            cgen = self->m_body->m_codegen;
+            if (!(*cgen)((ast_expression*)(self->m_body), func, false, &dummy))
                 return false;
         }
 
-        end_bbody = func->curblock;
-        func->breakblocks.pop_back();
-        func->continueblocks.pop_back();
+        end_bbody = func->m_curblock;
+        func->m_breakblocks.pop_back();
+        func->m_continueblocks.pop_back();
     }
 
     /* post-loop-condition */
-    if (self->postcond)
+    if (self->m_postcond)
     {
         /* enter */
-        func->curblock = bpostcond;
+        func->m_curblock = bpostcond;
 
         /* generate */
-        cgen = self->postcond->codegen;
-        if (!(*cgen)((ast_expression*)(self->postcond), func, false, &postcond))
+        cgen = self->m_postcond->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_postcond), func, false, &postcond))
             return false;
 
-        end_bpostcond = func->curblock;
+        end_bpostcond = func->m_curblock;
     }
 
     /* The incrementor */
-    if (self->increment)
+    if (self->m_increment)
     {
         /* enter */
-        func->curblock = bincrement;
+        func->m_curblock = bincrement;
 
         /* generate */
-        cgen = self->increment->codegen;
-        if (!(*cgen)((ast_expression*)(self->increment), func, false, &dummy))
+        cgen = self->m_increment->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_increment), func, false, &dummy))
             return false;
 
-        end_bincrement = func->curblock;
+        end_bincrement = func->m_curblock;
     }
 
     /* In any case now, we continue from the outgoing block */
-    func->curblock = bout;
+    func->m_curblock = bout;
 
     /* Now all blocks are in place */
     /* From 'bin' we jump to whatever comes first */
@@ -2946,7 +2766,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
     else                 tmpblock = bout;
     */
 
-    if (!ir_block_create_jump(bin, ast_ctx(self), tmpblock))
+    if (!ir_block_create_jump(bin, self->m_context, tmpblock))
         return false;
 
     /* From precond */
@@ -2961,12 +2781,12 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         */
 
         onfalse = bout;
-        if (self->pre_not) {
+        if (self->m_pre_not) {
             tmpblock = ontrue;
             ontrue   = onfalse;
             onfalse  = tmpblock;
         }
-        if (!ir_block_create_if(end_bprecond, ast_ctx(self), precond, ontrue, onfalse))
+        if (!ir_block_create_if(end_bprecond, self->m_context, precond, ontrue, onfalse))
             return false;
     }
 
@@ -2977,7 +2797,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         else if (bpostcond)  tmpblock = bpostcond;
         else if (bprecond)   tmpblock = bprecond;
         else                 tmpblock = bbody;
-        if (!end_bbody->final && !ir_block_create_jump(end_bbody, ast_ctx(self), tmpblock))
+        if (!end_bbody->m_final && !ir_block_create_jump(end_bbody, self->m_context, tmpblock))
             return false;
     }
 
@@ -2988,7 +2808,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         else if (bprecond)   tmpblock = bprecond;
         else if (bbody)      tmpblock = bbody;
         else                 tmpblock = bout;
-        if (!ir_block_create_jump(end_bincrement, ast_ctx(self), tmpblock))
+        if (!ir_block_create_jump(end_bincrement, self->m_context, tmpblock))
             return false;
     }
 
@@ -3005,18 +2825,22 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
         */
 
         onfalse = bout;
-        if (self->post_not) {
+        if (self->m_post_not) {
             tmpblock = ontrue;
             ontrue   = onfalse;
             onfalse  = tmpblock;
         }
-        if (!ir_block_create_if(end_bpostcond, ast_ctx(self), postcond, ontrue, onfalse))
+        if (!ir_block_create_if(end_bpostcond, self->m_context, postcond, ontrue, onfalse))
             return false;
     }
 
     /* Move 'bout' to the end */
-    vec_remove(func->ir_func->blocks, bout_id, 1);
-    vec_push(func->ir_func->blocks, bout);
+    algo::shiftback(func->m_ir_func->m_blocks.begin() + bout_id,
+                    func->m_ir_func->m_blocks.end());
+    // FIXME::DELME::
+    //func->m_ir_func->m_blocks[bout_id].release(); // it's a vector<unique_ptr<>>
+    //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + bout_id);
+    //func->m_ir_func->m_blocks.emplace_back(bout);
 
     return true;
 }
@@ -3028,27 +2852,27 @@ bool ast_breakcont_codegen(ast_breakcont *self, ast_function *func, bool lvalue,
     *out = nullptr;
 
     if (lvalue) {
-        compile_error(ast_ctx(self), "break/continue expression is not an l-value");
+        compile_error(self->m_context, "break/continue expression is not an l-value");
         return false;
     }
 
-    if (self->expression.outr) {
-        compile_error(ast_ctx(self), "internal error: ast_breakcont cannot be reused!");
+    if (self->m_outr) {
+        compile_error(self->m_context, "internal error: ast_breakcont cannot be reused!");
         return false;
     }
-    self->expression.outr = (ir_value*)1;
+    self->m_outr = (ir_value*)1;
 
-    if (self->is_continue)
-        target = func->continueblocks[func->continueblocks.size()-1-self->levels];
+    if (self->m_is_continue)
+        target = func->m_continueblocks[func->m_continueblocks.size()-1-self->m_levels];
     else
-        target = func->breakblocks[func->breakblocks.size()-1-self->levels];
+        target = func->m_breakblocks[func->m_breakblocks.size()-1-self->m_levels];
 
     if (!target) {
-        compile_error(ast_ctx(self), "%s is lacking a target block", (self->is_continue ? "continue" : "break"));
+        compile_error(self->m_context, "%s is lacking a target block", (self->m_is_continue ? "continue" : "break"));
         return false;
     }
 
-    if (!ir_block_create_jump(func->curblock, ast_ctx(self), target))
+    if (!ir_block_create_jump(func->m_curblock, self->m_context, target))
         return false;
     return true;
 }
@@ -3072,91 +2896,95 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     uint16_t  cmpinstr;
 
     if (lvalue) {
-        compile_error(ast_ctx(self), "switch expression is not an l-value");
+        compile_error(self->m_context, "switch expression is not an l-value");
         return false;
     }
 
-    if (self->expression.outr) {
-        compile_error(ast_ctx(self), "internal error: ast_switch cannot be reused!");
+    if (self->m_outr) {
+        compile_error(self->m_context, "internal error: ast_switch cannot be reused!");
         return false;
     }
-    self->expression.outr = (ir_value*)1;
+    self->m_outr = (ir_value*)1;
 
     (void)lvalue;
     (void)out;
 
-    cgen = self->operand->codegen;
-    if (!(*cgen)((ast_expression*)(self->operand), func, false, &irop))
+    cgen = self->m_operand->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_operand), func, false, &irop))
         return false;
 
-    if (self->cases.empty())
+    if (self->m_cases.empty())
         return true;
 
-    cmpinstr = type_eq_instr[irop->vtype];
+    cmpinstr = type_eq_instr[irop->m_vtype];
     if (cmpinstr >= VINSTR_END) {
-        ast_type_to_string(self->operand, typestr, sizeof(typestr));
-        compile_error(ast_ctx(self), "invalid type to perform a switch on: %s", typestr);
+        ast_type_to_string(self->m_operand, typestr, sizeof(typestr));
+        compile_error(self->m_context, "invalid type to perform a switch on: %s", typestr);
         return false;
     }
 
-    bout_id = vec_size(func->ir_func->blocks);
-    bout = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "after_switch"));
+    bout_id = func->m_ir_func->m_blocks.size();
+    bout = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "after_switch"));
     if (!bout)
         return false;
 
     /* setup the break block */
-    func->breakblocks.push_back(bout);
+    func->m_breakblocks.push_back(bout);
 
     /* Now create all cases */
-    for (auto &it : self->cases) {
+    for (auto &it : self->m_cases) {
         ir_value *cond, *val;
         ir_block *bcase, *bnot;
         size_t bnot_id;
 
         ast_switch_case *swcase = &it;
 
-        if (swcase->value) {
+        if (swcase->m_value) {
             /* A regular case */
             /* generate the condition operand */
-            cgen = swcase->value->codegen;
-            if (!(*cgen)((ast_expression*)(swcase->value), func, false, &val))
+            cgen = swcase->m_value->m_codegen;
+            if (!(*cgen)((ast_expression*)(swcase->m_value), func, false, &val))
                 return false;
             /* generate the condition */
-            cond = ir_block_create_binop(func->curblock, ast_ctx(self), ast_function_label(func, "switch_eq"), cmpinstr, irop, val);
+            cond = ir_block_create_binop(func->m_curblock, self->m_context, ast_function_label(func, "switch_eq"), cmpinstr, irop, val);
             if (!cond)
                 return false;
 
-            bcase = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "case"));
-            bnot_id = vec_size(func->ir_func->blocks);
-            bnot = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "not_case"));
+            bcase = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "case"));
+            bnot_id = func->m_ir_func->m_blocks.size();
+            bnot = ir_function_create_block(self->m_context, func->m_ir_func, ast_function_label(func, "not_case"));
             if (!bcase || !bnot)
                 return false;
             if (set_def_bfall_to) {
                 set_def_bfall_to = false;
                 def_bfall_to = bcase;
             }
-            if (!ir_block_create_if(func->curblock, ast_ctx(self), cond, bcase, bnot))
+            if (!ir_block_create_if(func->m_curblock, self->m_context, cond, bcase, bnot))
                 return false;
 
             /* Make the previous case-end fall through */
-            if (bfall && !bfall->final) {
-                if (!ir_block_create_jump(bfall, ast_ctx(self), bcase))
+            if (bfall && !bfall->m_final) {
+                if (!ir_block_create_jump(bfall, self->m_context, bcase))
                     return false;
             }
 
             /* enter the case */
-            func->curblock = bcase;
-            cgen = swcase->code->codegen;
-            if (!(*cgen)((ast_expression*)swcase->code, func, false, &dummy))
+            func->m_curblock = bcase;
+            cgen = swcase->m_code->m_codegen;
+            if (!(*cgen)((ast_expression*)swcase->m_code, func, false, &dummy))
                 return false;
 
             /* remember this block to fall through from */
-            bfall = func->curblock;
+            bfall = func->m_curblock;
 
             /* enter the else and move it down */
-            func->curblock = bnot;
-            vec_remove(func->ir_func->blocks, bnot_id, 1);
-            vec_push(func->ir_func->blocks, bnot);
+            func->m_curblock = bnot;
+            algo::shiftback(func->m_ir_func->m_blocks.begin() + bnot_id,
+                            func->m_ir_func->m_blocks.end());
+            // FIXME::DELME::
+            //func->m_ir_func->m_blocks[bnot_id].release();
+            //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + bnot_id);
+            //func->m_ir_func->m_blocks.emplace_back(bnot);
         } else {
             /* The default case */
             /* Remember where to fall through from: */
@@ -3170,9 +2998,9 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
     }
 
     /* Jump from the last bnot to bout */
-    if (bfall && !bfall->final && !ir_block_create_jump(bfall, ast_ctx(self), bout)) {
+    if (bfall && !bfall->m_final && !ir_block_create_jump(bfall, self->m_context, bout)) {
         /*
-        astwarning(ast_ctx(bfall), WARN_???, "missing break after last case");
+        astwarning(bfall->m_context, WARN_???, "missing break after last case");
         */
         return false;
     }
@@ -3182,39 +3010,43 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
         ir_block *bcase;
 
         /* No need to create an extra block */
-        bcase = func->curblock;
+        bcase = func->m_curblock;
 
         /* Insert the fallthrough jump */
-        if (def_bfall && !def_bfall->final) {
-            if (!ir_block_create_jump(def_bfall, ast_ctx(self), bcase))
+        if (def_bfall && !def_bfall->m_final) {
+            if (!ir_block_create_jump(def_bfall, self->m_context, bcase))
                 return false;
         }
 
         /* Now generate the default code */
-        cgen = def_case->code->codegen;
-        if (!(*cgen)((ast_expression*)def_case->code, func, false, &dummy))
+        cgen = def_case->m_code->m_codegen;
+        if (!(*cgen)((ast_expression*)def_case->m_code, func, false, &dummy))
             return false;
 
         /* see if we need to fall through */
-        if (def_bfall_to && !func->curblock->final)
+        if (def_bfall_to && !func->m_curblock->m_final)
         {
-            if (!ir_block_create_jump(func->curblock, ast_ctx(self), def_bfall_to))
+            if (!ir_block_create_jump(func->m_curblock, self->m_context, def_bfall_to))
                 return false;
         }
     }
 
     /* Jump from the last bnot to bout */
-    if (!func->curblock->final && !ir_block_create_jump(func->curblock, ast_ctx(self), bout))
+    if (!func->m_curblock->m_final && !ir_block_create_jump(func->m_curblock, self->m_context, bout))
         return false;
     /* enter the outgoing block */
-    func->curblock = bout;
+    func->m_curblock = bout;
 
     /* restore the break block */
-    func->breakblocks.pop_back();
+    func->m_breakblocks.pop_back();
 
     /* Move 'bout' to the end, it's nicer */
-    vec_remove(func->ir_func->blocks, bout_id, 1);
-    vec_push(func->ir_func->blocks, bout);
+    algo::shiftback(func->m_ir_func->m_blocks.begin() + bout_id,
+                    func->m_ir_func->m_blocks.end());
+    // FIXME::DELME::
+    //func->m_ir_func->m_blocks[bout_id].release();
+    //func->m_ir_func->m_blocks.erase(func->m_ir_func->m_blocks.begin() + bout_id);
+    //func->m_ir_func->m_blocks.emplace_back(bout);
 
     return true;
 }
@@ -3223,33 +3055,33 @@ bool ast_label_codegen(ast_label *self, ast_function *func, bool lvalue, ir_valu
 {
     ir_value *dummy;
 
-    if (self->undefined) {
-        compile_error(ast_ctx(self), "internal error: ast_label never defined");
+    if (self->m_undefined) {
+        compile_error(self->m_context, "internal error: ast_label never defined");
         return false;
     }
 
     *out = nullptr;
     if (lvalue) {
-        compile_error(ast_ctx(self), "internal error: ast_label cannot be an lvalue");
+        compile_error(self->m_context, "internal error: ast_label cannot be an lvalue");
         return false;
     }
 
     /* simply create a new block and jump to it */
-    self->irblock = ir_function_create_block(ast_ctx(self), func->ir_func, self->name);
-    if (!self->irblock) {
-        compile_error(ast_ctx(self), "failed to allocate label block `%s`", self->name);
+    self->m_irblock = ir_function_create_block(self->m_context, func->m_ir_func, self->m_name);
+    if (!self->m_irblock) {
+        compile_error(self->m_context, "failed to allocate label block `%s`", self->m_name);
         return false;
     }
-    if (!func->curblock->final) {
-        if (!ir_block_create_jump(func->curblock, ast_ctx(self), self->irblock))
+    if (!func->m_curblock->m_final) {
+        if (!ir_block_create_jump(func->m_curblock, self->m_context, self->m_irblock))
             return false;
     }
 
     /* enter the new block */
-    func->curblock = self->irblock;
+    func->m_curblock = self->m_irblock;
 
     /* Generate all the leftover gotos */
-    for (auto &it : self->gotos) {
+    for (auto &it : self->m_gotos) {
         if (!ast_goto_codegen(it, func, false, &dummy))
             return false;
     }
@@ -3261,23 +3093,23 @@ bool ast_goto_codegen(ast_goto *self, ast_function *func, bool lvalue, ir_value
 {
     *out = nullptr;
     if (lvalue) {
-        compile_error(ast_ctx(self), "internal error: ast_goto cannot be an lvalue");
+        compile_error(self->m_context, "internal error: ast_goto cannot be an lvalue");
         return false;
     }
 
-    if (self->target->irblock) {
-        if (self->irblock_from) {
+    if (self->m_target->m_irblock) {
+        if (self->m_irblock_from) {
             /* we already tried once, this is the callback */
-            self->irblock_from->final = false;
-            if (!ir_block_create_goto(self->irblock_from, ast_ctx(self), self->target->irblock)) {
-                compile_error(ast_ctx(self), "failed to generate goto to `%s`", self->name);
+            self->m_irblock_from->m_final = false;
+            if (!ir_block_create_goto(self->m_irblock_from, self->m_context, self->m_target->m_irblock)) {
+                compile_error(self->m_context, "failed to generate goto to `%s`", self->m_name);
                 return false;
             }
         }
         else
         {
-            if (!ir_block_create_goto(func->curblock, ast_ctx(self), self->target->irblock)) {
-                compile_error(ast_ctx(self), "failed to generate goto to `%s`", self->name);
+            if (!ir_block_create_goto(func->m_curblock, self->m_context, self->m_target->m_irblock)) {
+                compile_error(self->m_context, "failed to generate goto to `%s`", self->m_name);
                 return false;
             }
         }
@@ -3287,9 +3119,9 @@ bool ast_goto_codegen(ast_goto *self, ast_function *func, bool lvalue, ir_value
         /* the target has not yet been created...
          * close this block in a sneaky way:
          */
-        func->curblock->final = true;
-        self->irblock_from = func->curblock;
-        ast_label_register_goto(self->target, self);
+        func->m_curblock->m_final = true;
+        self->m_irblock_from = func->m_curblock;
+        ast_label_register_goto(self->m_target, self);
     }
 
     return true;
@@ -3303,33 +3135,33 @@ bool ast_state_codegen(ast_state *self, ast_function *func, bool lvalue, ir_valu
     ir_value *frameval, *thinkval;
 
     if (lvalue) {
-        compile_error(ast_ctx(self), "not an l-value (state operation)");
+        compile_error(self->m_context, "not an l-value (state operation)");
         return false;
     }
-    if (self->expression.outr) {
-        compile_error(ast_ctx(self), "internal error: ast_state cannot be reused!");
+    if (self->m_outr) {
+        compile_error(self->m_context, "internal error: ast_state cannot be reused!");
         return false;
     }
     *out = nullptr;
 
-    cgen = self->framenum->codegen;
-    if (!(*cgen)((ast_expression*)(self->framenum), func, false, &frameval))
+    cgen = self->m_framenum->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_framenum), func, false, &frameval))
         return false;
     if (!frameval)
         return false;
 
-    cgen = self->nextthink->codegen;
-    if (!(*cgen)((ast_expression*)(self->nextthink), func, false, &thinkval))
+    cgen = self->m_nextthink->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_nextthink), func, false, &thinkval))
         return false;
     if (!frameval)
         return false;
 
-    if (!ir_block_create_state_op(func->curblock, ast_ctx(self), frameval, thinkval)) {
-        compile_error(ast_ctx(self), "failed to create STATE instruction");
+    if (!ir_block_create_state_op(func->m_curblock, self->m_context, frameval, thinkval)) {
+        compile_error(self->m_context, "failed to create STATE instruction");
         return false;
     }
 
-    self->expression.outr = (ir_value*)1;
+    self->m_outr = (ir_value*)1;
     return true;
 }
 
@@ -3343,25 +3175,25 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
 
     /* return values are never lvalues */
     if (lvalue) {
-        compile_error(ast_ctx(self), "not an l-value (function call)");
+        compile_error(self->m_context, "not an l-value (function call)");
         return false;
     }
 
-    if (self->expression.outr) {
-        *out = self->expression.outr;
+    if (self->m_outr) {
+        *out = self->m_outr;
         return true;
     }
 
-    cgen = self->func->codegen;
-    if (!(*cgen)((ast_expression*)(self->func), func, false, &funval))
+    cgen = self->m_func->m_codegen;
+    if (!(*cgen)((ast_expression*)(self->m_func), func, false, &funval))
         return false;
     if (!funval)
         return false;
 
     /* parameters */
-    for (auto &it : self->params) {
+    for (auto &it : self->m_params) {
         ir_value *param;
-        cgen = it->codegen;
+        cgen = it->m_codegen;
         if (!(*cgen)(it, func, false, &param))
             return false;
         if (!param)
@@ -3370,22 +3202,22 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
     }
 
     /* varargs counter */
-    if (self->va_count) {
+    if (self->m_va_count) {
         ir_value   *va_count;
-        ir_builder *builder = func->curblock->owner->owner;
-        cgen = self->va_count->codegen;
-        if (!(*cgen)((ast_expression*)(self->va_count), func, false, &va_count))
+        ir_builder *builder = func->m_curblock->m_owner->m_owner;
+        cgen = self->m_va_count->m_codegen;
+        if (!(*cgen)((ast_expression*)(self->m_va_count), func, false, &va_count))
             return false;
-        if (!ir_block_create_store_op(func->curblock, ast_ctx(self), INSTR_STORE_F,
+        if (!ir_block_create_store_op(func->m_curblock, self->m_context, INSTR_STORE_F,
                                       ir_builder_get_va_count(builder), va_count))
         {
             return false;
         }
     }
 
-    callinstr = ir_block_create_call(func->curblock, ast_ctx(self),
+    callinstr = ir_block_create_call(func->m_curblock, self->m_context,
                                      ast_function_label(func, "call"),
-                                     funval, !!(self->func->flags & AST_FLAG_NORETURN));
+                                     funval, !!(self->m_func->m_flags & AST_FLAG_NORETURN));
     if (!callinstr)
         return false;
 
@@ -3393,7 +3225,7 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
         ir_call_param(callinstr, it);
 
     *out = ir_call_value(callinstr);
-    self->expression.outr = *out;
+    self->m_outr = *out;
 
     codegen_output_type(self, *out);
 
diff --git a/ast.h b/ast.h
index 09f901a30542d539a5e2a2f2c375bb7db7103921..354ce05ee48690df0e1ff75e70c2ff84d35ad9cb 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -93,9 +93,7 @@ enum {
     TYPE_ast_state        /* 22 */
 };
 
-#define ast_istype(x, t) ( ((ast_node*)x)->nodetype == (TYPE_##t) )
-#define ast_ctx(node) (((ast_node*)(node))->context)
-#define ast_side_effects(node) (((ast_node*)(node))->side_effects)
+#define ast_istype(x, t) ( (x)->m_node_type == (TYPE_##t) )
 
 /* Node interface with common components
  */
@@ -103,25 +101,32 @@ typedef void ast_node_delete(ast_node*);
 
 struct ast_node
 {
-    lex_ctx_t context;
+    ast_node() = delete;
+    ast_node(lex_ctx_t, int nodetype);
+    virtual ~ast_node();
+
+    lex_ctx_t m_context;
     /* I don't feel comfortable using keywords like 'delete' as names... */
-    ast_node_delete *destroy;
-    int              nodetype;
-    /* keep: if a node contains this node, 'keep'
+    int              m_node_type;
+    /* keep_node: if a node contains this node, 'keep_node'
      * prevents its dtor from destroying this node as well.
      */
-    bool             keep;
-    bool             side_effects;
+    bool             m_keep_node;
+    bool             m_side_effects;
+
+    void propagate_side_effects(ast_node *other) const;
 };
 
-#define ast_delete(x) (*( ((ast_node*)(x))->destroy ))((ast_node*)(x))
-#define ast_unref(x) do                \
-{                                      \
-    if (! (((ast_node*)(x))->keep) ) { \
-        ast_delete(x);                 \
-    }                                  \
+#define ast_unref(x) do        \
+{                              \
+    if (! (x)->m_keep_node ) { \
+        delete (x);            \
+    }                          \
 } while(0)
 
+enum class ast_copy_type_t { value };
+static const ast_copy_type_t ast_copy_type = ast_copy_type_t::value;
+
 /* Expression interface
  *
  * Any expression or block returns an ir_value, and needs
@@ -141,29 +146,37 @@ typedef bool ast_expression_codegen(ast_expression*,
  * type `expression`, so the ast_ident's codegen would search for
  * variables through the environment (or functions, constants...).
  */
-struct ast_expression {
-    ast_expression() {}
+struct ast_expression : ast_node {
+    ast_expression() = delete;
+    ast_expression(lex_ctx_t ctx, int nodetype, qc_type vtype);
+    ast_expression(lex_ctx_t ctx, int nodetype);
+    ~ast_expression();
+    ast_expression(ast_copy_type_t, int nodetype, const ast_expression&);
+    ast_expression(ast_copy_type_t, const ast_expression&);
+
+    static ast_expression *shallow_type(lex_ctx_t ctx, qc_type vtype);
+
+    bool compare_type(const ast_expression &other) const;
+    void adopt_type(const ast_expression &other);
 
-    ast_node                node;
-    ast_expression_codegen *codegen;
-    int                     vtype;
-    ast_expression         *next;
+    qc_type                 m_vtype = TYPE_VOID;
+    ast_expression         *m_next = nullptr;
     /* arrays get a member-count */
-    size_t                  count;
-    std::vector<ast_value*> params;
+    size_t                  m_count = 0;
+    std::vector<std::unique_ptr<ast_value>> m_type_params;
 
-    ast_flag_t              flags;
+    ast_flag_t              m_flags = 0;
     /* void foo(string...) gets varparam set as a restriction
      * for variadic parameters
      */
-    ast_expression         *varparam;
+    ast_expression         *m_varparam = nullptr;
     /* The codegen functions should store their output values
      * so we can call it multiple times without re-evaluating.
      * Store lvalue and rvalue seperately though. So that
      * ast_entfield for example can generate both if required.
      */
-    ir_value               *outl;
-    ir_value               *outr;
+    ir_value               *m_outl = nullptr;
+    ir_value               *m_outr = nullptr;
 };
 
 /* Value
@@ -174,72 +187,62 @@ struct ast_expression {
  * is like creating a 'float foo', foo serving as the type's name.
  */
 union basic_value_t {
-    qcfloat_t vfloat;
-    int vint;
-    vec3_t vvec;
-    const char *vstring;
-    int ventity;
+    qcfloat_t     vfloat;
+    int           vint;
+    vec3_t        vvec;
+    const char   *vstring;
+    int           ventity;
     ast_function *vfunc;
-    ast_value *vfield;
+    ast_value    *vfield;
 };
 
-struct ast_value
+struct ast_value : ast_expression
 {
-    ast_expression expression;
+    ast_value() = delete;
+    ast_value(lex_ctx_t ctx, const std::string &name, qc_type qctype);
+    ~ast_value();
 
-    const char *name;
-    const char *desc;
+    ast_value(ast_copy_type_t, const ast_expression&, const std::string&);
+    ast_value(ast_copy_type_t, const ast_value&);
+    ast_value(ast_copy_type_t, const ast_value&, const std::string&);
 
-    const char *argcounter;
+    void add_param(ast_value*);
 
-    int cvq;     /* const/var qualifier */
-    bool isfield; /* this declares a field */
-    bool isimm;   /* an immediate, not just const */
-    bool hasvalue;
-    bool inexact; /* inexact coming from folded expression */
-    basic_value_t constval;
+    std::string m_name;
+    std::string m_desc;
+
+    const char *m_argcounter = nullptr;
+
+    int m_cvq = CV_NONE;     /* const/var qualifier */
+    bool m_isfield = false; /* this declares a field */
+    bool m_isimm = false;   /* an immediate, not just const */
+    bool m_hasvalue = false;
+    bool m_inexact = false; /* inexact coming from folded expression */
+    basic_value_t m_constval;
     /* for TYPE_ARRAY we have an optional vector
      * of constants when an initializer list
      * was provided.
      */
-    std::vector<basic_value_t> initlist;
+    std::vector<basic_value_t> m_initlist;
 
     /* usecount for the parser */
-    size_t uses;
+    size_t m_uses = 0;
 
-    ir_value *ir_v;
-    ir_value **ir_values;
-    size_t ir_value_count;
+    ir_value *m_ir_v = nullptr;
+    ir_value **m_ir_values = nullptr;
+    size_t m_ir_value_count = 0;
 
     /* ONLY for arrays in progs version up to 6 */
-    ast_value *setter;
-    ast_value *getter;
+    ast_value *m_setter = nullptr;
+    ast_value *m_getter = nullptr;
 
 
-    bool intrinsic; /* true if associated with intrinsic */
+    bool m_intrinsic = false; /* true if associated with intrinsic */
 };
 
-ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int qctype);
-ast_value* ast_value_copy(const ast_value *self);
-/* This will NOT delete an underlying ast_function */
-void ast_value_delete(ast_value*);
-
-bool ast_value_set_name(ast_value*, const char *name);
-
-/*
-bool ast_value_codegen(ast_value*, ast_function*, bool lvalue, ir_value**);
-bool ast_local_codegen(ast_value *self, ir_function *func, bool isparam);
-*/
-
 bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield);
 
-void ast_value_params_add(ast_value*, ast_value*);
-
-bool ast_compare_type(ast_expression *a, ast_expression *b);
-ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex);
-#define ast_type_adopt(a, b) ast_type_adopt_impl((ast_expression*)(a), (ast_expression*)(b))
-void ast_type_adopt_impl(ast_expression *self, const ast_expression *other);
-void ast_type_to_string(ast_expression *e, char *buf, size_t bufsize);
+void ast_type_to_string(const ast_expression *e, char *buf, size_t bufsize);
 
 enum ast_binary_ref {
     AST_REF_NONE  = 0,
@@ -253,34 +256,36 @@ enum ast_binary_ref {
  *
  * A value-returning binary expression.
  */
-struct ast_binary
+struct ast_binary : ast_expression
 {
-    ast_expression expression;
-    int op;
-    ast_expression *left;
-    ast_expression *right;
-    ast_binary_ref refs;
-    bool right_first;
+    ast_binary() = delete;
+    ast_binary(lex_ctx_t ctx, int op, ast_expression *l, ast_expression *r);
+    ~ast_binary();
+
+    int m_op;
+    ast_expression *m_left;
+    ast_expression *m_right;
+    ast_binary_ref m_refs;
+    bool m_right_first;
 };
-ast_binary* ast_binary_new(lex_ctx_t    ctx,
-                           int        op,
-                           ast_expression *left,
-                           ast_expression *right);
 
 /* Binstore
  *
  * An assignment including a binary expression with the source as left operand.
  * Eg. a += b; is a binstore { INSTR_STORE, INSTR_ADD, a, b }
  */
-struct ast_binstore
+struct ast_binstore : ast_expression
 {
-    ast_expression expression;
-    int opstore;
-    int opbin;
-    ast_expression *dest;
-    ast_expression *source;
+    ast_binstore() = delete;
+    ast_binstore(lex_ctx_t ctx, int storeop, int mathop, ast_expression *l, ast_expression *r);
+    ~ast_binstore();
+
+    int m_opstore;
+    int m_opbin;
+    ast_expression *m_dest;
+    ast_expression *m_source;
     /* for &~= which uses the destination in a binary in source we can use this */
-    bool keep_dest;
+    bool m_keep_dest;
 };
 ast_binstore* ast_binstore_new(lex_ctx_t    ctx,
                                int        storeop,
@@ -292,15 +297,16 @@ ast_binstore* ast_binstore_new(lex_ctx_t    ctx,
  *
  * Regular unary expressions: not,neg
  */
-struct ast_unary
+struct ast_unary : ast_expression
 {
-    ast_expression expression;
-    int op;
-    ast_expression *operand;
+    ast_unary() = delete;
+    ~ast_unary();
+    int m_op;
+    ast_expression *m_operand;
+    static ast_unary* make(lex_ctx_t ctx, int op, ast_expression *expr);
+private:
+    ast_unary(lex_ctx_t ctx, int op, ast_expression *expr);
 };
-ast_unary* ast_unary_new(lex_ctx_t ctx,
-                         int op,
-                         ast_expression *expr);
 
 /* Return
  *
@@ -308,13 +314,13 @@ ast_unary* ast_unary_new(lex_ctx_t ctx,
  * will refuse to create further instructions.
  * This should be honored by the parser.
  */
-struct ast_return
+struct ast_return : ast_expression
 {
-    ast_expression expression;
-    ast_expression *operand;
+    ast_return() = delete;
+    ast_return(lex_ctx_t ctx, ast_expression *expr);
+    ~ast_return();
+    ast_expression *m_operand;
 };
-ast_return* ast_return_new(lex_ctx_t ctx,
-                           ast_expression *expr);
 
 /* Entity-field
  *
@@ -329,34 +335,37 @@ ast_return* ast_return_new(lex_ctx_t ctx,
  * For this we will have to extend the codegen() functions with
  * a flag saying whether or not we need an L or an R-value.
  */
-struct ast_entfield
+struct ast_entfield : ast_expression
 {
-    ast_expression expression;
-    /* The entity can come from an expression of course. */
-    ast_expression *entity;
-    /* As can the field, it just must result in a value of TYPE_FIELD */
-    ast_expression *field;
+    ast_entfield() = delete;
+    ast_entfield(lex_ctx_t ctx, ast_expression *entity, ast_expression *field);
+    ast_entfield(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype);
+    ~ast_entfield();
+    // The entity can come from an expression of course.
+    ast_expression *m_entity;
+    // As can the field, it just must result in a value of TYPE_FIELD
+    ast_expression *m_field;
 };
-ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expression *field);
-ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_expression *field, const ast_expression *outtype);
 
 /* Member access:
  *
  * For now used for vectors. If we get structs or unions
  * we can have them handled here as well.
  */
-struct ast_member
+struct ast_member : ast_expression
 {
-    ast_expression expression;
-    ast_expression *owner;
-    unsigned int field;
-    const char *name;
-    bool rvalue;
-};
-ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const char *name);
-void ast_member_delete(ast_member*);
-bool ast_member_set_name(ast_member*, const char *name);
+    static ast_member *make(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const std::string &name);
+    ~ast_member();
 
+    ast_expression *m_owner;
+    unsigned int m_field;
+    std::string m_name;
+    bool m_rvalue;
+
+private:
+    ast_member() = delete;
+    ast_member(lex_ctx_t ctx, ast_expression *owner, unsigned int field, const std::string &name);
+};
 
 /* Array index access:
  *
@@ -368,39 +377,43 @@ bool ast_member_set_name(ast_member*, const char *name);
  * In any case, accessing an element via a compiletime-constant index will
  * result in quick access to that variable.
  */
-struct ast_array_index
+struct ast_array_index : ast_expression
 {
-    ast_expression expression;
-    ast_expression *array;
-    ast_expression *index;
+    static ast_array_index* make(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
+    ~ast_array_index();
+    ast_expression *m_array;
+    ast_expression *m_index;
+private:
+    ast_array_index() = delete;
+    ast_array_index(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
 };
-ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_expression *index);
 
 /* Vararg pipe node:
  *
  * copy all varargs starting from a specific index
  */
-struct ast_argpipe
+struct ast_argpipe : ast_expression
 {
-    ast_expression expression;
-    ast_expression *index;
+    ast_argpipe() = delete;
+    ast_argpipe(lex_ctx_t ctx, ast_expression *index);
+    ~ast_argpipe();
+    ast_expression *m_index;
 };
-ast_argpipe* ast_argpipe_new(lex_ctx_t ctx, ast_expression *index);
 
 /* Store
  *
  * Stores left<-right and returns left.
  * Specialized binary expression node
  */
-struct ast_store
+struct ast_store : ast_expression
 {
-    ast_expression expression;
-    int op;
-    ast_expression *dest;
-    ast_expression *source;
+    ast_store() = delete;
+    ast_store(lex_ctx_t ctx, int op, ast_expression *d, ast_expression *s);
+    ~ast_store();
+    int m_op;
+    ast_expression *m_dest;
+    ast_expression *m_source;
 };
-ast_store* ast_store_new(lex_ctx_t ctx, int op,
-                         ast_expression *d, ast_expression *s);
 
 /* If
  *
@@ -413,15 +426,16 @@ ast_store* ast_store_new(lex_ctx_t ctx, int op,
  * output field though. For ternary expressions an ast_ternary will be
  * added.
  */
-struct ast_ifthen
+struct ast_ifthen : ast_expression
 {
-    ast_expression expression;
-    ast_expression *cond;
+    ast_ifthen() = delete;
+    ast_ifthen(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
+    ~ast_ifthen();
+    ast_expression *m_cond;
     /* It's all just 'expressions', since an ast_block is one too. */
-    ast_expression *on_true;
-    ast_expression *on_false;
+    ast_expression *m_on_true;
+    ast_expression *m_on_false;
 };
-ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
 
 /* Ternary expressions...
  *
@@ -436,15 +450,16 @@ ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *
  * This is the only ast_node beside ast_value which contains
  * an ir_value. Theoretically we don't need to remember it though.
  */
-struct ast_ternary
+struct ast_ternary : ast_expression
 {
-    ast_expression expression;
-    ast_expression *cond;
+    ast_ternary() = delete;
+    ast_ternary(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
+    ~ast_ternary();
+    ast_expression *m_cond;
     /* It's all just 'expressions', since an ast_block is one too. */
-    ast_expression *on_true;
-    ast_expression *on_false;
+    ast_expression *m_on_true;
+    ast_expression *m_on_false;
 };
-ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *ontrue, ast_expression *onfalse);
 
 /* A general loop node
  *
@@ -469,37 +484,37 @@ continue:      // a 'continue' will jump here
     {inc};
 }
  */
-struct ast_loop
+struct ast_loop : ast_expression
 {
-    ast_expression expression;
-    ast_expression *initexpr;
-    ast_expression *precond;
-    ast_expression *postcond;
-    ast_expression *increment;
-    ast_expression *body;
+    ast_loop() = delete;
+    ast_loop(lex_ctx_t ctx,
+             ast_expression *initexpr,
+             ast_expression *precond, bool pre_not,
+             ast_expression *postcond, bool post_not,
+             ast_expression *increment,
+             ast_expression *body);
+    ~ast_loop();
+    ast_expression *m_initexpr;
+    ast_expression *m_precond;
+    ast_expression *m_postcond;
+    ast_expression *m_increment;
+    ast_expression *m_body;
     /* For now we allow a seperate flag on whether or not the condition
      * is supposed to be true or false.
      * That way, the parser can generate a 'while not(!x)' for `while(x)`
      * if desired, which is useful for the new -f{true,false}-empty-strings
      * flag.
      */
-    bool pre_not;
-    bool post_not;
+    bool m_pre_not;
+    bool m_post_not;
 };
-ast_loop* ast_loop_new(lex_ctx_t ctx,
-                       ast_expression *initexpr,
-                       ast_expression *precond, bool pre_not,
-                       ast_expression *postcond, bool post_not,
-                       ast_expression *increment,
-                       ast_expression *body);
 
 /* Break/Continue
  */
-struct ast_breakcont
+struct ast_breakcont : ast_expression
 {
-    ast_expression expression;
-    bool is_continue;
-    unsigned int levels;
+    bool         m_is_continue;
+    unsigned int m_levels;
 };
 ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels);
 
@@ -514,15 +529,14 @@ ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels
  * TODO: Ticket #20
  */
 struct ast_switch_case {
-    ast_expression *value; /* #20 will replace this */
-    ast_expression *code;
+    ast_expression *m_value; /* #20 will replace this */
+    ast_expression *m_code;
 };
 
-struct ast_switch
+struct ast_switch : ast_expression
 {
-    ast_expression expression;
-    ast_expression *operand;
-    std::vector<ast_switch_case> cases;
+    ast_expression *m_operand;
+    std::vector<ast_switch_case> m_cases;
 };
 
 ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op);
@@ -531,15 +545,14 @@ ast_switch* ast_switch_new(lex_ctx_t ctx, ast_expression *op);
  *
  * Introduce a label which can be used together with 'goto'
  */
-struct ast_label
+struct ast_label : ast_expression
 {
-    ast_expression expression;
-    const char *name;
-    ir_block *irblock;
-    std::vector<ast_goto*> gotos;
+    const char *m_name;
+    ir_block *m_irblock;
+    std::vector<ast_goto*> m_gotos;
 
     /* means it has not yet been defined */
-    bool undefined;
+    bool m_undefined;
 };
 
 ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined);
@@ -548,12 +561,11 @@ ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined);
  *
  * Go to a label, the label node is filled in at a later point!
  */
-struct ast_goto
+struct ast_goto : ast_expression
 {
-    ast_expression expression;
-    const char *name;
-    ast_label *target;
-    ir_block *irblock_from;
+    const char *m_name;
+    ast_label *m_target;
+    ir_block *m_irblock_from;
 };
 
 ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name);
@@ -563,11 +575,10 @@ void ast_goto_set_label(ast_goto*, ast_label*);
  *
  * For frame/think state updates: void foo() [framenum, nextthink] {}
  */
-struct ast_state
+struct ast_state : ast_expression
 {
-    ast_expression expression;
-    ast_expression *framenum;
-    ast_expression *nextthink;
+    ast_expression *m_framenum;
+    ast_expression *m_nextthink;
 };
 ast_state* ast_state_new(lex_ctx_t ctx, ast_expression *frame, ast_expression *think);
 void ast_state_delete(ast_state*);
@@ -582,12 +593,11 @@ void ast_state_delete(ast_state*);
  * Additionally it contains a list of ast_expressions as parameters.
  * Since calls can return values, an ast_call is also an ast_expression.
  */
-struct ast_call
+struct ast_call : ast_expression
 {
-    ast_expression expression;
-    ast_expression *func;
-    std::vector<ast_expression *> params;
-    ast_expression *va_count;
+    ast_expression *m_func;
+    std::vector<ast_expression *> m_params;
+    ast_expression *m_va_count;
 };
 ast_call* ast_call_new(lex_ctx_t ctx,
                        ast_expression *funcexpr);
@@ -596,13 +606,11 @@ bool ast_call_check_types(ast_call*, ast_expression *this_func_va_type);
 /* Blocks
  *
  */
-struct ast_block
+struct ast_block : ast_expression
 {
-    ast_expression expression;
-
-    std::vector<ast_value*> locals;
-    std::vector<ast_expression*> exprs;
-    std::vector<ast_expression*> collect;
+    std::vector<ast_value*>      m_locals;
+    std::vector<ast_expression*> m_exprs;
+    std::vector<ast_expression*> m_collect;
 };
 ast_block* ast_block_new(lex_ctx_t ctx);
 void ast_block_delete(ast_block*);
@@ -621,39 +629,37 @@ bool GMQCC_WARN ast_block_add_expr(ast_block*, ast_expression*);
  * pointers could just work with a name. However, this way could be
  * more flexible, and adds no real complexity.
  */
-struct ast_function
+struct ast_function : ast_node
 {
-    ast_node node;
-
-    ast_value *vtype;
-    const char *name;
+    ast_value  *m_function_type;
+    const char *m_name;
 
-    int builtin;
+    int m_builtin;
 
     /* list of used-up names for statics without the count suffix */
-    std::vector<char*> static_names;
+    std::vector<char*> m_static_names;
     /* number of static variables, by convention this includes the
      * ones without the count-suffix - remember this when dealing
      * with savegames. uint instead of size_t as %zu in printf is
      * C99, so no windows support. */
-    unsigned int static_count;
+    unsigned int m_static_count;
 
-    ir_function *ir_func;
-    ir_block *curblock;
-    std::vector<ir_block*> breakblocks;
-    std::vector<ir_block*> continueblocks;
+    ir_function *m_ir_func;
+    ir_block *m_curblock;
+    std::vector<ir_block*> m_breakblocks;
+    std::vector<ir_block*> m_continueblocks;
 
-    size_t labelcount;
+    size_t m_labelcount;
     /* in order for thread safety - for the optional
      * channel abesed multithreading... keeping a buffer
      * here to use in ast_function_label.
      */
-    char labelbuf[64];
-    std::vector<ast_block*> blocks;
-    ast_value *varargs;
-    ast_value *argc;
-    ast_value *fixedparams;
-    ast_value *return_value;
+    char m_labelbuf[64];
+    std::vector<std::unique_ptr<ast_block>> m_blocks;
+    ast_value *m_varargs;
+    ast_value *m_argc;
+    ast_value *m_fixedparams;
+    ast_value *m_return_value;
 };
 ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype);
 /* This will NOT delete the underlying ast_value */
index 2f55535c32d2b4d5e2c04d685600418170f9dde4..645ad257042b5973c20d4b08e5701e7be9e812a0 100644 (file)
--- a/code.cpp
+++ b/code.cpp
@@ -106,35 +106,39 @@ void code_pop_statement(code_t *code)
     code->columnnums.pop_back();
 }
 
-code_t *code_init() {
+void *code_t::operator new(std::size_t bytes) {
+  return mem_a(bytes);
+}
+
+void code_t::operator delete(void *ptr) {
+  mem_d(ptr);
+}
+
+code_t::code_t()
+{
     static lex_ctx_t                empty_ctx       = {0, 0, 0};
     static prog_section_function_t  empty_function  = {0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0}};
     static prog_section_statement_t empty_statement = {0,{0},{0},{0}};
     static prog_section_def_t       empty_def       = {0, 0, 0};
 
-    code_t *code       = (code_t*)mem_a(sizeof(code_t));
-    int     i          = 0;
+    string_cache = util_htnew(OPTS_OPTIMIZATION(OPTIM_OVERLAP_STRINGS) ? 0x100 : 1024);
 
-    memset(code, 0, sizeof(code_t));
-    code->entfields    = 0;
-    code->string_cache = util_htnew(OPTS_OPTIMIZATION(OPTIM_OVERLAP_STRINGS) ? 0x100 : 1024);
+    // The way progs.dat is suppose to work is odd, there needs to be
+    // some null (empty) statements, functions, and 28 globals
+    globals.insert(globals.begin(), 28, 0);
 
-    /*
-     * The way progs.dat is suppose to work is odd, there needs to be
-     * some null (empty) statements, functions, and 28 globals
-     */
-    for(; i < 28; i++)
-        code->globals.push_back(0);
+    chars.push_back('\0');
+    functions.push_back(empty_function);
 
-    code->chars.push_back('\0');
-    code->functions.push_back(empty_function);
+    code_push_statement(this, &empty_statement, empty_ctx);
 
-    code_push_statement(code, &empty_statement, empty_ctx);
-
-    code->defs.push_back(empty_def);
-    code->fields.push_back(empty_def);
+    defs.push_back(empty_def);
+    fields.push_back(empty_def);
+}
 
-    return code;
+code_t::~code_t()
+{
+    util_htdel(string_cache);
 }
 
 void *code_util_str_htgeth(hash_table_t *ht, const char *key, size_t bin);
@@ -342,8 +346,3 @@ bool code_write(code_t *code, const char *filename, const char *lnofile) {
     code_stats(filename, lnofile, code, &code_header);
     return true;
 }
-
-void code_cleanup(code_t *code) {
-    util_htdel(code->string_cache);
-    mem_d(code);
-}
index dab7436a4ee60641358bfca6fb51c9d2c0463c46..0f861171cbc7ec4f5c7d7f820425b989f3dec234 100644 (file)
--- a/fold.cpp
+++ b/fold.cpp
@@ -535,10 +535,10 @@ static GMQCC_INLINE void sfloat_init(sfloat_state_t *state) {
  * This file is thus, split into two parts.
  */
 
-#define isfloat(X)      (((ast_expression*)(X))->vtype == TYPE_FLOAT)
-#define isvector(X)     (((ast_expression*)(X))->vtype == TYPE_VECTOR)
-#define isstring(X)     (((ast_expression*)(X))->vtype == TYPE_STRING)
-#define isarray(X)      (((ast_expression*)(X))->vtype == TYPE_ARRAY)
+#define isfloat(X)      (((ast_expression*)(X))->m_vtype == TYPE_FLOAT)
+#define isvector(X)     (((ast_expression*)(X))->m_vtype == TYPE_VECTOR)
+#define isstring(X)     (((ast_expression*)(X))->m_vtype == TYPE_STRING)
+#define isarray(X)      (((ast_expression*)(X))->m_vtype == TYPE_ARRAY)
 #define isfloats(X,Y)   (isfloat  (X) && isfloat (Y))
 
 /*
@@ -858,15 +858,15 @@ end:
 }
 
 qcfloat_t fold::immvalue_float(ast_value *value) {
-    return value->constval.vfloat;
+    return value->m_constval.vfloat;
 }
 
 vec3_t fold::immvalue_vector(ast_value *value) {
-    return value->constval.vvec;
+    return value->m_constval.vvec;
 }
 
 const char *fold::immvalue_string(ast_value *value) {
-    return value->constval.vstring;
+    return value->m_constval.vstring;
 }
 
 lex_ctx_t fold::ctx() {
@@ -878,32 +878,32 @@ lex_ctx_t fold::ctx() {
 }
 
 bool fold::immediate_true(ast_value *v) {
-    switch (v->expression.vtype) {
+    switch (v->m_vtype) {
         case TYPE_FLOAT:
-            return !!v->constval.vfloat;
+            return !!v->m_constval.vfloat;
         case TYPE_INTEGER:
-            return !!v->constval.vint;
+            return !!v->m_constval.vint;
         case TYPE_VECTOR:
             if (OPTS_FLAG(CORRECT_LOGIC))
-                return vec3_pbool(v->constval.vvec);
-            return !!(v->constval.vvec.x);
+                return vec3_pbool(v->m_constval.vvec);
+            return !!(v->m_constval.vvec.x);
         case TYPE_STRING:
-            if (!v->constval.vstring)
+            if (!v->m_constval.vstring)
                 return false;
             if (OPTS_FLAG(TRUE_EMPTY_STRINGS))
                 return true;
-            return !!v->constval.vstring[0];
+            return !!v->m_constval.vstring[0];
         default:
             compile_error(ctx(), "internal error: fold_immediate_true on invalid type");
             break;
     }
-    return !!v->constval.vfunc;
+    return !!v->m_constval.vfunc;
 }
 
 /* Handy macros to determine if an ast_value can be constant folded. */
 #define fold_can_1(X)  \
-    (ast_istype(((ast_expression*)(X)), ast_value) && (X)->hasvalue && ((X)->cvq == CV_CONST) && \
-                ((ast_expression*)(X))->vtype != TYPE_FUNCTION)
+    (ast_istype(((ast_expression*)(X)), ast_value) && (X)->m_hasvalue && ((X)->m_cvq == CV_CONST) && \
+                ((ast_expression*)(X))->m_vtype != TYPE_FUNCTION)
 
 #define fold_can_2(X, Y) (fold_can_1(X) && fold_can_1(Y))
 
@@ -938,8 +938,8 @@ bool fold::generate(ir_builder *ir) {
         if (!ast_global_codegen((cur = it), ir, false)) goto err;
     return true;
 err:
-    con_out("failed to generate global %s\n", cur->name);
-    ir_builder_delete(ir);
+    con_out("failed to generate global %s\n", cur->m_name);
+    delete ir;
     return false;
 }
 
@@ -957,14 +957,14 @@ fold::~fold() {
 
 ast_expression *fold::constgen_float(qcfloat_t value, bool inexact) {
     for (auto &it : m_imm_float)
-        if (!memcmp(&it->constval.vfloat, &value, sizeof(qcfloat_t)))
+        if (!memcmp(&it->m_constval.vfloat, &value, sizeof(qcfloat_t)))
             return (ast_expression*)it;
 
     ast_value *out  = ast_value_new(ctx(), "#IMMEDIATE", TYPE_FLOAT);
-    out->cvq = CV_CONST;
-    out->hasvalue = true;
-    out->inexact = inexact;
-    out->constval.vfloat = value;
+    out->m_cvq = CV_CONST;
+    out->m_hasvalue = true;
+    out->m_inexact = inexact;
+    out->m_constval.vfloat = value;
 
     m_imm_float.push_back(out);
 
@@ -973,13 +973,13 @@ ast_expression *fold::constgen_float(qcfloat_t value, bool inexact) {
 
 ast_expression *fold::constgen_vector(vec3_t value) {
     for (auto &it : m_imm_vector)
-        if (vec3_cmp(it->constval.vvec, value))
+        if (vec3_cmp(it->m_constval.vvec, value))
             return (ast_expression*)it;
 
     ast_value *out = ast_value_new(ctx(), "#IMMEDIATE", TYPE_VECTOR);
-    out->cvq = CV_CONST;
-    out->hasvalue = true;
-    out->constval.vvec = value;
+    out->m_cvq = CV_CONST;
+    out->m_hasvalue = true;
+    out->m_constval.vvec = value;
 
     m_imm_vector.push_back(out);
 
@@ -998,15 +998,15 @@ ast_expression *fold::constgen_string(const char *str, bool translate) {
         char name[32];
         util_snprintf(name, sizeof(name), "dotranslate_%zu", m_parser->translated++);
         out = ast_value_new(ctx(), name, TYPE_STRING);
-        out->expression.flags |= AST_FLAG_INCLUDE_DEF; /* def needs to be included for translatables */
+        out->m_flags |= AST_FLAG_INCLUDE_DEF; /* def needs to be included for translatables */
     } else {
         out = ast_value_new(ctx(), "#IMMEDIATE", TYPE_STRING);
     }
 
-    out->cvq = CV_CONST;
-    out->hasvalue = true;
-    out->isimm = true;
-    out->constval.vstring = parser_strdup(str);
+    out->m_cvq = CV_CONST;
+    out->m_hasvalue = true;
+    out->m_isimm = true;
+    out->m_constval.vstring = parser_strdup(str);
 
     m_imm_string.push_back(out);
     util_htseth(table, str, hash, out);
@@ -1057,7 +1057,7 @@ inexact_possible:
 bool fold::check_inexact_float(ast_value *a, ast_value *b) {
     if (!OPTS_WARN(WARN_INEXACT_COMPARES))
         return false;
-    if (!a->inexact && !b->inexact)
+    if (!a->m_inexact && !b->m_inexact)
         return false;
     return compile_warning(ctx(), WARN_INEXACT_COMPARES, "inexact value in comparison");
 }
@@ -1070,8 +1070,8 @@ ast_expression *fold::op_mul_vec(vec3_t vec, ast_value *sel, const char *set) {
         ast_expression *out;
         ++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
         out = (ast_expression*)ast_member_new(ctx(), (ast_expression*)sel, set[0]-'x', nullptr);
-        out->node.keep = false;
-        ((ast_member*)out)->rvalue = true;
+        out->m_keep_node = false;
+        ((ast_member*)out)->m_rvalue = true;
         if (x != -1.0f)
             return (ast_expression*)ast_binary_new(ctx(), INSTR_MUL_F, constgen_float(x, false), out);
     }
@@ -1374,7 +1374,7 @@ ast_expression *fold::op_length(ast_value *a) {
     if (fold_can_1(a) && isstring(a))
         return constgen_float(strlen(immvalue_string(a)), false);
     if (isarray(a))
-        return constgen_float(a->initlist.size(), false);
+        return constgen_float(a->m_initlist.size(), false);
     return nullptr;
 }
 
@@ -1526,18 +1526,18 @@ ast_expression *fold::intrinsic(const char *intrinsic, ast_expression **arg) {
 #undef fold_can_1
 #undef fold_can_2
 
-#define isfloat(X)              ((X)->vtype == TYPE_FLOAT)
-/*#define isstring(X)             ((X)->vtype == TYPE_STRING)*/
-/*#define isvector(X)             ((X)->vtype == TYPE_VECTOR)*/
-#define fold_can_1(X)           ((X)->hasvalue && (X)->cvq == CV_CONST)
+#define isfloat(X)              ((X)->m_vtype == TYPE_FLOAT)
+/*#define isstring(X)             ((X)->m_vtype == TYPE_STRING)*/
+/*#define isvector(X)             ((X)->m_vtype == TYPE_VECTOR)*/
+#define fold_can_1(X)           ((X)->m_hasvalue && (X)->m_cvq == CV_CONST)
 /*#define fold_can_2(X,Y)         (fold_can_1(X) && fold_can_1(Y))*/
 
 qcfloat_t fold::immvalue_float(ir_value *value) {
-    return value->constval.vfloat;
+    return value->m_constval.vfloat;
 }
 
 vec3_t fold::immvalue_vector(ir_value *value) {
-    return value->constval.vvec;
+    return value->m_constval.vvec;
 }
 
 ast_expression *fold::superfluous(ast_expression *left, ast_expression *right, int op) {
@@ -1612,10 +1612,10 @@ int fold::cond(ir_value *condval, ast_function *func, ast_ifthen *branch) {
         ast_expression_codegen *cgen;
         ir_block               *elide;
         ir_value               *dummy;
-        bool                    istrue  = (immvalue_float(condval) != 0.0f && branch->on_true);
-        bool                    isfalse = (immvalue_float(condval) == 0.0f && branch->on_false);
-        ast_expression         *path    = (istrue)  ? branch->on_true  :
-                                          (isfalse) ? branch->on_false : nullptr;
+        bool                    istrue  = (immvalue_float(condval) != 0.0f && branch->m_on_true);
+        bool                    isfalse = (immvalue_float(condval) == 0.0f && branch->m_on_false);
+        ast_expression         *path    = (istrue)  ? branch->m_on_true  :
+                                          (isfalse) ? branch->m_on_false : nullptr;
         if (!path) {
             /*
              * no path to take implies that the evaluation is if(0) and there
@@ -1625,17 +1625,17 @@ int fold::cond(ir_value *condval, ast_function *func, ast_ifthen *branch) {
             return true;
         }
 
-        if (!(elide = ir_function_create_block(ast_ctx(branch), func->ir_func, ast_function_label(func, ((istrue) ? "ontrue" : "onfalse")))))
+        if (!(elide = ir_function_create_block(branch->m_context, func->m_ir_func, ast_function_label(func, ((istrue) ? "ontrue" : "onfalse")))))
             return false;
-        if (!(*(cgen = path->codegen))((ast_expression*)path, func, false, &dummy))
+        if (!(*(cgen = path->m_codegen))((ast_expression*)path, func, false, &dummy))
             return false;
-        if (!ir_block_create_jump(func->curblock, ast_ctx(branch), elide))
+        if (!ir_block_create_jump(func->m_curblock, branch->m_context, elide))
             return false;
         /*
          * now the branch has been eliminated and the correct block for the constant evaluation
          * is expanded into the current block for the function.
          */
-        func->curblock = elide;
+        func->m_curblock = elide;
         ++opts_optimizationcount[OPTIM_CONST_FOLD_DCE];
         return true;
     }
diff --git a/gmqcc.h b/gmqcc.h
index 48570ff7a6d0aa712385fd84fa98e437a79c877c..88cf7ff21831336c15f1d6d87515af82176fb6f6 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1,6 +1,10 @@
 #ifndef GMQCC_HDR
 #define GMQCC_HDR
 #include <vector>
+#include <string>
+#include <utility>
+#include <memory>
+using std::move;
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -259,7 +263,7 @@ int util_getline(char  **, size_t *, FILE *);
 /* code.c */
 
 /* Note: if you change the order, fix type_sizeof in ir.c */
-enum {
+enum qc_type {
     TYPE_VOID     ,
     TYPE_STRING   ,
     TYPE_FLOAT    ,
@@ -498,6 +502,10 @@ typedef int32_t qcint_t;
 typedef uint32_t qcuint_t;
 
 struct code_t {
+    void* operator new(std::size_t);
+    void operator delete(void*);
+    code_t();
+    ~code_t();
     std::vector<prog_section_statement_t> statements;
     std::vector<int> linenums;
     std::vector<int> columnnums;
@@ -506,10 +514,10 @@ struct code_t {
     std::vector<prog_section_function_t> functions;
     std::vector<int> globals;
     std::vector<char> chars;
-    uint16_t crc;
-    uint32_t entfields;
+    uint16_t crc = 0;
+    uint32_t entfields = 0;
     ht string_cache;
-    qcint_t string_cached_empty;
+    qcint_t string_cached_empty = 0;
 };
 
 /*
@@ -589,7 +597,7 @@ void            compile_show_werrors(void);
 
 /* ir.c */
 /* TODO: cleanup */
-enum store_types {
+enum store_type {
     store_global,
     store_local,  /* local, assignable for now, should get promoted later */
     store_param,  /* parameters, they are locals with a fixed position */
index e55cf0ff5546d639554e8f00a79cfad7f2e1b709..cc6250be7cd1194986ba31d3001dca24204337ac 100644 (file)
@@ -8,7 +8,7 @@ lex_ctx_t intrin::ctx() const {
     return parser_ctx(m_parser);
 }
 
-ast_function *intrin::value(ast_value **out, const char *name, qcint_t vtype) {
+ast_function *intrin::value(ast_value **out, const char *name, qc_type vtype) {
     ast_value *value = nullptr;
     ast_function *func  = nullptr;
     char buffer[1024];
@@ -18,10 +18,10 @@ ast_function *intrin::value(ast_value **out, const char *name, qcint_t vtype) {
     util_snprintf(stype,  sizeof(stype),   "<%s>",        type_name[vtype]);
 
     value = ast_value_new(ctx(), buffer, TYPE_FUNCTION);
-    value->intrinsic = true;
-    value->expression.next = (ast_expression*)ast_value_new(ctx(), stype, vtype);
+    value->m_intrinsic = true;
+    value->m_next = (ast_expression*)ast_value_new(ctx(), stype, vtype);
     func = ast_function_new(ctx(), buffer, value);
-    value->expression.flags |= AST_FLAG_ERASEABLE;
+    value->m_flags |= AST_FLAG_ERASEABLE;
 
     *out = value;
     return func;
@@ -55,16 +55,16 @@ ast_expression *intrin::isfinite_() {
     ast_block    *block     = ast_block_new(ctx());
 
     /* float x; */
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
     /* <callisnan> = isnan(x); */
-    callisnan->params.push_back((ast_expression*)x);
+    callisnan->m_params.push_back((ast_expression*)x);
 
     /* <callisinf> = isinf(x); */
-    callisinf->params.push_back((ast_expression*)x);
+    callisinf->m_params.push_back((ast_expression*)x);
 
     /* return (!<callisnan> || <callisinf>); */
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_unary_new(
@@ -80,7 +80,7 @@ ast_expression *intrin::isfinite_() {
         )
     );
 
-    func->blocks.push_back(block);
+    func->m_blocks.emplace_back(block);
     reg(val, func);
 
     return (ast_expression*)val;;
@@ -97,7 +97,7 @@ ast_expression *intrin::isinf_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "isinf", TYPE_FLOAT);
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -124,8 +124,8 @@ ast_expression *intrin::isinf_() {
         )
     );
 
-    val->expression.params.push_back(x);
-    func->blocks.push_back(body);
+    val->m_type_params.push_back(x);
+    func->m_blocks.emplace_back(body);
 
     reg(val, func);
 
@@ -147,8 +147,8 @@ ast_expression *intrin::isnan_() {
     ast_block *body  = ast_block_new(ctx());
     ast_function *func = value(&val, "isnan", TYPE_FLOAT);
 
-    body->locals.push_back(local);
-    body->exprs.push_back(
+    body->m_locals.push_back(local);
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -157,7 +157,7 @@ ast_expression *intrin::isnan_() {
         )
     );
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -169,8 +169,8 @@ ast_expression *intrin::isnan_() {
         )
     );
 
-    val->expression.params.push_back(arg1);
-    func->blocks.push_back(body);
+    val->m_type_params.push_back(arg1);
+    func->m_blocks.emplace_back(body);
 
     reg(val, func);
 
@@ -189,18 +189,18 @@ ast_expression *intrin::isnormal_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "isnormal", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
-    callisfinite->params.push_back((ast_expression*)x);
+    val->m_type_params.push_back(x);
+    callisfinite->m_params.push_back((ast_expression*)x);
 
     /* return <callisfinite> */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)callisfinite
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -216,10 +216,10 @@ ast_expression *intrin::signbit_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "signbit", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
     /* return (x < 0); */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_ternary_new(
@@ -236,7 +236,7 @@ ast_expression *intrin::signbit_() {
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -254,10 +254,10 @@ ast_expression *intrin::acosh_() {
     ast_block    *body     = ast_block_new(ctx());
     ast_function *func     = value(&val, "acosh", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
     /* <callsqrt> = sqrt((x * x) - 1); */
-    callsqrt->params.push_back(
+    callsqrt->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_SUB_F,
@@ -272,7 +272,7 @@ ast_expression *intrin::acosh_() {
     );
 
     /* <calllog> = log(x + <callsqrt>); */
-    calllog->params.push_back(
+    calllog->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_ADD_F,
@@ -282,14 +282,14 @@ ast_expression *intrin::acosh_() {
     );
 
     /* return <calllog>; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)calllog
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -307,10 +307,10 @@ ast_expression *intrin::asinh_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "asinh", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
     /* <callsqrt> = sqrt((x * x) + 1); */
-    callsqrt->params.push_back(
+    callsqrt->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_ADD_F,
@@ -325,7 +325,7 @@ ast_expression *intrin::asinh_() {
     );
 
     /* <calllog> = log(x + <callsqrt>); */
-    calllog->params.push_back(
+    calllog->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_ADD_F,
@@ -335,14 +335,14 @@ ast_expression *intrin::asinh_() {
     );
 
     /* return <calllog>; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)calllog
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -359,10 +359,10 @@ ast_expression *intrin::atanh_() {
     ast_block    *body    = ast_block_new(ctx());
     ast_function *func    = value(&val, "atanh", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
     /* <callog> = log((1 + x) / (1 - x)); */
-    calllog->params.push_back(
+    calllog->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_DIV_F,
@@ -382,7 +382,7 @@ ast_expression *intrin::atanh_() {
     );
 
     /* return 0.5 * <calllog>; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_MUL_F,
@@ -391,7 +391,7 @@ ast_expression *intrin::atanh_() {
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -416,14 +416,14 @@ ast_expression *intrin::exp_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "exp", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
-    body->locals.push_back(sum);
-    body->locals.push_back(acc);
-    body->locals.push_back(i);
+    body->m_locals.push_back(sum);
+    body->m_locals.push_back(acc);
+    body->m_locals.push_back(i);
 
     /* sum = 1.0; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -433,7 +433,7 @@ ast_expression *intrin::exp_() {
     );
 
     /* acc = 1.0; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -446,7 +446,7 @@ ast_expression *intrin::exp_() {
      * for (i = 1; i < 200; ++i)
      *     sum += (acc *= x / i);
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_loop_new(
             ctx(),
             /* i = 1; */
@@ -497,14 +497,14 @@ ast_expression *intrin::exp_() {
     );
 
     /* return sum; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)sum
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -521,20 +521,20 @@ ast_expression *intrin::exp2_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "exp2", TYPE_FLOAT);
 
-    val->expression.params.push_back(arg1);
+    val->m_type_params.push_back(arg1);
 
-    callpow->params.push_back((ast_expression*)m_fold->m_imm_float[3]);
-    callpow->params.push_back((ast_expression*)arg1);
+    callpow->m_params.push_back((ast_expression*)m_fold->m_imm_float[3]);
+    callpow->m_params.push_back((ast_expression*)arg1);
 
     /* return <callpow> */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)callpow
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -551,13 +551,13 @@ ast_expression *intrin::expm1_() {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, "expm1", TYPE_FLOAT);
 
-    val->expression.params.push_back(x);
+    val->m_type_params.push_back(x);
 
     /* <callexp> = exp(x); */
-    callexp->params.push_back((ast_expression*)x);
+    callexp->m_params.push_back((ast_expression*)x);
 
     /* return <callexp> - 1; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -569,7 +569,7 @@ ast_expression *intrin::expm1_() {
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -652,21 +652,21 @@ ast_expression *intrin::pow_() {
     ast_value *square     = ast_value_new(ctx(), "square",     TYPE_FLOAT);
     ast_value *accumulate = ast_value_new(ctx(), "accumulate", TYPE_FLOAT);
     ast_value *mid        = ast_value_new(ctx(), "mid",        TYPE_FLOAT);
-    body->locals.push_back(result);
-    body->locals.push_back(low);
-    body->locals.push_back(high);
-    body->locals.push_back(square);
-    body->locals.push_back(accumulate);
-    body->locals.push_back(mid);
+    body->m_locals.push_back(result);
+    body->m_locals.push_back(low);
+    body->m_locals.push_back(high);
+    body->m_locals.push_back(square);
+    body->m_locals.push_back(accumulate);
+    body->m_locals.push_back(mid);
 
-    val->expression.params.push_back(base);
-    val->expression.params.push_back(exp);
+    val->m_type_params.push_back(base);
+    val->m_type_params.push_back(exp);
 
     /*
      * if (exp == 0.0)
      *     return 1;
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -687,7 +687,7 @@ ast_expression *intrin::pow_() {
      * if (exp == 1.0)
      *     return base;
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -705,8 +705,8 @@ ast_expression *intrin::pow_() {
     );
 
     /* <callpow1> = pow(base, -exp) */
-    callpow1->params.push_back((ast_expression*)base);
-    callpow1->params.push_back(
+    callpow1->m_params.push_back((ast_expression*)base);
+    callpow1->m_params.push_back(
         (ast_expression*)ast_unary_new(
             ctx(),
             VINSTR_NEG_F,
@@ -718,7 +718,7 @@ ast_expression *intrin::pow_() {
      * if (exp < 0)
      *     return 1.0 / <callpow1>;
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -741,8 +741,8 @@ ast_expression *intrin::pow_() {
     );
 
     /* <callpow2> = pow(base, exp / 2) */
-    callpow2->params.push_back((ast_expression*)base);
-    callpow2->params.push_back(
+    callpow2->m_params.push_back((ast_expression*)base);
+    callpow2->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_DIV_F,
@@ -757,7 +757,7 @@ ast_expression *intrin::pow_() {
      *     return result * result;
      * }
      */
-    expgt1->exprs.push_back(
+    expgt1->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -765,7 +765,7 @@ ast_expression *intrin::pow_() {
             (ast_expression*)callpow2
         )
     );
-    expgt1->exprs.push_back(
+    expgt1->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -782,7 +782,7 @@ ast_expression *intrin::pow_() {
      *     <expgt1>
      * }
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -799,7 +799,7 @@ ast_expression *intrin::pow_() {
     /*
      * <callsqrt1> = sqrt(base)
      */
-    callsqrt1->params.push_back((ast_expression*)base);
+    callsqrt1->m_params.push_back((ast_expression*)base);
 
     /*
      * low        = 0.0f;
@@ -808,14 +808,14 @@ ast_expression *intrin::pow_() {
      * accumulate = square;
      * mid        = high / 2.0f;
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(ctx(),
             INSTR_STORE_F,
             (ast_expression*)low,
             (ast_expression*)m_fold->m_imm_float[0]
         )
     );
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -824,7 +824,7 @@ ast_expression *intrin::pow_() {
         )
     );
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -833,7 +833,7 @@ ast_expression *intrin::pow_() {
         )
     );
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -841,7 +841,7 @@ ast_expression *intrin::pow_() {
             (ast_expression*)square
         )
     );
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -861,7 +861,7 @@ ast_expression *intrin::pow_() {
      *     accumulate *= square;
      * }
      */
-    midltexp->exprs.push_back(
+    midltexp->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -869,7 +869,7 @@ ast_expression *intrin::pow_() {
             (ast_expression*)mid
         )
     );
-    midltexp->exprs.push_back(
+    midltexp->m_exprs.push_back(
         (ast_expression*)ast_binstore_new(
             ctx(),
             INSTR_STORE_F,
@@ -885,7 +885,7 @@ ast_expression *intrin::pow_() {
      *     accumulate *= (1.0 / square);
      * }
      */
-    midltexpelse->exprs.push_back(
+    midltexpelse->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -893,7 +893,7 @@ ast_expression *intrin::pow_() {
             (ast_expression*)mid
         )
     );
-    midltexpelse->exprs.push_back(
+    midltexpelse->m_exprs.push_back(
         (ast_expression*)ast_binstore_new(
             ctx(),
             INSTR_STORE_F,
@@ -911,7 +911,7 @@ ast_expression *intrin::pow_() {
     /*
      * <callsqrt2> = sqrt(square)
      */
-    callsqrt2->params.push_back((ast_expression*)square);
+    callsqrt2->m_params.push_back((ast_expression*)square);
 
     /*
      * <whileblock> = {
@@ -924,7 +924,7 @@ ast_expression *intrin::pow_() {
      *     mid = (low + high) / 2;
      * }
      */
-    whileblock->exprs.push_back(
+    whileblock->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -932,7 +932,7 @@ ast_expression *intrin::pow_() {
             (ast_expression*)callsqrt2
         )
     );
-    whileblock->exprs.push_back(
+    whileblock->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -945,7 +945,7 @@ ast_expression *intrin::pow_() {
             (ast_expression*)midltexpelse
         )
     );
-    whileblock->exprs.push_back(
+    whileblock->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -967,7 +967,7 @@ ast_expression *intrin::pow_() {
     /*
      * <callabs> = fabs(mid - exp)
      */
-    callfabs->params.push_back(
+    callfabs->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_SUB_F,
@@ -980,7 +980,7 @@ ast_expression *intrin::pow_() {
      * while (<callfabs>  > epsilon)
      *     <whileblock>
      */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_loop_new(
             ctx(),
             /* init */
@@ -1006,7 +1006,7 @@ ast_expression *intrin::pow_() {
     );
 
     /* return accumulate */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)accumulate
@@ -1014,7 +1014,7 @@ ast_expression *intrin::pow_() {
     );
 
     /* } */
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1036,14 +1036,14 @@ ast_expression *intrin::mod_() {
     ast_block    *body  = ast_block_new(ctx());
     ast_function *func  = value(&val, "mod", TYPE_FLOAT);
 
-    val->expression.params.push_back(a);
-    val->expression.params.push_back(b);
+    val->m_type_params.push_back(a);
+    val->m_type_params.push_back(b);
 
-    body->locals.push_back(div);
-    body->locals.push_back(sign);
+    body->m_locals.push_back(div);
+    body->m_locals.push_back(sign);
 
     /* div = a / b; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1058,7 +1058,7 @@ ast_expression *intrin::mod_() {
     );
 
     /* sign = (div < 0.0f) ? -1 : 1; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1078,7 +1078,7 @@ ast_expression *intrin::mod_() {
     );
 
     /* floor(sign * div) */
-    call->params.push_back(
+    call->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             INSTR_MUL_F,
@@ -1088,7 +1088,7 @@ ast_expression *intrin::mod_() {
     );
 
     /* return a - b * sign * <call> */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -1110,7 +1110,7 @@ ast_expression *intrin::mod_() {
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1126,7 +1126,7 @@ ast_expression *intrin::fabs_() {
     ast_block    *body   = ast_block_new(ctx());
     ast_function *func   = value(&val, "fabs", TYPE_FLOAT);
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_ternary_new(
@@ -1147,9 +1147,9 @@ ast_expression *intrin::fabs_() {
         )
     );
 
-    val->expression.params.push_back(arg1);
+    val->m_type_params.push_back(arg1);
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1167,10 +1167,10 @@ ast_expression *intrin::epsilon_() {
     ast_block    *body   = ast_block_new(ctx());
     ast_function *func   = value(&val, "epsilon", TYPE_FLOAT);
 
-    body->locals.push_back(eps);
+    body->m_locals.push_back(eps);
 
     /* eps = 1.0f; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1179,7 +1179,7 @@ ast_expression *intrin::epsilon_() {
         )
     );
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_loop_new(
             ctx(),
             nullptr,
@@ -1214,14 +1214,14 @@ ast_expression *intrin::epsilon_() {
     );
 
     /* return eps; */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)eps
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1238,9 +1238,9 @@ ast_expression *intrin::nan_() {
     ast_function *func   = value(&val, "nan", TYPE_FLOAT);
     ast_block    *block  = ast_block_new(ctx());
 
-    block->locals.push_back(x);
+    block->m_locals.push_back(x);
 
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1249,7 +1249,7 @@ ast_expression *intrin::nan_() {
         )
     );
 
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -1261,7 +1261,7 @@ ast_expression *intrin::nan_() {
         )
     );
 
-    func->blocks.push_back(block);
+    func->m_blocks.emplace_back(block);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1281,12 +1281,12 @@ ast_expression *intrin::inf_() {
     ast_block    *block  = ast_block_new(ctx());
     size_t        i;
 
-    block->locals.push_back(x);
-    block->locals.push_back(y);
+    block->m_locals.push_back(x);
+    block->m_locals.push_back(y);
 
     /* to keep code size down */
     for (i = 0; i <= 1; i++) {
-        block->exprs.push_back(
+        block->m_exprs.push_back(
             (ast_expression*)ast_store_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1296,7 +1296,7 @@ ast_expression *intrin::inf_() {
         );
     }
 
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -1308,7 +1308,7 @@ ast_expression *intrin::inf_() {
         )
     );
 
-    func->blocks.push_back(block);
+    func->m_blocks.emplace_back(block);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1406,20 +1406,20 @@ ast_expression *intrin::ln_() {
     ast_function *func = value(&val, "ln", TYPE_FLOAT);
     size_t i;
 
-    val->expression.params.push_back(power);
-    val->expression.params.push_back(base);
+    val->m_type_params.push_back(power);
+    val->m_type_params.push_back(base);
 
-    block->locals.push_back(whole);
-    block->locals.push_back(nth);
-    block->locals.push_back(sign);
-    block->locals.push_back(eps);
-    block->locals.push_back(A_i);
-    block->locals.push_back(B_i);
-    block->locals.push_back(A_iminus1);
-    block->locals.push_back(B_iminus1);
+    block->m_locals.push_back(whole);
+    block->m_locals.push_back(nth);
+    block->m_locals.push_back(sign);
+    block->m_locals.push_back(eps);
+    block->m_locals.push_back(A_i);
+    block->m_locals.push_back(B_i);
+    block->m_locals.push_back(A_iminus1);
+    block->m_locals.push_back(B_iminus1);
 
     /* sign = 1.0f; */
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1429,7 +1429,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* eps = __builtin_epsilon(); */
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1450,7 +1450,7 @@ ast_expression *intrin::ln_() {
     for (i = 0; i <= 1; i++) {
         int j;
         for (j = 1; j >= 0; j--) {
-            block->exprs.push_back(
+            block->m_exprs.push_back(
                 (ast_expression*)ast_store_new(
                     ctx(),
                     INSTR_STORE_F,
@@ -1473,7 +1473,7 @@ ast_expression *intrin::ln_() {
      * }
      */
     for (i = 0; i <= 1; i++) {
-        ((i) ? blt1 : plt1)->exprs.push_back(
+        ((i) ? blt1 : plt1)->m_exprs.push_back(
             (ast_expression*)ast_store_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1486,7 +1486,7 @@ ast_expression *intrin::ln_() {
                 )
             )
         );
-        plt1->exprs.push_back(
+        plt1->m_exprs.push_back(
             (ast_expression*)ast_binstore_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1507,7 +1507,7 @@ ast_expression *intrin::ln_() {
      *         <blt1>
      * }
      */
-    plt1orblt1->exprs.push_back(
+    plt1orblt1->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -1538,7 +1538,7 @@ ast_expression *intrin::ln_() {
     );
 
     for (i = 0; i <= 1; i++) {
-        plt1orblt1->exprs.push_back(
+        plt1orblt1->m_exprs.push_back(
             (ast_expression*)ast_ifthen_new(
                 ctx(),
                 (ast_expression*)ast_binary_new(
@@ -1553,11 +1553,11 @@ ast_expression *intrin::ln_() {
         );
     }
 
-    block->exprs.push_back((ast_expression*)plt1orblt1);
+    block->m_exprs.push_back((ast_expression*)plt1orblt1);
 
 
     /* whole = power; */
-    forloop->exprs.push_back(
+    forloop->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1567,7 +1567,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* nth = 0.0f; */
-    forloop->exprs.push_back(
+    forloop->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1577,7 +1577,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* base2 = base; */
-    whileloop->exprs.push_back(
+    whileloop->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1587,7 +1587,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* n2 = 1.0f; */
-    whileloop->exprs.push_back(
+    whileloop->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1597,7 +1597,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* newbase2 = base2 * base2; */
-    whileloop->exprs.push_back(
+    whileloop->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1612,12 +1612,12 @@ ast_expression *intrin::ln_() {
     );
 
     /* while loop locals */
-    whileloop->locals.push_back(base2);
-    whileloop->locals.push_back(n2);
-    whileloop->locals.push_back(newbase2);
+    whileloop->m_locals.push_back(base2);
+    whileloop->m_locals.push_back(n2);
+    whileloop->m_locals.push_back(newbase2);
 
     /* base2 = newbase2; */
-    nestwhile->exprs.push_back(
+    nestwhile->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1627,7 +1627,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* n2 *= 2; */
-    nestwhile->exprs.push_back(
+    nestwhile->m_exprs.push_back(
         (ast_expression*)ast_binstore_new(
             ctx(),
             INSTR_STORE_F,
@@ -1638,7 +1638,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* newbase2 *= newbase2; */
-    nestwhile->exprs.push_back(
+    nestwhile->m_exprs.push_back(
         (ast_expression*)ast_binstore_new(
             ctx(),
             INSTR_STORE_F,
@@ -1649,7 +1649,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* while (whole >= newbase2) */
-    whileloop->exprs.push_back(
+    whileloop->m_exprs.push_back(
         (ast_expression*)ast_loop_new(
             ctx(),
             nullptr,
@@ -1668,7 +1668,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* whole /= base2; */
-    whileloop->exprs.push_back(
+    whileloop->m_exprs.push_back(
         (ast_expression*)ast_binstore_new(
             ctx(),
             INSTR_STORE_F,
@@ -1679,7 +1679,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* nth += n2; */
-    whileloop->exprs.push_back(
+    whileloop->m_exprs.push_back(
         (ast_expression*)ast_binstore_new(
             ctx(),
             INSTR_STORE_F,
@@ -1690,7 +1690,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* while (whole >= base) */
-    forloop->exprs.push_back(
+    forloop->m_exprs.push_back(
         (ast_expression*)ast_loop_new(
             ctx(),
             nullptr,
@@ -1708,12 +1708,12 @@ ast_expression *intrin::ln_() {
         )
     );
 
-    forloop->locals.push_back(b_iplus1);
-    forloop->locals.push_back(A_iplus1);
-    forloop->locals.push_back(B_iplus1);
+    forloop->m_locals.push_back(b_iplus1);
+    forloop->m_locals.push_back(A_iplus1);
+    forloop->m_locals.push_back(B_iplus1);
 
     /* b_iplus1 = nth; */
-    forloop->exprs.push_back(
+    forloop->m_exprs.push_back(
         (ast_expression*)ast_store_new(
             ctx(),
             INSTR_STORE_F,
@@ -1727,7 +1727,7 @@ ast_expression *intrin::ln_() {
      * B_iplus1 = b_iplus1 * B_i + B_iminus1;
      */
     for (i = 0; i <= 1; i++) {
-        forloop->exprs.push_back(
+        forloop->m_exprs.push_back(
             (ast_expression*)ast_store_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1752,7 +1752,7 @@ ast_expression *intrin::ln_() {
      * B_iminus1 = B_i;
      */
     for (i = 0; i <= 1; i++) {
-        forloop->exprs.push_back(
+        forloop->m_exprs.push_back(
             (ast_expression*)ast_store_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1767,7 +1767,7 @@ ast_expression *intrin::ln_() {
      * B_i = B_iplus1;
      */
     for (i = 0; i <= 1; i++) {
-        forloop->exprs.push_back(
+        forloop->m_exprs.push_back(
             (ast_expression*)ast_store_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1781,7 +1781,7 @@ ast_expression *intrin::ln_() {
      * if (whole <= 1.0f + eps)
      *     break;
      */
-    forloop->exprs.push_back(
+    forloop->m_exprs.push_back(
         (ast_expression*)ast_ifthen_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -1809,7 +1809,7 @@ ast_expression *intrin::ln_() {
      * base  = whole;
      */
     for (i = 0; i <= 1; i++) {
-        forloop->exprs.push_back(
+        forloop->m_exprs.push_back(
             (ast_expression*)ast_store_new(
                 ctx(),
                 INSTR_STORE_F,
@@ -1820,7 +1820,7 @@ ast_expression *intrin::ln_() {
     }
 
     /* add the for loop block */
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_loop_new(
             ctx(),
             nullptr,
@@ -1835,7 +1835,7 @@ ast_expression *intrin::ln_() {
     );
 
     /* return sign * A_i / B_il */
-    block->exprs.push_back(
+    block->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)ast_binary_new(
@@ -1852,7 +1852,7 @@ ast_expression *intrin::ln_() {
         )
     );
 
-    func->blocks.push_back(block);
+    func->m_blocks.emplace_back(block);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1864,19 +1864,19 @@ ast_expression *intrin::log_variant(const char *name, float base) {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, name, TYPE_FLOAT);
 
-    val->expression.params.push_back(arg1);
+    val->m_type_params.push_back(arg1);
 
-    callln->params.push_back((ast_expression*)arg1);
-    callln->params.push_back((ast_expression*)m_fold->constgen_float(base, false));
+    callln->m_params.push_back((ast_expression*)arg1);
+    callln->m_params.push_back((ast_expression*)m_fold->constgen_float(base, false));
 
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)callln
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1908,15 +1908,15 @@ ast_expression *intrin::shift_variant(const char *name, size_t instr) {
     ast_block *body = ast_block_new(ctx());
     ast_function *func = value(&val, name, TYPE_FLOAT);
 
-    val->expression.params.push_back(a);
-    val->expression.params.push_back(b);
+    val->m_type_params.push_back(a);
+    val->m_type_params.push_back(b);
 
     /* <callpow> = pow(2, b) */
-    callpow->params.push_back((ast_expression*)m_fold->m_imm_float[3]);
-    callpow->params.push_back((ast_expression*)b);
+    callpow->m_params.push_back((ast_expression*)m_fold->m_imm_float[3]);
+    callpow->m_params.push_back((ast_expression*)b);
 
     /* <callfloor> = floor(a [instr] <callpow>) */
-    callfloor->params.push_back(
+    callfloor->m_params.push_back(
         (ast_expression*)ast_binary_new(
             ctx(),
             instr,
@@ -1926,14 +1926,14 @@ ast_expression *intrin::shift_variant(const char *name, size_t instr) {
     );
 
     /* return <callfloor> */
-    body->exprs.push_back(
+    body->m_exprs.push_back(
         (ast_expression*)ast_return_new(
             ctx(),
             (ast_expression*)callfloor
         )
     );
 
-    func->blocks.push_back(body);
+    func->m_blocks.emplace_back(body);
     reg(val, func);
     return (ast_expression*)val;
 }
@@ -1998,14 +1998,14 @@ intrin::intrin(parser_t *parser)
 }
 
 ast_expression *intrin::do_fold(ast_value *val, ast_expression **exprs) {
-    if (!val || !val->name)
+    if (!val || !val->m_name)
         return nullptr;
     static constexpr size_t kPrefixLength = 10; // "__builtin_"
     for (auto &it : m_intrinsics) {
-        if (!strcmp(val->name, it.name))
+        if (!strcmp(val->m_name, it.name))
             return (vec_size(exprs) != it.args)
                         ? nullptr
-                        : m_fold->intrinsic(val->name + kPrefixLength, exprs);
+                        : m_fold->intrinsic(val->m_name + kPrefixLength, exprs);
     }
     return nullptr;
 }
@@ -2025,9 +2025,9 @@ ast_expression *intrin::func_try(size_t offset, const char *compare) {
 ast_expression *intrin::func_self(const char *name, const char *from) {
     ast_expression *find;
     /* try current first */
-    if ((find = parser_find_global(m_parser, name)) && ((ast_value*)find)->expression.vtype == TYPE_FUNCTION)
+    if ((find = parser_find_global(m_parser, name)) && ((ast_value*)find)->m_vtype == TYPE_FUNCTION)
         for (auto &it : m_parser->functions)
-            if (((ast_value*)find)->name && !strcmp(it->name, ((ast_value*)find)->name) && it->builtin < 0)
+            if (((ast_value*)find)->m_name && !strcmp(it->m_name, ((ast_value*)find)->m_name) && it->m_builtin < 0)
                 return find;
     /* try name second */
     if ((find = func_try(offsetof(intrin_func_t, name),  name)))
index e0151d8bdabb33c1ba87b39f9240cfe5a3a26a39..fe9ee78631d38735d4d742113a66dc75270c54bd 100644 (file)
--- a/intrin.h
+++ b/intrin.h
@@ -30,7 +30,7 @@ struct intrin {
 
 protected:
     lex_ctx_t ctx() const;
-    ast_function *value(ast_value **out, const char *name, qcint_t vtype);
+    ast_function *value(ast_value **out, const char *name, qc_type vtype);
     void reg(ast_value *const value, ast_function *const func);
 
     ast_expression *nullfunc();
diff --git a/ir.cpp b/ir.cpp
index 92cd11d41f318fd0ead169de7e6edc00cc9f5649..ba4ed649b7eea9eebe41f5d3b36260696c798409 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -190,30 +190,19 @@ const uint16_t type_not_instr[TYPE_COUNT] = {
 };
 
 /* protos */
-static ir_value*       ir_value_var(const char *name, int st, int vtype);
-static bool            ir_value_set_name(ir_value*, const char *name);
 static void            ir_value_dump(ir_value*, int (*oprintf)(const char*,...));
 
 static ir_value*       ir_gen_extparam_proto(ir_builder *ir);
 static void            ir_gen_extparam      (ir_builder *ir);
 
-static bool            ir_builder_set_name(ir_builder *self, const char *name);
-
-static ir_function*    ir_function_new(ir_builder *owner, int returntype);
-static bool            ir_function_set_name(ir_function*, const char *name);
-static void            ir_function_delete(ir_function*);
 static void            ir_function_dump(ir_function*, char *ind, int (*oprintf)(const char*,...));
 
 static ir_value*       ir_block_create_general_instr(ir_block *self, lex_ctx_t, const char *label,
-                                        int op, ir_value *a, ir_value *b, int outype);
-static void            ir_block_delete(ir_block*);
-static ir_block*       ir_block_new(ir_function *owner, const char *label);
+                                                     int op, ir_value *a, ir_value *b, qc_type outype);
 static bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx_t, ir_value *target, ir_value *what);
-static bool            ir_block_set_label(ir_block*, const char *label);
 static void            ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...));
 
 static bool            ir_instr_op(ir_instr*, int op, ir_value *value, bool writing);
-static void            ir_instr_delete(ir_instr*);
 static void            ir_instr_dump(ir_instr* in, char *ind, int (*oprintf)(const char*,...));
 /* error functions */
 
@@ -284,184 +273,124 @@ static void ir_block_delete_quick(ir_block* self);
 static void ir_instr_delete_quick(ir_instr *self);
 static void ir_function_delete_quick(ir_function *self);
 
-ir_builder* ir_builder_new(const char *modulename)
+ir_builder::ir_builder(const std::string& modulename)
+: m_name(modulename),
+  m_code(new code_t)
 {
-    ir_builder* self;
-    size_t      i;
-
-    self = (ir_builder*)mem_a(sizeof(*self));
-    if (!self)
-        return nullptr;
-
-    self->functions   = nullptr;
-    self->globals     = nullptr;
-    self->fields      = nullptr;
-    self->filenames   = nullptr;
-    self->filestrings = nullptr;
-    self->htglobals   = util_htnew(IR_HT_SIZE);
-    self->htfields    = util_htnew(IR_HT_SIZE);
-    self->htfunctions = util_htnew(IR_HT_SIZE);
-
-    self->extparams       = nullptr;
-    self->extparam_protos = nullptr;
-
-    self->first_common_globaltemp = 0;
-    self->max_globaltemps         = 0;
-    self->first_common_local      = 0;
-    self->max_locals              = 0;
-
-    self->str_immediate = 0;
-    self->name = nullptr;
-    if (!ir_builder_set_name(self, modulename)) {
-        mem_d(self);
-        return nullptr;
-    }
+    m_htglobals   = util_htnew(IR_HT_SIZE);
+    m_htfields    = util_htnew(IR_HT_SIZE);
+    m_htfunctions = util_htnew(IR_HT_SIZE);
 
-    self->nil = ir_value_var("nil", store_value, TYPE_NIL);
-    self->nil->cvq = CV_CONST;
+    m_nil = new ir_value("nil", store_value, TYPE_NIL);
+    m_nil->m_cvq = CV_CONST;
 
-    for (i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
+    for (size_t i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
         /* we write to them, but they're not supposed to be used outside the IR, so
          * let's not allow the generation of ir_instrs which use these.
          * So it's a constant noexpr.
          */
-        self->vinstr_temp[i] = ir_value_var("vinstr_temp", store_value, TYPE_NOEXPR);
-        self->vinstr_temp[i]->cvq = CV_CONST;
+        m_vinstr_temp[i] = new ir_value("vinstr_temp", store_value, TYPE_NOEXPR);
+        m_vinstr_temp[i]->m_cvq = CV_CONST;
     }
-
-    self->reserved_va_count = nullptr;
-    self->coverage_func     = nullptr;
-
-    self->code              = code_init();
-
-    return self;
 }
 
-void ir_builder_delete(ir_builder* self)
+ir_builder::~ir_builder()
 {
-    size_t i;
-    util_htdel(self->htglobals);
-    util_htdel(self->htfields);
-    util_htdel(self->htfunctions);
-    mem_d((void*)self->name);
-    for (i = 0; i != vec_size(self->functions); ++i) {
-        ir_function_delete_quick(self->functions[i]);
-    }
-    vec_free(self->functions);
-    for (i = 0; i != vec_size(self->extparams); ++i) {
-        ir_value_delete(self->extparams[i]);
-    }
-    vec_free(self->extparams);
-    vec_free(self->extparam_protos);
-    for (i = 0; i != vec_size(self->globals); ++i) {
-        ir_value_delete(self->globals[i]);
-    }
-    vec_free(self->globals);
-    for (i = 0; i != vec_size(self->fields); ++i) {
-        ir_value_delete(self->fields[i]);
-    }
-    ir_value_delete(self->nil);
-    for (i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
-        ir_value_delete(self->vinstr_temp[i]);
-    }
-    vec_free(self->fields);
-    vec_free(self->filenames);
-    vec_free(self->filestrings);
-
-    code_cleanup(self->code);
-    mem_d(self);
-}
+    util_htdel(m_htglobals);
+    util_htdel(m_htfields);
+    util_htdel(m_htfunctions);
+    for (auto& f : m_functions)
+        ir_function_delete_quick(f.release());
+    m_functions.clear(); // delete them now before deleting the rest:
 
-bool ir_builder_set_name(ir_builder *self, const char *name)
-{
-    if (self->name)
-        mem_d((void*)self->name);
-    self->name = util_strdup(name);
-    return !!self->name;
+    delete m_nil;
+
+    for (size_t i = 0; i != IR_MAX_VINSTR_TEMPS; ++i) {
+        delete m_vinstr_temp[i];
+    }
+
+    m_extparams.clear();
+    m_extparam_protos.clear();
 }
 
 static ir_function* ir_builder_get_function(ir_builder *self, const char *name)
 {
-    return (ir_function*)util_htget(self->htfunctions, name);
+    return (ir_function*)util_htget(self->m_htfunctions, name);
 }
 
-ir_function* ir_builder_create_function(ir_builder *self, const char *name, int outtype)
+ir_function* ir_builder_create_function(ir_builder *self, const std::string& name, qc_type outtype)
 {
-    ir_function *fn = ir_builder_get_function(self, name);
+    ir_function *fn = ir_builder_get_function(self, name.c_str());
     if (fn) {
         return nullptr;
     }
 
-    fn = ir_function_new(self, outtype);
-    if (!ir_function_set_name(fn, name))
-    {
-        ir_function_delete(fn);
-        return nullptr;
-    }
-    vec_push(self->functions, fn);
-    util_htset(self->htfunctions, name, fn);
+    fn = new ir_function(self, outtype);
+    fn->m_name = name;
+    self->m_functions.emplace_back(fn);
+    util_htset(self->m_htfunctions, name.c_str(), fn);
 
-    fn->value = ir_builder_create_global(self, fn->name, TYPE_FUNCTION);
-    if (!fn->value) {
-        ir_function_delete(fn);
+    fn->m_value = ir_builder_create_global(self, fn->m_name, TYPE_FUNCTION);
+    if (!fn->m_value) {
+        delete fn;
         return nullptr;
     }
 
-    fn->value->hasvalue = true;
-    fn->value->outtype = outtype;
-    fn->value->constval.vfunc = fn;
-    fn->value->context = fn->context;
+    fn->m_value->m_hasvalue = true;
+    fn->m_value->m_outtype = outtype;
+    fn->m_value->m_constval.vfunc = fn;
+    fn->m_value->m_context = fn->m_context;
 
     return fn;
 }
 
 static ir_value* ir_builder_get_global(ir_builder *self, const char *name)
 {
-    return (ir_value*)util_htget(self->htglobals, name);
+    return (ir_value*)util_htget(self->m_htglobals, name);
 }
 
-ir_value* ir_builder_create_global(ir_builder *self, const char *name, int vtype)
+ir_value* ir_builder_create_global(ir_builder *self, const std::string& name, qc_type vtype)
 {
     ir_value *ve;
 
     if (name[0] != '#')
     {
-        ve = ir_builder_get_global(self, name);
+        ve = ir_builder_get_global(self, name.c_str());
         if (ve) {
             return nullptr;
         }
     }
 
-    ve = ir_value_var(name, store_global, vtype);
-    vec_push(self->globals, ve);
-    util_htset(self->htglobals, name, ve);
+    ve = new ir_value(std::string(name), store_global, vtype);
+    self->m_globals.emplace_back(ve);
+    util_htset(self->m_htglobals, name.c_str(), ve);
     return ve;
 }
 
 ir_value* ir_builder_get_va_count(ir_builder *self)
 {
-    if (self->reserved_va_count)
-        return self->reserved_va_count;
-    return (self->reserved_va_count = ir_builder_create_global(self, "reserved:va_count", TYPE_FLOAT));
+    if (self->m_reserved_va_count)
+        return self->m_reserved_va_count;
+    return (self->m_reserved_va_count = ir_builder_create_global(self, "reserved:va_count", TYPE_FLOAT));
 }
 
 static ir_value* ir_builder_get_field(ir_builder *self, const char *name)
 {
-    return (ir_value*)util_htget(self->htfields, name);
+    return (ir_value*)util_htget(self->m_htfields, name);
 }
 
 
-ir_value* ir_builder_create_field(ir_builder *self, const char *name, int vtype)
+ir_value* ir_builder_create_field(ir_builder *self, const std::string& name, qc_type vtype)
 {
-    ir_value *ve = ir_builder_get_field(self, name);
+    ir_value *ve = ir_builder_get_field(self, name.c_str());
     if (ve) {
         return nullptr;
     }
 
-    ve = ir_value_var(name, store_global, TYPE_FIELD);
-    ve->fieldtype = vtype;
-    vec_push(self->fields, ve);
-    util_htset(self->htfields, name, ve);
+    ve = new ir_value(std::string(name), store_global, TYPE_FIELD);
+    ve->m_fieldtype = vtype;
+    self->m_fields.emplace_back(ve);
+    util_htset(self->m_htfields, name.c_str(), ve);
     return ve;
 }
 
@@ -474,114 +403,39 @@ static void ir_function_enumerate(ir_function*);
 static bool ir_function_calculate_liferanges(ir_function*);
 static bool ir_function_allocate_locals(ir_function*);
 
-ir_function* ir_function_new(ir_builder* owner, int outtype)
+ir_function::ir_function(ir_builder* owner_, qc_type outtype_)
+: m_owner(owner_),
+  m_name("<@unnamed>"),
+  m_outtype(outtype_)
 {
-    ir_function *self;
-    self = (ir_function*)mem_a(sizeof(*self));
-
-    if (!self)
-        return nullptr;
-
-    memset(self, 0, sizeof(*self));
-
-    self->name = nullptr;
-    if (!ir_function_set_name(self, "<@unnamed>")) {
-        mem_d(self);
-        return nullptr;
-    }
-    self->flags = 0;
-
-    self->owner = owner;
-    self->context.file = "<@no context>";
-    self->context.line = 0;
-    self->outtype = outtype;
-    self->value = nullptr;
-    self->builtin = 0;
-
-    self->params = nullptr;
-    self->blocks = nullptr;
-    self->values = nullptr;
-    self->locals = nullptr;
-
-    self->max_varargs = 0;
-
-    self->code_function_def = -1;
-    self->allocated_locals = 0;
-    self->globaltemps      = 0;
-
-    self->run_id = 0;
-    return self;
+    m_context.file = "<@no context>";
+    m_context.line = 0;
 }
 
-bool ir_function_set_name(ir_function *self, const char *name)
+ir_function::~ir_function()
 {
-    if (self->name)
-        mem_d((void*)self->name);
-    self->name = util_strdup(name);
-    return !!self->name;
 }
 
 static void ir_function_delete_quick(ir_function *self)
 {
-    size_t i;
-    mem_d((void*)self->name);
-
-    for (i = 0; i != vec_size(self->blocks); ++i)
-        ir_block_delete_quick(self->blocks[i]);
-    vec_free(self->blocks);
-
-    vec_free(self->params);
-
-    for (i = 0; i != vec_size(self->values); ++i)
-        ir_value_delete(self->values[i]);
-    vec_free(self->values);
-
-    for (i = 0; i != vec_size(self->locals); ++i)
-        ir_value_delete(self->locals[i]);
-    vec_free(self->locals);
-
-    /* self->value is deleted by the builder */
-
-    mem_d(self);
-}
-
-void ir_function_delete(ir_function *self)
-{
-    size_t i;
-    mem_d((void*)self->name);
-
-    for (i = 0; i != vec_size(self->blocks); ++i)
-        ir_block_delete(self->blocks[i]);
-    vec_free(self->blocks);
-
-    vec_free(self->params);
-
-    for (i = 0; i != vec_size(self->values); ++i)
-        ir_value_delete(self->values[i]);
-    vec_free(self->values);
-
-    for (i = 0; i != vec_size(self->locals); ++i)
-        ir_value_delete(self->locals[i]);
-    vec_free(self->locals);
-
-    /* self->value is deleted by the builder */
-
-    mem_d(self);
+    for (auto& b : self->m_blocks)
+        ir_block_delete_quick(b.release());
+    delete self;
 }
 
 static void ir_function_collect_value(ir_function *self, ir_value *v)
 {
-    vec_push(self->values, v);
+    self->m_values.emplace_back(v);
 }
 
 ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function *self, const char *label)
 {
-    ir_block* bn = ir_block_new(self, label);
-    bn->context = ctx;
-    vec_push(self->blocks, bn);
+    ir_block* bn = new ir_block(self, label ? std::string(label) : std::string());
+    bn->m_context = ctx;
+    self->m_blocks.emplace_back(bn);
 
-    if ((self->flags & IR_FLAG_BLOCK_COVERAGE) && self->owner->coverage_func)
-        (void)ir_block_create_call(bn, ctx, nullptr, self->owner->coverage_func, false);
+    if ((self->m_flags & IR_FLAG_BLOCK_COVERAGE) && self->m_owner->m_coverage_func)
+        (void)ir_block_create_call(bn, ctx, nullptr, self->m_owner->m_coverage_func, false);
 
     return bn;
 }
@@ -599,19 +453,15 @@ static bool instr_is_operation(uint16_t op)
 
 static bool ir_function_pass_peephole(ir_function *self)
 {
-    size_t b;
-
-    for (b = 0; b < vec_size(self->blocks); ++b) {
-        size_t    i;
-        ir_block *block = self->blocks[b];
-
-        for (i = 0; i < vec_size(block->instr); ++i) {
+    for (auto& bp : self->m_blocks) {
+        ir_block *block = bp.get();
+        for (size_t i = 0; i < vec_size(block->m_instr); ++i) {
             ir_instr *inst;
-            inst = block->instr[i];
+            inst = block->m_instr[i];
 
             if (i >= 1 &&
-                (inst->opcode >= INSTR_STORE_F &&
-                 inst->opcode <= INSTR_STORE_FNC))
+                (inst->m_opcode >= INSTR_STORE_F &&
+                 inst->m_opcode <= INSTR_STORE_FNC))
             {
                 ir_instr *store;
                 ir_instr *oper;
@@ -619,44 +469,44 @@ static bool ir_function_pass_peephole(ir_function *self)
 
                 store = inst;
 
-                oper  = block->instr[i-1];
-                if (!instr_is_operation(oper->opcode))
+                oper  = block->m_instr[i-1];
+                if (!instr_is_operation(oper->m_opcode))
                     continue;
 
                 /* Don't change semantics of MUL_VF in engines where these may not alias. */
                 if (OPTS_FLAG(LEGACY_VECTOR_MATHS)) {
-                    if (oper->opcode == INSTR_MUL_VF && oper->_ops[2]->memberof == oper->_ops[1])
+                    if (oper->m_opcode == INSTR_MUL_VF && oper->_m_ops[2]->m_memberof == oper->_m_ops[1])
                         continue;
-                    if (oper->opcode == INSTR_MUL_FV && oper->_ops[1]->memberof == oper->_ops[2])
+                    if (oper->m_opcode == INSTR_MUL_FV && oper->_m_ops[1]->m_memberof == oper->_m_ops[2])
                         continue;
                 }
 
-                value = oper->_ops[0];
+                value = oper->_m_ops[0];
 
                 /* only do it for SSA values */
-                if (value->store != store_value)
+                if (value->m_store != store_value)
                     continue;
 
                 /* don't optimize out the temp if it's used later again */
-                if (value->reads.size() != 1)
+                if (value->m_reads.size() != 1)
                     continue;
 
                 /* The very next store must use this value */
-                if (value->reads[0] != store)
+                if (value->m_reads[0] != store)
                     continue;
 
                 /* And of course the store must _read_ from it, so it's in
                  * OP 1 */
-                if (store->_ops[1] != value)
+                if (store->_m_ops[1] != value)
                     continue;
 
                 ++opts_optimizationcount[OPTIM_PEEPHOLE];
-                (void)!ir_instr_op(oper, 0, store->_ops[0], true);
+                (void)!ir_instr_op(oper, 0, store->_m_ops[0], true);
 
-                vec_remove(block->instr, i, 1);
-                ir_instr_delete(store);
+                vec_remove(block->m_instr, i, 1);
+                delete store;
             }
-            else if (inst->opcode == VINSTR_COND)
+            else if (inst->m_opcode == VINSTR_COND)
             {
                 /* COND on a value resulting from a NOT could
                  * remove the NOT and swap its operands
@@ -666,17 +516,17 @@ static bool ir_function_pass_peephole(ir_function *self)
                     size_t    inotid;
                     ir_instr *inot;
                     ir_value *value;
-                    value = inst->_ops[0];
+                    value = inst->_m_ops[0];
 
-                    if (value->store != store_value || value->reads.size() != 1 || value->reads[0] != inst)
+                    if (value->m_store != store_value || value->m_reads.size() != 1 || value->m_reads[0] != inst)
                         break;
 
-                    inot = value->writes[0];
-                    if (inot->_ops[0] != value ||
-                        inot->opcode < INSTR_NOT_F ||
-                        inot->opcode > INSTR_NOT_FNC ||
-                        inot->opcode == INSTR_NOT_V || /* can't do these */
-                        inot->opcode == INSTR_NOT_S)
+                    inot = value->m_writes[0];
+                    if (inot->_m_ops[0] != value ||
+                        inot->m_opcode < INSTR_NOT_F ||
+                        inot->m_opcode > INSTR_NOT_FNC ||
+                        inot->m_opcode == INSTR_NOT_V || /* can't do these */
+                        inot->m_opcode == INSTR_NOT_S)
                     {
                         break;
                     }
@@ -684,23 +534,23 @@ static bool ir_function_pass_peephole(ir_function *self)
                     /* count */
                     ++opts_optimizationcount[OPTIM_PEEPHOLE];
                     /* change operand */
-                    (void)!ir_instr_op(inst, 0, inot->_ops[1], false);
+                    (void)!ir_instr_op(inst, 0, inot->_m_ops[1], false);
                     /* remove NOT */
-                    tmp = inot->owner;
-                    for (inotid = 0; inotid < vec_size(tmp->instr); ++inotid) {
-                        if (tmp->instr[inotid] == inot)
+                    tmp = inot->m_owner;
+                    for (inotid = 0; inotid < vec_size(tmp->m_instr); ++inotid) {
+                        if (tmp->m_instr[inotid] == inot)
                             break;
                     }
-                    if (inotid >= vec_size(tmp->instr)) {
-                        compile_error(inst->context, "sanity-check failed: failed to find instruction to optimize out");
+                    if (inotid >= vec_size(tmp->m_instr)) {
+                        compile_error(inst->m_context, "sanity-check failed: failed to find instruction to optimize out");
                         return false;
                     }
-                    vec_remove(tmp->instr, inotid, 1);
-                    ir_instr_delete(inot);
+                    vec_remove(tmp->m_instr, inotid, 1);
+                    delete inot;
                     /* swap ontrue/onfalse */
-                    tmp = inst->bops[0];
-                    inst->bops[0] = inst->bops[1];
-                    inst->bops[1] = tmp;
+                    tmp = inst->m_bops[0];
+                    inst->m_bops[0] = inst->m_bops[1];
+                    inst->m_bops[1] = tmp;
                 }
                 continue;
             }
@@ -712,86 +562,87 @@ static bool ir_function_pass_peephole(ir_function *self)
 
 static bool ir_function_pass_tailrecursion(ir_function *self)
 {
-    size_t b, p;
+    size_t p;
+
+    for (auto& bp : self->m_blocks) {
+        ir_block *block = bp.get();
 
-    for (b = 0; b < vec_size(self->blocks); ++b) {
         ir_value *funcval;
         ir_instr *ret, *call, *store = nullptr;
-        ir_block *block = self->blocks[b];
 
-        if (!block->final || vec_size(block->instr) < 2)
+        if (!block->m_final || vec_size(block->m_instr) < 2)
             continue;
 
-        ret = block->instr[vec_size(block->instr)-1];
-        if (ret->opcode != INSTR_DONE && ret->opcode != INSTR_RETURN)
+        ret = block->m_instr[vec_size(block->m_instr)-1];
+        if (ret->m_opcode != INSTR_DONE && ret->m_opcode != INSTR_RETURN)
             continue;
 
-        call = block->instr[vec_size(block->instr)-2];
-        if (call->opcode >= INSTR_STORE_F && call->opcode <= INSTR_STORE_FNC) {
+        call = block->m_instr[vec_size(block->m_instr)-2];
+        if (call->m_opcode >= INSTR_STORE_F && call->m_opcode <= INSTR_STORE_FNC) {
             /* account for the unoptimized
              * CALL
              * STORE %return, %tmp
              * RETURN %tmp
              * version
              */
-            if (vec_size(block->instr) < 3)
+            if (vec_size(block->m_instr) < 3)
                 continue;
 
             store = call;
-            call = block->instr[vec_size(block->instr)-3];
+            call = block->m_instr[vec_size(block->m_instr)-3];
         }
 
-        if (call->opcode < INSTR_CALL0 || call->opcode > INSTR_CALL8)
+        if (call->m_opcode < INSTR_CALL0 || call->m_opcode > INSTR_CALL8)
             continue;
 
         if (store) {
             /* optimize out the STORE */
-            if (ret->_ops[0]   &&
-                ret->_ops[0]   == store->_ops[0] &&
-                store->_ops[1] == call->_ops[0])
+            if (ret->_m_ops[0]   &&
+                ret->_m_ops[0]   == store->_m_ops[0] &&
+                store->_m_ops[1] == call->_m_ops[0])
             {
                 ++opts_optimizationcount[OPTIM_PEEPHOLE];
-                call->_ops[0] = store->_ops[0];
-                vec_remove(block->instr, vec_size(block->instr) - 2, 1);
-                ir_instr_delete(store);
+                call->_m_ops[0] = store->_m_ops[0];
+                vec_remove(block->m_instr, vec_size(block->m_instr) - 2, 1);
+                delete store;
             }
             else
                 continue;
         }
 
-        if (!call->_ops[0])
+        if (!call->_m_ops[0])
             continue;
 
-        funcval = call->_ops[1];
+        funcval = call->_m_ops[1];
         if (!funcval)
             continue;
-        if (funcval->vtype != TYPE_FUNCTION || funcval->constval.vfunc != self)
+        if (funcval->m_vtype != TYPE_FUNCTION || funcval->m_constval.vfunc != self)
             continue;
 
         /* now we have a CALL and a RET, check if it's a tailcall */
-        if (ret->_ops[0] && call->_ops[0] != ret->_ops[0])
+        if (ret->_m_ops[0] && call->_m_ops[0] != ret->_m_ops[0])
             continue;
 
         ++opts_optimizationcount[OPTIM_TAIL_RECURSION];
-        vec_shrinkby(block->instr, 2);
+        vec_shrinkby(block->m_instr, 2);
 
-        block->final = false; /* open it back up */
+        block->m_final = false; /* open it back up */
 
         /* emite parameter-stores */
-        for (p = 0; p < call->params.size(); ++p) {
+        for (p = 0; p < call->m_params.size(); ++p) {
             /* assert(call->params_count <= self->locals_count); */
-            if (!ir_block_create_store(block, call->context, self->locals[p], call->params[p])) {
-                irerror(call->context, "failed to create tailcall store instruction for parameter %i", (int)p);
+            if (!ir_block_create_store(block, call->m_context, self->m_locals[p].get(), call->m_params[p])) {
+                irerror(call->m_context, "failed to create tailcall store instruction for parameter %i", (int)p);
                 return false;
             }
         }
-        if (!ir_block_create_jump(block, call->context, self->blocks[0])) {
-            irerror(call->context, "failed to create tailcall jump");
+        if (!ir_block_create_jump(block, call->m_context, self->m_blocks[0].get())) {
+            irerror(call->m_context, "failed to create tailcall jump");
             return false;
         }
 
-        ir_instr_delete(call);
-        ir_instr_delete(ret);
+        delete call;
+        delete ret;
     }
 
     return true;
@@ -799,44 +650,42 @@ static bool ir_function_pass_tailrecursion(ir_function *self)
 
 bool ir_function_finalize(ir_function *self)
 {
-    size_t i;
-
-    if (self->builtin)
+    if (self->m_builtin)
         return true;
 
     if (OPTS_OPTIMIZATION(OPTIM_PEEPHOLE)) {
         if (!ir_function_pass_peephole(self)) {
-            irerror(self->context, "generic optimization pass broke something in `%s`", self->name);
+            irerror(self->m_context, "generic optimization pass broke something in `%s`", self->m_name.c_str());
             return false;
         }
     }
 
     if (OPTS_OPTIMIZATION(OPTIM_TAIL_RECURSION)) {
         if (!ir_function_pass_tailrecursion(self)) {
-            irerror(self->context, "tail-recursion optimization pass broke something in `%s`", self->name);
+            irerror(self->m_context, "tail-recursion optimization pass broke something in `%s`", self->m_name.c_str());
             return false;
         }
     }
 
     if (!ir_function_naive_phi(self)) {
-        irerror(self->context, "internal error: ir_function_naive_phi failed");
+        irerror(self->m_context, "internal error: ir_function_naive_phi failed");
         return false;
     }
 
-    for (i = 0; i < vec_size(self->locals); ++i) {
-        ir_value *v = self->locals[i];
-        if (v->vtype == TYPE_VECTOR ||
-            (v->vtype == TYPE_FIELD && v->outtype == TYPE_VECTOR))
+    for (auto& lp : self->m_locals) {
+        ir_value *v = lp.get();
+        if (v->m_vtype == TYPE_VECTOR ||
+            (v->m_vtype == TYPE_FIELD && v->m_outtype == TYPE_VECTOR))
         {
             ir_value_vector_member(v, 0);
             ir_value_vector_member(v, 1);
             ir_value_vector_member(v, 2);
         }
     }
-    for (i = 0; i < vec_size(self->values); ++i) {
-        ir_value *v = self->values[i];
-        if (v->vtype == TYPE_VECTOR ||
-            (v->vtype == TYPE_FIELD && v->outtype == TYPE_VECTOR))
+    for (auto& vp : self->m_values) {
+        ir_value *v = vp.get();
+        if (v->m_vtype == TYPE_VECTOR ||
+            (v->m_vtype == TYPE_FIELD && v->m_outtype == TYPE_VECTOR))
         {
             ir_value_vector_member(v, 0);
             ir_value_vector_member(v, 1);
@@ -853,21 +702,22 @@ bool ir_function_finalize(ir_function *self)
     return true;
 }
 
-ir_value* ir_function_create_local(ir_function *self, const char *name, int vtype, bool param)
+ir_value* ir_function_create_local(ir_function *self, const std::string& name, qc_type vtype, bool param)
 {
     ir_value *ve;
 
     if (param &&
-        vec_size(self->locals) &&
-        self->locals[vec_size(self->locals)-1]->store != store_param) {
-        irerror(self->context, "cannot add parameters after adding locals");
+        !self->m_locals.empty() &&
+        self->m_locals.back()->m_store != store_param)
+    {
+        irerror(self->m_context, "cannot add parameters after adding locals");
         return nullptr;
     }
 
-    ve = ir_value_var(name, (param ? store_param : store_local), vtype);
+    ve = new ir_value(std::string(name), (param ? store_param : store_local), vtype);
     if (param)
-        ve->locked = true;
-    vec_push(self->locals, ve);
+        ve->m_locked = true;
+    self->m_locals.emplace_back(ve);
     return ve;
 }
 
@@ -875,138 +725,97 @@ ir_value* ir_function_create_local(ir_function *self, const char *name, int vtyp
  *IR Block
  */
 
-ir_block* ir_block_new(ir_function* owner, const char *name)
+ir_block::ir_block(ir_function* owner, const std::string& name)
+: m_owner(owner),
+  m_label(name)
 {
-    ir_block *self = new ir_block;
-    memset(self, 0, sizeof(*self));
-
-    self->label = nullptr;
-    if (name && !ir_block_set_label(self, name)) {
-        mem_d(self);
-        return nullptr;
-    }
-    self->owner = owner;
-    self->context.file = "<@no context>";
-    self->context.line = 0;
-    self->final = false;
-
-    self->instr = nullptr;
-    self->entries = nullptr;
-    self->exits = nullptr;
-
-    self->eid = 0;
-    self->is_return = false;
-    self->generated = false;
-
-    return self;
+    m_context.file = "<@no context>";
+    m_context.line = 0;
 }
 
-static void ir_block_delete_quick(ir_block* self)
+ir_block::~ir_block()
 {
-    size_t i;
-    if (self->label) mem_d(self->label);
-    for (i = 0; i != vec_size(self->instr); ++i)
-        ir_instr_delete_quick(self->instr[i]);
-    vec_free(self->instr);
-    vec_free(self->entries);
-    vec_free(self->exits);
-    delete self;
+    for (size_t i = 0; i != vec_size(m_instr); ++i)
+        delete m_instr[i];
+    vec_free(m_instr);
+    vec_free(m_entries);
+    vec_free(m_exits);
 }
 
-void ir_block_delete(ir_block* self)
+static void ir_block_delete_quick(ir_block* self)
 {
     size_t i;
-    if (self->label) mem_d(self->label);
-    for (i = 0; i != vec_size(self->instr); ++i)
-        ir_instr_delete(self->instr[i]);
-    vec_free(self->instr);
-    vec_free(self->entries);
-    vec_free(self->exits);
+    for (i = 0; i != vec_size(self->m_instr); ++i)
+        ir_instr_delete_quick(self->m_instr[i]);
+    vec_free(self->m_instr);
     delete self;
 }
 
-bool ir_block_set_label(ir_block *self, const char *name)
-{
-    if (self->label)
-        mem_d((void*)self->label);
-    self->label = util_strdup(name);
-    return !!self->label;
-}
-
 /***********************************************************************
  *IR Instructions
  */
 
-static ir_instr* ir_instr_new(lex_ctx_t ctx, ir_block* owner, int op)
+ir_instr::ir_instr(lex_ctx_t ctx, ir_block* owner_, int op)
+: m_opcode(op),
+  m_context(ctx),
+  m_owner(owner_)
 {
-    ir_instr *self = new ir_instr;
-    self->owner = owner;
-    self->context = ctx;
-    self->opcode = op;
-    self->_ops[0] = nullptr;
-    self->_ops[1] = nullptr;
-    self->_ops[2] = nullptr;
-    self->bops[0] = nullptr;
-    self->bops[1] = nullptr;
-    self->eid = 0;
-    self->likely = true;
-    return self;
 }
 
-static void ir_instr_delete_quick(ir_instr *self)
+ir_instr::~ir_instr()
 {
-    delete self;
-}
-
-static void ir_instr_delete(ir_instr *self)
-{
-    /* The following calls can only delete from
-     * vectors, we still want to delete this instruction
-     * so ignore the return value. Since with the warn_unused_result attribute
-     * gcc doesn't care about an explicit: (void)foo(); to ignore the result,
-     * I have to improvise here and use if(foo());
-     */
-    for (auto &it : self->phi) {
+    // The following calls can only delete from
+    // vectors, we still want to delete this instruction
+    // so ignore the return value. Since with the warn_unused_result attribute
+    // gcc doesn't care about an explicit: (void)foo(); to ignore the result,
+    // I have to improvise here and use if(foo());
+    for (auto &it : m_phi) {
         size_t idx;
-        if (vec_ir_instr_find(it.value->writes, self, &idx))
-            it.value->writes.erase(it.value->writes.begin() + idx);
-        if (vec_ir_instr_find(it.value->reads, self, &idx))
-            it.value->reads.erase(it.value->reads.begin() + idx);
+        if (vec_ir_instr_find(it.value->m_writes, this, &idx))
+            it.value->m_writes.erase(it.value->m_writes.begin() + idx);
+        if (vec_ir_instr_find(it.value->m_reads, this, &idx))
+            it.value->m_reads.erase(it.value->m_reads.begin() + idx);
     }
-    for (auto &it : self->params) {
+    for (auto &it : m_params) {
         size_t idx;
-        if (vec_ir_instr_find(it->writes, self, &idx))
-            it->writes.erase(it->writes.begin() + idx);
-        if (vec_ir_instr_find(it->reads, self, &idx))
-            it->reads.erase(it->reads.begin() + idx);
-    }
-    (void)!ir_instr_op(self, 0, nullptr, false);
-    (void)!ir_instr_op(self, 1, nullptr, false);
-    (void)!ir_instr_op(self, 2, nullptr, false);
-    mem_d(self);
+        if (vec_ir_instr_find(it->m_writes, this, &idx))
+            it->m_writes.erase(it->m_writes.begin() + idx);
+        if (vec_ir_instr_find(it->m_reads, this, &idx))
+            it->m_reads.erase(it->m_reads.begin() + idx);
+    }
+    (void)!ir_instr_op(this, 0, nullptr, false);
+    (void)!ir_instr_op(this, 1, nullptr, false);
+    (void)!ir_instr_op(this, 2, nullptr, false);
+}
+
+static void ir_instr_delete_quick(ir_instr *self)
+{
+    self->m_phi.clear();
+    self->m_params.clear();
+    delete self;
 }
 
 static bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing)
 {
-    if (v && v->vtype == TYPE_NOEXPR) {
-        irerror(self->context, "tried to use a NOEXPR value");
+    if (v && v->m_vtype == TYPE_NOEXPR) {
+        irerror(self->m_context, "tried to use a NOEXPR value");
         return false;
     }
 
-    if (self->_ops[op]) {
+    if (self->_m_ops[op]) {
         size_t idx;
-        if (writing && vec_ir_instr_find(self->_ops[op]->writes, self, &idx))
-            self->_ops[op]->writes.erase(self->_ops[op]->writes.begin() + idx);
-        else if (vec_ir_instr_find(self->_ops[op]->reads, self, &idx))
-            self->_ops[op]->reads.erase(self->_ops[op]->reads.begin() + idx);
+        if (writing && vec_ir_instr_find(self->_m_ops[op]->m_writes, self, &idx))
+            self->_m_ops[op]->m_writes.erase(self->_m_ops[op]->m_writes.begin() + idx);
+        else if (vec_ir_instr_find(self->_m_ops[op]->m_reads, self, &idx))
+            self->_m_ops[op]->m_reads.erase(self->_m_ops[op]->m_reads.begin() + idx);
     }
     if (v) {
         if (writing)
-            v->writes.push_back(self);
+            v->m_writes.push_back(self);
         else
-            v->reads.push_back(self);
+            v->m_reads.push_back(self);
     }
-    self->_ops[op] = v;
+    self->_m_ops[op] = v;
     return true;
 }
 
@@ -1016,239 +825,202 @@ static bool ir_instr_op(ir_instr *self, int op, ir_value *v, bool writing)
 
 static void ir_value_code_setaddr(ir_value *self, int32_t gaddr)
 {
-    self->code.globaladdr = gaddr;
-    if (self->members[0]) self->members[0]->code.globaladdr = gaddr;
-    if (self->members[1]) self->members[1]->code.globaladdr = gaddr;
-    if (self->members[2]) self->members[2]->code.globaladdr = gaddr;
+    self->m_code.globaladdr = gaddr;
+    if (self->m_members[0]) self->m_members[0]->m_code.globaladdr = gaddr;
+    if (self->m_members[1]) self->m_members[1]->m_code.globaladdr = gaddr;
+    if (self->m_members[2]) self->m_members[2]->m_code.globaladdr = gaddr;
 }
 
 static int32_t ir_value_code_addr(const ir_value *self)
 {
-    if (self->store == store_return)
-        return OFS_RETURN + self->code.addroffset;
-    return self->code.globaladdr + self->code.addroffset;
+    if (self->m_store == store_return)
+        return OFS_RETURN + self->m_code.addroffset;
+    return self->m_code.globaladdr + self->m_code.addroffset;
 }
 
-ir_value* ir_value_var(const char *name, int storetype, int vtype)
+ir_value::ir_value(std::string&& name_, store_type store_, qc_type vtype_)
+: m_name(move(name_)),
+  m_vtype(vtype_),
+  m_store(store_)
 {
-    ir_value *self;
-    self = (ir_value*)mem_a(sizeof(*self));
-    new (self) ir_value();
-    self->vtype = vtype;
-    self->fieldtype = TYPE_VOID;
-    self->outtype = TYPE_VOID;
-    self->store = storetype;
-    self->flags = 0;
-
-    self->cvq = CV_NONE;
-    self->hasvalue = false;
-    self->context.file = "<@no context>";
-    self->context.line = 0;
-    self->name = nullptr;
-    if (name && !ir_value_set_name(self, name)) {
-        irerror(self->context, "out of memory");
-        mem_d(self);
-        return nullptr;
-    }
-
-    memset(&self->constval, 0, sizeof(self->constval));
-    memset(&self->code,     0, sizeof(self->code));
-
-    self->members[0] = nullptr;
-    self->members[1] = nullptr;
-    self->members[2] = nullptr;
-    self->memberof = nullptr;
-
-    self->unique_life = false;
-    self->locked = false;
-    self->callparam  = false;
+    m_fieldtype = TYPE_VOID;
+    m_outtype = TYPE_VOID;
+    m_flags = 0;
+
+    m_cvq          = CV_NONE;
+    m_hasvalue     = false;
+    m_context.file = "<@no context>";
+    m_context.line = 0;
+
+    memset(&m_constval, 0, sizeof(m_constval));
+    memset(&m_code,     0, sizeof(m_code));
+
+    m_members[0] = nullptr;
+    m_members[1] = nullptr;
+    m_members[2] = nullptr;
+    m_memberof = nullptr;
+
+    m_unique_life = false;
+    m_locked = false;
+    m_callparam  = false;
+}
 
-    self->life = nullptr;
-    return self;
+ir_value::~ir_value()
+{
+    size_t i;
+    if (m_hasvalue) {
+        if (m_vtype == TYPE_STRING)
+            mem_d((void*)m_constval.vstring);
+    }
+    if (!(m_flags & IR_FLAG_SPLIT_VECTOR)) {
+        for (i = 0; i < 3; ++i) {
+            if (m_members[i])
+                delete m_members[i];
+        }
+    }
 }
 
+
 /*  helper function */
 static ir_value* ir_builder_imm_float(ir_builder *self, float value, bool add_to_list) {
-    ir_value *v = ir_value_var("#IMMEDIATE", store_global, TYPE_FLOAT);
-    v->flags |= IR_FLAG_ERASABLE;
-    v->hasvalue = true;
-    v->cvq = CV_CONST;
-    v->constval.vfloat = value;
+    ir_value *v = new ir_value("#IMMEDIATE", store_global, TYPE_FLOAT);
+    v->m_flags |= IR_FLAG_ERASABLE;
+    v->m_hasvalue = true;
+    v->m_cvq = CV_CONST;
+    v->m_constval.vfloat = value;
 
-    vec_push(self->globals, v);
+    self->m_globals.emplace_back(v);
     if (add_to_list)
-        vec_push(self->const_floats, v);
+        self->m_const_floats.emplace_back(v);
     return v;
 }
 
 ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
 {
-    char *name;
-    size_t len;
+    std::string name;
     ir_value *m;
     if (member >= 3)
         return nullptr;
 
-    if (self->members[member])
-        return self->members[member];
+    if (self->m_members[member])
+        return self->m_members[member];
 
-    if (self->name) {
-        len = strlen(self->name);
-        name = (char*)mem_a(len + 3);
-        memcpy(name, self->name, len);
-        name[len+0] = '_';
-        name[len+1] = 'x' + member;
-        name[len+2] = '\0';
+    if (!self->m_name.empty()) {
+        char member_name[3] = { '_', char('x' + member), 0 };
+        name = self->m_name + member_name;
     }
-    else
-        name = nullptr;
 
-    if (self->vtype == TYPE_VECTOR)
+    if (self->m_vtype == TYPE_VECTOR)
     {
-        m = ir_value_var(name, self->store, TYPE_FLOAT);
-        if (name)
-            mem_d(name);
+        m = new ir_value(move(name), self->m_store, TYPE_FLOAT);
         if (!m)
             return nullptr;
-        m->context = self->context;
+        m->m_context = self->m_context;
 
-        self->members[member] = m;
-        m->code.addroffset = member;
+        self->m_members[member] = m;
+        m->m_code.addroffset = member;
     }
-    else if (self->vtype == TYPE_FIELD)
+    else if (self->m_vtype == TYPE_FIELD)
     {
-        if (self->fieldtype != TYPE_VECTOR)
+        if (self->m_fieldtype != TYPE_VECTOR)
             return nullptr;
-        m = ir_value_var(name, self->store, TYPE_FIELD);
-        if (name)
-            mem_d(name);
+        m = new ir_value(move(name), self->m_store, TYPE_FIELD);
         if (!m)
             return nullptr;
-        m->fieldtype = TYPE_FLOAT;
-        m->context = self->context;
+        m->m_fieldtype = TYPE_FLOAT;
+        m->m_context = self->m_context;
 
-        self->members[member] = m;
-        m->code.addroffset = member;
+        self->m_members[member] = m;
+        m->m_code.addroffset = member;
     }
     else
     {
-        irerror(self->context, "invalid member access on %s", self->name);
+        irerror(self->m_context, "invalid member access on %s", self->m_name.c_str());
         return nullptr;
     }
 
-    m->memberof = self;
+    m->m_memberof = self;
     return m;
 }
 
 static GMQCC_INLINE size_t ir_value_sizeof(const ir_value *self)
 {
-    if (self->vtype == TYPE_FIELD && self->fieldtype == TYPE_VECTOR)
+    if (self->m_vtype == TYPE_FIELD && self->m_fieldtype == TYPE_VECTOR)
         return type_sizeof_[TYPE_VECTOR];
-    return type_sizeof_[self->vtype];
+    return type_sizeof_[self->m_vtype];
 }
 
-static ir_value* ir_value_out(ir_function *owner, const char *name, int storetype, int vtype)
+static ir_value* ir_value_out(ir_function *owner, const char *name, store_type storetype, qc_type vtype)
 {
-    ir_value *v = ir_value_var(name, storetype, vtype);
+    ir_value *v = new ir_value(name ? std::string(name) : std::string(), storetype, vtype);
     if (!v)
         return nullptr;
     ir_function_collect_value(owner, v);
     return v;
 }
 
-void ir_value_delete(ir_value* self)
-{
-    size_t i;
-    if (self->name)
-        mem_d((void*)self->name);
-    if (self->hasvalue)
-    {
-        if (self->vtype == TYPE_STRING)
-            mem_d((void*)self->constval.vstring);
-    }
-    if (!(self->flags & IR_FLAG_SPLIT_VECTOR)) {
-        for (i = 0; i < 3; ++i) {
-            if (self->members[i])
-                ir_value_delete(self->members[i]);
-        }
-    }
-    vec_free(self->life);
-    mem_d(self);
-}
-
-bool ir_value_set_name(ir_value *self, const char *name)
-{
-    if (self->name)
-        mem_d((void*)self->name);
-    self->name = util_strdup(name);
-    return !!self->name;
-}
-
 bool ir_value_set_float(ir_value *self, float f)
 {
-    if (self->vtype != TYPE_FLOAT)
+    if (self->m_vtype != TYPE_FLOAT)
         return false;
-    self->constval.vfloat = f;
-    self->hasvalue = true;
+    self->m_constval.vfloat = f;
+    self->m_hasvalue = true;
     return true;
 }
 
 bool ir_value_set_func(ir_value *self, int f)
 {
-    if (self->vtype != TYPE_FUNCTION)
+    if (self->m_vtype != TYPE_FUNCTION)
         return false;
-    self->constval.vint = f;
-    self->hasvalue = true;
+    self->m_constval.vint = f;
+    self->m_hasvalue = true;
     return true;
 }
 
 bool ir_value_set_vector(ir_value *self, vec3_t v)
 {
-    if (self->vtype != TYPE_VECTOR)
+    if (self->m_vtype != TYPE_VECTOR)
         return false;
-    self->constval.vvec = v;
-    self->hasvalue = true;
+    self->m_constval.vvec = v;
+    self->m_hasvalue = true;
     return true;
 }
 
 bool ir_value_set_field(ir_value *self, ir_value *fld)
 {
-    if (self->vtype != TYPE_FIELD)
+    if (self->m_vtype != TYPE_FIELD)
         return false;
-    self->constval.vpointer = fld;
-    self->hasvalue = true;
+    self->m_constval.vpointer = fld;
+    self->m_hasvalue = true;
     return true;
 }
 
 bool ir_value_set_string(ir_value *self, const char *str)
 {
-    if (self->vtype != TYPE_STRING)
+    if (self->m_vtype != TYPE_STRING)
         return false;
-    self->constval.vstring = util_strdupe(str);
-    self->hasvalue = true;
+    self->m_constval.vstring = util_strdupe(str);
+    self->m_hasvalue = true;
     return true;
 }
 
 #if 0
 bool ir_value_set_int(ir_value *self, int i)
 {
-    if (self->vtype != TYPE_INTEGER)
+    if (self->m_vtype != TYPE_INTEGER)
         return false;
-    self->constval.vint = i;
-    self->hasvalue = true;
+    self->m_constval.vint = i;
+    self->m_hasvalue = true;
     return true;
 }
 #endif
 
 bool ir_value_lives(ir_value *self, size_t at)
 {
-    size_t i;
-    for (i = 0; i < vec_size(self->life); ++i)
-    {
-        ir_life_entry_t *life = &self->life[i];
-        if (life->start <= at && at <= life->end)
+    for (auto& l : self->m_life) {
+        if (l.start <= at && at <= l.end)
             return true;
-        if (life->start > at) /* since it's ordered */
+        if (l.start > at) /* since it's ordered */
             return false;
     }
     return false;
@@ -1256,54 +1028,50 @@ bool ir_value_lives(ir_value *self, size_t at)
 
 static bool ir_value_life_insert(ir_value *self, size_t idx, ir_life_entry_t e)
 {
-    size_t k;
-    vec_push(self->life, e);
-    for (k = vec_size(self->life)-1; k > idx; --k)
-        self->life[k] = self->life[k-1];
-    self->life[idx] = e;
+    self->m_life.insert(self->m_life.begin() + idx, e);
     return true;
 }
 
 static bool ir_value_life_merge(ir_value *self, size_t s)
 {
     size_t i;
-    const size_t vs = vec_size(self->life);
-    ir_life_entry_t *life = nullptr;
+    const size_t vs = self->m_life.size();
+    ir_life_entry_t *life_found = nullptr;
     ir_life_entry_t *before = nullptr;
     ir_life_entry_t new_entry;
 
     /* Find the first range >= s */
     for (i = 0; i < vs; ++i)
     {
-        before = life;
-        life = &self->life[i];
-        if (life->start > s)
+        before = life_found;
+        life_found = &self->m_life[i];
+        if (life_found->start > s)
             break;
     }
     /* nothing found? append */
     if (i == vs) {
         ir_life_entry_t e;
-        if (life && life->end+1 == s)
+        if (life_found && life_found->end+1 == s)
         {
             /* previous life range can be merged in */
-            life->end++;
+            life_found->end++;
             return true;
         }
-        if (life && life->end >= s)
+        if (life_found && life_found->end >= s)
             return false;
         e.start = e.end = s;
-        vec_push(self->life, e);
+        self->m_life.emplace_back(e);
         return true;
     }
     /* found */
     if (before)
     {
         if (before->end + 1 == s &&
-            life->start - 1 == s)
+            life_found->start - 1 == s)
         {
             /* merge */
-            before->end = life->end;
-            vec_remove(self->life, i, 1);
+            before->end = life_found->end;
+            self->m_life.erase(self->m_life.begin()+i);
             return true;
         }
         if (before->end + 1 == s)
@@ -1317,9 +1085,9 @@ static bool ir_value_life_merge(ir_value *self, size_t s)
             return false;
     }
     /* extend */
-    if (life->start - 1 == s)
+    if (life_found->start - 1 == s)
     {
-        life->start--;
+        life_found->start--;
         return true;
     }
     /* insert a new entry */
@@ -1331,65 +1099,63 @@ static bool ir_value_life_merge_into(ir_value *self, const ir_value *other)
 {
     size_t i, myi;
 
-    if (!vec_size(other->life))
+    if (other->m_life.empty())
         return true;
 
-    if (!vec_size(self->life)) {
-        size_t count = vec_size(other->life);
-        ir_life_entry_t *life = vec_add(self->life, count);
-        memcpy(life, other->life, count * sizeof(*life));
+    if (self->m_life.empty()) {
+        self->m_life = other->m_life;
         return true;
     }
 
     myi = 0;
-    for (i = 0; i < vec_size(other->life); ++i)
+    for (i = 0; i < other->m_life.size(); ++i)
     {
-        const ir_life_entry_t *life = &other->life[i];
+        const ir_life_entry_t &otherlife = other->m_life[i];
         while (true)
         {
-            ir_life_entry_t *entry = &self->life[myi];
+            ir_life_entry_t *entry = &self->m_life[myi];
 
-            if (life->end+1 < entry->start)
+            if (otherlife.end+1 < entry->start)
             {
                 /* adding an interval before entry */
-                if (!ir_value_life_insert(self, myi, *life))
+                if (!ir_value_life_insert(self, myi, otherlife))
                     return false;
                 ++myi;
                 break;
             }
 
-            if (life->start <  entry->start &&
-                life->end+1 >= entry->start)
+            if (otherlife.start <  entry->start &&
+                otherlife.end+1 >= entry->start)
             {
                 /* starts earlier and overlaps */
-                entry->start = life->start;
+                entry->start = otherlife.start;
             }
 
-            if (life->end   >  entry->end &&
-                life->start <= entry->end+1)
+            if (otherlife.end   >  entry->end &&
+                otherlife.start <= entry->end+1)
             {
                 /* ends later and overlaps */
-                entry->end = life->end;
+                entry->end = otherlife.end;
             }
 
             /* see if our change combines it with the next ranges */
-            while (myi+1 < vec_size(self->life) &&
-                   entry->end+1 >= self->life[1+myi].start)
+            while (myi+1 < self->m_life.size() &&
+                   entry->end+1 >= self->m_life[1+myi].start)
             {
                 /* overlaps with (myi+1) */
-                if (entry->end < self->life[1+myi].end)
-                    entry->end = self->life[1+myi].end;
-                vec_remove(self->life, myi+1, 1);
-                entry = &self->life[myi];
+                if (entry->end < self->m_life[1+myi].end)
+                    entry->end = self->m_life[1+myi].end;
+                self->m_life.erase(self->m_life.begin() + (myi + 1));
+                entry = &self->m_life[myi];
             }
 
             /* see if we're after the entry */
-            if (life->start > entry->end)
+            if (otherlife.start > entry->end)
             {
                 ++myi;
                 /* append if we're at the end */
-                if (myi >= vec_size(self->life)) {
-                    vec_push(self->life, *life);
+                if (myi >= self->m_life.size()) {
+                    self->m_life.emplace_back(otherlife);
                     break;
                 }
                 /* otherweise check the next range */
@@ -1410,16 +1176,16 @@ static bool ir_values_overlap(const ir_value *a, const ir_value *b)
      * statement above.
      */
 
-    ir_life_entry_t *la, *lb, *enda, *endb;
+    const ir_life_entry_t *la, *lb, *enda, *endb;
 
     /* first of all, if either has no life range, they cannot clash */
-    if (!vec_size(a->life) || !vec_size(b->life))
+    if (a->m_life.empty() || b->m_life.empty())
         return false;
 
-    la = a->life;
-    lb = b->life;
-    enda = la + vec_size(a->life);
-    endb = lb + vec_size(b->life);
+    la = &a->m_life.front();
+    lb = &b->m_life.front();
+    enda = &a->m_life.back() + 1;
+    endb = &b->m_life.back() + 1;
     while (true)
     {
         /* check if the entries overlap, for that,
@@ -1462,9 +1228,9 @@ static bool ir_values_overlap(const ir_value *a, const ir_value *b)
 static bool ir_check_unreachable(ir_block *self)
 {
     /* The IR should never have to deal with unreachable code */
-    if (!self->final/* || OPTS_FLAG(ALLOW_UNREACHABLE_CODE)*/)
+    if (!self->m_final/* || OPTS_FLAG(ALLOW_UNREACHABLE_CODE)*/)
         return true;
-    irerror(self->context, "unreachable statement (%s)", self->label);
+    irerror(self->m_context, "unreachable statement (%s)", self->m_label.c_str());
     return false;
 }
 
@@ -1474,26 +1240,26 @@ bool ir_block_create_store_op(ir_block *self, lex_ctx_t ctx, int op, ir_value *t
     if (!ir_check_unreachable(self))
         return false;
 
-    if (target->store == store_value &&
+    if (target->m_store == store_value &&
         (op < INSTR_STOREP_F || op > INSTR_STOREP_FNC))
     {
-        irerror(self->context, "cannot store to an SSA value");
-        irerror(self->context, "trying to store: %s <- %s", target->name, what->name);
-        irerror(self->context, "instruction: %s", util_instr_str[op]);
+        irerror(self->m_context, "cannot store to an SSA value");
+        irerror(self->m_context, "trying to store: %s <- %s", target->m_name.c_str(), what->m_name.c_str());
+        irerror(self->m_context, "instruction: %s", util_instr_str[op]);
         return false;
     }
 
-    in = ir_instr_new(ctx, self, op);
+    in = new ir_instr(ctx, self, op);
     if (!in)
         return false;
 
     if (!ir_instr_op(in, 0, target, (op < INSTR_STOREP_F || op > INSTR_STOREP_FNC)) ||
         !ir_instr_op(in, 1, what, false))
     {
-        ir_instr_delete(in);
+        delete in;
         return false;
     }
-    vec_push(self->instr, in);
+    vec_push(self->m_instr, in);
     return true;
 }
 
@@ -1503,39 +1269,39 @@ bool ir_block_create_state_op(ir_block *self, lex_ctx_t ctx, ir_value *frame, ir
     if (!ir_check_unreachable(self))
         return false;
 
-    in = ir_instr_new(ctx, self, INSTR_STATE);
+    in = new ir_instr(ctx, self, INSTR_STATE);
     if (!in)
         return false;
 
     if (!ir_instr_op(in, 0, frame, false) ||
         !ir_instr_op(in, 1, think, false))
     {
-        ir_instr_delete(in);
+        delete in;
         return false;
     }
-    vec_push(self->instr, in);
+    vec_push(self->m_instr, in);
     return true;
 }
 
 static bool ir_block_create_store(ir_block *self, lex_ctx_t ctx, ir_value *target, ir_value *what)
 {
     int op = 0;
-    int vtype;
-    if (target->vtype == TYPE_VARIANT)
-        vtype = what->vtype;
+    qc_type vtype;
+    if (target->m_vtype == TYPE_VARIANT)
+        vtype = what->m_vtype;
     else
-        vtype = target->vtype;
+        vtype = target->m_vtype;
 
 #if 0
-    if      (vtype == TYPE_FLOAT   && what->vtype == TYPE_INTEGER)
+    if      (vtype == TYPE_FLOAT   && what->m_vtype == TYPE_INTEGER)
         op = INSTR_CONV_ITOF;
-    else if (vtype == TYPE_INTEGER && what->vtype == TYPE_FLOAT)
+    else if (vtype == TYPE_INTEGER && what->m_vtype == TYPE_FLOAT)
         op = INSTR_CONV_FTOI;
 #endif
         op = type_store_instr[vtype];
 
     if (OPTS_FLAG(ADJUST_VECTOR_FIELDS)) {
-        if (op == INSTR_STORE_FLD && what->fieldtype == TYPE_VECTOR)
+        if (op == INSTR_STORE_FLD && what->m_fieldtype == TYPE_VECTOR)
             op = INSTR_STORE_V;
     }
 
@@ -1545,19 +1311,19 @@ static bool ir_block_create_store(ir_block *self, lex_ctx_t ctx, ir_value *targe
 bool ir_block_create_storep(ir_block *self, lex_ctx_t ctx, ir_value *target, ir_value *what)
 {
     int op = 0;
-    int vtype;
+    qc_type vtype;
 
-    if (target->vtype != TYPE_POINTER)
+    if (target->m_vtype != TYPE_POINTER)
         return false;
 
     /* storing using pointer - target is a pointer, type must be
      * inferred from source
      */
-    vtype = what->vtype;
+    vtype = what->m_vtype;
 
     op = type_storep_instr[vtype];
     if (OPTS_FLAG(ADJUST_VECTOR_FIELDS)) {
-        if (op == INSTR_STOREP_FLD && what->fieldtype == TYPE_VECTOR)
+        if (op == INSTR_STOREP_FLD && what->m_fieldtype == TYPE_VECTOR)
             op = INSTR_STOREP_V;
     }
 
@@ -1570,19 +1336,19 @@ bool ir_block_create_return(ir_block *self, lex_ctx_t ctx, ir_value *v)
     if (!ir_check_unreachable(self))
         return false;
 
-    self->final = true;
+    self->m_final = true;
 
-    self->is_return = true;
-    in = ir_instr_new(ctx, self, INSTR_RETURN);
+    self->m_is_return = true;
+    in = new ir_instr(ctx, self, INSTR_RETURN);
     if (!in)
         return false;
 
     if (v && !ir_instr_op(in, 0, v, false)) {
-        ir_instr_delete(in);
+        delete in;
         return false;
     }
 
-    vec_push(self->instr, in);
+    vec_push(self->m_instr, in);
     return true;
 }
 
@@ -1592,26 +1358,26 @@ bool ir_block_create_if(ir_block *self, lex_ctx_t ctx, ir_value *v,
     ir_instr *in;
     if (!ir_check_unreachable(self))
         return false;
-    self->final = true;
-    /*in = ir_instr_new(ctx, self, (v->vtype == TYPE_STRING ? INSTR_IF_S : INSTR_IF_F));*/
-    in = ir_instr_new(ctx, self, VINSTR_COND);
+    self->m_final = true;
+    /*in = new ir_instr(ctx, self, (v->m_vtype == TYPE_STRING ? INSTR_IF_S : INSTR_IF_F));*/
+    in = new ir_instr(ctx, self, VINSTR_COND);
     if (!in)
         return false;
 
     if (!ir_instr_op(in, 0, v, false)) {
-        ir_instr_delete(in);
+        delete in;
         return false;
     }
 
-    in->bops[0] = ontrue;
-    in->bops[1] = onfalse;
+    in->m_bops[0] = ontrue;
+  &nbs