⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mal_instruction.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 3 页
字号:
#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"#include "mal_config.h"#include "mal_instruction.h"#include "mal_function.h"	/* for getPC() */#include "mal_utils.h"#include "mal_exception.h"SymbolnewSymbol(str nme, int kind){	Symbol cur;	if (nme == NULL) {		GDKfatal("@1:unexpected name (=null)\n");	}	cur = (Symbol) GDKzalloc(sizeof(SymRecord));	if (cur == NULL) {		GDKfatal("@1: cannot initialize scope\n");	}	cur->name = nme;	cur->kind = kind;	cur->peer = NULL;	cur->def = newMalBlk(MAXVARS, STMT_INCREMENT);	return cur;}voidfreeSymbol(Symbol s){	if (s == NULL)		return;	if (s->def) {		freeMalBlk(s->def);		s->def = NULL;	}	GDKfree(s);}voidfreeSymbolList(Symbol s){	Symbol t = s;	while (s) {		t = s->peer;		s->peer = NULL;		freeSymbol(s);		s = t;	}}voidnewMalBlkStmt(MalBlkPtr mb, int maxstmts){	InstrPtr *p;	p = (InstrPtr *) GDKzalloc(sizeof(InstrPtr) * maxstmts);	if (p == NULL)		GDKfatal("newMalBlk:could not get instruction storage\n");	mb->stmt = p;	mb->stop = 0;	mb->ssize = maxstmts;}MalBlkPtrnewMalBlk(int maxvars, int maxstmts){	MalBlkPtr mb;	VarPtr *v;	v = (VarPtr *) GDKzalloc(sizeof(VarPtr) * maxvars);	if (v == NULL)		GDKfatal("newMalBlk:could not get variable storage\n");	mb = (MalBlkPtr) GDKmalloc(sizeof(MalBlkRecord));	if (mb == NULL)		GDKfatal("newMalBlk:could not get storage\n");	newMalBlkStmt(mb, maxstmts);	mb->var = v;	mb->vtop = 0;	mb->vsize = maxvars;	mb->help = mb->binding = NULL;	mb->errors = 0;	mb->props = NULL;	mb->alternative = NULL;	mb->history = NULL;	mb->typefixed = 0;	mb->flowfixed = 0;	mb->profiler = NULL;	return mb;}#line 649 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"voidresetMalBlk(MalBlkPtr mb, int stop){	mb->stop = stop;}#line 659 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"voidfreeMalBlk(MalBlkPtr mb){	int i;	for (i = 0; i < mb->stop; i++) {		freeInstruction(getInstrPtr(mb, i));		mb->stmt[i] = NULL;	}	mb->stop = 0;	for (i = 0; i < mb->vtop; i++)		freeVariable(mb, i);	mb->vtop = 0;	GDKfree(mb->stmt);	mb->stmt = 0;	GDKfree(mb->var);	mb->var = 0;	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->props)		GDKfree(mb->props);	mb->props = NULL;	if (mb->profiler)		GDKfree(mb->profiler);	mb->profiler = NULL;	GDKfree(mb);}#line 698 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"MalBlkPtrcopyMalBlk(MalBlkPtr old){	MalBlkPtr mb;	int i;	mb = (MalBlkPtr) GDKzalloc(sizeof(MalBlkRecord));	if (mb == NULL)		GDKfatal("newMalBlk:could not get storage\n");	mb->props = old->props;	mb->alternative = old->alternative;	mb->history = NULL;	mb->var = (VarPtr *) GDKmalloc(sizeof(VarPtr) * old->vsize);	if (mb->var == NULL)		GDKfatal("newMalBlk:could not get variable storage\n");	mb->vsize = old->vsize;	memcpy((char *) mb->var, old->var, sizeof(VarPtr) * old->vsize);	mb->vtop = 0;	for (i = 0; i < old->vtop; i++) {		copyVariable(mb, old, getVar(old, i));		mb->vtop++;	}	mb->stmt = (InstrPtr *) GDKzalloc(sizeof(InstrPtr) * old->ssize);	if (mb->stmt == NULL)		GDKfatal("newMalBlk:could not get instruction storage\n");	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;	/* copy the properties as well */	if (mb->props)		mb->props = cpyPropertySet(old->props);	mb->profiler = NULL;	return mb;}voidaddtoMalBlkHistory(MalBlkPtr mb){	MalBlkPtr cpy;	cpy= copyMalBlk(mb);	cpy->alternative= NULL;	cpy->history= mb->history;	mb->history= cpy;}MalBlkPtrgetMalBlkHistory(MalBlkPtr mb, int idx){	while( mb && idx-- > 0)		mb= mb->history;	return mb;}#line 770 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"voidtrimexpand(MalBlkPtr mb, int varsize, int stmtsize){	VarRecord **v;	InstrPtr *stmt;	int len;	assert(varsize > 0 && stmtsize > 0);	len = sizeof(ValPtr) * (mb->vtop + varsize);	v = (VarRecord **) GDKzalloc(len);	if (v == NULL)		GDKfatal("newMalBlk:could not get variable storage\n");	memcpy((str) v, (str) mb->var, sizeof(ValPtr) * mb->vtop);	if (mb->var)		GDKfree(mb->var);	mb->var = v;	mb->vsize = mb->vtop + varsize;	len = sizeof(InstrPtr) * (mb->ssize + stmtsize);	stmt = (InstrPtr *) GDKzalloc(len);	if (stmt == NULL)		GDKfatal("newMalBlk:could not get instruction storage\n");	memcpy((str) stmt, (str) mb->stmt, sizeof(InstrPtr) * mb->stop);	GDKfree(mb->stmt);	mb->stmt = stmt;	mb->ssize = mb->ssize + stmtsize;	if (mb->profiler) {		GDKfree(mb->profiler);		mb->profiler = 0;	}}voidexpandMalBlk(MalBlkPtr mb, int lines){	int newlines = (int) (lines * 1.1);	if (newlines > mb->ssize || newlines > mb->vsize)		trimexpand(mb, newlines, newlines);}voidtrimMalBlk(MalBlkPtr mb){	(void) mb;		/* fool the compiler */	/* printf("safe %d %d\n",mb->vtop, (mb->vsize-mb->vtop)*sizeof(VarPtr));	   trimexpand(mb,0); */}#line 835 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"voidprepareMalBlk(MalBlkPtr mb, str s){	int cnt = 0;	while(s){		s= strchr(s,'\n');		if(s) { s++; cnt++;}	}	expandMalBlk(mb, cnt);}InstrPtrnewInstruction(MalBlkPtr mb, int kind){	InstrPtr p = NULL;	int space;	if (mb && mb->stop <mb->ssize) {		p = mb->stmt[mb->stop];		if (p && p->maxarg < MAXARG)			p = NULL;		mb->stmt[mb->stop] = NULL;	}	if (p == NULL) {		space = (MAXARG - 1) * sizeof(int) + sizeof(InstrRecord);		p = GDKmalloc(space);		p->maxarg = MAXARG;	}	p->typechk = TYPE_UNKNOWN;	setModuleId(p, NULL);	setFunctionId(p, NULL);	p->fcn = NULL;	p->blk = NULL;	p->polymorphic = 0;	p->varargs = 0;	p->argc = 1;	p->retc = 1;	p->argv[0] = -1;	/* watch out for direct use in variable table */#line 880 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"	switch (kind) {	case BARRIERsymbol:	case REDOsymbol:	case LEAVEsymbol:	case EXITsymbol:	case RETURNsymbol:	case YIELDsymbol:	case CATCHsymbol:	case RAISEsymbol:		p->token = ASSIGNsymbol;		p->barrier = kind;		break;	default:		p->token = kind;		p->barrier = 0;	}	p->gc = 0;	p->jump = 0;	return p;}#line 904 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"InstrPtrcopyInstruction(InstrPtr p){	InstrPtr new;	new = (InstrPtr) GDKmalloc(sizeof(InstrRecord) + sizeof(int) * p->maxarg - 1);	oldmoveInstruction(new, p);	return new;}voidclrFunction(InstrPtr p){	p->fcn = 0;	setModuleId(p, NULL);	setFunctionId(p, NULL);}voidclrInstruction(InstrPtr p){	clrFunction(p);	memset((char *) p, 0, sizeof(InstrRecord) + (p->argc - 1) * sizeof(int));}voidfreeInstruction(InstrPtr p){	assert(p != 0);	GDKfree(p);}#line 940 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"voidoldmoveInstruction(InstrPtr new, InstrPtr p){	int space;	space = sizeof(InstrRecord) + sizeof(int) * p->argc;	memcpy((char *) new, (char *) p, space);	setFunctionId(new, getFunctionId(p));	setModuleId(new, getModuleId(p));}#line 958 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"voidremoveInstruction(MalBlkPtr mb, InstrPtr p){	int i;	for (i = 0; i < mb->stop - 1; i++)		if (mb->stmt[i] == p)			break;	if (i == mb->stop)		return;	for (; i < mb->stop - 1; i++)		mb->stmt[i] = mb->stmt[i + 1];	mb->stop--;	mb->stmt[i] = p;	/* freeInstruction(p); */}voidremoveInstructionBlock(MalBlkPtr mb, int pc, int cnt){	int i;	InstrPtr p;	for (i = pc; i < pc + cnt; i++) {		p = getInstrPtr(mb, i);		freeInstruction(p);	}	for (i = pc; i < mb->stop - cnt; i++)		mb->stmt[i] = mb->stmt[i + cnt];	mb->stop -= cnt;	for (; i < mb->stop; i++)		mb->stmt[i] = 0;}voidmoveInstruction(MalBlkPtr mb, int pc, int target){	InstrPtr p;	int i;	p = getInstrPtr(mb, pc);	if (pc > target) {		for (i = pc; i > target; i--)			mb->stmt[i] = mb->stmt[i - 1];		mb->stmt[i] = p;	} else {		for (i = target; i > pc; i--)			mb->stmt[i] = mb->stmt[i - 1];		mb->stmt[i] = p;	}}voidinsertInstruction(MalBlkPtr mb, InstrPtr p, int pc){	pushInstruction(mb, p);	/* to ensure room */	moveInstruction(mb, mb->stop - 1, pc);}#line 1054 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"INLINE strgetVarName(MalBlkPtr mb, int i){	str nme;	char buf[PATHLENGTH];	nme = mb->var[i]->name;	if (nme == 0) {		snprintf(buf, PATHLENGTH, "%c%d", TMPMARKER, mb->var[i]->tmpindex);		nme = mb->var[i]->name = GDKstrdup(buf);	}	return nme;}INLINE strgetRefName(MalBlkPtr mb, int i){	str nme;	char buf[PATHLENGTH];	nme = mb->var[i]->name;	if (nme == 0) {		snprintf(buf, PATHLENGTH, "%c%d", REFMARKER, mb->var[i]->tmpindex);		nme = mb->var[i]->name = GDKstrdup(buf);	}	return nme;}#line 1084 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"intfindVariable(MalBlkPtr mb, str name){	int i;	#line 1041 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"    if( isTmpName(name)){		int j;        i= atol(name+1);        /* quick test validity*/        if( i< mb->vtop && isTmpVar(mb,i) && getVarTmp(mb,i) == i)            return i;		for(j=0; j< mb->vtop; j++)			if( getVarTmp(mb,j)== i && isTmpVar(mb,j)) return j;        return -1;    }#line 1089 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"	if (name == NULL)		return -1;	for (i = mb->vtop - 1; i >= 0; i--)		if (!isTmpVar(mb, i) && idcmp(name, getVarName(mb, i)) == 0)			return i;	return -1;}intfindTmpVariable(MalBlkPtr mb, int type){	int i;	for (i = 0; i < mb->vtop; i++)		if (isTmpVar(mb, i) && getVarType(mb, i) == type)			return i;	return -1;}#line 1115 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"intfindVariableLength(MalBlkPtr mb, str name, int len){	int i;	int j;	for (i = mb->vtop - 1; i >= 0; i--)		if (mb->var[i]->name && !isTmpVar(mb, i)) {			str s = mb->var[i]->name;			j = 0;			if (s)				for (j = 0; j < len; j++)					if (name[j] != s[j])						break;			if (j == len && s && s[j] == 0)				return i;		}	/* most variables are not temporary */	#line 1041 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"    if( isTmpName(name)){		int j;        i= atol(name+1);        /* quick test validity*/        if( i< mb->vtop && isTmpVar(mb,i) && getVarTmp(mb,i) == i)            return i;		for(j=0; j< mb->vtop; j++)			if( getVarTmp(mb,j)== i && isTmpVar(mb,j)) return j;        return -1;    }#line 1134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"	return -1;}#line 1142 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"malTypegetType(MalBlkPtr mb, str nme){	int i;	i = findVariable(mb, nme);	if (i < 0)		return getTypeIndex(nme, -1, TYPE_any);	if (i >= 0)		return getVarType(mb, i);	return TYPE_any;}strgetArgDefault(MalBlkPtr mb, InstrPtr p, int idx){	ValPtr v = &getVarConstant(mb, getArg(p, idx));	if (v->vtype == TYPE_str)		return v->val.sval;	return NULL;}#line 1177 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"intisReserved(str nme){	switch (*nme) {	case 'A':	case 'a':		if (idcmp("atom", nme) == 0)			return 1;		break;	case 'B':	case 'b':		if (idcmp("barrier", nme) == 0)			return 1;		break;	case 'C':	case 'c':		if (idcmp("command", nme) == 0)			return 1;		break;	case 'E':	case 'e':		if (idcmp("exit", nme) == 0)			return 1;		if (idcmp("end", nme) == 0)			return 1;		break;	case 'F':	case 'f':		if (idcmp("false", nme) == 0)			return 1;		if (idcmp("function", nme) == 0)			return 1;		if (idcmp("factory", nme) == 0)			return 1;		break;	case 'I':	case 'i':		if (idcmp("include", nme) == 0)			return 1;		break;	case 'M':	case 'm':		if (idcmp("module", nme) == 0)			return 1;		if (idcmp("macro", nme) == 0)			return 1;		break;	case 'O':	case 'o':		if (idcmp("orcam", nme) == 0)			return 1;		break;	case 'P':	case 'p':		if (idcmp("pattern", nme) == 0)			return 1;		break;	case 'T':	case 't':		if (idcmp("thread", nme) == 0)			return 1;		if (idcmp("true", nme) == 0)			return 1;		break;	}	return 0;}#line 1275 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/mal/mal_instruction.mx"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -