Changeset: 405b8fd4a303 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/405b8fd4a303
Modified Files:
monetdb5/mal/mal_module.c
monetdb5/mal/mal_prelude.c
Branch: default
Log Message:
Layout and some very minor changes.
diffs (truncated from 428 to 300 lines):
diff --git a/monetdb5/mal/mal_module.c b/monetdb5/mal/mal_module.c
--- a/monetdb5/mal/mal_module.c
+++ b/monetdb5/mal/mal_module.c
@@ -123,11 +123,15 @@ mal_module_reset(void)
}
}
-static int getModuleIndex(const char *name) {
+static int
+getModuleIndex(const char *name)
+{
return (int) (strHash(name) % MODULE_HASH_SIZE);
}
-static void clrModuleIndex(Module cur){
+static void
+clrModuleIndex(Module cur)
+{
int index = getModuleIndex(cur->name);
Module prev = NULL;
Module m = moduleIndex[index];
@@ -145,16 +149,20 @@ static void clrModuleIndex(Module cur){
}
}
-static void addModuleToIndex(Module cur){
+static void
+addModuleToIndex(Module cur)
+{
int index = getModuleIndex(cur->name);
cur->link = moduleIndex[index];
moduleIndex[index] = cur;
}
-Module getModule(const char *name) {
+Module
+getModule(const char *name)
+{
int index = getModuleIndex(name);
Module m = moduleIndex[index];
- while(m) {
+ while (m) {
if (name == m->name)
return m;
m = m->link;
@@ -162,7 +170,9 @@ Module getModule(const char *name) {
return NULL;
}
-void getModuleList(Module** out, int* length) {
+void
+getModuleList(Module** out, int* length)
+{
int i;
int moduleCount = 0;
int currentIndex = 0;
@@ -188,7 +198,9 @@ void getModuleList(Module** out, int* le
}
}
-void freeModuleList(Module* list) {
+void
+freeModuleList(Module* list)
+{
GDKfree(list);
}
@@ -196,11 +208,13 @@ void freeModuleList(Module* list) {
* Module scope management
* It will contain the symbol table of all globally accessible functions.
*/
-Module globalModule(const char *nme)
-{ Module cur;
+Module
+globalModule(const char *nme)
+{
+ Module cur;
// Global modules are not named 'user'
- assert (strcmp(nme, "user"));
+ assert(strcmp(nme, "user"));
nme = putName(nme);
cur = (Module) GDKzalloc(sizeof(ModuleRecord));
if (cur == NULL)
@@ -218,7 +232,9 @@ Module globalModule(const char *nme)
/* Every client record has a private module name 'user'
* for keeping around non-shared functions */
-Module userModule(void){
+Module
+userModule(void)
+{
Module cur;
cur = (Module) GDKzalloc(sizeof(ModuleRecord));
@@ -238,7 +254,9 @@ Module userModule(void){
* The scope can be fixed. This is used by the parser.
* Reading a module often calls for creation first.
*/
-Module fixModule(const char *nme) {
+Module
+fixModule(const char *nme)
+{
Module m;
m = getModule(nme);
@@ -249,7 +267,8 @@ Module fixModule(const char *nme) {
* The freeModule operation throws away a symbol without
* concerns on it whereabouts in the scope structure.
*/
-static void freeSubScope(Module scope)
+static void
+freeSubScope(Module scope)
{
int i;
Symbol s;
@@ -267,7 +286,8 @@ static void freeSubScope(Module scope)
scope->space = 0;
}
-void freeModule(Module m)
+void
+freeModule(Module m)
{
Symbol s;
@@ -300,7 +320,9 @@ void freeModule(Module m)
* This speeds up searching provided the modules adhere to the
* structure and group the functions as well.
*/
-void insertSymbol(Module scope, Symbol prg){
+void
+insertSymbol(Module scope, Symbol prg)
+{
InstrPtr sig;
int t;
Module c;
@@ -341,7 +363,9 @@ void insertSymbol(Module scope, Symbol p
* moment of removal. This situation can not easily
* checked at runtime, without tremendous overhead.
*/
-void deleteSymbol(Module scope, Symbol prg){
+void
+deleteSymbol(Module scope, Symbol prg)
+{
InstrPtr sig;
int t;
@@ -379,7 +403,9 @@ void deleteSymbol(Module scope, Symbol p
* The 'user' module is an alias for the scope attached
* to the current user.
*/
-Module findModule(Module scope, const char *name){
+Module
+findModule(Module scope, const char *name)
+{
Module def = scope;
Module m;
if (name == NULL) return scope;
@@ -402,7 +428,9 @@ Module findModule(Module scope, const ch
* The variation on this routine is to dump the definition of
* all matching definitions.
*/
-Symbol findSymbolInModule(Module v, const char *fcn) {
+Symbol
+findSymbolInModule(Module v, const char *fcn)
+{
Symbol s;
if (v == NULL || fcn == NULL) return NULL;
s = v->space[(int)(*fcn)];
@@ -413,7 +441,9 @@ Symbol findSymbolInModule(Module v, cons
return NULL;
}
-Symbol findSymbol(Module usermodule, const char *mod, const char *fcn) {
+Symbol
+findSymbol(Module usermodule, const char *mod, const char *fcn)
+{
Module m = findModule(usermodule, mod);
return findSymbolInModule(m, fcn);
}
diff --git a/monetdb5/mal/mal_prelude.c b/monetdb5/mal/mal_prelude.c
--- a/monetdb5/mal/mal_prelude.c
+++ b/monetdb5/mal/mal_prelude.c
@@ -117,16 +117,16 @@ initModule(Client c, const char *name, c
* their underlying structure.
*/
static str
-addAtom( mel_atom *atoms)
+addAtom(mel_atom *atoms)
{
- for(; atoms && atoms->name[0]; atoms++) {
+ for (; atoms && atoms->name[0]; atoms++) {
int i = ATOMallocate(atoms->name);
if (is_int_nil(i))
- throw(TYPE,"addAtom", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ throw(TYPE,"addAtom", GDK_EXCEPTION);
if (atoms->basetype[0]) {
int tpe = ATOMindex(atoms->basetype);
if (tpe < 0)
- throw(TYPE,"addAtom", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ throw(TYPE,"addAtom", TYPE_NOT_SUPPORTED);
BATatoms[i] = BATatoms[tpe];
strcpy_len(BATatoms[i].name, atoms->name,
sizeof(BATatoms[i].name));
BATatoms[i].storage = ATOMstorage(tpe);
@@ -203,9 +203,9 @@ makeArgument(MalBlkPtr mb, const mel_arg
tpe = newBatType(tpe) | mask;
}
/*
- if (a->name){
+ if (a->name) {
*idx = findVariableLength(mb, a->name, l = strlen(a->name));
- if( *idx != -1)
+ if (*idx != -1)
throw(LOADER, "addFunctions", "Duplicate argument name %s", a->name);
*idx = newVariable(mb, a->name, l, tpe);
} else
@@ -215,7 +215,8 @@ makeArgument(MalBlkPtr mb, const mel_arg
}
static str
-addFunctions(mel_func *fcn){
+addFunctions(mel_func *fcn)
+{
str msg = MAL_SUCCEED;
const char *mod;
int idx;
@@ -224,54 +225,50 @@ addFunctions(mel_func *fcn){
MalBlkPtr mb;
InstrPtr sig;
- for(; fcn && fcn->mod[0]; fcn++) {
+ for (; fcn && fcn->mod[0]; fcn++) {
assert(fcn->mod);
mod = putName(fcn->mod);
c = getModule(mod);
- if( c == NULL){
- if (globalModule(mod) == NULL)
- throw(LOADER, "addFunctions", "Module %s can
not be created", fcn->mod);
- c = getModule(mod);
- }
+ if (c == NULL && (c = globalModule(mod)) == NULL)
+ throw(LOADER, "addFunctions", "Module %s can not be
created", fcn->mod);
- s = newSymbol(fcn->fcn, fcn->command ? COMMANDsymbol:
PATTERNsymbol );
- if ( s == NULL)
+ s = newSymbol(fcn->fcn, fcn->command ? COMMANDsymbol :
PATTERNsymbol);
+ if (s == NULL)
throw(LOADER, "addFunctions", "Can not create symbol
for %s.%s missing", fcn->mod, fcn->fcn);
mb = s->def;
- if( mb == NULL) {
- freeSymbol(s);
- throw(LOADER, "addFunctions", "Can not create program
block for %s.%s missing", fcn->mod, fcn->fcn);
- }
+ assert(mb); /* if this is NULL, s
should have been NULL */
if (fcn->cname && fcn->cname[0])
strcpy_len(mb->binding, fcn->cname,
sizeof(mb->binding));
- /* keep the comment around, setting the static avoid freeing
the string accidentally , saving on duplicate documentation in the code. */
+ /* keep the comment around, setting the static avoids freeing
+ * the string accidentally, saving on duplicate documentation in
+ * the code. */
mb->statichelp = mb->help = fcn->comment;
- sig= newInstructionArgs(mb, mod, putName(fcn->fcn), fcn->argc +
(fcn->retc == 0));
+ sig = newInstructionArgs(mb, mod, putName(fcn->fcn), fcn->argc
+ (fcn->retc == 0));
if (sig == NULL) {
freeSymbol(s);
throw(LOADER, "addFunctions", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
sig->retc = 0;
sig->argc = 0;
- sig->token = fcn->command?COMMANDsymbol:PATTERNsymbol;
+ sig->token = fcn->command ? COMMANDsymbol : PATTERNsymbol;
sig->fcn = fcn->imp;
- if( fcn->unsafe)
+ if (fcn->unsafe)
mb->unsafeProp = 1;
/* add the return variables */
- if(fcn->retc == 0){
+ if (fcn->retc == 0) {
int idx = newTmpVariable(mb, TYPE_void);
sig = pushReturn(mb, sig, idx);
if (sig == NULL)
throw(LOADER, "addFunctions", "Failed to create
void return");
}
int i;
- for (i = 0; i<fcn->retc; i++ ){
+ for (i = 0; i<fcn->retc; i++) {
const mel_arg *a = fcn->args+i;
msg = makeArgument(mb, a, &idx);
- if( msg)
+ if (msg)
return msg;
sig = pushReturn(mb, sig, idx);
if (sig == NULL)
@@ -289,10 +286,10 @@ addFunctions(mel_func *fcn){
}
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]