Author SHA1 Message Date
fred 1fe89c0b6a feat: delete done on hash members
fix: end of line comment formating
2026-02-22 19:13:22 +01:00
fred ddbbb29038 feat: hash.count
fix:DELE woth PVAR, todo with hash
2026-02-21 21:02:07 +01:00
fred eca0605104 feat: foreach numeric, @var oid level, free deleted 2026-02-21 16:06:54 +01:00
fred 72f749172f fix: encod lib Base64 + hash MD5 2026-02-15 13:18:12 +01:00
19 changed files with 1436 additions and 310 deletions

No files matched your search

+28 -8
View File
@@ -421,8 +421,13 @@ int assembler(env * e, char * fichier, int * cptLig)
case IN_PIDH:
case IN_PHDO:
case IN_PIDO:
case IN_DELE:
case IN_PHDN:
case IN_PIDN:
case IN_PHDV:
case IN_PIDV:
case IN_NLET:
case IN_PVHD:
case IN_PVID:
// CPSH / PARM / PVAR / PVAH / PVAI / DELE / NLET / PHDE / PIDE
//dynField(e, &ligne, &tmp, i++, 0, ' ', 0, 1);
//num = dynToNum(e, &tmp, 0, 3) & 255;
@@ -457,6 +462,8 @@ int assembler(env * e, char * fichier, int * cptLig)
PCODE(CMP_OR);
else if(strcmp(tmp.mPtr, "NOT") == 0)
PCODE(CMP_NOT);
else if(strcmp(tmp.mPtr, "FOR") == 0)
PCODE(CMP_FOR);
else
ret = -9; // code comparaison inconnu
break;
@@ -542,6 +549,10 @@ int assembler(env * e, char * fichier, int * cptLig)
// DESV
case IN_DEZV:
// DEZV
case IN_SADV:
case IN_VLET:
case IN_HCOU:
case IN_DELE:
PCODE(instr);
break;
case IN_MODL:
@@ -628,14 +639,14 @@ int assembler(env * e, char * fichier, int * cptLig)
// DEZI
case IN_DSTO:
// DSTO
case IN_VLET:
// VLET
case IN_LETV:
// LETV
case IN_DCAT:
// DCAT
dynField(e, &ligne, &tmp, i++, 0, ' ', 0, 1);
if(tmp.mLg < 1 || tmp.mLg > 255) { ret = -4; break; } // erreur longueur nom var
num = tmp.mLg;
if(num == 1 && tmp.mPtr[0] == '_') // assembler DEXF/DEXV/VLET/DCAT _ pour avoir lg = 0
if(num == 1 && tmp.mPtr[0] == '_') // assembler DEXF/DEXV/LETV/DCAT _ pour avoir lg = 0
num = 0;
PCODE(instr);
PCODE(num);
@@ -936,8 +947,13 @@ int disassembler(env * e, char * fichier)
case IN_PIDH:
case IN_PHDO:
case IN_PIDO:
case IN_DELE:
case IN_PHDN:
case IN_PIDN:
case IN_PHDV:
case IN_PIDV:
case IN_NLET:
case IN_PVHD:
case IN_PVID:
case IN_PNAM:
case IN_INCL:
// CPSH / PARM / PVAR / PVAH / PVAI / DELE / NLET / PNAM / INCL / PHDE / PIDE
@@ -967,7 +983,7 @@ int disassembler(env * e, char * fichier)
// COMP
si++;
num = pcode.ptr[si++];
if(num < CMP_EQ || num > CMP_NOT)
if(num < CMP_EQ || num > CMP_FOR)
printf("%d\n", num);
else
{
@@ -1058,6 +1074,10 @@ int disassembler(env * e, char * fichier)
// DESV
case IN_DEZV:
// DEZV
case IN_SADV:
case IN_VLET:
case IN_HCOU:
case IN_DELE:
si++;
printf("\n");
dumpHex(&pcode, si_instr, si);
@@ -1162,8 +1182,8 @@ int disassembler(env * e, char * fichier)
// DEZI
case IN_DSTO:
// DSTO
case IN_VLET:
// VLET
case IN_LETV:
// LETV
case IN_DCAT:
// DCAT
si++;
+123 -61
View File
@@ -59,7 +59,8 @@ char * strerr[] = {
"EX_INSERT_KO insert field error",
"EX_REMOVE_KO remove field error",
"EX_CHILD_FORK cannot fork process",
"EX_CHILD_EXEC cannot run new process"
"EX_CHILD_EXEC cannot run new process",
"EX_ZERO_FOR_INCR foreach increment is zero" // 40
};
enum {
@@ -80,10 +81,10 @@ long rg(env * e, Dynamic * regles, char * nom, Dynamic * tmp)
return pos;
}
/*
blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,reste,8
blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,identnext,8,reste,9
*/
static struct {
ent16 blanc,commande,aide,nombre,ajouter,supprimer,ident,reste;
ent16 blanc,commande,aide,nombre,ajouter,supprimer,ident,identnext,reste;
} r;
void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
@@ -95,6 +96,7 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.ajouter = rg(e, regles, "ajouter", tmp);
r.supprimer = rg(e, regles, "supprimer", tmp);
r.ident = rg(e, regles, "ident", tmp);
r.identnext = rg(e, regles, "identnext", tmp);
r.reste = rg(e, regles, "reste", tmp);
}
@@ -434,9 +436,9 @@ void debug(env * e)
"q Q continuer et arreter le mode debug 0\n"
"n N continuer en mode debug pas a pas 1\n"
"c C continuer en mode debug 2 arret aux points d'arret uniquement\n"
"v V :ident voir le contenu de la variable <ident>\n"
"v V :ident.hash... voir le contenu de la variable <ident>.<hash>...\n"
"vg VG voir le contenu de la hash globale 'g'\n"
"vg VG :ident voir le contenu de la var <ident> a l'interieur de la hash globale 'g'\n"
"vg VG :ident.hash... voir le contenu de la var <ident>.<hash>... a l'interieur de la hash globale 'g'\n"
"vl VL voir le contenu de la hash locale courante\n"
"b B liste des breakpoints\n"
"b B +/- num ajouter ou supprimer un breakpoint ; si pas de nombre, à l'emplacement en cours, sinon numero de ligne source <num>\n"
@@ -478,36 +480,59 @@ void debug(env * e)
hashtable_printdebug(e, &e->g, 1);
else
{
dynField(e, &e->debugvalex, &tmp, 1, n, cFM, cVM, 1);
dynIconv(e, &tmp, &e->debugcmd, "X");
if(e->debugcmd.mLg < 2 || e->debugcmd.mLg > 24)
var * v = &e->g, * vnext;
while(tok)
{
if(e->demon)
dynPrintfSz(e, "Incorrect var name\n", NULL);
else
printf("Incorrect var name\n");
}
else
{
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
for(int i = 0; i < e->debugcmd.mLg - 1; i++)
e->nom[i] = e->debugcmd.mPtr[i + 1];
var * v;
hashtable_do(e, HASH_READ, &e->g, e->nom, &v);
if(v != NULL)
if(tok == r.blanc)
{
print_var(e, v, &tmp, prettyPrint);
tok = ntok(++n);
continue;
}
else
if(tok != r.identnext && tok != r.ident)
{
if(e->demon)
dynPrintfSz(e, "Unknown global var\n", NULL);
dynPrintfSz(e, "Missing var name\n", NULL);
else
printf("Unknown global var\n");
printf("Missing var name\n");
v = NULL;
break;
}
dynField(e, &e->debugvalex, &tmp, 1, n, cFM, cVM, 1);
dynIconv(e, &tmp, &e->debugcmd, "X");
if(e->debugcmd.mLg < 2 || e->debugcmd.mLg > 24)
{
if(e->demon)
dynPrintfSz(e, "Incorrect var name : %s\n", e->debugcmd.mPtr);
else
printf("Incorrect var name : %s\n", e->debugcmd.mPtr);
v = NULL;
break;
}
else
{
vnext = NULL;
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
for(int i = 0; i < e->debugcmd.mLg - 1; i++)
e->nom[i] = e->debugcmd.mPtr[i + 1];
hashtable_do(e, HASH_READ, v, e->nom, &vnext);
v = vnext;
if( ! v)
{
if(e->demon)
dynPrintfSz(e, "Not a member of hashtable : %s\n", e->nom);
else
printf("Not a member of hashtable : %s\n", e->nom);
v = NULL;
break;
}
// continue
tok = ntok(++n);
}
}
if(v != NULL)
print_var(e, v, &tmp, prettyPrint);
}
continue;
}
@@ -693,42 +718,76 @@ void debug(env * e)
}
else
{
dynField(e, &e->debugvalex, &tmp, 1, n, cFM, cVM, 1);
dynIconv(e, &tmp, &e->debugcmd, "X");
if(e->debugcmd.mLg < 2 || e->debugcmd.mLg > 24)
var * v = NULL, * vnext = NULL;
while(tok)
{
if(e->demon)
dynPrintfSz(e, "Incorrect var name\n", NULL);
else
printf("Incorrect var name\n");
}
else
{
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
for(int i = 0; i < e->debugcmd.mLg - 1; i++)
e->nom[i] = e->debugcmd.mPtr[i + 1];
// chercher la var
var * v = NULL;
if(e->local)
if(tok == r.blanc)
{
hashtable_do(e, HASH_READ, e->local, e->nom, &v);
tok = ntok(++n);
continue;
}
if(v == NULL)
{
/* si pas trouve (ou pas de locale), cherche dans la hash "globale" */
hashtable_do(e, HASH_READ, &e->g, e->nom, &v);
}
if(v != NULL)
print_var(e, v, &tmp, prettyPrint);
else
if(tok != r.identnext && tok != r.ident)
{
if(e->demon)
dynPrintfSz(e, "Unknown var\n", NULL);
dynPrintfSz(e, "Missing var name\n", NULL);
else
printf("Unknown var\n");
printf("Missing var name\n");
v = NULL;
break;
}
dynField(e, &e->debugvalex, &tmp, 1, n, cFM, cVM, 1);
dynIconv(e, &tmp, &e->debugcmd, "X");
if(e->debugcmd.mLg < 2 || e->debugcmd.mLg > 24)
{
if(e->demon)
dynPrintfSz(e, "Incorrect var name : %s\n", e->debugcmd.mPtr);
else
printf("Incorrect var name : %s\n", e->debugcmd.mPtr);
v = NULL;
break;
}
else
{
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
for(int i = 0; i < e->debugcmd.mLg - 1; i++)
e->nom[i] = e->debugcmd.mPtr[i + 1];
// chercher la var
vnext = NULL;
if( ! v)
{
if(e->local)
{
hashtable_do(e, HASH_READ, e->local, e->nom, &vnext);
}
if(v == NULL)
{
/* si pas trouve (ou pas de locale), cherche dans la hash "globale" */
hashtable_do(e, HASH_READ, &e->g, e->nom, &vnext);
}
}
else
{
hashtable_do(e, HASH_READ, v, e->nom, &vnext);
}
if(! vnext )
{
if(e->demon)
dynPrintfSz(e, "Unknown var and/or not member of hashtable : %s\n", e->nom);
else
printf("Unknown var and/or not member of hashtable : %s\n", e->nom);
v = NULL;
break;
}
v = vnext;
// continue
tok = ntok(++n);
}
}
if(v != NULL)
{
print_var(e, v, &tmp, prettyPrint);
}
}
continue;
@@ -763,7 +822,8 @@ void debug(env * e)
nombre: [1,9,0-9]
ajouter: (1,1,#2B) ; +
supprimer:(1,1,#2D) ; -
ident: (1,1,#3A) (1,1,a-zA-Z_) (0,23,a-zA-Z0-9) ; :abcABC123
ident: (1,1,#3A) (1,1,a-zA-Z_) (0,23,a-zA-Z0-9) ; :_abcABC123
identnext:(1,1,#2E) (1,1,a-zA-Z) (0,23,a-zA-Z0-9) ; .abcABC123
reste: (1,1,#00-#FF)
Commandes :
@@ -773,7 +833,7 @@ void debug(env * e)
q Q continuer et arreter le mode debug 0
n N continuer en mode debug pas a pas 1
c C continuer en mode debug 2 arret aux points d'arret uniquement
v V :ident voir le contenu de la variable <ident>
v V :ident.hash voir le contenu de la variable <ident>.<hash>...
b B liste des breakpoints
b B +/- <nombre> ajouter ou supprimer un breakpoint ; si pas de nombre, à l'emplacement en cours, sinon numero de ligne source <nombre>
a A + afficher les infos assembleur (idem trace)
@@ -787,13 +847,14 @@ blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,reste,8
1,9,30-39
1,1,2B
1,1,2D
1,1,3A;5F:1,1,61-7A:41-5A;0,23,61-7A:41-5A:30-39
1,1,3A;5F:1,1,61-7A:41-5A:5F;0,23,61-7A:41-5A:30-39
1,1,2E;5F:1,1,61-7A:41-5A;0,23,61-7A:41-5A:30-39
1,1,00-FF
blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,reste,8
blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,identnext,8,reste,9
ent16 blanc,commande,aide,nombre,ajouter,supprimer,ident,reste;
ent16 blanc,commande,aide,nombre,ajouter,supprimer,ident,identnext,reste;
r.blanc = rg(e, regles, "blanc", tmp);
r.commande = rg(e, regles, "commande", tmp);
@@ -802,6 +863,7 @@ r.nombre = rg(e, regles, "nombre", tmp);
r.ajouter = rg(e, regles, "ajouter", tmp);
r.supprimer = rg(e, regles, "supprimer", tmp);
r.ident = rg(e, regles, "ident", tmp);
r.identnext = rg(e, regles, "identnext", tmp);
r.reste = rg(e, regles, "reste", tmp);
*/
+3 -1
View File
@@ -5,5 +5,7 @@ aide: (1,1,?)
nombre: (1,9,0-9)
ajouter: (1,1,#2B) ; +
supprimer:(1,1,#2D) ; -
ident: (1,1,#3A) (1,1,a-zA-Z_) (0,23,a-zA-Z0-9) ; :abcABC123
ident: (1,1,#3A) (1,1,a-zA-Z_) (0,23,a-zA-Z0-9) ; :_abcABC123
identnext:(1,1,#2E) (1,1,a-zA-Z) (0,23,a-zA-Z0-9) ; .abcABC123
reste: (1,1,#00-#FF)
+1 -1
View File
@@ -2,7 +2,7 @@
__ __ __
\ \/ \/ / W language
\ /\ /
\/ \/ Copyright 2024,2025 lanisys.fr
\/ \/ Copyright 2024-2026 lanisys.fr
This file is part of W language.
+11 -10
View File
@@ -58,11 +58,11 @@ static char carhex[16] = {"0123456789abcdef"};
static char base64[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* '+' = 62 ; '/' = 63 ; '-' (62) se trouve au milieu entre les deux */
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,99,-1,-1, /* '=' mis a 99 */
-1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, /* dernier -1 ici = '_' (63) */
-1,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1, /* 128 cars a la fin de cette ligne */
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,99,-1,-1, /* '=' mis a 99 */
-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* dernier -1 ici = '_' (63) */
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 128 cars a la fin de cette ligne */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
@@ -72,8 +72,8 @@ static char base64[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; // "=" mis a 99
static char carBase64[65] = {"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/="}; /* et caractere "=" en complement */
// TODO static char carBase64url[65] = {"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_="}; /* et caractere "=" en complement */
static char carBase64[65] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}; /* et caractere "=" en complement */
// TODO static char carBase64url[65] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="}; /* et caractere "=" en complement */
/* TODO compatible UTF8 !! */
@@ -174,7 +174,7 @@ WAPIDECL long hex2str(env * e, Dynamic * this, Dynamic * resultat)
return DYN_ERR; /* erreur format hexa incorrect */
resultat->mPtr[to++] = (c1 << 4) | c2;
}
/* */
dynSetLen(e, resultat, this->mLg / 2);
return DYN_OK;
}
@@ -205,7 +205,7 @@ WAPIDECL long base642str(env * e, Dynamic * this, Dynamic * resultat)
char c4 = base64[this->mPtr[from + 3]];
if(c1 == -1 || c2 == -1 || c3 == -1 || c4 == -1 || c1 == 99 || c2 == 99 || (c3 == 99 && c4 != 99))
return DYN_ERR; /* erreur format base64 incorrect */
if((c3 == 99 || c4 == 99) && from + 4 < this->mLg)
if(c4 == 99 && from + 4 < this->mLg)
return DYN_ERR; /* '=' autorise en fin de chaine uniquement */
//
resultat->mPtr[to] = 0;
@@ -222,7 +222,8 @@ WAPIDECL long base642str(env * e, Dynamic * this, Dynamic * resultat)
resultat->mPtr[to + 2] = (c3 & 3) << 6;
resultat->mPtr[to + 2] |= c4;
}
lgClair--;
else
lgClair--;
}
else
lgClair--;
+16 -5
View File
@@ -49,7 +49,7 @@ blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,
sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,20
return,21,returnon,22,loop,23,endloop,24,foreach,25,in,26,like,27,endfor,28,break,29,breakon,30
continue,31,continueon,32,nop,33,part,34,echonl,35,echo,36,input,37,declare,38,let,39,delet,40
new,41,class,42,this,43,parent,44,free,45,precision,46,setsep,47,int,48,frac,49,abs,50
new,41,class,42,this,43,parent,44,hold,45,precision,46,setsep,47,int,48,frac,49,abs,50
neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,change,60
format,61,insert,62,remove,63,tonum,64,tostring,65,equal,66,diff,67,gt,68,lt,69,gte,70
lte,71,and,72,or,73,not,74,beginpar,75,endpar,76,beginh,77,endh,78,begins,79,ends,80
@@ -61,7 +61,7 @@ struct {
ent16 sub,endsub,if_,then,else_,elseif,endif,do_,call,invoke;
ent16 return_,returnon,loop,endloop,foreach,in,like,endfor,break_,breakon;
ent16 continue_,continueon,nop,part,echonl,echo,input,declare,let,delet;
ent16 new,class,this,parent,free,precision,setsep,int_,frac,abs;
ent16 new,class,this,parent,hold,precision,setsep,int_,frac,abs;
ent16 neg,round,type,len,count,dcount,field,index,search,change;
ent16 format,insert,remove,tonum,tostring,equal,diff,gt,lt,gte;
ent16 lte,and,or,not,beginpar,endpar,beginh,endh,begins,ends;
@@ -119,7 +119,7 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.class = rg(e, regles, "class", tmp);
r.this = rg(e, regles, "this", tmp);
r.parent = rg(e, regles, "parent", tmp);
r.free = rg(e, regles, "free", tmp);
r.hold = rg(e, regles, "hold", tmp);
r.precision = rg(e, regles, "precision", tmp);
r.setsep = rg(e, regles, "setsep", tmp);
r.int_ = rg(e, regles, "int", tmp);
@@ -186,9 +186,19 @@ enum {
COMMENT_EOL = 8
};
static void formatage_asm(Dynamic * s, Dynamic * f)
{
// TODO
}
static void formatage(Dynamic * s, Dynamic * f, int type)
{
// s : source ; f : source apres formatage, type : 1 w, 2 pcode
if(type == 2)
{
formatage_asm(s, f);
return;
}
//Dynamic token; /* contient les tokens suite au decodage lex d'une ligne */
ent16 tok; //,tok2,tok3; /* token lu par la macro ci-dessous "nreg" */
long n; /* indice en cours dans les token (parametre de la macro "nreg") base 1 */
@@ -319,7 +329,7 @@ static void formatage(Dynamic * s, Dynamic * f, int type)
//if(tok2 != r.comment)
// pos_comment = -1;
}
// si pos_comment > -1 traiter le commentaire en fin de ligne, position multiple de 10 (par exemple), >= position actuelle
// si pos_comment > -1 traiter le commentaire en fin de ligne, position multiple de 8, >= position actuelle
// + formatage debut de ligne
if(pos_comment == -1)
{
@@ -331,7 +341,8 @@ static void formatage(Dynamic * s, Dynamic * f, int type)
}
else
{
dynSubstr(&e, &trav, &lig, pos - 1, pos_comment - pos, 1, DYN_NONE, 10, DYN_NONE);
dynSubstr(&e, &trav, &tmp, pos - 1, pos_comment - pos, 1, DYN_NONE, 10, DYN_NONE);
dynTrim(&e, &tmp, &lig, ' ', 2);
#ifdef WINLIB
dynSubstr(&e, &trav, &tmp, pos_comment - 1, ((intptr_t)(trav.mPtr)) - pos_comment, 1, DYN_NONE, 10, DYN_NONE);
#else
+202 -36
View File
@@ -98,6 +98,8 @@ Dynamic dercode;/* pour la gestion des variables de hash a gauche du signe " = "
long setfld; /* pour gestion let x{1} et let x{1,1} : 1 ou 2 si field ou value */
long setsubstr; /* pour gestion let x[1,2] et x{3,4}[1,2] : 1 si substr avec 2 params */
Dynamic forend,forinc; /* variables pour le code asm des boucles foreach numeriques */
/* -------------------- */
ent64 lap = 0; /* calcul temps du programme (hors init, alloc et free), en ms */
@@ -135,6 +137,8 @@ long init(env * e)
dynInit(e, &dercode, 0);
dynInit(e, &wdir, 0);
dynInit(e, &srcdbg, 0);
dynInit(e, &forend, 0);
dynInit(e, &forinc, 0);
iPrio = 0;
iImbriPrio = 1;
numNiv = 0;
@@ -154,6 +158,8 @@ void fin(env * e)
dynFree(e, &dercode);
dynFree(e, &wdir);
dynFree(e, &srcdbg);
dynFree(e, &forend);
dynFree(e, &forinc);
}
long rg(env * e, Dynamic * regles, char * nom, Dynamic * tmp)
@@ -175,7 +181,7 @@ blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,
sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,20
return,21,returnon,22,loop,23,endloop,24,foreach,25,in,26,like,27,endfor,28,break,29,breakon,30
continue,31,continueon,32,nop,33,part,34,echonl,35,echo,36,input,37,declare,38,let,39,delet,40
new,41,class,42,this,43,parent,44,free,45,precision,46,setsep,47,int,48,frac,49,abs,50
new,41,class,42,this,43,parent,44,hold,45,precision,46,setsep,47,int,48,frac,49,abs,50
neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,change,60
format,61,insert,62,remove,63,tonum,64,tostring,65,equal,66,diff,67,gt,68,lt,69,gte,70
lte,71,and,72,or,73,not,74,beginpar,75,endpar,76,beginh,77,endh,78,begins,79,ends,80
@@ -187,7 +193,7 @@ struct {
ent16 sub,endsub,if_,then,else_,elseif,endif,do_,call,invoke;
ent16 return_,returnon,loop,endloop,foreach,in,like,endfor,break_,breakon;
ent16 continue_,continueon,nop,part,echonl,echo,input,declare,let,delet;
ent16 new,class,this,parent,free,precision,setsep,int_,frac,abs;
ent16 new,class,this,parent,hold,precision,setsep,int_,frac,abs;
ent16 neg,round,type,len,count,dcount,field,index,search,change;
ent16 format,insert,remove,tonum,tostring,equal,diff,gt,lt,gte;
ent16 lte,and,or,not,beginpar,endpar,beginh,endh,begins,ends;
@@ -254,7 +260,7 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.class = rg(e, regles, "class", tmp);
r.this = rg(e, regles, "this", tmp);
r.parent = rg(e, regles, "parent", tmp);
r.free = rg(e, regles, "free", tmp);
r.hold = rg(e, regles, "hold", tmp);
r.precision = rg(e, regles, "precision", tmp);
r.setsep = rg(e, regles, "setsep", tmp);
r.int_ = rg(e, regles, "int", tmp);
@@ -413,18 +419,25 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
tok = nreg(n);
tok2 = nreg(n+1);
tok3 = nreg(n+2);
if((tok == r.identsep || tok == r.indirect) && tok2 == r.ident) ; else break;
if((tok == r.identsep || tok == r.indirect) && (tok2 == r.ident || tok2 == r.count)) ; else break;
/* */
n++;
dynField(e, valex, tmp, 1, norig(n), cFM, cVM, 1);
dynIconv(e, tmp, encours, "X");
if(tok3 == r.identsep || tok3 == r.indirect || ! *aGauche) // si a droite du " = " : toujours PVAH/PVAI !
{
if(tok == r.identsep)
dynConcatSz(e, resultat, "PVAH ", 5);
if(tok2 == r.count)
{
dynConcatSz(e, resultat, "HCOU", 4);
}
else
dynConcatSz(e, resultat, "PVAI ", 5);
dynConcat(e, resultat, encours);
{
if(tok == r.identsep)
dynConcatSz(e, resultat, "PVAH ", 5);
else
dynConcatSz(e, resultat, "PVAI ", 5);
dynConcat(e, resultat, encours);
}
dynConcatSz(e, resultat, "\n", 1);
}
else
@@ -444,6 +457,27 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
return VAR_OK;
}
long var_ident(env * e, Dynamic * instr, Dynamic * tmp, long offset)
{
// renvoi TRUE si instr ne contient que des PVAR/PVAH/PVAI, en partant de la fin (nb ligne de instr - offset)
// arret quand plus de ligne ou SRCL lu
long cr = FALSE, cpt, nb = dynDcount(e, instr, 10, DYN_NONE, DYN_NONE) - offset;
// lire instr de nb a 1, sauf si SRCL est lu (arret alors)
for(cpt = nb; cpt > 0; cpt--)
{
dynField(e, instr, tmp, cpt, DYN_NONE, 10, DYN_NONE, 1);
if(strncmp(tmp->mPtr, "SRCL", 4) == 0)
return cr;
if(strncmp(tmp->mPtr, "PVAR", 4) == 0 ||
strncmp(tmp->mPtr, "PVAH", 4) == 0 ||
strncmp(tmp->mPtr, "PVAI", 4) == 0)
cr = TRUE;
else
return FALSE;
}
return cr;
}
long terme(env * e, ent16 t, Dynamic * valex, Dynamic * tmp, Dynamic * encours)
{
long ret = TERM_ERR, aGauche = 0;
@@ -1564,35 +1598,117 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
printf("Erreur ligne %dc%s : foreach variable 2 incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
dynSetLen(e, &forend, 0);
dynSetLen(e, &forinc, 0);
if(tok == r.listesep)
{
/* forme numerique : foreach x in debut,fin,increment */
n++;
if(variable(e, &forend, valex, tmp, encours, &aGauche) != VAR_OK)
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : foreach variable 3 incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
if(tok == r.listesep)
{
n++;
if(variable(e, &forinc, valex, tmp, encours, &aGauche) != VAR_OK)
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : foreach variable 4 incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
}
// par defaut, l'increment est 1 (forinc vide)
}
if(tok != 0)
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : foreach fin incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
// trav = 1ere var, envers = 2eme var (in)
// trav = 1ere var, envers = 2eme var (in), forend = 3eme var, forinc = 4eme var
//
dynConcatSz(e, resultat, "SRCL ", DYN_LGNONE);
dynConcatSz(e, resultat, Int64ToSz(e, numlig, FALSE, 0), DYN_LGNONE);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
/* */
dynConcat(e, resultat, &envers);
dynConcatSz(e, resultat, "SELE\n", DYN_LGNONE);
if(forend.mLg == 0)
{
dynConcat(e, resultat, &envers);
dynConcatSz(e, resultat, "SELE\n", DYN_LGNONE);
/* */
AjoutNiveau(e, "F");
dynConcat(e, resultat, &label);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
/* */
//dynConcatSz(e, resultat, "PSH0\n", DYN_LGNONE); /* a remplacer */
dynConcat(e, resultat, &trav);
dynConcatSz(e, resultat, "CPHA\n", DYN_LGNONE);
dynConcat(e, resultat, &envers);
dynConcatSz(e, resultat, "RNXT\n", DYN_LGNONE);
/* */
label.mPtr[1] = 'F';
dynConcatSz(e, resultat, "JMPF ", DYN_LGNONE);
dynConcat(e, resultat, &label);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
}
else
{
// trav = envers - forinc (si forinc positif, sinon + forinc)
dynConcat(e, resultat, &envers);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
if(forinc.mLg == 0)
dynConcatSz(e, resultat, "PSH1\n", DYN_LGNONE);
else
{
dynConcat(e, resultat, &forinc);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
}
dynConcatSz(e, resultat, "SBCN\n", DYN_LGNONE);
dynConcat(e, resultat, &trav);
dynConcatSz(e, resultat, "POPV\n", DYN_LGNONE);
/* */
AjoutNiveau(e, "F");
dynConcat(e, resultat, &label);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
/* */
// trav = trav + forinc
dynConcat(e, resultat, &trav);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
if(forinc.mLg == 0)
dynConcatSz(e, resultat, "PSH1\n", DYN_LGNONE);
else
{
dynConcat(e, resultat, &forinc);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
}
dynConcatSz(e, resultat, "ADDN\n", DYN_LGNONE);
dynConcat(e, resultat, &trav);
dynConcatSz(e, resultat, "POPV\n", DYN_LGNONE);
/* */
// compare trav <= forend (si forinc positif, sinon trav >= forend)
dynConcat(e, resultat, &trav);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
dynConcat(e, resultat, &forend);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
if(forinc.mLg == 0)
dynConcatSz(e, resultat, "PSH1\n", DYN_LGNONE);
else
{
dynConcat(e, resultat, &forinc);
dynConcatSz(e, resultat, "PSHV\n", DYN_LGNONE);
}
dynConcatSz(e, resultat, "COMP FOR\n", DYN_LGNONE); // instruction qui compare selon la valeur de forinc (pile) : positif <=, negatif >=, 0 exception => COMP FOR
//dynConcatSz(e, resultat, "PSH0\n", DYN_LGNONE); /* a remplacer */
/* */
label.mPtr[1] = 'F';
dynConcatSz(e, resultat, "JMPF ", DYN_LGNONE);
dynConcat(e, resultat, &label);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
}
/* */
AjoutNiveau(e, "F");
dynConcat(e, resultat, &label);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
/* */
//dynConcatSz(e, resultat, "PSH0\n", DYN_LGNONE); /* a remplacer */
dynConcat(e, resultat, &trav);
dynConcatSz(e, resultat, "CPHA\n", DYN_LGNONE);
dynConcat(e, resultat, &envers);
dynConcatSz(e, resultat, "RNXT\n", DYN_LGNONE);
/* */
label.mPtr[1] = 'F';
dynConcatSz(e, resultat, "JMPF ", DYN_LGNONE);
dynConcat(e, resultat, &label);
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
return OK;
}
/* -------------------------------------------------------------------------------------- */
@@ -2232,11 +2348,19 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
printf("Erreur ligne %dc%s : new, classe incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
// pbm test suivant si new appele dans library...
if(IdentInconnu(e, tmp))
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : new, classe inconnue\n", numlig, tmp->mPtr);
return DYN_ERR;
//dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
//printf("Erreur ligne %dc%s : new, classe inconnue\n", numlig, tmp->mPtr);
//return DYN_ERR;
// TODO : mettre un warning ?
}
if(aGauche == 2)
{
// TODO dercode avec une var a creer : PHDN/PIDN - TODO
dercode.mPtr[3] = 'N';
dynConcat(e, resultat, &dercode);
}
dynConcatSz(e, resultat, "NLET ", DYN_LGNONE);
dynConcat(e, resultat, tmp);
@@ -2261,17 +2385,39 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
}
if(setsubstr == 0)
{
dynConcat(e, resultat, &envers);
//dynConcat(e, resultat, &envers);
if(setfld == 0)
{
// var
if(aGauche != 2)
dynConcatSz(e, resultat, "POPV\n", 5); // une seule var a gauche
// var - si juste enchainement de var a droite (a.b!c) => nouvelles instructions VLET/PHDV/PIDV
// verifier dans &envers et fin de &resultat (depuis le dernier SRCL en partant de la fin) si que des PVAR/PVAH/PVAI
// offset 2 pour ne pas lire PSHV de resultat, et 1/2 pour sauter la derniere ligne (car se termine avec \n)
if(var_ident(e, resultat, tmp, 2) && var_ident(e, &envers, tmp, 1))
{
// que des enchainement de PVAR/PVAI/PVAH => affectation "simple" de var (var_let au final)
// remplacer dans la derniere ligne de resultat PHSV par SADV
dynStoreSz(e, resultat, dynDcount(e, resultat, 10, DYN_NONE, DYN_NONE) - 1,DYN_NONE, "SADV", 4, 10, DYN_NONE); // -1 car resultat se termine par \n
dynConcat(e, resultat, &envers);
if(aGauche != 2)
dynConcatSz(e, resultat, "VLET\n", 5); // une seule var a gauche
else
{
dercode.mPtr[3] = 'V';
dynConcat(e, resultat, &dercode); // PHDV PIDV
}
}
else
dynConcat(e, resultat, &dercode); // PHDE PIDE
{
// var
dynConcat(e, resultat, &envers);
if(aGauche != 2)
dynConcatSz(e, resultat, "POPV\n", 5); // une seule var a gauche
else
dynConcat(e, resultat, &dercode); // PHDE PIDE
}
}
else
{
dynConcat(e, resultat, &envers);
// setfld = 1 ou 2 : var{}
if(aGauche != 2)
dynConcatSz(e, resultat, "DEXV\n", 5); // une seule var a gauche
@@ -2369,9 +2515,10 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
return OK;
}
/* -------------------------------------------------------------------------------------- */
if(tok == r.free)
if(tok == r.hold)
{
// TODO
// plugin mode - TODO
return OK;
}
/* -------------------------------------------------------------------------------------- */
if(tok == r.echo || tok == r.echonl)
@@ -2435,7 +2582,26 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
printf("Erreur ligne %dc%s : fin delet incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
dynConcatSz(e, resultat, "DELE\n", 5);
// var_ident(e, resultat, tmp, 1)) pas necessaire, car que des enchainements de PVAR/PVAH/PVAI a droite
// remplacer dans la derniere ligne de resultat PVAH/PVAI par PVHD/PVID ; si PVAR, ajouter en fin DELE
long lig = dynDcount(e, resultat, 10, DYN_NONE, DYN_NONE) - 1; // -1 car resultat se termine par \n
dynField(e, resultat, tmp, lig, DYN_NONE, 10, DYN_NONE, 1);
if(strncmp(tmp->mPtr, "PVAH", 4) == 0)
{
tmp->mPtr[2] = 'H';
tmp->mPtr[3] = 'D';
dynStore(e, resultat, lig, DYN_NONE, tmp, 10, DYN_NONE);
}
else if(strncmp(tmp->mPtr, "PVAI", 4) == 0)
{
tmp->mPtr[2] = 'I';
tmp->mPtr[3] = 'D';
dynStore(e, resultat, lig, DYN_NONE, tmp, 10, DYN_NONE);
}
else
{
dynConcatSz(e, resultat, "DELE\n", 5);
}
return OK;
}
/* -------------------------------------------------------------------------------------- */
+287 -29
View File
@@ -55,7 +55,7 @@ static int setError(modEtat * p, int err)
return EX_MODERR;
}
static void encodageMD2(char * entree, ent64 longueur, char * sortie)
static void encodageMD2(env * e, var * entree, var * sortie)
{
unsigned char checksum[16] = {0};
unsigned char padding[16] = {0};
@@ -74,8 +74,9 @@ static void encodageMD2(char * entree, ent64 longueur, char * sortie)
235, 117, 75, 10, 49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 };
static char carhex[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
/* */
unsigned char * p = (unsigned char *)entree;
unsigned char * p = (unsigned char *)(entree->ptr);
unsigned char L = 0, T;
long longueur = entree->mLg;
while(longueur >= 16)
{
for(i = 0; i < 16; i++)
@@ -131,13 +132,13 @@ static void encodageMD2(char * entree, ent64 longueur, char * sortie)
/* fin du calcul md2 : en hexa dans sortie (tableau de 32 cars mini) et binaire dans binaire */
for(i = 0, j = 0; i < 16; i++)
{
sortie[j++] = carhex[buffer[i] / 16];
sortie[j++] = carhex[buffer[i] % 16];
sortie->ptr[j++] = carhex[buffer[i] / 16];
sortie->ptr[j++] = carhex[buffer[i] % 16];
}
sortie[j] = 0;
dynSetLen(e, sortie, j); // len = 32 ici
}
static void majMD4(unsigned int * md4, unsigned int * buffer)
static void majMD4(unsigned int * md4, pointeur buffer)
{
unsigned int A, B, C, D, tmp;
unsigned int buf[16];
@@ -150,7 +151,7 @@ static void majMD4(unsigned int * md4, unsigned int * buffer)
#define h(W,X,Y,Z,i,r) W = rot((W + (X^Y^Z) + buf[i] + 0x6ED9EBA1),r)
/* coder le buffer en little endian */
octet = (unsigned char *)buffer;
octet = buffer;
for(i=0; i<16; i++, octet+=4)
buf[i] = (*octet) | ((*(octet+1))<<8) | ((*(octet+2))<<16) | ((*(octet+3))<<24);
/* */
@@ -217,7 +218,7 @@ static void majMD4(unsigned int * md4, unsigned int * buffer)
md4[3] += D;
}
void encodageMD4(char * entree, ent64 longueur, char * sortie)
static void encodageMD4(env * e, var * entree, var * sortie)
{
unsigned char lg[8];
unsigned char buffer[64];
@@ -229,12 +230,14 @@ void encodageMD4(char * entree, ent64 longueur, char * sortie)
md4[1] = (unsigned int)0xefcdab89;
md4[2] = (unsigned int)0x98badcfe;
md4[3] = (unsigned int)0x10325476;
long longueur = entree->mLg;
*(ent64 *)lg = (ent64)longueur * 8;
/* */
pointeur p = entree->ptr;
while(longueur >= 64)
{
majMD4(md4, (unsigned int *)entree);
entree += 64;
majMD4(md4, p);
p += 64;
longueur -= 64;
}
/* traitement du dernier bloc */
@@ -242,7 +245,7 @@ void encodageMD4(char * entree, ent64 longueur, char * sortie)
/* si pas assez de place, faire un nouveau bloc */
memset(buffer, 0, 64);
if(longueur > 0)
memcpy(buffer, entree, longueur);
memcpy(buffer, p, longueur);
buffer[longueur] = 128; /* 0x80 */
if(longueur <= 55)
{
@@ -256,12 +259,12 @@ void encodageMD4(char * entree, ent64 longueur, char * sortie)
*(unsigned char *)(buffer+61) = (*(ent64 *)lg >> 40) & 255;
*(unsigned char *)(buffer+62) = (*(ent64 *)lg >> 48) & 255;
*(unsigned char *)(buffer+63) = (*(ent64 *)lg >> 56) & 255;
majMD4(md4, (unsigned int *)buffer);
majMD4(md4, buffer);
}
else
{
/* 2 derniers blocs */
majMD4(md4, (unsigned int *)buffer);
majMD4(md4, buffer);
/* */
memset(buffer, 0, 64);
// encoder la longueur en little endian
@@ -273,7 +276,7 @@ void encodageMD4(char * entree, ent64 longueur, char * sortie)
*(unsigned char *)(buffer+61) = (*(ent64 *)lg >> 40) & 255;
*(unsigned char *)(buffer+62) = (*(ent64 *)lg >> 48) & 255;
*(unsigned char *)(buffer+63) = (*(ent64 *)lg >> 56) & 255;
majMD4(md4, (unsigned int *)buffer);
majMD4(md4, buffer);
}
//
/* calcul md4 en hexa dans sortie (tableau de 32 cars mini) et binaire dans binaire */
@@ -281,26 +284,257 @@ void encodageMD4(char * entree, ent64 longueur, char * sortie)
{
buffer[0] = md4[i] & 255;
md4[i] >>= 8;
sortie[j] = carhex[buffer[0]/16];
sortie[j+1] = carhex[buffer[0]%16];
sortie->ptr[j] = carhex[buffer[0]/16];
sortie->ptr[j+1] = carhex[buffer[0]%16];
/* */
buffer[0] = md4[i] & 255;
md4[i] >>= 8;
sortie[j+2] = carhex[buffer[0]/16];
sortie[j+3] = carhex[buffer[0]%16];
sortie->ptr[j+2] = carhex[buffer[0]/16];
sortie->ptr[j+3] = carhex[buffer[0]%16];
/* */
buffer[0] = md4[i] & 255;
md4[i] >>= 8;
sortie[j+4] = carhex[buffer[0]/16];
sortie[j+5] = carhex[buffer[0]%16];
sortie->ptr[j+4] = carhex[buffer[0]/16];
sortie->ptr[j+5] = carhex[buffer[0]%16];
/* */
buffer[0] = md4[i] & 255;
sortie[j+6] = carhex[buffer[0]/16];
sortie[j+7] = carhex[buffer[0]%16];
sortie->ptr[j+6] = carhex[buffer[0]/16];
sortie->ptr[j+7] = carhex[buffer[0]%16];
}
sortie[32] = 0;
dynSetLen(e, sortie, 32);
}
/* MD5 stuff, as of RFC 1321 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
#define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (ent32)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define GG(a, b, c, d, x, s, ac) { (a) += G ((b), (c), (d)) + (x) + (ent32)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define HH(a, b, c, d, x, s, ac) { (a) += H ((b), (c), (d)) + (x) + (ent32)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
#define II(a, b, c, d, x, s, ac) { (a) += I ((b), (c), (d)) + (x) + (ent32)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
static void encodageMD5(env * e, var * entree, var * sortie)
{
ent32 a, b, c, d, s0, s1, s2, s3, i, x[16];
unsigned char buffer[64];
/* */
s0 = 0x67452301;
s1 = 0xefcdab89;
s2 = 0x98badcfe;
s3 = 0x10325476;
/* */
long len64 = entree->mLg % 64;
long nb64 = entree->mLg / 64;
long der1 = 0, der2 = 0, der3 = 0;
if(len64 < 56)
{
// dernier bloc : len64(entree) 1(128) 55-len64(0) 8(mLg)
der1 = ++nb64;
}
else
{
// avant dernier bloc : len64(entree) 1(128) 63-len64(0)
// dernier bloc : 0(56) 8(mLg)
der2 = ++nb64;
der3 = ++nb64;
}
ent64 nb = (ent64)(entree->mLg * 8); /* en bits */
pointeur p = entree->ptr;
/* pour chaque bloc de 64 octets (512 bits) */
for(long cpt = 1; cpt <= nb64; cpt++)
{
if(cpt == der1)
{
// dernier bloc cas modulo < 56
memset(buffer, 0, 64);
if(len64 > 0)
memcpy(buffer, p, len64);
buffer[len64] = 128;
buffer[56] = (nb) & 0xff;
buffer[57] = (nb >> 8) & 0xff;
buffer[58] = (nb >> 16) & 0xff;
buffer[59] = (nb >> 24) & 0xff;
buffer[60] = (nb >> 32) & 0xff;
buffer[61] = (nb >> 40) & 0xff;
buffer[62] = (nb >> 48) & 0xff;
buffer[63] = (nb >> 56) & 0xff;
p = buffer;
}
else if(cpt == der2)
{
// avant dernier bloc cas modulo >= 56
memset(buffer, 0, 64);
memcpy(buffer, p, len64);
buffer[len64] = 128;
p = buffer;
}
else if (cpt == der3)
{
// dernier bloc cas modulo >= 56
memset(buffer, 0, 64);
buffer[56] = (nb) & 0xff;
buffer[57] = (nb >> 8) & 0xff;
buffer[58] = (nb >> 16) & 0xff;
buffer[59] = (nb >> 24) & 0xff;
buffer[60] = (nb >> 32) & 0xff;
buffer[61] = (nb >> 40) & 0xff;
buffer[62] = (nb >> 48) & 0xff;
buffer[63] = (nb >> 56) & 0xff;
p = buffer;
}
/* deplier la boucle ? */
for (i = 0; i < 16; i++)
{
x[i] = ((ent32)(*p++));
x[i] |= (((ent32)(*p++)) << 8);
x[i] |= (((ent32)(*p++)) << 16);
x[i] |= (((ent32)(*p++)) << 24);
}
//hex(p, 64);
/* */
a = s0;
b = s1;
c = s2;
d = s3;
/* Round 1 */
FF(a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF(d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF(c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF(b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF(a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF(d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF(c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF(b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF(a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF(d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG(a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG(d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG(b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG(a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG(d, a, b, c, x[10], S22, 0x02441453); /* 22 */
GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG(b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG(a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG(c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG(b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG(d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG(c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH(a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH(d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH(a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH(d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH(c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH(d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH(c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH(b, c, d, a, x[ 6], S34, 0x04881d05); /* 44 */
HH(a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH(b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II(a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II(d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II(b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II(d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II(b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II(a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II(c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II(a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II(c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II(b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
/* */
s0 += a;
s1 += b;
s2 += c;
s3 += d;
}
p = sortie->ptr; /* 16 octets en hexa */
char hexa[16] = "0123456789abcdef";
/* */
*p++ = hexa[(s0 >> 4) & 0xf];
*p++ = hexa[(s0) & 0xf];
*p++ = hexa[(s0 >> 12) & 0xf];
*p++ = hexa[(s0 >> 8) & 0xf];
*p++ = hexa[(s0 >> 20) & 0xf];
*p++ = hexa[(s0 >> 16) & 0xf];
*p++ = hexa[(s0 >> 28) & 0xf];
*p++ = hexa[(s0 >> 24) & 0xf];
/* */
*p++ = hexa[(s1 >> 4) & 0xf];
*p++ = hexa[(s1) & 0xf];
*p++ = hexa[(s1 >> 12) & 0xf];
*p++ = hexa[(s1 >> 8) & 0xf];
*p++ = hexa[(s1 >> 20) & 0xf];
*p++ = hexa[(s1 >> 16) & 0xf];
*p++ = hexa[(s1 >> 28) & 0xf];
*p++ = hexa[(s1 >> 24) & 0xf];
/* */
*p++ = hexa[(s2 >> 4) & 0xf];
*p++ = hexa[(s2) & 0xf];
*p++ = hexa[(s2 >> 12) & 0xf];
*p++ = hexa[(s2 >> 8) & 0xf];
*p++ = hexa[(s2 >> 20) & 0xf];
*p++ = hexa[(s2 >> 16) & 0xf];
*p++ = hexa[(s2 >> 28) & 0xf];
*p++ = hexa[(s2 >> 24) & 0xf];
/* */
*p++ = hexa[(s3 >> 4) & 0xf];
*p++ = hexa[(s3) & 0xf];
*p++ = hexa[(s3 >> 12) & 0xf];
*p++ = hexa[(s3 >> 8) & 0xf];
*p++ = hexa[(s3 >> 20) & 0xf];
*p++ = hexa[(s3 >> 16) & 0xf];
*p++ = hexa[(s3 >> 28) & 0xf];
*p++ = hexa[(s3 >> 24) & 0xf];
/* */
dynSetLen(e, sortie, 32);
}
/* *********************************************************************************** */
#ifdef WINLIB
/* Sous Windows, export de la fonction de base au sein d'une DLL : 1 module = 1 DLL */
__declspec(dllexport) long execModule(env * , var * , var * , var * , void ** );
@@ -356,8 +590,10 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
}
else if(modFnIs(e, "vers", 4))
{
if(param1 == NULL)
exc = EX_MODETAT;
// renvoie la version du module/plugins
if(param1->type == VAR_DYNAMIC)
else if(param1->type == VAR_DYNAMIC)
dynLet(e, param1, "1", 1); // version 1 ici
else if(param1->type == VAR_NUMBER)
param1->num = NUM_UN;
@@ -371,7 +607,9 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
exc = EX_MODETAT;
else
{
if(param1->type == VAR_NUMBER)
if(param1 == NULL)
exc = EX_MODETAT;
else if(param1->type == VAR_NUMBER)
param1->num = (ent64)(NUM_FACTEUR * p_etat->error);
else
exc = EX_MODPARAM; // variable en parametre du mauvais type
@@ -382,13 +620,15 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
{
p_etat->error = 0;
// pour les vars en sortie, forcer le chgt de type si besoin ?
if(param1->type != VAR_DYNAMIC)
if(param1 == NULL || param2 == NULL)
exc = EX_MODPARAM;
else if(param1->type != VAR_DYNAMIC)
exc = EX_MODPARAM;
else if(param2->type != VAR_DYNAMIC)
exc = EX_MODPARAM;
else
{
encodageMD2(param1->mPtr, param1->lg, param2->mPtr);
encodageMD2(e, param1, param2);
}
}
/* ----------------------------------------------------------------------------------------------- */
@@ -396,13 +636,31 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
{
p_etat->error = 0;
// pour les vars en sortie, forcer le chgt de type si besoin ?
if(param1->type != VAR_DYNAMIC)
if(param1 == NULL || param2 == NULL)
exc = EX_MODPARAM;
else if(param1->type != VAR_DYNAMIC)
exc = EX_MODPARAM;
else if(param2->type != VAR_DYNAMIC)
exc = EX_MODPARAM;
else
{
encodageMD4(param1->mPtr, param1->lg, param2->mPtr);
encodageMD4(e, param1, param2);
}
}
/* ----------------------------------------------------------------------------------------------- */
else if(modFnIs(e, "MD5", 3))
{
p_etat->error = 0;
// pour les vars en sortie, forcer le chgt de type si besoin ?
if(param1 == NULL || param2 == NULL)
exc = EX_MODPARAM;
else if(param1->type != VAR_DYNAMIC)
exc = EX_MODPARAM;
else if(param2->type != VAR_DYNAMIC)
exc = EX_MODPARAM;
else
{
encodageMD5(e, param1, param2);
}
}
/* ----------------------------------------------------------------------------------------------- */
+6 -1
View File
@@ -27,6 +27,7 @@
#include "langage.h"
#include "var.h"
#include "hashtable.h"
#include "dynamic.h"
// force exporting
#ifdef WINLIB
@@ -371,7 +372,11 @@ WAPIDECL void hashtable_printdebug(env * e, var * varht, int detail)
pchain = (entry *)((ent64)pchain_first + varht->separateur);
}
if(ptrClass)
printf("%s : %s\n", GUV_CLASS, ptrClass);
{
dynLet(e, &e->tmp_dynamic, ptrClass, DYN_LGNONE);
dynReplace(e, &e->tmp_dynamic, cFM, ':');
printf("%s %s\n", GUV_CLASS, e->tmp_dynamic.mPtr);
}
printf("taille totale=%lld, occupee=%lld (taux %lld%%), nb item=%lld\n", tot, occ, occ * 100 / tot, nb);
}
+7 -1
View File
@@ -28,7 +28,7 @@ void instr_unassemble(env * e, pointeur debutBin, ent64 nolig)
/* special 2 bytes w opcode */
case IN_COMP:
d1 = lire8(p);
if(d1 < CMP_EQ || d1 > CMP_NOT)
if(d1 < CMP_EQ || d1 > CMP_FOR)
printf("??? (%d)", d1);
else
{
@@ -73,6 +73,12 @@ void instr_unassemble(env * e, pointeur debutBin, ent64 nolig)
case IN_PIDH:
case IN_PHDO:
case IN_PIDO:
case IN_PHDN:
case IN_PIDN:
case IN_PHDV:
case IN_PIDV:
case IN_PVHD:
case IN_PVID:
case IN_DEXH:
case IN_DEXI:
case IN_DESH:
+25 -6
View File
@@ -27,6 +27,7 @@
/* ************************************ */
/* AJOUT D'UNE INSTRUCTION
- instr.h : ci-dessous, 2 constantes + ajout a libInstr
- instr.c : ajout constante, si besoin, dans instr_unassemble
- langage.c : ajout dans le tableau de function instr + dans le commentaire en dessous,
ajouter la function instr_xxx
- assembler.c : ajout switch de la function assembler,
@@ -38,7 +39,7 @@
char libInstr[256 * 4] ={"VERS" "JUMP" "DECL" "SRCL" "BEXC" "EXCE" "CATC" "THRW" "PART" "RETN"
"CALL" "PARM" "SUBR" "COMP" "JMPF" "JMPT" "ADDN" "SBCN" "MULN" "DIVN"
"INTE" "FRAC" "NEGN" "ABSN" "MODL" "PSHC" "PSHV" "POPV" "PVAR" "PVAH"
"WRIT" "WRLN" "DSET" "DEXV" "DCMP" "DSTO" "VLET" "DCAT" "DTON" "NTOD"
"WRIT" "WRLN" "DSET" "DEXV" "DCMP" "DSTO" "LETV" "DCAT" "DTON" "NTOD"
"DELE" "HLET" "CLAS" "NLET" "INCL" "PNAM" "PSH0" "PSH1" "PSH2" "PSH3"
"PSH4" "PSH5" "PSH6" "PSH7" "PSH8" "PSH9" "PSHA" "PROG" "BACK" "CLIB"
"PVAI" "DIVE" "MODN" "INPT" "PVAT" "TYPO" "PSHT" "CRAZ" "CPSH" "RETT"
@@ -46,8 +47,8 @@ char libInstr[256 * 4] ={"VERS" "JUMP" "DECL" "SRCL" "BEXC" "EXCE" "CATC" "THRW"
"PIDS" "TYPE" "ROUN" "LENG" "COUN" "DCOF" "FIEL" "INDX" "SRCH" "CHNG"
"FMTA" "INSE" "REMV" "TONU" "TOST" "CCAT" "SSTR" "SSEP" "FLDF" "FLDS" /* 0-99 */
"DCOS" "FMTT" "FMTS" "SCHS" "INSS" "REMS" "DEXH" "DEXI" "PREC" "DESV"
"DESH" "DESI" "DEZV" "DEZH" "DEZI" "SDBG" "xxxx" "xxxx" "xxxx" "xxxx" /* 110-119 */
"xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx"
"DESH" "DESI" "DEZV" "DEZH" "DEZI" "SDBG" "PHDN" "PIDN" "SADV" "VLET" /* 110-119 */
"PHDV" "PIDV" "HCOU" "PVHD" "PVID" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" /* 124 */
"xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx"
"xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx"
"xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx"
@@ -62,7 +63,7 @@ char libInstr[256 * 4] ={"VERS" "JUMP" "DECL" "SRCL" "BEXC" "EXCE" "CATC" "THRW"
"xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" /* 200-249 */
"xxxx" "LIBR" "ENDL" "TEST" "ENDS" "ENDP"};
char libComp[9 * 3] = {"EQ " "NE " "LT " "GT " "LE " "GE " "AND" "OR " "NOT"};
char libComp[10 * 3] = {"EQ " "NE " "LT " "GT " "LE " "GE " "AND" "OR " "NOT" "FOR"};
#define IS_VERS "\x00"
#define IN_VERS 0
@@ -139,8 +140,8 @@ char libComp[9 * 3] = {"EQ " "NE " "LT " "GT " "LE " "GE " "AND" "OR " "NOT"};
#define IN_DCMP 34
#define IS_DSTO "\x23"
#define IN_DSTO 35
#define IS_VLET "\x24"
#define IN_VLET 36
#define IS_LETV "\x24"
#define IN_LETV 36
#define IS_DCAT "\x25"
#define IN_DCAT 37
#define IS_DTON "\x26"
@@ -307,6 +308,24 @@ char libComp[9 * 3] = {"EQ " "NE " "LT " "GT " "LE " "GE " "AND" "OR " "NOT"};
#define IN_DEZI 114
#define IS_SDBG "\x73"
#define IN_SDBG 115
#define IS_PHDN "\x74"
#define IN_PHDN 116
#define IS_PIDN "\x75"
#define IN_PIDN 117
#define IS_SADV "\x76"
#define IN_SADV 118
#define IS_VLET "\x77"
#define IN_VLET 119
#define IS_PHDV "\x78"
#define IN_PHDV 120
#define IS_PIDV "\x79"
#define IN_PIDV 121
#define IS_HCOU "\x7A"
#define IN_HCOU 122
#define IS_PVHD "\x7B"
#define IN_PVHD 123
#define IS_PVID "\x7C"
#define IN_PVID 124
#define IS_LIBR "\xFB"
#define IN_LIBR 251
+563 -133
View File
@@ -553,54 +553,99 @@ void ncmp(env * e, ent64 cmp)
if(e != NULL)
{
/* ok pour depiler */
if((cmp != CMP_NOT && e->numstr_stack.read < 2 * sizeof(numstr)) || (cmp == CMP_NOT && e->numstr_stack.read < sizeof(numstr)))
if((cmp != CMP_NOT && cmp != CMP_FOR && e->numstr_stack.read < 2 * sizeof(numstr)) ||
(cmp == CMP_NOT && e->numstr_stack.read < sizeof(numstr)) ||
(cmp == CMP_FOR && e->numstr_stack.read < 3 * sizeof(numstr)))
{
/* depassement capacite buffer */
e->exception = EX_BUFOVF;
return;
}
/* */
numstr * pns, * pns2, * pns3;
if(cmp == CMP_NOT)
{
/* not : operateur unaire */
e->numstr_stack.write = e->numstr_stack.read - sizeof(numstr);
pns = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.write);
stack_num(e, pns);
pns->num = (!pns->num) * NUM_FACTEUR;
pns->str = NULL;
}
else if(cmp == CMP_FOR)
{
/* comparaison specifique a la boucle foreach numerique (debut,fin,increment) */
e->numstr_stack.write = e->numstr_stack.read - 3 * sizeof(numstr);
e->numstr_stack.read -= 2 * sizeof(numstr);
pns = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.write);
pns2 = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.read);
pns3 = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.read + sizeof(numstr));
/* foreach x in pns, pns2, pns3 */
stack_num(e, pns); // cpt
stack_num(e, pns2); // fin
stack_num(e, pns3); // increment
if(e->exception == EX_NOTNUM)
return;
if(pns3->num == 0)
{
e->exception = EX_ZERO_FOR_INCR;
return;
}
if(pns3->num > 0)
pns->num = (pns->num <= pns2->num); // positif
else
pns->num = (pns->num >= pns2->num); // negatif
}
else
{
numstr * pns, * pns2;
if(cmp == CMP_NOT)
e->numstr_stack.write = e->numstr_stack.read - 2 * sizeof(numstr);
e->numstr_stack.read -= sizeof(numstr);
/* comparaison write vs read (ns vs ns2) ; resultat dans write */
pns = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.write);
pns2 = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.read);
if(pns->str == NULL && pns2->str == NULL)
{
/* not : operateur unaire */
e->numstr_stack.write = e->numstr_stack.read - sizeof(numstr);
pns = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.write);
stack_num(e, pns);
pns->num = (!pns->num) * NUM_FACTEUR;
pns->str = NULL;
/* 2 numbers : ok => maj de write */
switch(cmp)
{
case CMP_EQ:
pns->num = (pns->num == pns2->num);
break;
case CMP_NE:
pns->num = (pns->num != pns2->num);
break;
case CMP_LT:
pns->num = (pns->num < pns2->num);
break;
case CMP_GT:
pns->num = (pns->num > pns2->num);
break;
case CMP_LE:
pns->num = (pns->num <= pns2->num);
break;
case CMP_GE:
pns->num = (pns->num >= pns2->num);
break;
case CMP_AND:
pns->num = (pns->num && pns2->num);
break;
case CMP_OR:
pns->num = (pns->num || pns2->num);
break;
default:
pns->num = 0; /* faux par defaut */
break;
}
}
else
{
e->numstr_stack.write = e->numstr_stack.read - 2 * sizeof(numstr);
e->numstr_stack.read -= sizeof(numstr);
/* comparaison write vs read (ns vs ns2) ; resultat dans write*/
pns = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.write);
pns2 = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.read);
if(pns->str == NULL && pns2->str == NULL)
/* traiter les cas avec 1/2 string : convertir en num pour AND/OR et en string pour les comparaisons */
if(cmp == CMP_AND || cmp == CMP_OR)
{
/* 2 numbers : ok => maj de write */
stack_num(e, pns);
stack_num(e, pns2);
switch(cmp)
{
case CMP_EQ:
pns->num = (pns->num == pns2->num);
break;
case CMP_NE:
pns->num = (pns->num != pns2->num);
break;
case CMP_LT:
pns->num = (pns->num < pns2->num);
break;
case CMP_GT:
pns->num = (pns->num > pns2->num);
break;
case CMP_LE:
pns->num = (pns->num <= pns2->num);
break;
case CMP_GE:
pns->num = (pns->num >= pns2->num);
break;
case CMP_AND:
pns->num = (pns->num && pns2->num);
break;
@@ -614,57 +659,36 @@ void ncmp(env * e, ent64 cmp)
}
else
{
/* traiter les cas avec 1/2 string : convertir en num pour AND/OR et en string pour les comparaisons */
if(cmp == CMP_AND || cmp == CMP_OR)
stack_str(e, pns);
stack_str(e, pns2);
switch(cmp)
{
stack_num(e, pns);
stack_num(e, pns2);
switch(cmp)
{
case CMP_AND:
pns->num = (pns->num && pns2->num);
break;
case CMP_OR:
pns->num = (pns->num || pns2->num);
break;
default:
pns->num = 0; /* faux par defaut */
break;
}
case CMP_EQ:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) == 0);
break;
case CMP_NE:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) != 0);
break;
case CMP_LT:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) < 0);
break;
case CMP_GT:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) > 0);
break;
case CMP_LE:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) <= 0);
break;
case CMP_GE:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) >= 0);
break;
default:
pns->num = 0; /* faux par defaut */
break;
}
else
{
stack_str(e, pns);
stack_str(e, pns2);
switch(cmp)
{
case CMP_EQ:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) == 0);
break;
case CMP_NE:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) != 0);
break;
case CMP_LT:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) < 0);
break;
case CMP_GT:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) > 0);
break;
case CMP_LE:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) <= 0);
break;
case CMP_GE:
pns->num = (strcmp(pns->str->mPtr, pns2->str->mPtr) >= 0);
break;
default:
pns->num = 0; /* faux par defaut */
break;
}
}
pns->str = NULL;
}
pns->num *= NUM_FACTEUR;
pns->str = NULL;
}
pns->num *= NUM_FACTEUR;
}
}
}
@@ -1790,9 +1814,10 @@ void get_new_oid(env * e)
{
if((++e->oid_cpt) > OID_MAX)
e->oid_cpt = OID_MIN;
/* convertir en ascii et mettre dans e->oid1 et e->oid2 via union oidc */
/* convertir en ascii et mettre dans e->oidc avec un 0 devant */
memset(e->oidc, 0, 24);
strncpy(e->oidc, Int64ToSz(e, e->oid_cpt, FALSE, 16), 16);
*e->oidc = '0';
strcpy(e->oidc + 1, Int64ToSz(e, e->oid_cpt, FALSE, 0));
}
/************************************************************/
@@ -2112,7 +2137,7 @@ void instr_010(env * e)
e->ad_var_obj = NULL;
e->ad_var_class = NULL;
}
/* memoriser dans la hash locale : e->si e->si_except e->debut e->fin e->except_ex */
/* memoriser dans la hash locale : e->si e->si_except e->debut e->fin e->except_ex e->part */
//var_init(e, v, VAR_DYNAMIC, 0, 0, NULL);
v = &e->int_dynamic;
pointeur * pe = (pointeur *)v->ptr;
@@ -2122,7 +2147,8 @@ void instr_010(env * e)
*pe++ = e->fin;
*pe++ = e->si_except;
*pe++ = (pointeur)e->except_ex;
v->mLg = 6 * sizeof(pointeur); /* sinon la copie lors du HASHWRITE ne fonctionne pas */
*pe++ = (pointeur)((ent64)e->part);
v->mLg = 7 * sizeof(pointeur); /* sinon la copie lors du HASHWRITE ne fonctionne pas */
strncpy(e->nom, GUV_STACK, 6);
hashtable_do(e, HASH_WRITE, e->local, e->nom, &v);
/* aller au debut de la sub */
@@ -2131,6 +2157,9 @@ void instr_010(env * e)
e->si = e->debut;
e->si_except = e->fin;
e->except_ex = 0;
e->part = 0;
/* */
e->level++;
}
}
}
@@ -2823,8 +2852,9 @@ void instr_035(env * e)
/* */
void instr_036(env * e)
{
/* VLET */
// var lg nom recoit celle pointee par ad_var ; si lg = 0, va dans int_dynamic
/* LETV */
/* var lg nom recoit celle pointee par ad_var ; si lg = 0, va dans int_dynamic
! ne sert pas ! */
if(e->si > e->fin) { e->exception = EX_END; return; }
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin) { e->exception = EX_END; return; }
@@ -2948,19 +2978,19 @@ void instr_040(env * e)
e->exception = EX_NOADVAR;
return;
}
if(e->ad_var_hash == NULL)
{
/* suppression variable "simple" (que PVAR : locale ou globale) */
if(e->global)
hashtable_do(e, HASH_DELETE, &e->g, e->nom, &e->ad_var);
else
hashtable_do(e, HASH_DELETE, e->local, e->nom, &e->ad_var);
}
else
{
/* suppression d'une var appartenant a la hash */
hashtable_do(e, HASH_DELETE, e->ad_var_hash, e->nom, &e->ad_var);
}
//if(e->ad_var_hash == NULL)
//{
/* suppression variable "simple" (que PVAR : locale ou globale) => mis en VARNULL, idem declare */
var * v = &e->v;
e->v.type = VAR_NULL;
var_let(e, e->ad_var, v, TRUE, FALSE);
//}
//else
//{
/* KO A REVOIR !!!! */
/* suppression d'une var appartenant a la hash KO a remplacer par PVHD/PVID*/
// hashtable_do(e, HASH_DELETE, e->ad_var_hash, e->nom, &e->ad_var);
//}
}
/* */
void instr_041(env * e)
@@ -3084,7 +3114,7 @@ void instr_043(env * e)
e->nom64[2] = 0;
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
var * v = NULL, * class = NULL, * obj = NULL, * membre = NULL, * pvar = NULL;
var * v = NULL, * class = NULL, * membre = NULL, * pvar = NULL;
hashtable_do(e, HASH_READ, &e->g, e->nom, &v);
if(v == NULL)
{
@@ -3096,6 +3126,11 @@ void instr_043(env * e)
e->exception = EX_NAVAR; // la classe n'est pas une hash table
return;
}
if(e->ad_var == NULL)
{
e->exception = EX_NAVAR; // pas de var pour recevoir l'objet
return;
}
// lecture _class depuis v
hashtable_do(e, HASH_READ, v, copy_nom(e, GUV_CLASS), &class);
if(class == NULL)
@@ -3105,32 +3140,25 @@ void instr_043(env * e)
}
get_new_oid(e); // nouveau numero dans e
dynLet(e, &e->int_dynamic, class->mPtr, class->mLg);
dynInsSz(e, &e->int_dynamic, 1, DYN_NONE, e->oidc, 16, cFM, DYN_NONE);
dynInsSz(e, &e->int_dynamic, 1, DYN_NONE, e->oidc, DYN_LGNONE, cFM, DYN_NONE);
//
// creation hash table dans e->g, de nom "oid" et creation du pointeur dans ad_var ; maj de l'object a partir de sa classe "v"
// maj de l'object, mis dans ad_var, a partir de sa classe "v"
hashtable_clear(e, &e->int_hash);
e->int_hash.type = VAR_OBJECT;
pvar = &e->int_hash;
hashtable_do(e, HASH_WRITE, &e->g, e->oidc, &pvar);
//var_free(e, pvar, FALSE);
//hashtable_do(e, HASH_READ, &e->g, e->nom, &pvar);
//obj = ((entry *)(e->g.ptr))->pvar;
obj = hashtable_lastitemwritten(&e->g);
var_let(e, e->ad_var, pvar, TRUE, TRUE);
// ecriture de _class, puis des membres de la classe : NUMBER DYNAMIC HASHTABLE OBJECT, ne sont pas copies les PARAM (impossible) SUBROUTINE BUFFER (interne) NULL
// (affectation d'un param a un element de HASH/OBJET : copie de la valeur)
pvar = &e->int_dynamic;
hashtable_do(e, HASH_WRITE, obj, e->nom, &pvar); /* ecriture _class avec oid en debut */
hashtable_do(e, HASH_WRITE, e->ad_var, e->nom, &pvar); /* ecriture _class avec oid en debut */
/* */
hashtable_select(e, v);
while(hashtable_next(e, v, e->nom, &membre))
{
// ne pas prendre les membres commencant par "_..."
if(e->nom[0] != '_' && (membre->type == VAR_NUMBER || membre->type == VAR_DYNAMIC || membre->type == VAR_HASHTABLE || membre->type == VAR_OBJECT))
hashtable_do(e, HASH_WRITE, obj, e->nom, &membre);
hashtable_do(e, HASH_WRITE, e->ad_var, e->nom, &membre);
}
// ad_var est un "pointeur" sur l'objet
var_init(e, &e->int_param, VAR_PARAM, 0, 0, (pointeur)obj);
var_let(e, e->ad_var, &e->int_param, TRUE, TRUE);
}
/* */
void instr_044(env * e)
@@ -3237,8 +3265,8 @@ void instr_056(env * e)
/*
@varnull,@varnumber,@varsubroutine,@varparam,@vardynamic,@varhashtable,@varobject,@varbuffer,@false,@true
1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,10 ,11
@forcount,@kill,@fork,@prog,@exceptstr,@exceptline,@except,@part,@line,@os,@vers,@verw,@demon,@endian,@file,@arg,@pi
12 ,13 ,14 ,15 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30
@level,@kill,@oid,@prog,@exceptstr,@exceptline,@except,@part,@line,@os,@vers,@verw,@demon,@endian,@file,@arg,@pi
12 ,13 ,14 ,15 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30
@fm,@vm,@svm,@tm,@currfm,@currvm,@number,@dynamic,@empty,@trim,@left,@right,@center,@surround
31 ,32 ,33 ,34 ,35 ,36 ,40 ,41 ,42 ,50 ,51 ,52 ,53 ,54
*/
@@ -3277,7 +3305,7 @@ void instr_056(env * e)
break;
/* */
case 12:
npushc(e, NUM_ZERO); /* for count TODO */
npushc(e, e->level * NUM_FACTEUR); /* level */
break;
case 13:
if(ctx_env_kill == 0)
@@ -3286,7 +3314,7 @@ void instr_056(env * e)
npushc(e, NUM_UN); /* true */
break;
case 14:
npushc(e, NUM_ZERO); /* fork TODO */
npushc(e, e->oid_cpt * NUM_FACTEUR); /* oid */
break;
case 15:
{
@@ -3312,7 +3340,7 @@ void instr_056(env * e)
npushc(e, e->except_ex * NUM_FACTEUR);
break;
case 21:
npushc(e, e->part * NUM_FACTEUR);
npushc(e, e->part * NUM_FACTEUR); // mis a jour dans e->local a chaque appel
break;
// case 22: // cf. case 28:
case 23:
@@ -3570,7 +3598,8 @@ void instr_059(env * e)
*pe++ = e->fin;
*pe++ = e->si_except;
*pe++ = (pointeur)e->except_ex;
v->mLg = 6 * sizeof(pointeur); /* sinon la copie lors du HASHWRITE ne fonctionne pas */
*pe++ = (pointeur)((ent64)e->part);
v->mLg = 7 * sizeof(pointeur); /* sinon la copie lors du HASHWRITE ne fonctionne pas */
copy_nom(e, GUV_STACK);
hashtable_do(e, HASH_WRITE, e->local, e->nom, &v);
/* aller au debut de la library */
@@ -3579,6 +3608,9 @@ void instr_059(env * e)
e->si = e->debut;
e->si_except = e->fin;
e->except_ex = 0;
e->part = 0;
/* */
e->level++;
}
/* */
void instr_060(env * e)
@@ -5249,6 +5281,375 @@ void instr_115(env * e)
}
}
/* */
void instr_116(env * e)
{
/* PHDN */
/* maj <ad_var_hash>.<nom> pour mise a jour par un objet (NLET a suivre), mis dans <ad_var>
*/
if(e->si > e->fin) { e->exception = EX_END; return; }
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin) { e->exception = EX_END; return; }
//
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
if(lg < 1 || lg > 24)
{
e->exception = EX_LGNOM;
return;
}
else
{
/* lire la var */
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
if(e->ad_var_hash == NULL)
{
e->exception = EX_NOADVAR;
return;
}
}
/* */
var * v = NULL;
hashtable_do(e, HASH_READ, e->ad_var_hash, e->nom, &v);
if(v == NULL)
{
// creer la var <nom>
v = &e->v;
var_init(e, v, VAR_NULL, 0, 0, NULL);
hashtable_do(e, HASH_WRITE, e->ad_var_hash, e->nom, &v);
e->ad_var = hashtable_lastitemwritten(e->ad_var_hash);
}
else
{
e->ad_var = v;
}
}
/* */
void instr_117(env * e)
{
/* PIDN */
/* maj <ad_var_hash>!<nom> pour mise a jour par un objet (NLET a suivre), mis dans <ad_var>
*/
if(e->si > e->fin) { e->exception = EX_END; return; }
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin) { e->exception = EX_END; return; }
//
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
if(lg < 1 || lg > 24)
{
e->exception = EX_LGNOM;
return;
}
else
{
/* lire la var */
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
if(e->ad_var_hash == NULL)
{
e->exception = EX_NOADVAR;
return;
}
}
/* */
var * v;
var_search(e, &v);
if(e->exception != OK)
return;
if(v->type == VAR_PARAM)
v = (var *)v->ptr; /* travailler avec la var pointee ! */
if(v->type != VAR_DYNAMIC)
{
e->exception = EX_NAVAR;
return;
}
if(v->lg < 1 || v->lg > 24)
{
e->exception = EX_LGNOM;
return;
}
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
strncpy(e->nom, v->mPtr, v->lg);
/* */
v = NULL;
hashtable_do(e, HASH_READ, e->ad_var_hash, e->nom, &v);
if(v == NULL)
{
// creer la var <nom>
v = &e->v;
var_init(e, v, VAR_NULL, 0, 0, NULL);
hashtable_do(e, HASH_WRITE, e->ad_var_hash, e->nom, &v);
e->ad_var = hashtable_lastitemwritten(e->ad_var_hash);
}
else
{
e->ad_var = v;
}
}
/* */
void instr_118(env * e)
{
/* SADV */
e->ad_var_sav = e->ad_var;
}
/* */
void instr_119(env * e)
{
/* VLET */
/* affectation simple <ad_var> = <ad_var_sav>, tous types */
if(e->ad_var == NULL || e->ad_var_sav == NULL)
{
e->exception = EX_NAVAR;
return;
}
var_let(e, e->ad_var, e->ad_var_sav, TRUE, TRUE);
}
/* */
void instr_120(env * e)
{
/* PHDV */
/* affectation simple <ad_var_hash>.<nom> = <ad_var_sav> */
if(e->si > e->fin) { e->exception = EX_END; return; }
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin) { e->exception = EX_END; return; }
//
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
if(lg < 1 || lg > 24)
{
e->exception = EX_LGNOM;
return;
}
else
{
/* lire la var */
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
if(e->ad_var_hash == NULL)
{
e->exception = EX_NOADVAR;
return;
}
}
/* */
var * v = NULL;
hashtable_do(e, HASH_READ, e->ad_var_hash, e->nom, &v);
if(v == NULL)
{
// creer la var <nom>
v = &e->v;
var_init(e, v, VAR_NULL, 0, 0, NULL);
hashtable_do(e, HASH_WRITE, e->ad_var_hash, e->nom, &v);
v = hashtable_lastitemwritten(e->ad_var_hash);
}
var_let(e, v, e->ad_var_sav, TRUE, TRUE);
}
/* */
void instr_121(env * e)
{
/* PIDV */
/* affectation simple <ad_var_hash>!<nom> = <ad_var_sav> */
if(e->si > e->fin) { e->exception = EX_END; return; }
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin) { e->exception = EX_END; return; }
//
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
if(lg < 1 || lg > 24)
{
e->exception = EX_LGNOM;
return;
}
else
{
/* lire la var */
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
if(e->ad_var_hash == NULL)
{
e->exception = EX_NOADVAR;
return;
}
}
/* */
var * v;
var_search(e, &v);
if(e->exception != OK)
return;
if(v->type == VAR_PARAM)
v = (var *)v->ptr; /* travailler avec la var pointee ! */
if(v->type != VAR_DYNAMIC)
{
e->exception = EX_NAVAR;
return;
}
if(v->lg < 1 || v->lg > 24)
{
e->exception = EX_LGNOM;
return;
}
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
strncpy(e->nom, v->mPtr, v->lg);
/* */
v = NULL;
hashtable_do(e, HASH_READ, e->ad_var_hash, e->nom, &v);
if(v == NULL)
{
// creer la var <nom>
v = &e->v;
var_init(e, v, VAR_NULL, 0, 0, NULL);
hashtable_do(e, HASH_WRITE, e->ad_var_hash, e->nom, &v);
v = hashtable_lastitemwritten(e->ad_var_hash);
}
var_let(e, v, e->ad_var_sav, TRUE, TRUE);
}
/* */
void instr_122(env * e)
{
/* HCOU */
/* compter le nb d'elem de la hash/objet en cours <ad_var> (equiv. a PVAH/PVAI) */
/* */
if(e->mode_typeof && e->typeof_ == -1) return; /* derniere var inconnue : mode typeof, continuer en attendant le PSHT */
/* */
if(e->ad_var == NULL)
{
e->exception = EX_NOADVAR;
if(e->mode_typeof) e->mode_typeof = FALSE; /* annuler le mode "typeof" si exception autre que var inconnue */
return;
}
if(e->ad_var->type == VAR_PARAM)
e->ad_var = (var *)e->ad_var->ptr; /* travailler avec la var pointee ! */
if(e->ad_var->type != VAR_HASHTABLE && e->ad_var->type != VAR_OBJECT)
{
e->exception = EX_NAVAR;
if(e->mode_typeof)
{
e->typeof_ = -1;
e->exception = OK;
}
return;
}
e->int_number.num = hashtable_count(e, e->ad_var) * NUM_FACTEUR;
e->ad_var = &e->int_number;
e->ad_var_hash = NULL;
}
/* */
void instr_123(env * e)
{
/* PVHD */
/* idem DELE mais sur element de hash/objet (vraie suppression) */
if(e->si > e->fin)
{
e->exception = EX_END;
return;
}
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin)
{
e->exception = EX_END;
return;
}
//
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
if(lg < 1 || lg > 24)
{
e->exception = EX_LGNOM;
return;
}
else
{
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
/* */
if(e->ad_var == NULL)
{
e->exception = EX_NOADVAR;
return;
}
if(e->ad_var->type == VAR_PARAM)
e->ad_var = (var *)e->ad_var->ptr; /* travailler avec la var pointee ! */
if(e->ad_var->type != VAR_HASHTABLE && e->ad_var->type != VAR_OBJECT)
{
e->exception = EX_NAVAR;
return;
}
/* */
var * v = NULL;
hashtable_do(e, HASH_DELETE, e->ad_var, e->nom, &v);
return;
}
}
/* */
void instr_124(env * e)
{
/* PVID */
/* idem DELE mais sur element de hash/objet (vraie suppression), avec indirection */
if(e->si > e->fin)
{
e->exception = EX_END;
return;
}
int lg = lire8(e->si++);
if(e->si + lg - 1 > e->fin)
{
e->exception = EX_END;
return;
}
//
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
if(lg < 1 || lg > 24)
{
e->exception = EX_LGNOM;
return;
}
else
{
var * v;
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
/* */
var_search(e, &v);
if(e->exception != OK)
{
return; /* pas trouve */
}
if(v->type == VAR_PARAM)
v = (var *)v->ptr; /* travailler avec la var pointee ! */
if(v->type != VAR_DYNAMIC)
{
e->exception = EX_NAVAR;
return;
}
if(v->lg < 1 || v->lg > 24)
{
e->exception = EX_LGNOM;
}
else
{
e->nom64[0] = 0;
e->nom64[1] = 0;
e->nom64[2] = 0;
strncpy(e->nom, v->mPtr, v->lg);
e->ad_var_hash = NULL;
v = NULL;
hashtable_do(e, HASH_DELETE, e->ad_var, e->nom, &v);
}
}
}
/* */
/* */
void instr_251(env * e)
{
@@ -5280,20 +5681,22 @@ void instr_252(env * e)
return;
}
var * local_prec = e->local;
/* maj e : <1> = hash local prec <2> = si <3> = debut <4> = fin <5> = si_except <6> = except_ex */
/* maj e : <1> = hash local prec <2> = si <3> = debut <4> = fin <5> = si_except <6> = except_ex <7> = part */
pointeur * pe = (pointeur *)v->ptr;
e->local = (var *)(*pe++); /* retour au niveau global par defaut sauf si var trouvee */
e->si = *pe++;
e->debut = *pe++;
e->fin = *pe++;
e->si_except = *pe++;
ent64 ex_ex = (ent64)*pe++;
e->part = (octet)((ent64)*pe++);
/* selon si appel/retour dans bloc except ou non, pas la meme gestion du retour de l'except */
/* A verifier (faire les cas au papier) */
/* A REVOIR */
if(e->except_ex == OK)
e->except_ex = *(ent64 *)pe; // garder l'erreur en cours si exception en cours
else if(*(ent64 *)pe == OK)
e->exception = *(ent64 *)pe; // exception dans la call appelee : remonte a l'appelante
e->except_ex = ex_ex; // garder l'erreur en cours si exception en cours
else if(ex_ex == OK)
e->exception = ex_ex; // exception dans la call appelee : remonte a l'appelante
/* */
if(e->local != NULL)
{
@@ -5325,6 +5728,8 @@ void instr_252(env * e)
}
e->exception = e->except_ex;
e->except_ex = ex; /* restauration */
/* */
e->level--;
}
/* */
void instr_253(env * e)
@@ -5356,21 +5761,23 @@ void instr_254(env * e)
else
{
var * local_prec = e->local;
/* maj e : <1> = hash local prec <2> = si <3> = debut <4> = fin <5> = si_except <6> = except_ex */
/* maj e : <1> = hash local prec <2> = si <3> = debut <4> = fin <5> = si_except <6> = except_ex <7> = part */
pointeur * pe = (pointeur *)v->ptr;
e->local = (var *)(*pe++); /* retour au niveau global par defaut sauf si var trouvee */
e->si = *pe++;
e->debut = *pe++;
e->fin = *pe++;
e->si_except = *pe++;
ent64 ex_ex = (ent64)*pe++;
e->part = (octet)((ent64)*pe++);
/* selon si appel/retour dans bloc except ou non, pas la meme gestion du retour de l'except */
/* A verifier (faire les cas au papier) */
if(e->except_ex == OK)
e->exception = *(ent64 *)pe; // garder l'erreur en cours si pas d'exception dans l'appelante
e->exception = ex_ex; // garder l'erreur en cours si pas d'exception dans l'appelante
else
e->exception = e->except_ex;
//else if(*(ent64 *)pe == OK)
// e->exception = *(ent64 *)pe; // exception dans la call appelee : remonte a l'appelante
//else if(ex_ex == OK)
// e->exception = ex_ex; // exception dans la call appelee : remonte a l'appelante
/* */
if(e->local != NULL)
{
@@ -5396,6 +5803,8 @@ void instr_254(env * e)
SetBinIndex(e);
e->exception = e->except_ex;
e->except_ex = ex; /* restauration */
/* */
e->level--;
}
}
}
@@ -5492,8 +5901,8 @@ void (*instr[256])(env * e) = {instr_000,instr_001,instr_002,instr_003,instr_004
instr_080,instr_081,instr_082,instr_083,instr_084,instr_085,instr_086,instr_087,instr_088,instr_089,
instr_090,instr_091,instr_092,instr_093,instr_094,instr_095,instr_096,instr_097,instr_098,instr_099,
instr_100,instr_101,instr_102,instr_103,instr_104,instr_105,instr_106,instr_107,instr_108,instr_109,
instr_110,instr_111,instr_112,instr_113,instr_114,instr_115,instr_255,instr_255,instr_255,instr_255, /* 114 */
instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,
instr_110,instr_111,instr_112,instr_113,instr_114,instr_115,instr_116,instr_117,instr_118,instr_119, /* 119 */
instr_120,instr_121,instr_122,instr_123,instr_124,instr_255,instr_255,instr_255,instr_255,instr_255,
instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,
instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,
instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,instr_255,
@@ -5547,7 +5956,7 @@ void (*instr[256])(env * e) = {instr_000,instr_001,instr_002,instr_003,instr_004
; 033 21 DEXV 1 ad_var<pile1, pile2> = pile3 (suite PVAR)
; 034 22 DCMP op lg nom 3+lg compare la chaine ad_var avec nom (op: EQ NE LT GT LE GE, 1 a 6) empilage resultat 1 si cond. vraie, 0 si fausse
; 035 23 DSTO lg nom 2+lg var<pile1, pile2> = nom, var lu de ad_var ; si lg = 0, lu de int_dynamic ; pile2 = 0, que niveau attribut
; 036 24 VLET lg nom 2+lg affectation : <nom> = ad_var (=> let var(<nom>) = var(ad_var)) ; si lg = 0, var dans int_dynamic
; 036 24 LETV lg nom 2+lg affectation : <nom> = ad_var (=> let var(<nom>) = var(ad_var)) ; si lg = 0, var dans int_dynamic
; 037 25 DCAT lg nom 2+lg concatene a nom la var ad_var (nom = concat(nom, advar)) ; si lg = 0, concatenation dans int_dynamic
; 038 26 DTON 1 convertit la variable ad_var en numerique et l'empile dans la num_stack
; 039 27 NTOD 1 depile la num_stack et convertit le nombre en dynamic dans ad_var
@@ -5629,6 +6038,15 @@ void (*instr[256])(env * e) = {instr_000,instr_001,instr_002,instr_003,instr_004
; 113 71 DEZH lg nom 2+lg ad_var_hash.nom<pile1, pile2>[pile3, pile4] = pile5 (suite PHDE/PIDE)
; 114 72 DEZI lg nom 2+lg ad_var_hash!nom<pile1, pile2>[pile3, pile4] = pile5 (suite PHDE/PIDE)
; 115 73 SDBG d3 chaine 4+d3 liste des fichiers sources + num lignes (pour debugger)
; 116 74 PHDN lg nom 2+lg enchainement PVAH/PVAI, en dernier cree/remplace dans la hash <ad_var_hash> la var <nom> qui sera utilisee ensuite par NLET (mis dans <ad_var>)
; 117 75 PIDN lg nom 2+lg enchainement PVAH/PVAI, en dernier cree/remplace dans la hash <ad_var_hash> (avec indirection) la var <nom> qui sera utilisee ensuite par NLET (mis dans <ad_var>)
; 118 76 SADV 1 sauvegarde ad_var dans ad_var_sav (suite enchainement PVAR/PVAH/PVAI)
; 119 77 VLET 1 affectation de variable sans expression, traite tous les types. Correspond a : ad_var = ad_var_sav (copie)
; 120 78 PHDV lg nom 2+lg idem VLET enchainement PVAH/PVAI, en dernier cree/remplace dans la hash : <ad_var_hash>.<nom> = <ad_var_sav>
; 121 79 PIDV lg nom 2+lg idem VLETenchainement PVAH/PVAI, en dernier cree/remplace dans la hash avec indirection : <ad_var_hash>.<nom> = <ad_var_sav>
; 122 7A HCOU 1 idem PVAH/PVAI mais renvoi le nombre d'element de la hash/objet en cours (dans ad_var = e->int_number)
; 123 7B PVHD lg nom 2+lg enchainement PVAH/PVAI, en dernier supprime dans la hash <ad_var_hash> la var <nom> (idem DELE mais avec suppression)
; 124 7C PVID lg nom 2+lg enchainement PVAH/PVAI, en dernier supprime dans la hash <ad_var_hash> la var <nom> (avec indirection) (idem DELE mais avec suppression)
;
; 251 FB LIBR 1 indique que le binaire est une library, non executable directement, premiere instruction du binaire, sinon except (dans les 2 cas)
; 252 FC ENDL 1 fin de library
@@ -5941,6 +6359,7 @@ int CreateContext(env ** ctx, int useSignal, int argc, char *argv[])
/* */
e->precision = NUM_CINQ;
e->oid_cpt = OID_MIN;
e->level = 1;
/* */
e->nom64[0] = 0;
e->nom64[1] = 0;
@@ -5979,6 +6398,7 @@ int CreateContext(env ** ctx, int useSignal, int argc, char *argv[])
/* alloc structures globales */
var_init(e, &e->g, VAR_HASHTABLE, 13, 10, NULL);
var_init(e, &e->int_dynamic, VAR_DYNAMIC, 0, 0, NULL);
var_init(e, &e->varptrtbl, VAR_DYNAMIC, 0, 0, NULL);
var_init(e, &e->tmp_dynamic, VAR_DYNAMIC, 0, 0, NULL);
var_init(e, &e->int_number, VAR_NUMBER, 0, 0, NULL);
var_init(e, &e->num_stack, VAR_BUFFER, 0, 0, NULL);
@@ -6000,9 +6420,11 @@ int CreateContext(env ** ctx, int useSignal, int argc, char *argv[])
e->numstr_stack.type == VAR_NULL || e->int_hash.type == VAR_NULL || e->tmp_dynamic.type == VAR_NULL ||
e->num_stack.type == VAR_NULL || e->call_stack.type == VAR_NULL || e->debugbrkpoint.type == VAR_NULL ||
e->debugreglelex.type == VAR_NULL || e->debugcmd.type == VAR_NULL || e->debugvalex.type == VAR_NULL ||
e->printf.type == VAR_NULL)
e->printf.type == VAR_NULL || e->varptrtbl.type == VAR_NULL)
return (e->except_ex = EX_MEM);
//
*((ent64 *)e->varptrtbl.ptr) = 0; // nb = 0
//
/* dans hash globale, creer "_arg" dynamic contenant les arguments en FM (ceux du prog w uniquement !) */
/* puis creer les autres => @ARG = _arg, @BIN = _bin, @ENV = _env */
/* d'autres sont en memoire dans <e> : @PART = e->part, @LINE = e->ligscr, @EXCEPT = e->except_ex (dans bloc EXCEPT uniquement) */
@@ -6121,6 +6543,7 @@ void FreeContext(env * ctx)
var_free(ctx, &ctx->int_hash, TRUE);
var_free(ctx, &ctx->int_dynamic, TRUE);
var_free(ctx, &ctx->tmp_dynamic, TRUE);
var_free(ctx, &ctx->varptrtbl, TRUE);
var_free(ctx, &ctx->int_number, TRUE);
var_free(ctx, &ctx->num_stack, TRUE);
var_free(ctx, &ctx->call_stack, TRUE);
@@ -6185,6 +6608,10 @@ int ReadProg(env * ctx, char * fichier, pointeur * prg, int * lg)
fseek(fic, 0, SEEK_END);
*lg = ftell(fic);
fseek(fic, 0, SEEK_SET);
/* TODO : si bit7 = 1 du premier octet (ou 0xFF), le binaire est compresse lzw
gerer avec un type 4/5 du lzw pour ne pas ecrire en sortie le compresse
et modif ici pour lire 1 octet, puis affecter simplement le resultat
*/
if((*prg = memalloc(ctx, *lg)) == NULL)
{
fclose(fic);
@@ -6396,8 +6823,11 @@ int main(int argc, char *argv[])
/* TODO : avant de liberer, supprimer toutes les fonctions des modules dans les vars : ?? */
/* supprimer tous les progs de _binaddr */
Unload(ctx_env);
/* TODO : prevoir un ExecLibr (utilisation de w comme langage de plugins type lua dans Garry's Mod)
non, prevoir un prog de base + instruction WAIT qui rend la main et attend un Execlibr = CALL */
/* TODO : utilisation de w comme langage de plugins : prevoir un prog de base + instruction HOLD
qui rend la main et attend un Execlibr = CALL, exception apres HOLD est traitee en specifique
pour sortir propre. Prog, pas d'I/O console (EOFF = echo off ?) ou io console redirigee dans var
A l'init, choix du nom de la CALL externe, 1 seul param, hashtable (!?). Definir le pseudo PROG...
*/
cr = ctx_env->except_ex;
}
/* */
+9 -4
View File
@@ -252,7 +252,8 @@ enum {
EX_REMOVE_KO = 37, /* erreur de parametre ou memoire dans remove() */
EX_CHILD_FORK = 38, /* erreur de fork sur nouveau process */
EX_CHILD_EXEC = 39, /* erreur execution nouveau process */
EXNB = 39 /* MEMO !!!! */
EX_ZERO_FOR_INCR = 40, /* erreur increment a zero dans une boucle foreach numerique */
EXNB = 40 /* MEMO !!!! */
};
typedef struct {
@@ -268,7 +269,7 @@ typedef struct {
octet tmp_cpt; /* nb de var tmp Dynamic, ne pas sauvegarder car dans la hash globale */
octet tmp_free; /* numero de var tmp Dynamic dispo ; si > tmp_cpt, a creer dans la hash globale */
//
//var tblptr; /* contient les pointeurs sur les vars de type SUB/PARAM/OBJET, pour les rendre VAR_NULL si le ptr est libere */
var varptrtbl; /* contient les pointeurs sur les vars de type SUB/PARAM/OBJET, pour les rendre VAR_NULL si le ptr est libere */
//
var tmp_dynamic; /* comme son nom l'indique... doit etre utilise localement et sur une portee tres courte ; pas d'utilisation inter instruction */
var int_number; /* variable number interne servant aux conversions */
@@ -280,6 +281,7 @@ typedef struct {
var * ad_var_hash; /* dans les enchainements PVAR/PVAH-PVAI, donne l'adresse de la hash possédant la "derniere" variable */
var * ad_var_obj; /* dans une affectation let ou do sub, donne l'objet concerne si objet, pour lire les membres (hors sub) -> pour creer this */
var * ad_var_class; /* donne l'objet de la classe mere de l'objet courant, objet Base si objet de classe Base */
var * ad_var_sav; /* pour memoriser ad_var sur une affectation simple let a.b = c.d, instruction SADV / VLET / PHDV / PIDV */
/* */
ent64 exception; /* exception courante (di) ; 0 ok, si # 0, levee d'une exception et saut au code qui le traite, 0 a chaque debut de fonction */
ent64 except_ex; /* dans bloc except, code erreur ayant genere l'exception ; a mettre a 0 a chaque debut de methode sauf si appel depuis le bloc except ! */
@@ -314,6 +316,8 @@ typedef struct {
int endianess; /* pour detection automatique de l'endianess de la plateforme d'execution */
int use_signal; /* 1 si w gere et traite les signaux, 0 sinon (mode plugin : signaux geres par programme maitre) */
/* */
int level; /* niveau d'imvrication des appels do/call ; prog principal = level 1 */
/* */
int bin_indice; /* position dans _bin du binaire en cours d'exec ( _bin<2, bin_indice> ) */
/* */
pointeur debut,fin; /* position en memoire de la fonction, fin est toujours l'instruction END ou ENDS */
@@ -354,7 +358,8 @@ enum {
CMP_GE = 6,
CMP_AND = 7,
CMP_OR = 8,
CMP_NOT = 9
CMP_NOT = 9,
CMP_FOR = 10
};
#define GUV_CLASS "_class"
@@ -370,7 +375,7 @@ enum {
#define GUV_BIN "_bin"
#define GUV_WDIR "_wdir"
#define VARSYS "@varnull,@varnumber,@varsubroutine,@varparam,@vardynamic,@varhashtable,@varobject,@varbuffer,@false,@true,@forcount,@kill,@fork,@prog,@exceptstr,@exceptline,@except,@part,@line,@os,@vers,@verw,@demon,@endian,@file,@arg,@pi,@fm,@vm,@svm,@tm,@currfm,@currvm,@number,@dynamic,@empty,@trim,@left,@right,@center,@surround;1,2,3,4,5,6,7,8,10,11,12,13,14,15,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,40,41,42,50,51,52,53,54"
#define VARSYS "@varnull,@varnumber,@varsubroutine,@varparam,@vardynamic,@varhashtable,@varobject,@varbuffer,@false,@true,@level,@kill,@oid,@prog,@exceptstr,@exceptline,@except,@part,@line,@os,@vers,@verw,@demon,@endian,@file,@arg,@pi,@fm,@vm,@svm,@tm,@currfm,@currvm,@number,@dynamic,@empty,@trim,@left,@right,@center,@surround;1,2,3,4,5,6,7,8,10,11,12,13,14,15,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,40,41,42,50,51,52,53,54"
#include "global.h"
+4 -2
View File
@@ -1,6 +1,8 @@
//static char file_debuglex[] = "";
static char file_debuglex[] = "blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,reste,8\n1,-1,20:09:0A:0D\n1,2,61-7A:41-5A\n1,1,3F\n1,9,30-39\n1,1,2B\n1,1,2D\n1,1,3A;1,1,61-7A:41-5A:5F;0,23,61-7A:41-5A:30-39\n1,1,00-FF";
static char file_debuglex[] = "blanc,1,commande,2,aide,3,nombre,4,ajouter,5,supprimer,6,ident,7,identnext,8,reste,9\n"
"1,-1,20:09:0A:0D\n1,2,61-7A:41-5A\n1,1,3F\n1,9,30-39\n1,1,2B\n1,1,2D\n1,1,3A;1,1,61-7A:41-5A:5F;0,23,61-7A:41-5A:30-39\n1,1,2E;1,1,61-7A:41-5A;0,23,61-7A:41-5A:30-39\n1,1,00-FF";
//static char file_wlex[] = "";
static char file_wlex[] = "blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,include,10,sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,20,return,21,returnon,22,loop,23,endloop,24,foreach,25,in,26,like,27,endfor,28,break,29,breakon,30,continue,31,continueon,32,nop,33,part,34,echonl,35,echo,36,input,37,declare,38,let,39,delet,40,new,41,class,42,this,43,parent,44,free,45,precision,46,setsep,47,int,48,frac,49,abs,50,neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,change,60,format,61,insert,62,remove,63,tonum,64,tostring,65,equal,66,diff,67,gt,68,lt,69,gte,70,lte,71,and,72,or,73,not,74,beginpar,75,endpar,76,beginh,77,endh,78,begins,79,ends,80,indirect,81,typeof,82,stringdq,83,stringq,84,ident,85,varsys,86,numberdec,87,numberint,88,minus,89,plus,90,multiply,91,divide,92,divident,93,modulo,94,concat,95,listesep,96,identsep,97,modsep,98,other,99\n1,-1,20:09\n1,1,3B;0,-1,00-FF\n1,1,62;1,1,65;1,1,67;1,1,69;1,1,6E\n1,1,62;1,1,61;1,1,63;1,1,6B;1,1,67;1,1,72;1,1,6F;1,1,75;1,1,6E;1,1,64\n1,1,6C;1,1,69;1,1,62;1,1,72;1,1,61;1,1,72;1,1,79\n1,1,65;1,1,6E;1,1,64\n1,1,65;1,1,78;1,1,63;1,1,65;1,1,70;1,1,74\n1,1,74;1,1,68;1,1,72;1,1,6F;1,1,77\n1,1,63;1,1,61;1,1,74;1,1,63;1,1,68\n1,1,69;1,1,6E;1,1,63;1,1,6C;1,1,75;1,1,64;1,1,65\n1,1,73;1,1,75;1,1,62\n1,1,65;1,1,6E;1,1,64;1,1,73;1,1,75;1,1,62\n1,1,69;1,1,66\n1,1,74;1,1,68;1,1,65;1,1,6E\n1,1,65;1,1,6C;1,1,73;1,1,65\n1,1,65;1,1,6C;1,1,73;1,1,65;1,1,69;1,1,66\n1,1,65;1,1,6E;1,1,64;1,1,69;1,1,66\n1,1,64;1,1,6F\n1,1,63;1,1,61;1,1,6C;1,1,6C\n1,1,69;1,1,6E;1,1,76;1,1,6F;1,1,6B;1,1,65\n1,1,72;1,1,65;1,1,74;1,1,75;1,1,72;1,1,6E\n1,1,72;1,1,65;1,1,74;1,1,75;1,1,72;1,1,6E;1,1,6F;1,1,6E\n1,1,6C;1,1,6F;1,1,6F;1,1,70\n1,1,65;1,1,6E;1,1,64;1,1,6C;1,1,6F;1,1,6F;1,1,70\n1,1,66;1,1,6F;1,1,72;1,1,65;1,1,61;1,1,63;1,1,68\n1,1,69;1,1,6E\n1,1,6C;1,1,69;1,1,6B;1,1,65\n1,1,65;1,1,6E;1,1,64;1,1,66;1,1,6F;1,1,72\n1,1,62;1,1,72;1,1,65;1,1,61;1,1,6B\n1,1,62;1,1,72;1,1,65;1,1,61;1,1,6B;1,1,6F;1,1,6E\n1,1,63;1,1,6F;1,1,6E;1,1,74;1,1,69;1,1,6E;1,1,75;1,1,65\n1,1,63;1,1,6F;1,1,6E;1,1,74;1,1,69;1,1,6E;1,1,75;1,1,65;1,1,6F;1,1,6E\n1,1,6E;1,1,6F;1,1,70\n1,1,70;1,1,61;1,1,72;1,1,74\n1,1,65;1,1,63;1,1,68;1,1,6F;1,1,6E;1,1,6C\n1,1,65;1,1,63;1,1,68;1,1,6F\n1,1,69;1,1,6E;1,1,70;1,1,75;1,1,74\n1,1,64;1,1,65;1,1,63;1,1,6C;1,1,61;1,1,72;1,1,65\n1,1,6C;1,1,65;1,1,74\n1,1,64;1,1,65;1,1,6C;1,1,65;1,1,74\n1,1,6E;1,1,65;1,1,77\n1,1,63;1,1,6C;1,1,61;1,1,73;1,1,73\n1,1,74;1,1,68;1,1,69;1,1,73\n1,1,70;1,1,61;1,1,72;1,1,65;1,1,6E;1,1,74\n1,1,66;1,1,72;1,1,65;1,1,65\n1,1,70;1,1,72;1,1,65;1,1,63;1,1,69;1,1,73;1,1,69;1,1,6F;1,1,6E\n1,1,73;1,1,65;1,1,74;1,1,73;1,1,65;1,1,70\n1,1,69;1,1,6E;1,1,74\n1,1,66;1,1,72;1,1,61;1,1,63\n1,1,61;1,1,62;1,1,73\n1,1,6E;1,1,65;1,1,67\n1,1,72;1,1,6F;1,1,75;1,1,6E;1,1,64\n1,1,74;1,1,79;1,1,70;1,1,65\n1,1,6C;1,1,65;1,1,6E\n1,1,63;1,1,6F;1,1,75;1,1,6E;1,1,74\n1,1,64;1,1,63;1,1,6F;1,1,75;1,1,6E;1,1,74\n1,1,66;1,1,69;1,1,65;1,1,6C;1,1,64\n1,1,69;1,1,6E;1,1,64;1,1,65;1,1,78\n1,1,73;1,1,65;1,1,61;1,1,72;1,1,63;1,1,68\n1,1,63;1,1,68;1,1,61;1,1,6E;1,1,67;1,1,65\n1,1,66;1,1,6F;1,1,72;1,1,6D;1,1,61;1,1,74\n1,1,69;1,1,6E;1,1,73;1,1,65;1,1,72;1,1,74\n1,1,72;1,1,65;1,1,6D;1,1,6F;1,1,76;1,1,65\n1,1,74;1,1,6F;1,1,6E;1,1,75;1,1,6D\n1,1,74;1,1,6F;1,1,73;1,1,74;1,1,72;1,1,69;1,1,6E;1,1,67\n1,1,3D\n1,1,23\n1,1,3E\n1,1,3C\n1,1,3E;1,1,3D\n1,1,3C;1,1,3D\n1,1,61;1,1,6E;1,1,64\n1,1,6F;1,1,72\n1,1,6E;1,1,6F;1,1,74\n1,1,28\n1,1,29\n1,1,7B\n1,1,7D\n1,1,5B\n1,1,5D\n1,1,21\n1,1,3F\n1,1,22;0,765,20-21:23-EF;1,1,22\n1,1,27;0,765,20-26:28-EF;1,1,27\n1,1,61-7A:41-5A;0,23,61-7A:41-5A:30-39\n1,1,40;1,-1,61-7A\n1,13,30-39;1,1,2E;0,5,30-39\n1,13,30-39\n1,1,2D\n1,1,2B\n1,1,2A\n1,1,2F\n1,1,5C\n1,1,25\n1,1,3A\n1,1,2C\n1,1,2E\n1,1,26\n1,1,00-FF";
static char file_wlex[] = "blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,include,10,sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,20,return,21,returnon,22,loop,23,endloop,24,foreach,25,in,26,like,27,endfor,28,break,29,breakon,30,continue,31,continueon,32,nop,33,part,34,echonl,35,echo,36,input,37,declare,38,let,39,delet,40,new,41,class,42,this,43,parent,44,hold,45,precision,46,setsep,47,int,48,frac,49,abs,50,neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,change,60,format,61,insert,62,remove,63,tonum,64,tostring,65,equal,66,diff,67,gt,68,lt,69,gte,70,lte,71,and,72,or,73,not,74,beginpar,75,endpar,76,beginh,77,endh,78,begins,79,ends,80,indirect,81,typeof,82,stringdq,83,stringq,84,ident,85,varsys,86,numberdec,87,numberint,88,minus,89,plus,90,multiply,91,divide,92,divident,93,modulo,94,concat,95,listesep,96,identsep,97,modsep,98,other,99\n"
"1,-1,20:09\n1,1,3B;0,-1,00-FF\n1,1,62;1,1,65;1,1,67;1,1,69;1,1,6E\n1,1,62;1,1,61;1,1,63;1,1,6B;1,1,67;1,1,72;1,1,6F;1,1,75;1,1,6E;1,1,64\n1,1,6C;1,1,69;1,1,62;1,1,72;1,1,61;1,1,72;1,1,79\n1,1,65;1,1,6E;1,1,64\n1,1,65;1,1,78;1,1,63;1,1,65;1,1,70;1,1,74\n1,1,74;1,1,68;1,1,72;1,1,6F;1,1,77\n1,1,63;1,1,61;1,1,74;1,1,63;1,1,68\n1,1,69;1,1,6E;1,1,63;1,1,6C;1,1,75;1,1,64;1,1,65\n1,1,73;1,1,75;1,1,62\n1,1,65;1,1,6E;1,1,64;1,1,73;1,1,75;1,1,62\n1,1,69;1,1,66\n1,1,74;1,1,68;1,1,65;1,1,6E\n1,1,65;1,1,6C;1,1,73;1,1,65\n1,1,65;1,1,6C;1,1,73;1,1,65;1,1,69;1,1,66\n1,1,65;1,1,6E;1,1,64;1,1,69;1,1,66\n1,1,64;1,1,6F\n1,1,63;1,1,61;1,1,6C;1,1,6C\n1,1,69;1,1,6E;1,1,76;1,1,6F;1,1,6B;1,1,65\n1,1,72;1,1,65;1,1,74;1,1,75;1,1,72;1,1,6E\n1,1,72;1,1,65;1,1,74;1,1,75;1,1,72;1,1,6E;1,1,6F;1,1,6E\n1,1,6C;1,1,6F;1,1,6F;1,1,70\n1,1,65;1,1,6E;1,1,64;1,1,6C;1,1,6F;1,1,6F;1,1,70\n1,1,66;1,1,6F;1,1,72;1,1,65;1,1,61;1,1,63;1,1,68\n1,1,69;1,1,6E\n1,1,6C;1,1,69;1,1,6B;1,1,65\n1,1,65;1,1,6E;1,1,64;1,1,66;1,1,6F;1,1,72\n1,1,62;1,1,72;1,1,65;1,1,61;1,1,6B\n1,1,62;1,1,72;1,1,65;1,1,61;1,1,6B;1,1,6F;1,1,6E\n1,1,63;1,1,6F;1,1,6E;1,1,74;1,1,69;1,1,6E;1,1,75;1,1,65\n1,1,63;1,1,6F;1,1,6E;1,1,74;1,1,69;1,1,6E;1,1,75;1,1,65;1,1,6F;1,1,6E\n1,1,6E;1,1,6F;1,1,70\n1,1,70;1,1,61;1,1,72;1,1,74\n1,1,65;1,1,63;1,1,68;1,1,6F;1,1,6E;1,1,6C\n1,1,65;1,1,63;1,1,68;1,1,6F\n1,1,69;1,1,6E;1,1,70;1,1,75;1,1,74\n1,1,64;1,1,65;1,1,63;1,1,6C;1,1,61;1,1,72;1,1,65\n1,1,6C;1,1,65;1,1,74\n1,1,64;1,1,65;1,1,6C;1,1,65;1,1,74\n1,1,6E;1,1,65;1,1,77\n1,1,63;1,1,6C;1,1,61;1,1,73;1,1,73\n1,1,74;1,1,68;1,1,69;1,1,73\n1,1,70;1,1,61;1,1,72;1,1,65;1,1,6E;1,1,74\n1,1,68;1,1,6F;1,1,6C;1,1,64\n1,1,70;1,1,72;1,1,65;1,1,63;1,1,69;1,1,73;1,1,69;1,1,6F;1,1,6E\n1,1,73;1,1,65;1,1,74;1,1,73;1,1,65;1,1,70\n1,1,69;1,1,6E;1,1,74\n1,1,66;1,1,72;1,1,61;1,1,63\n1,1,61;1,1,62;1,1,73\n1,1,6E;1,1,65;1,1,67\n1,1,72;1,1,6F;1,1,75;1,1,6E;1,1,64\n1,1,74;1,1,79;1,1,70;1,1,65\n1,1,6C;1,1,65;1,1,6E\n1,1,63;1,1,6F;1,1,75;1,1,6E;1,1,74\n1,1,64;1,1,63;1,1,6F;1,1,75;1,1,6E;1,1,74\n1,1,66;1,1,69;1,1,65;1,1,6C;1,1,64\n1,1,69;1,1,6E;1,1,64;1,1,65;1,1,78\n1,1,73;1,1,65;1,1,61;1,1,72;1,1,63;1,1,68\n1,1,63;1,1,68;1,1,61;1,1,6E;1,1,67;1,1,65\n1,1,66;1,1,6F;1,1,72;1,1,6D;1,1,61;1,1,74\n1,1,69;1,1,6E;1,1,73;1,1,65;1,1,72;1,1,74\n1,1,72;1,1,65;1,1,6D;1,1,6F;1,1,76;1,1,65\n1,1,74;1,1,6F;1,1,6E;1,1,75;1,1,6D\n1,1,74;1,1,6F;1,1,73;1,1,74;1,1,72;1,1,69;1,1,6E;1,1,67\n1,1,3D\n1,1,23\n1,1,3E\n1,1,3C\n1,1,3E;1,1,3D\n1,1,3C;1,1,3D\n1,1,61;1,1,6E;1,1,64\n1,1,6F;1,1,72\n1,1,6E;1,1,6F;1,1,74\n1,1,28\n1,1,29\n1,1,7B\n1,1,7D\n1,1,5B\n1,1,5D\n1,1,21\n1,1,3F\n1,1,22;0,765,20-21:23-EF;1,1,22\n1,1,27;0,765,20-26:28-EF;1,1,27\n1,1,61-7A:41-5A;0,23,61-7A:41-5A:30-39\n1,1,40;1,-1,61-7A\n1,13,30-39;1,1,2E;0,5,30-39\n1,13,30-39\n1,1,2D\n1,1,2B\n1,1,2A\n1,1,2F\n1,1,5C\n1,1,25\n1,1,3A\n1,1,2C\n1,1,2E\n1,1,26\n1,1,00-FF";
+63
View File
@@ -0,0 +1,63 @@
/* **********************************************
__ __ __
\ \/ \/ / W language
\ /\ /
\/ \/ Copyright 2024-2026 lanisys.fr
This file is part of W language.
W language is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version (GPL-3.0-or-later).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
********************************************** */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "langage.h"
#include "dynamic.h"
#include "var.h"
/* programme de test unitaire de lib/fonctions */
/* gcc w_src/test.c -s -o exec/test -Wall -m64 -DUNIX -L./exec -l:libw.so -l:encod_lib.so */
#include "encod.h"
env e;
int main(int argc, char * argv[])
{
init_env(&e);
//
Dynamic v, w;
dynInit(&e, &v, DYN_LGMIN);
dynInit(&e, &w, DYN_LGMIN);
//
dynLet(&e, &v, "test des encodages12", DYN_LGNONE);
printf("test base64: %s\n", v.mPtr);
//str2hex(&e, &v, &w);
str2base64(&e, &v, &w);
printf("%s\n", w.mPtr);
dynLet(&e, &v, "dGVzdCBkZXMgZW5jb2RhZ2VzMTI=", DYN_LGNONE);
base642str(&e, &v, &w);
printf("decodage: %s\n", w.mPtr);
dynLet(&e, &v, "303132333435363738394142434445", DYN_LGNONE);
hex2str(&e, &v, &w);
printf("hexa2str: %s\n", w.mPtr);
//
dynFree(&e, &v);
dynFree(&e, &w);
//
return 0;
}
+80 -7
View File
@@ -111,13 +111,88 @@ WAPIDECL void var_init(env * e, var * v, octet type, ent64 mod_lg, ent64 sep_lgm
}
}
WAPIDECL void var_ctrl_param(env * e, var * v)
WAPIDECL int varptrtbl_ctrl(env * e, var * v)
{
/* controle que la var "v", si de type PARAM, pointe sur une var toujours existante... */
/* indique si la var "v" appartient a une var de type pointeur (TRUE) */
if(v == NULL)
return FALSE;
if(v->type == VAR_PARAM)
return FALSE;
/*
format de varptrtbl : toutes les entrees sont de 8 octets
v[1] = nb, v[2] = ad ptr, v[3] = ptr sur la var param, v[4] = ad ptr 2, etc.
*/
pointeur * beg = (pointeur *)e->varptrtbl.ptr;
ent64 nb = *((ent64 *)beg); // ok si sizeof(pointeur) = sizeof(ent64)
pointeur * curr = ++beg;
while(nb--)
if((pointeur *)(*curr) == (pointeur *)v->ptr)
return TRUE; // deja existant
else
curr += 2;
// pas trouve
return FALSE;
}
WAPIDECL void varptrtbl_add(env * e, var * v)
{
// ajoute a e->varptrtbl la var si de type "pointeur" : VAR_PARAM, objet...
if(v == NULL)
return;
if(v->type != VAR_PARAM)
return;
/* TODO lire e->par_ptr de type dynamic ??? */
/* dans le cas : hash, puis var de hash, puis clear hash : quid de la var de hash : ras car c'est une copie ! */
/*
format de varptrtbl : toutes les entrees sont de 8 octets
v[1] = nb, v[2] = ad ptr, v[3] = ptr sur la var param, v[4] = ad ptr 2, etc.
*/
pointeur * beg = (pointeur *)e->varptrtbl.ptr;
ent64 nb = *((ent64 *)beg); // ok si sizeof(pointeur) = sizeof(ent64)
pointeur * curr = ++beg;
ent64 addnb = nb + 1;
while(nb--)
if((pointeur *)(*curr) == (pointeur *)v->ptr)
return; // deja existant : RAS
else
curr += 2;
// pas trouve : ajout a la fin
if(dynCtrl(e, &e->varptrtbl, sizeof(pointeur) * addnb * 2 + 1, TRUE))
{
beg = (pointeur *)e->varptrtbl.ptr; // au cas ou realloc memoire
*((ent64 *)beg) = addnb;
curr = beg + addnb * 2;
*curr-- = (pointeur)v;
*curr = (pointeur)v->ptr;
}
}
WAPIDECL void varptrtbl_del(env * e, var * v)
{
// supprime de e->varptrtbl la var v
if(v == NULL)
return;
/*
format de varptrtbl : toutes les entrees sont de 8 octets
v[1] = nb, v[2] = ad ptr, v[3] = ptr sur la var param, v[4] = ad ptr 2, etc.
*/
pointeur * beg = (pointeur *)e->varptrtbl.ptr;
ent64 nb = *((ent64 *)beg); // ok si sizeof(pointeur) = sizeof(ent64)
pointeur * curr = ++beg;
ent64 savnb = nb;
while(nb--)
if((pointeur *)(*curr) == (pointeur *)v->ptr)
{
// trouve : mettre le dernier a la place de celui en cours, sauf si c'est le dernier
*((ent64 *)beg) = savnb - 1;
if(nb > 0) // pas de swap a faire si c'est le dernier qui est supprime
{
beg += savnb * 2 - 1; // le dernier
*curr++ = *beg++;
*curr = *beg;
}
}
else
curr += 2;
// pas trouve : RAS
}
WAPIDECL int var_conv_num(env * e, var * v, number * num)
@@ -200,7 +275,6 @@ WAPIDECL void var_let(env * e, var * let, var * v, int suivre_let, int suivre_v)
case VAR_DYNAMIC:
var_init(e, let, v->type, 0, v->lg + 1, NULL); // +1 pour le \0 de fin
memcopie(let->ptr, v->ptr, v->lg + 1); // permet de copier le \0 de fin
//memcpy(let->ptr, v->ptr, v->lg + 1);
let->lg = v->lg;
break;
//
@@ -210,8 +284,7 @@ WAPIDECL void var_let(env * e, var * let, var * v, int suivre_let, int suivre_v)
// boucler et copier les elements, attention aux cycles !
hashtable_select(e, v);
while(hashtable_next(e, v, e->nom, &pvar))
// TODO copie recursive + copie de la var "pvar"
hashtable_do(e, HASH_WRITE, let, e->nom, &pvar);
hashtable_do(e, HASH_WRITE, let, e->nom, &pvar); // WRITE appelle var_let : recursif de fait
break;
//
case VAR_PARAM:
+4 -1
View File
@@ -26,10 +26,13 @@
#include "apidecl.h"
WAPIDECL void var_init(env * e, var * v, octet type, ent64 mod_lg, ent64 sep_lgm, pointeur pf);
WAPIDECL void var_ctrl_param(env * e, var * v);
WAPIDECL int var_conv_num(env * e, var * v, number * num);
WAPIDECL void var_free(env * e, var * v, int suivre_par);
WAPIDECL void var_let(env * e, var * let, var * v, int suivre_let, int suivre_v);
WAPIDECL int varptrtbl_ctrl(env * e, var * v);
WAPIDECL void varptrtbl_add(env * e, var * v);
WAPIDECL void varptrtbl_del(env * e, var * v);
/* ********************************************** */
#endif
+1 -1
View File
@@ -57,7 +57,7 @@ new: new
class: class
this: this
parent: parent
free: free
hold: hold
precision: precision
setsep: setsep
+3 -3
View File
@@ -1,4 +1,4 @@
blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,include,10,sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,20,return,21,returnon,22,loop,23,endloop,24,foreach,25,in,26,like,27,endfor,28,break,29,breakon,30,continue,31,continueon,32,nop,33,part,34,echonl,35,echo,36,input,37,declare,38,let,39,delet,40,new,41,class,42,this,43,parent,44,free,45,precision,46,setsep,47,int,48,frac,49,abs,50,neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,change,60,format,61,insert,62,remove,63,tonum,64,tostring,65,equal,66,diff,67,gt,68,lt,69,gte,70,lte,71,and,72,or,73,not,74,beginpar,75,endpar,76,beginh,77,endh,78,begins,79,ends,80,indirect,81,typeof,82,stringdq,83,stringq,84,ident,85,varsys,86,numberdec,87,numberint,88,minus,89,plus,90,multiply,91,divide,92,divident,93,modulo,94,concat,95,listesep,96,identsep,97,modsep,98,other,99
blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,include,10,sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,20,return,21,returnon,22,loop,23,endloop,24,foreach,25,in,26,like,27,endfor,28,break,29,breakon,30,continue,31,continueon,32,nop,33,part,34,echonl,35,echo,36,input,37,declare,38,let,39,delet,40,new,41,class,42,this,43,parent,44,hold,45,precision,46,setsep,47,int,48,frac,49,abs,50,neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,change,60,format,61,insert,62,remove,63,tonum,64,tostring,65,equal,66,diff,67,gt,68,lt,69,gte,70,lte,71,and,72,or,73,not,74,beginpar,75,endpar,76,beginh,77,endh,78,begins,79,ends,80,indirect,81,typeof,82,stringdq,83,stringq,84,ident,85,varsys,86,numberdec,87,numberint,88,minus,89,plus,90,multiply,91,divide,92,divident,93,modulo,94,concat,95,listesep,96,identsep,97,modsep,98,other,99
1,-1,20:09
1,1,3B;0,-1,00-FF
1,1,62;1,1,65;1,1,67;1,1,69;1,1,6E
@@ -43,7 +43,7 @@ blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,
1,1,63;1,1,6C;1,1,61;1,1,73;1,1,73
1,1,74;1,1,68;1,1,69;1,1,73
1,1,70;1,1,61;1,1,72;1,1,65;1,1,6E;1,1,74
1,1,66;1,1,72;1,1,65;1,1,65
1,1,68;1,1,6F;1,1,6C;1,1,64
1,1,70;1,1,72;1,1,65;1,1,63;1,1,69;1,1,73;1,1,69;1,1,6F;1,1,6E
1,1,73;1,1,65;1,1,74;1,1,73;1,1,65;1,1,70
1,1,69;1,1,6E;1,1,74
@@ -97,4 +97,4 @@ blank,1,comment,2,begin,3,background,4,library,5,end,6,except,7,throw,8,catch,9,
1,1,2C
1,1,2E
1,1,26
1,1,00-FF
1,1,00-FF