]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge branch 'master' into blub/bc3
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Sat, 28 Jul 2012 16:13:24 +0000 (18:13 +0200)
committerWolfgang Bumiller <wolfgang.linux@bumiller.com>
Sat, 28 Jul 2012 16:13:24 +0000 (18:13 +0200)
ast.c
ast.h
exec.c
test/ast-macros.h

diff --git a/ast.c b/ast.c
index 944fee9b613dec7ba830c4a5e3d5d05397e5a540..8182f7977cd6cbdcb8f3e94734decf7c03338f49 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -416,7 +416,7 @@ void ast_call_delete(ast_call *self)
 }
 
 ast_store* ast_store_new(lex_ctx ctx, int op,
-                         ast_value *dest, ast_expression *source)
+                         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);
diff --git a/ast.h b/ast.h
index 3dc30b2221c4c278906eb3a076ff7bbb934a1d13..61bacce6787ceaff6f5adf563a803c1bc97866a0 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -220,11 +220,11 @@ struct ast_store_s
 {
     ast_expression_common expression;
     int             op;
-    ast_value      *dest; /* When we add pointers this might have to change to expression */
+    ast_expression *dest;
     ast_expression *source;
 };
 ast_store* ast_store_new(lex_ctx ctx, int op,
-                         ast_value *d, ast_expression *s);
+                         ast_expression *d, ast_expression *s);
 void ast_store_delete(ast_store*);
 
 bool ast_store_codegen(ast_store*, ast_function*, bool lvalue, ir_value**);
diff --git a/exec.c b/exec.c
index f13d4da5cac2a37f0b1f6bdd0fa99ec83d2c5439..4a1ad09d8d600786df401b16f822a499173af020 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -22,6 +22,8 @@ MEM_VEC_FUNCTIONS(qc_program,   qc_exec_stack, stack)
 MEM_VEC_FUNCTIONS(qc_program,   size_t, profile)
 MEM_VEC_FUN_RESIZE(qc_program,  size_t, profile)
 
+MEM_VEC_FUNCTIONS(qc_program,   prog_builtin, builtins)
+
 static void loaderror(const char *fmt, ...)
 {
     int     err = errno;
@@ -134,6 +136,11 @@ void prog_delete(qc_program *prog)
     MEM_VECTOR_CLEAR(prog, localstack);
     MEM_VECTOR_CLEAR(prog, stack);
     MEM_VECTOR_CLEAR(prog, profile);
+
+    if (prog->builtins_alloc) {
+        MEM_VECTOR_CLEAR(prog, builtins);
+    }
+    /* otherwise the builtins were statically allocated */
     mem_d(prog);
 }
 
@@ -451,6 +458,19 @@ cleanup:
  */
 
 #if defined(QCVM_EXECUTOR)
+static int qc_print(qc_program *prog)
+{
+    qcany *str = (qcany*)(prog->globals + OFS_PARM0);
+    printf("%s", prog_getstring(prog, str->string));
+    return 0;
+}
+
+static prog_builtin qc_builtins[] = {
+    NULL,
+    &qc_print
+};
+static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);
+
 int main(int argc, char **argv)
 {
     size_t      i;
@@ -468,6 +488,10 @@ int main(int argc, char **argv)
         exit(1);
     }
 
+    prog->builtins       = qc_builtins;
+    prog->builtins_count = qc_builtins_count;
+    prog->builtins_alloc = 0;
+
     for (i = 1; i < prog->functions_count; ++i) {
         const char *name = prog_getstring(prog, prog->functions[i].name);
         printf("Found function: %s\n", name);
index c17b753696173db090398d7d78f713a15ecc0e07..ebb3a5bd6b7b09807622a90c8ef9523f0b09e4bb 100644 (file)
@@ -42,7 +42,7 @@ do {                                             \
 } while(0)
 
 #define ASSIGN(op, a, b) \
-(ast_expression*)ast_store_new(ctx, INSTR_##op, (a), (ast_expression*)(b))
+(ast_expression*)ast_store_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))
 
 #define BIN(op, a, b) \
 (ast_expression*)ast_binary_new(ctx, INSTR_##op, (ast_expression*)(a), (ast_expression*)(b))