Changeset: 77788bf6c313 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=77788bf6c313
Added Files:
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_instruction.h
Removed Files:
monetdb5/mal/mal_instruction.mx
Modified Files:
monetdb5/mal/Makefile.ag
Branch: default
Log Message:
de-Mx mal_instruction.c
diffs (truncated from 4380 to 300 lines):
diff --git a/monetdb5/mal/Makefile.ag b/monetdb5/mal/Makefile.ag
--- a/monetdb5/mal/Makefile.ag
+++ b/monetdb5/mal/Makefile.ag
@@ -38,7 +38,7 @@ lib_mal = {
mal_factory.c mal_factory.h \
mal_function.c mal_function.h \
mal_import.c mal_import.h \
- mal_instruction.mx \
+ mal_instruction.c mal_instruction.h \
mal_interpreter.mx \
mal_linker.c mal_linker.h \
mal_listing.c mal_listing.h \
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/mal/mal_instruction.c
@@ -0,0 +1,1875 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2012 MonetDB B.V.
+ * All Rights Reserved.
+*/
+/*
+ * Author M. Kersten
+ */
+#include "monetdb_config.h"
+#include "mal_instruction.h"
+#include "mal_function.h" /* for getPC() */
+#include "mal_utils.h"
+#include "mal_exception.h"
+
+Symbol
+newSymbol(str nme, int kind)
+{
+ Symbol cur;
+
+ if (nme == NULL) {
+ GDKerror("@1:unexpected name (=null)\n");
+ return NULL;
+ }
+ cur = (Symbol) GDKzalloc(sizeof(SymRecord));
+ if (cur == NULL) {
+ GDKerror("newSymbol:" MAL_MALLOC_FAIL);
+ return NULL;
+ }
+ cur->name = putName(nme, strlen(nme));
+ cur->kind = kind;
+ cur->peer = NULL;
+ cur->def = newMalBlk(MAXVARS, STMT_INCREMENT);
+ return cur;
+}
+
+void
+freeSymbol(Symbol s)
+{
+ if (s == NULL)
+ return;
+ if (s->def) {
+ freeMalBlk(s->def);
+ s->def = NULL;
+ }
+ GDKfree(s);
+}
+
+void
+freeSymbolList(Symbol s)
+{
+ Symbol t = s;
+
+ while (s) {
+ t = s->peer;
+ s->peer = NULL;
+ freeSymbol(s);
+ s = t;
+ }
+}
+
+int
+newMalBlkStmt(MalBlkPtr mb, int maxstmts)
+{
+ InstrPtr *p;
+
+ p = (InstrPtr *) GDKzalloc(sizeof(InstrPtr) * maxstmts);
+ if (p == NULL) {
+ GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
+ return -1;
+ }
+ mb->stmt = p;
+ mb->stop = 0;
+ mb->ssize = maxstmts;
+ if (mb->profiler) {
+ GDKfree(mb->profiler);
+ mb->profiler = (ProfPtr) GDKzalloc((mb->ssize + STMT_INCREMENT)
* sizeof(ProfRecord));
+ assert(mb->profiler);
+ }
+ return 0;
+}
+
+MalBlkPtr
+newMalBlk(int maxvars, int maxstmts)
+{
+ MalBlkPtr mb;
+ VarPtr *v;
+
+ v = (VarPtr *) GDKzalloc(sizeof(VarPtr) * maxvars);
+ if (v == NULL) {
+ GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
+ return NULL;
+ }
+ mb = (MalBlkPtr) GDKmalloc(sizeof(MalBlkRecord));
+ if (mb == NULL) {
+ GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
+ return NULL;
+ }
+
+ mb->var = v;
+
+ mb->vtop = 0;
+ mb->vsize = maxvars;
+ mb->help = mb->binding = NULL;
+ mb->errors = 0;
+ mb->alternative = NULL;
+ mb->history = NULL;
+ mb->keephistory = 0;
+ mb->marker = 0;
+ mb->maxarg = MAXARG; /* the minimum for each instruction */
+ mb->typefixed = 0;
+ mb->flowfixed = 0;
+ mb->profiler = NULL;
+ mb->ptop = mb->psize = 0;
+ mb->prps = NULL;
+ mb->replica = NULL;
+ mb->recycle = 0;
+ mb->recid = 0;
+ mb->trap = 0;
+ if (newMalBlkStmt(mb, maxstmts) < 0)
+ return NULL;
+ return mb;
+}
+
+/* The resetMalBlk code removes instructions, but without freeing the
+ * space. This way the structure is prepared for re-use */
+void
+resetMalBlk(MalBlkPtr mb, int stop)
+{
+ mb->stop = stop;
+}
+
+/* The freeMalBlk code is quite defensive. It is used to localize an
+ * illegal re-use of a MAL blk. */
+void
+freeMalBlk(MalBlkPtr mb)
+{
+ int i;
+
+ for (i = 0; i < mb->ssize; i++)
+ if (mb->stmt[i]) {
+ freeInstruction(mb->stmt[i]);
+ mb->stmt[i] = NULL;
+ }
+ mb->stop = 0;
+ for (i = 0; i < mb->vsize; i++)
+ if (mb->var[i]) {
+ freeVariable(mb, i);
+ mb->var[i] = 0;
+ }
+ mb->vtop = 0;
+ GDKfree(mb->stmt);
+ mb->stmt = 0;
+ GDKfree(mb->var);
+ mb->var = 0;
+ if (mb->prps)
+ GDKfree(mb->prps);
+ mb->ptop = mb->psize = 0;
+ mb->prps = NULL;
+
+ if (mb->history)
+ freeMalBlk(mb->history);
+ if (mb->binding)
+ GDKfree(mb->binding);
+ mb->binding = 0;
+ if (mb->help)
+ GDKfree(mb->help);
+ mb->help = 0;
+ if (mb->profiler)
+ GDKfree(mb->profiler);
+ mb->profiler = NULL;
+ GDKfree(mb);
+}
+
+/* The routine below should assure that all referenced structures are
+ * private. The copying is memory conservative. */
+MalBlkPtr
+copyMalBlk(MalBlkPtr old)
+{
+ MalBlkPtr mb;
+ int i;
+
+ mb = (MalBlkPtr) GDKzalloc(sizeof(MalBlkRecord));
+ if (mb == NULL) {
+ GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
+ return NULL;
+ }
+ mb->alternative = old->alternative;
+ mb->history = NULL;
+ mb->keephistory = old->keephistory;
+ mb->marker = 0;
+ mb->var = (VarPtr *) GDKzalloc(sizeof(VarPtr) * old->vsize);
+
+ if (mb->var == NULL) {
+ GDKfree(mb);
+ GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
+ return NULL;
+ }
+ mb->vsize = old->vsize;
+
+ mb->vtop = 0;
+ for (i = 0; i < old->vtop; i++) {
+ copyVariable(mb, getVar(old, i));
+ mb->vtop++;
+ }
+
+ mb->stmt = (InstrPtr *) GDKzalloc(sizeof(InstrPtr) * old->ssize);
+
+ if (mb->stmt == NULL) {
+ GDKfree(mb->var);
+ GDKfree(mb);
+ GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
+ return NULL;
+ }
+
+ mb->stop = old->stop;
+ mb->ssize = old->ssize;
+ assert(old->stop < old->ssize);
+ for (i = 0; i < old->stop; i++)
+ mb->stmt[i] = copyInstruction(old->stmt[i]);
+
+ mb->help = old->help ? GDKstrdup(old->help) : NULL;
+ mb->binding = old->binding ? GDKstrdup(old->binding) : NULL;
+ mb->errors = old->errors;
+ mb->typefixed = old->typefixed;
+ mb->flowfixed = old->flowfixed;
+ mb->recycle = old->recycle;
+ mb->recid = old->recid;
+ mb->trap = old->trap;
+ mb->replica = old->replica;
+ mb->maxarg = old->maxarg;
+ mb->profiler = NULL;
+
+ mb->ptop = mb->psize = 0;
+ mb->prps = NULL;
+ if (old->prps) {
+ mb->prps = (MalProp *) GDKzalloc(old->psize * sizeof(MalProp));
+ mb->psize = old->psize;
+ mb->ptop = old->ptop;
+ for (i = 0; i < old->ptop; i++)
+ mb->prps[i] = old->prps[i];
+ }
+ return mb;
+}
+
+void
+addtoMalBlkHistory(MalBlkPtr mb, str marker)
+{
+ MalBlkPtr cpy, h;
+ if (mb->keephistory) {
+ cpy = copyMalBlk(mb);
+ if (cpy == NULL)
+ return; /* ignore history */
+ cpy->history = NULL;
+ mb->marker = GDKstrdup(marker);
+ if (mb->history == NULL)
+ mb->history = cpy;
+ else {
+ for (h = mb; h->history; h = h->history)
+ ;
+ h->history = cpy;
+ }
+ }
+}
+
+MalBlkPtr
+getMalBlkHistory(MalBlkPtr mb, int idx)
+{
+ MalBlkPtr h = mb;
+ while (h && idx-- >= 0)
+ h = h->history;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list