Commit d4ba5671 by kollo

fixed error in virtual machine / compiler --> array functions

Array functions were not processed correctly in compiled programs
now fixed
parent 592a153a
......@@ -835,56 +835,40 @@ int bc_parser(const char *funktion){ /* Rekursiver Parser */
}
} else if((i=find_afunc(s))!=-1) {
if((pafuncs[i].opcode&FM_TYP)==F_SIMPLE || pafuncs[i].pmax==0) {
BCADD(BC_PUSHFUNC);BCADD(i);BCADD(0);
TP(PL_LEER); /* Fuer den Rueckgabewert*/
return(bcerror);
BCADD(BC_PUSHAFUNC);BCADD(i);BCADD(0);
} else if((pafuncs[i].opcode&FM_TYP)==F_ARGUMENT) {
BCADDPUSHX(pos);
BCADD(BC_PUSHAFUNC);BCADD(i);BCADD(1);
TP(PL_LEER); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if((pafuncs[i].opcode&FM_TYP)==F_PLISTE) {
/* TODO: das geht besser !*/
bc_parser(pos);
BCADD(BC_PUSHAFUNC);BCADD(i);BCADD(count_parameters(pos));
TA(count_parameters(pos));
TP(PL_LEER); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if(pafuncs[i].pmax==1 && (pafuncs[i].opcode&FM_TYP)==F_AQUICK) {
bc_parser(pos);
BCADD(BC_PUSHAFUNC);BCADD(i);BCADD(1);
TO();
TP(PL_LEER); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if(pafuncs[i].pmax==1 && (pafuncs[i].opcode&FM_TYP)==F_SQUICK) {
bc_parser(pos);
BCADD(BC_PUSHAFUNC);BCADD(i);BCADD(1);
TO();
TP(PL_LEER); /* Fuer den Rueckgabewert*/
return(bcerror);
}
TP(PL_ARRAY); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if((i=find_sfunc(s))!=-1) {
if((psfuncs[i].opcode&FM_TYP)==F_SIMPLE || psfuncs[i].pmax==0) {
BCADD(BC_PUSHSFUNC);BCADD(i);BCADD(0);
TP(PL_STRING); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if((psfuncs[i].opcode&FM_TYP)==F_ARGUMENT) {
BCADDPUSHX(pos);
BCADD(BC_PUSHSFUNC);BCADD(i);BCADD(1);
TP(PL_STRING); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if((psfuncs[i].opcode&FM_TYP)==F_PLISTE) {
bc_parser(pos);
BCADD(BC_PUSHSFUNC);BCADD(i);BCADD(count_parameters(pos));
TA(count_parameters(pos));
TP(PL_STRING); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if(psfuncs[i].pmax==2 && (psfuncs[i].opcode&FM_TYP)==F_DQUICK) {
bc_parser(pos);
BCADD(BC_PUSHSFUNC);BCADD(i);BCADD(2);
TA(2);
TP(PL_STRING); /* Fuer den Rueckgabewert*/
return(bcerror);
} else if(psfuncs[i].pmax==1 && ((psfuncs[i].opcode&FM_TYP)==F_SQUICK ||
(psfuncs[i].opcode&FM_TYP)==F_AQUICK ||
(psfuncs[i].opcode&FM_TYP)==F_IQUICK ||
......@@ -894,9 +878,9 @@ int bc_parser(const char *funktion){ /* Rekursiver Parser */
bc_parser(pos);
BCADD(BC_PUSHSFUNC);BCADD(i);BCADD(1);
TO();
TP(PL_STRING); /* Fuer den Rueckgabewert*/
return(bcerror);
}
TP(PL_STRING); /* Fuer den Rueckgabewert*/
return(bcerror);
} else {
char buf[strlen(s)+1+strlen(pos)+1+1];
sprintf(buf,"%s(%s)",s,pos);
......@@ -1704,7 +1688,7 @@ void compile(int verbose) {
TO();
} else {
if(typ&ARRAYTYP) {
if(TL!=PL_ARRAY) printf("ERROR: cannot convert to array.\n");
if(TL!=PL_ARRAY) printf("ERROR: cannot convert to array. $%x\n",TL);
}
bc_zuweis(vnr);
}
......
......@@ -261,6 +261,7 @@ int vm_neg(PARAMETER *sp);
void cast_to_real(PARAMETER *sp);
void cast_to_int(PARAMETER *sp);
int vm_sfunc(PARAMETER *sp,int i, int anzarg);
int vm_afunc(PARAMETER *sp,int i, int anzarg);
int vm_func(PARAMETER *sp,int i, int anzarg);
int vm_comm(PARAMETER *sp,int i, int anzarg);
int vm_pushvv(int vnr,PARAMETER *sp);
......
......@@ -189,7 +189,7 @@ const char *errortxt[] = {
/* 75*/ "Stack overflow!",
/* 76*/ "Illegal variable name %s. can not create.",
/* 77*/ "Function %s not defined for complex numbers.",
/* 78*/ "Error 78",
/* 78*/ "Incorrect parameter, %s must be array",
/* 79*/ "Error 79",
#ifdef GERMAN
/* 80*/ "Matrizenoperationen nur fr ein- oder zweidimensionale Felder",
......
......@@ -480,7 +480,7 @@ STATIC int vm_sfunc(PARAMETER *sp,int i, int anzarg) { /* */
a.len=sp[0].integer;
a.pointer=sp[0].pointer;
} else
xberror(47,(char *)pfuncs[i].name); /* Parameter %s falsch, kein String */
xberror(47,(char *)psfuncs[i].name); /* Parameter %s falsch, kein String */
STRING s=(psfuncs[i].routine)(a);
free_parameter(sp);
......@@ -507,6 +507,80 @@ STATIC int vm_sfunc(PARAMETER *sp,int i, int anzarg) { /* */
", this function does not get its parameters.");
return 1-anzarg;
}
STATIC int vm_afunc(PARAMETER *sp,int i, int anzarg) { /* */
VERBOSE("vm_%s(%d) ",psfuncs[i].name,anzarg);
if(anzarg<pafuncs[i].pmin) {
xberror(42,(char *)pafuncs[i].name); /* Zu wenig Parameter */
return 1-anzarg;
}
if(anzarg>pafuncs[i].pmax && !(pafuncs[i].pmax==-1)) {
xberror(45,(char *)pafuncs[i].name); /* Zu viele Parameter */
return 1-anzarg;
}
sp-=anzarg;
if((pafuncs[i].opcode&FM_TYP)==F_SIMPLE || pafuncs[i].pmax==0) {
ARRAY arr=(pafuncs[i].routine)();
*((ARRAY *)&(sp->integer))=arr;
sp->typ=PL_ARRAY;
return 1-anzarg;
}
if((pafuncs[i].opcode&FM_TYP)==F_ARGUMENT) {
if(sp->typ==PL_KEY) {
ARRAY arr=(pafuncs[i].routine)(sp->pointer);
free(sp->pointer);
*((ARRAY *)&(sp->integer))=arr;
sp->typ=PL_ARRAY;
return 1-anzarg;
} else {
VMERROR("SFUNC");
return 1-anzarg;
}
}
if((psfuncs[i].opcode&FM_TYP)==F_PLISTE) {
PARAMETER *plist;
ARRAY arr;
int e=make_pliste3(pafuncs[i].pmin,pafuncs[i].pmax,(unsigned short *)pafuncs[i].pliste,
&sp[0],&plist,anzarg);
arr=(pafuncs[i].routine)(plist,anzarg);
free_pliste(e,plist);
e=anzarg;
while(--e>=0) free_parameter(&sp[e]);
*((ARRAY *)&(sp->integer))=arr;
sp->typ=PL_ARRAY;
return 1-anzarg;
}
if((pafuncs[i].opcode&FM_TYP)==F_SQUICK) {
STRING s;
if(sp->typ==PL_STRING) {
s.len=sp[0].integer;
s.pointer=sp[0].pointer;
} else
xberror(47,(char *)pafuncs[i].name); /* Parameter %s falsch, kein String */
ARRAY arr=(pafuncs[i].routine)(s);
free_parameter(sp);
*((ARRAY *)&(sp->integer))=arr;
sp[0].typ=PL_ARRAY;
return 1-anzarg;
}
if((pafuncs[i].opcode&FM_TYP)==F_AQUICK) {
ARRAY s;
if(sp->typ==PL_ARRAY) {
s=*((ARRAY *)&(sp->integer));
} else
xberror(78,(char *)pafuncs[i].name); /* Parameter %s falsch, kein Array */
ARRAY arr=(pafuncs[i].routine)(s);
free_parameter(sp);
*((ARRAY *)&(sp->integer))=arr;
sp[0].typ=PL_ARRAY;
return 1-anzarg;
}
VMERROR("INCOMPLETE"
", this function does not get its parameters.");
return 1-anzarg;
}
STATIC int vm_func(PARAMETER *sp,int i, int anzarg) { /* */
VERBOSE("vm_.%s(%d) ",pfuncs[i].name,anzarg);
......@@ -1157,6 +1231,11 @@ PARAMETER *virtual_machine(const STRING bcpc, int offset, int *npar, const PARAM
n=bcpc.pointer[i++]&0xff;
opstack+=vm_sfunc(opstack,a,n);
break;
case BC_PUSHAFUNC:
a=bcpc.pointer[i++]&0xff;
n=bcpc.pointer[i++]&0xff;
opstack+=vm_afunc(opstack,a,n);
break;
case BC_PUSHCOMM:
a=bcpc.pointer[i++]&0xff;
n=bcpc.pointer[i++]&0xff;
......
......@@ -497,6 +497,11 @@ static void translate() {
n=bcpc[i++]&0xff;
fprintf(optr,"PUSHSFUNC(%d,%d); /* %s */\n",a,n,psfuncs[a].name);
break;
case BC_PUSHAFUNC:
a=bcpc[i++]&0xff;
n=bcpc[i++]&0xff;
fprintf(optr,"PUSHAFUNC(%d,%d); /* %s */\n",a,n,pafuncs[a].name);
break;
case BC_PUSHCOMM:
a=bcpc[i++]&0xff;
n=bcpc[i++]&0xff;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment