]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.cpp
qcvm: add stov builtin #16
[xonotic/gmqcc.git] / ast.cpp
diff --git a/ast.cpp b/ast.cpp
index 7529acdd4ce0ac373fad7420f5c93c4d967602e6..cbc5db9657a9af3beaf6d12b5e64bb442c4f0066 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -1132,6 +1132,8 @@ bool ast_value::generateGlobal(ir_builder *ir, bool isfield)
         m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
     if (m_flags & AST_FLAG_ERASEABLE)
         m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+    if (m_flags & AST_FLAG_NOREF)
+        m_ir_v->m_flags |= IR_FLAG_NOREF;
 
     /* initialize */
     if (m_hasvalue) {
@@ -1236,6 +1238,8 @@ bool ast_value::generateGlobalField(ir_builder *ir)
             m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
         if (m_flags & AST_FLAG_ERASEABLE)
             m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+        if (m_flags & AST_FLAG_NOREF)
+            m_ir_v->m_flags |= IR_FLAG_NOREF;
 
         const size_t namelen = m_name.length();
         std::unique_ptr<char[]> name(new char[namelen+16]);
@@ -1254,7 +1258,9 @@ bool ast_value::generateGlobalField(ir_builder *ir)
             array->m_ir_values[ai]->m_unique_life = true;
             array->m_ir_values[ai]->m_locked      = true;
             if (m_flags & AST_FLAG_INCLUDE_DEF)
-                m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
+                array->m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
+            if (m_flags & AST_FLAG_NOREF)
+                array->m_ir_values[ai]->m_flags |= IR_FLAG_NOREF;
         }
     }
     else
@@ -1266,9 +1272,10 @@ bool ast_value::generateGlobalField(ir_builder *ir)
         m_ir_v = v;
         if (m_flags & AST_FLAG_INCLUDE_DEF)
             m_ir_v->m_flags |= IR_FLAG_INCLUDE_DEF;
-
         if (m_flags & AST_FLAG_ERASEABLE)
             m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+        if (m_flags & AST_FLAG_NOREF)
+            m_ir_v->m_flags |= IR_FLAG_NOREF;
     }
     return true;
 }
@@ -1299,7 +1306,9 @@ ir_value *ast_value::prepareGlobalArray(ir_builder *ir)
     if (m_flags & AST_FLAG_INCLUDE_DEF)
         v->m_flags |= IR_FLAG_INCLUDE_DEF;
     if (m_flags & AST_FLAG_ERASEABLE)
-        m_ir_v->m_flags |= IR_FLAG_ERASABLE;
+        v->m_flags |= IR_FLAG_ERASABLE;
+    if (m_flags & AST_FLAG_NOREF)
+        v->m_flags |= IR_FLAG_NOREF;
 
     const size_t namelen = m_name.length();
     std::unique_ptr<char[]> name(new char[namelen+16]);
@@ -1319,6 +1328,8 @@ ir_value *ast_value::prepareGlobalArray(ir_builder *ir)
         m_ir_values[ai]->m_locked      = true;
         if (m_flags & AST_FLAG_INCLUDE_DEF)
             m_ir_values[ai]->m_flags |= IR_FLAG_INCLUDE_DEF;
+        if (m_flags & AST_FLAG_NOREF)
+            m_ir_values[ai]->m_flags |= IR_FLAG_NOREF;
     }
 
     return v;
@@ -1365,6 +1376,9 @@ bool ast_value::generateLocal(ir_function *func, bool param)
         v->m_unique_life = true;
         v->m_locked      = true;
 
+        if (m_flags & AST_FLAG_NOREF)
+            v->m_flags |= IR_FLAG_NOREF;
+
         const size_t namelen = m_name.length();
         std::unique_ptr<char[]> name(new char[namelen+16]);
         util_strncpy(name.get(), m_name.c_str(), namelen);
@@ -1379,7 +1393,10 @@ bool ast_value::generateLocal(ir_function *func, bool param)
             }
             m_ir_values[ai]->m_context = m_context;
             m_ir_values[ai]->m_unique_life = true;
-            m_ir_values[ai]->m_locked      = true;
+            m_ir_values[ai]->m_locked = true;
+
+            if (m_flags & AST_FLAG_NOREF)
+                m_ir_values[ai]->m_flags |= IR_FLAG_NOREF;
         }
     }
     else
@@ -1418,6 +1435,9 @@ bool ast_value::generateLocal(ir_function *func, bool param)
     v->m_cvq = m_cvq;
     m_ir_v = v;
 
+    if (m_flags & AST_FLAG_NOREF)
+        m_ir_v->m_flags |= IR_FLAG_NOREF;
+
     if (!generateAccessors(func->m_owner))
         return false;
     return true;
@@ -1490,9 +1510,9 @@ bool ast_function::generateFunction(ir_builder *ir)
     /* fill the parameter list */
     for (auto &it : m_function_type->m_type_params) {
         if (it->m_vtype == TYPE_FIELD)
-            vec_push(irf->m_params, it->m_next->m_vtype);
+            irf->m_params.push_back(it->m_next->m_vtype);
         else
-            vec_push(irf->m_params, it->m_vtype);
+            irf->m_params.push_back(it->m_vtype);
         if (!m_builtin) {
             if (!it->generateLocal(m_ir_func, true))
                 return false;
@@ -1562,7 +1582,7 @@ bool ast_function::generateFunction(ir_builder *ir)
         {
             return ir_block_create_return(m_curblock, m_context, nullptr);
         }
-        else if (vec_size(m_curblock->m_entries) || m_curblock == irf->m_first)
+        else if (m_curblock->m_entries.size() || m_curblock == irf->m_first)
         {
             if (m_return_value) {
                 if (!m_return_value->codegen(this, false, &dummy))
@@ -1784,7 +1804,7 @@ bool ast_binary::codegen(ast_function *func, bool lvalue, ir_value **out)
                 return false;
         }
         /* use the likely flag */
-        vec_last(func->m_curblock->m_instr)->m_likely = true;
+        func->m_curblock->m_instr.back()->m_likely = true;
 
         /* enter the right-expression's block */
         func->m_curblock = other;