Author SHA1 Message Date
fred fa533a0a2d fix: debug exception display 2026-03-08 18:31:01 +01:00
fred 5ddbd73146 fix: string #hexa escaping, debug local variables, SUBR updated si offset
feat: gened.w test program
2026-03-08 12:11:44 +01:00
fred 80847f4993 feat: lex mod, sortedsearch function
fix: dynIns bug (value in empty attribute), typeof mode
WIP varptrtbl
2026-03-07 18:26:27 +01:00
20 changed files with 1071 additions and 447 deletions

No files matched your search

+17 -6
View File
@@ -47,7 +47,8 @@ env e;
int subNiv;
Dynamic adrLabel;
/*
adrLabel<1> = label, adrLabel<2> = offset (adresse) du label
adrLabel<1> = label
adrLabel<2> = offset (adresse) du label
adrLabel<3, subNiv> = ad debut sub en cours (debut PROG/SUBR)
adrLabel<4> = liste labels dans des JUMP a completer
adrLabel<5> = liste de la position du JUMP ou ecrire l'offset (adresse) du label
@@ -82,8 +83,10 @@ void decodeString(env * e, Dynamic * this)
{
/* TODO ! voir avec le compilateur s'il ne fait pas deja le travail */
/* genw remplace " par #22 et ' ' par #20 : on fait l'inverse ici */
dynChange(e, this, "#22", "\"", DYN_ALL);
dynChange(e, this, "#20", " ", DYN_ALL);
/* + pbm #0A qui saute une ligen et ok ici ... */
//dynChange(e, this, "#22", "\"", DYN_ALL);
//dynChange(e, this, "#20", " ", DYN_ALL);
dynCleanHexaMark(e, this);
}
Dynamic pcode;
@@ -244,7 +247,7 @@ int assembler(env * e, char * fichier, int * cptLig)
dynField(e, &adrLabel, &trav, 3, subNiv, cFM, cVM, 1); // adresse debut sub en cours
debutSub = dynToNum(e, &trav, DYN_FALSE, 8);
if(subNiv > 1)
debutSub = debutSub + 2 + pcode.ptr[debutSub + 1];
debutSub = debutSub + 2 + 3 + 1 + pcode.ptr[debutSub + 1]; // se mettre APRES l'instruction SUBR/PHDS/PIDS (5 + lg et le 1 pour annuler le +1 qui est apres...)
offset = offset + 1 - debutSub; // ad debut loop - debut du prog/sub en cours
PCODE((offset >> 16) & 255); // 23/11/2025 - verif PCODE ok a la place de PCODEP
PCODE((offset >> 8 ) & 255); // 23/11/2025 - verif PCODE ok a la place de PCODEP
@@ -292,7 +295,7 @@ int assembler(env * e, char * fichier, int * cptLig)
dynField(e, &ligne, &tmp, i++, 0, ' ', 0, 1);
if(tmp.mLg < 1 || tmp.mLg > 255) { ret = -4; break; } // erreur longueur nom variable
num = tmp.mLg;
if(num == 1 && tmp.mPtr[0] == '_') // assembler SUBR _ pour avoir lg = 0
if(num == 1 && tmp.mPtr[0] == '_') // assembler SUBR _ pour avoir lg = 0 (?? A GARDER ?? FDE 08/03/2026)
num = 0;
PCODE(instr);
PCODE(num);
@@ -529,6 +532,10 @@ int assembler(env * e, char * fichier, int * cptLig)
// SRCH
case IN_SCHS:
// SCHS
case IN_SSRC:
// SSRC
case IN_SSCS:
// SSCS
case IN_CHNG:
// CHNG
case IN_INSE:
@@ -615,7 +622,7 @@ int assembler(env * e, char * fichier, int * cptLig)
PCODE(num);
break;
case IN_DSET:
// DSET - TODO decoder la chaine, cas des \xx en hexa (recalcul lg : fn qui met a jour directement tmp et maj lg)
// DSET - TODO decoder la chaine, cas des #xx en hexa (recalcul lg : fn qui met a jour directement tmp et maj lg)
dynField(e, &ligne, &tmp, 2, 0, '"', 0, 1);
decodeString(e, &tmp);
if(tmp.mLg < 0 || tmp.mLg > 255) { ret = -4; break; } // erreur longueur nom
@@ -1054,6 +1061,10 @@ int disassembler(env * e, char * fichier)
// SRCH
case IN_SCHS:
// SCHS
case IN_SSRC:
// SSRC
case IN_SSCS:
// SSCS
case IN_CHNG:
// CHNG
case IN_INSE:
+3 -2
View File
@@ -8,8 +8,9 @@ gcc -c w_src/hashtable.c -s -Wall -DUNIX -m64 -fPIC -o exec/hashtable.o
gcc -c w_src/buffer.c -s -Wall -DUNIX -m64 -fPIC -o exec/buffer.o
gcc -c w_src/global.c -s -Wall -DUNIX -m64 -fPIC -o exec/global.o
gcc -c w_src/rep.c -s -Wall -DUNIX -m64 -fPIC -o exec/rep.o
gcc -shared -s exec/dynamic.o exec/var.o exec/hashtable.o exec/global.o exec/rep.o exec/buffer.o -o exec/libw.so
rm -f exec/dynamic.o exec/var.o exec/hashtable.o exec/global.o exec/rep.o exec/buffer.o
gcc -c w_src/lex.c -s -Wall -DUNIX -m64 -fPIC -o exec/lex.o
gcc -shared -s exec/dynamic.o exec/var.o exec/hashtable.o exec/global.o exec/rep.o exec/buffer.o exec/lex.o -o exec/libw.so
rm -f exec/dynamic.o exec/var.o exec/hashtable.o exec/global.o exec/rep.o exec/buffer.o exec/lex.o
echo 1. Compilation de templateMod.c
gcc -shared -s -o exec/template.o w_src/templateMod.c -m64 -DUNIX -Wall -fPIC -L./exec -l:libw.so
+27 -24
View File
@@ -7,67 +7,70 @@ cd "C:\Users\Poupougne42\source\repos\win_w_src"
echo ------------------------------------------------------------------------------------------
echo 0. Compilation pour dynamic lib DLL
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\libw.dll w_src\dynamic.c w_src\var.c w_src\hashtable.c w_src\buffer.c w_src\global.c w_src\rep.c
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\libw.dll w_src\dynamic.c w_src\var.c w_src\hashtable.c w_src\buffer.c w_src\global.c w_src\rep.c w_src\lex.c /DEBUG:NONE
echo 1a. Compilation de templateMod.c
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\template.dll w_src\templateMod.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\template.dll w_src\templateMod.c exec\libw.lib /DEBUG:NONE
echo 1b. Compilation de fileMod.c
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\file.dll w_src\fileMod.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\file.dll w_src\fileMod.c exec\libw.lib /DEBUG:NONE
echo 1c. Compilation de timeMod.c
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\time.dll w_src\timeMod.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\time.dll w_src\timeMod.c exec\libw.lib /DEBUG:NONE
echo 1d. Compilation de hashMod.c
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\hash.dll w_src\hashMod.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\hash.dll w_src\hashMod.c exec\libw.lib /DEBUG:NONE
echo 1e. Compilation de systemMod.c (ws2_32.lib pour socket)
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\system.dll w_src\systemMod.c exec\libw.lib ws2_32.lib advapi32.lib
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\system.dll w_src\systemMod.c exec\libw.lib ws2_32.lib advapi32.lib /DEBUG:NONE
echo 1f. Compilation de randomMod.c
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\random.dll w_src\randomMod.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\random.dll w_src\randomMod.c exec\libw.lib /DEBUG:NONE
echo ------------------------------------------------------------------------------------------
echo 2a. Compilation de jsonMod.c
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\json_lib.dll w_src\json_lib.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\json.dll w_src\jsonMod.c exec\libw.lib exec\json_lib.lib
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\json_lib.dll w_src\json_lib.c exec\libw.lib /DEBUG:NONE
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\json.dll w_src\jsonMod.c exec\libw.lib exec\json_lib.lib /DEBUG:NONE
echo 2b. Compilation de shmMod.c
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\shm_lib.dll w_src\shm_lib.c exec\libw.lib advapi32.lib
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\shm.dll w_src\shmMod.c exec\libw.lib exec\shm_lib.lib
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\shm_lib.dll w_src\shm_lib.c exec\libw.lib advapi32.lib /DEBUG:NONE
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\shm.dll w_src\shmMod.c exec\libw.lib exec\shm_lib.lib /DEBUG:NONE
echo 2c. Compilation de lzwMod.c
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\lzw_lib.dll w_src\lzw_lib.c exec\libw.lib
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\lzw.dll w_src\lzwMod.c exec\libw.lib exec\lzw_lib.lib
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\lzw_lib.dll w_src\lzw_lib.c exec\libw.lib /DEBUG:NONE
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\lzw.dll w_src\lzwMod.c exec\libw.lib exec\lzw_lib.lib /DEBUG:NONE
echo 2d. Compilation de pdfMod.c
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\pdf_lib.dll w_src\pdf_lib.c exec\libw.lib exec\lzw_lib.lib
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\pdf.dll w_src\pdfMod.c exec\libw.lib exec\pdf_lib.lib
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\pdf_lib.dll w_src\pdf_lib.c exec\libw.lib exec\lzw_lib.lib /DEBUG:NONE
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\pdf.dll w_src\pdfMod.c exec\libw.lib exec\pdf_lib.lib /DEBUG:NONE
echo 2e. Compilation de sockMod.c
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\sock_lib.dll w_src\sock_lib.c exec\libw.lib ws2_32.lib
cl /LD /DWINLIB /DWAPIIMPORT /Feexec\sock.dll w_src\sockMod.c exec\libw.lib exec\sock_lib.lib ws2_32.lib
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\sock_lib.dll w_src\sock_lib.c exec\libw.lib ws2_32.lib /DEBUG:NONE
cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\sock.dll w_src\sockMod.c exec\libw.lib exec\sock_lib.lib ws2_32.lib /DEBUG:NONE
echo 2f. Compilation de encodMod.c
cl /LD /DWINLIB /DWAPIEXPORT /Feexec\encod_lib.dll w_src\encod_lib.c exec\libw.lib
rem cl /LD /DWINLIB /DWAPIIMPORT /Feexec\json.dll w_src\jsonMod.c exec\libw.lib exec\json_lib.lib
cl /LD /DWINLIB /DWAPIEXPORT /Gy /MD /Feexec\encod_lib.dll w_src\encod_lib.c exec\libw.lib /DEBUG:NONE
rem cl /LD /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\json.dll w_src\jsonMod.c exec\libw.lib exec\json_lib.lib /DEBUG:NONE
echo ------------------------------------------------------------------------------------------
echo 3a. Generation lw.exe
cl w_src\langage.c /DWINLIB /DWAPIIMPORT /Feexec\lw.exe exec\libw.lib exec\shm_lib.lib advapi32.lib /link
cl w_src\langage.c /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\lw.exe exec\libw.lib exec\shm_lib.lib advapi32.lib /link /DEBUG:NONE /OPT:REF /OPT:ICF
echo 3b. Generation lwa.exe
cl w_src\assembler.c /DWINLIB /DWAPIIMPORT /Feexec\lwa.exe exec\libw.lib /link
cl w_src\assembler.c /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\lwa.exe exec\libw.lib /link /DEBUG:NONE /OPT:REF /OPT:ICF
echo 3c. Generation lwc.exe
cl w_src\genw.c /DWINLIB /DWAPIIMPORT /Feexec\lwc.exe exec\libw.lib /link
cl w_src\genw.c /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\lwc.exe exec\libw.lib /link /DEBUG:NONE /OPT:REF /OPT:ICF
echo 3d. Generation lwf.exe
cl w_src\format.c /DWINLIB /DWAPIIMPORT /Feexec\lwf.exe exec\libw.lib /link
cl w_src\format.c /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\lwf.exe exec\libw.lib /link /DEBUG:NONE /OPT:REF /OPT:ICF
echo 3d. Generation wlex.exe
cl w_src\genlex.c /DWINLIB /DWAPIIMPORT /Feexec\wlex.exe exec\libw.lib /link
cl w_src\genlex.c /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\wlex.exe exec\libw.lib /link /DEBUG:NONE /OPT:REF /OPT:ICF
rem echo 3e. Generation test.exe
rem cl w_src\test.c /DWINLIB /DWAPIIMPORT /Gy /MD /Feexec\test.exe exec\libw.lib exec\encod_lib.lib /link /DEBUG:NONE /OPT:REF /OPT:ICF
echo ------------------------------------------------------------------------------------------
echo 4. Purge
+6 -4
View File
@@ -60,7 +60,8 @@ char * strerr[] = {
"EX_REMOVE_KO remove field error",
"EX_CHILD_FORK cannot fork process",
"EX_CHILD_EXEC cannot run new process",
"EX_ZERO_FOR_INCR foreach increment is zero" // 40
"EX_ZERO_FOR_INCR foreach increment is zero", // 40
"EX_SORTEDSEARCH_KO sort type incorrect"
};
enum {
@@ -369,6 +370,7 @@ void debug(env * e)
dynPrintfInt64(e, "W" PRINTF_MARK, VERSION, 0);
if( ! srcFound)
dynPrintfInt64(e, ":" PRINTF_MARK, e->ligsrc, 0);
dynPrintfInt64(e, "!" PRINTF_MARK, e->except_ex, 0);
dynPrintfSz(e, "> ", NULL);
writeShm(e, (modContextShm *)e->debugCtxShm);
//
@@ -392,9 +394,9 @@ void debug(env * e)
{
// prompt
if(srcFound)
printf("W%d> ", VERSION);
printf("W%d!%lld> ", VERSION, e->except_ex);
else
printf("W%d:%lld> ", VERSION, e->ligsrc);
printf("W%d:%lld!%lld> ", VERSION, e->ligsrc, e->except_ex);
dynSetLen(e, &e->debugcmd, 0);
int c;
char cmd[2];
@@ -761,7 +763,7 @@ void debug(env * e)
{
hashtable_do(e, HASH_READ, e->local, e->nom, &vnext);
}
if(v == NULL)
if(vnext == NULL)
{
/* si pas trouve (ou pas de locale), cherche dans la hash "globale" */
hashtable_do(e, HASH_READ, &e->g, e->nom, &vnext);
+96 -3
View File
@@ -1310,6 +1310,8 @@ WAPIDECL long dynInsSz(env * e, Dynamic * this, long numChamp, long numSousChamp
}
/* chercher le sousChamp */
nSep = 1;
if(numSousChamp == 0 && (this->mPtr[iPos + 1] == separateurChamp || iPos + 1 == this->mLg))
nSep = 0; // si champ vide et sous-champ no 1, ne pas ajouter de marque de sous-champ a la fin
for(iScan = iPos + 1; numSousChamp > 0 && iScan < this->mLg; iScan++)
if(this->mPtr[iScan] == separateurSousChamp)
{
@@ -1318,9 +1320,9 @@ WAPIDECL long dynInsSz(env * e, Dynamic * this, long numChamp, long numSousChamp
}
else if(this->mPtr[iScan] == separateurChamp)
{
iPos = iScan - 1;
nSep = 0;
break;
iPos = iScan - 1;
nSep = 0;
break;
}
else if(iScan == this->mLg - 1)
{
@@ -3170,4 +3172,95 @@ WAPIDECL long dynTrimUtf8(env * e, Dynamic * this, Dynamic * resultat, char * ca
return DYN_OK;
}
WAPIDECL long dynCleanString(env * e, Dynamic * this, octet debutGarde, octet finGarde, long convHexa)
{
/* nettoie la chaine <this> des octets dont le code ascii n'est PAS dans [debutGarde, finGarde]
convHexa : FALSE pour supprimer et ne pas convertir en hexa #xx, TRUE garder le car et mis en hexa #xx
*/
if(this == NULL || debutGarde > finGarde)
return DYN_ERR;
if(this->mLg == 0)
return DYN_OK;
/* */
if(convHexa)
{
long scan = 0, lgc = 1, lgr = 3;
do
{
if(this->mPtr[scan] >= debutGarde && this->mPtr[scan] <= finGarde)
scan++;
else
{
// repris de dynChange, quand remplace est plus grand que cherchee : insertion de 2 cars
// car remplace par # et insertion du code ascii (remplace 1 octet (lgc) par 3 octets (lgr))
// scan = pos_p ( => p - this->mPtr )
if(dynCtrl(e, this, this->mLg + lgr - lgc, DYN_TRUE))
return DYN_ERR; // erreur memoire
char * p = this->mPtr + scan;
//
// deplacement depuis la fin
long n = this->mLg - scan - lgc + 1; // +1 pour copier le \0 de fin...
memcopie(p + lgr, p + lgc, n);
//
char * hex = dynConvertCharToCharHexa((octet)(*p));
*p++ = '#';
*p++ = hex[0];
*p++ = hex[1];
//
this->mLg += (lgr - lgc);
scan += lgr;
}
} while (scan < this->mLg);
/* this->mLg et 0 de fin deja a jour */
this->mPtr[this->mLg] = 0;
}
else
{
/* equivalent a dynErase sur octets hors de la plage de codes ASCII, PAS de gestion UTF8 ici, uniquement octets */
long i, pos = 0;
for(i = 0; i < this->mLg; i++)
{
if(this->mPtr[i] >= debutGarde && this->mPtr[i] <= finGarde)
{
if(pos != i) /* pour ne pas recopier les premiers caracteres quand pas de suppression */
this->mPtr[pos++] = this->mPtr[i];
else
pos++;
}
}
this->mLg = pos;
this->mPtr[this->mLg] = 0;
}
return DYN_OK;
}
WAPIDECL void dynCleanHexaMark(env * e, Dynamic * this)
{
if(this == NULL)
return;
/* */
/* equivalent a dynErase sur #xx, suppression "xx" et remplacement # par l'octet "xx" */
long i, pos = 0;
for(i = 0; i < this->mLg; i++)
{
if(this->mPtr[i] != '#' || i >= this->mLg - 2) // car si pas la place pour le code ascii, ne pas traiter # comme debut du code (securite)
{
if(pos != i) /* pour ne pas recopier les premiers caracteres quand pas de suppression */
this->mPtr[pos++] = this->mPtr[i];
else
pos++;
}
else
{
// remplace #xx (hexa) par l'octet correspondant
if(dynConvertCharHexaToChar(this->mPtr[i + 1], this->mPtr[i + 2], &this->mPtr[pos]) == DYN_ERR)
this->mPtr[pos] = '?'; // securite
pos++;
i += 2;
}
}
this->mLg = pos;
this->mPtr[this->mLg] = 0;
}
/* ********************************************** */
+2
View File
@@ -149,6 +149,8 @@ WAPIDECL long dynFmtUtf8(env * e, Dynamic * this, Dynamic * resultat, char cadra
WAPIDECL long dynFmtNumber(env * e, ent64s valeur, Dynamic * resultat, char cadrage, char filler, long lg);
WAPIDECL long dynTrim(env * e, Dynamic * this, Dynamic * resultat, char car, long option);
WAPIDECL long dynTrimUtf8(env * e, Dynamic * this, Dynamic * resultat, char * car, long option);
WAPIDECL long dynCleanString(env * e, Dynamic * this, octet debut, octet fin, long convHexa);
WAPIDECL void dynCleanHexaMark(env * e, Dynamic * this);
/* ********************************************** */
#endif
+2 -2
View File
@@ -2,7 +2,7 @@
__ __ __
\ \/ \/ / W language
\ /\ /
\/ \/ Copyright 2024 lanisys.fr
\/ \/ Copyright 2024-2026 lanisys.fr
This file is part of W language.
@@ -27,7 +27,7 @@
#include "langage.h"
#include "dynamic.h"
#include "lex.c"
#include "lex.h"
env e;
+5 -209
View File
@@ -2,7 +2,7 @@
__ __ __
\ \/ \/ / W language
\ /\ /
\/ \/ Copyright 2024 lanisys.fr
\/ \/ Copyright 2024-2026 lanisys.fr
This file is part of W language.
@@ -27,213 +27,10 @@
#include "langage.h"
#include "dynamic.h"
#include "lex.c"
#include "lex.h"
env e;
long rg(env * e, Dynamic * regles, char * nom, Dynamic * tmp)
{
// renvoie le numero de la regle a partir de son nom, 0 si non trouvee ou erreur conversion en numerique
long pos = dynLocateSz(e, regles, nom, ',', 1, 10);
if(pos > 0)
{
dynField(e, regles, tmp, 1, pos + 1, 10, ',', 1);
pos = dynToNum(e, tmp, DYN_FALSE, 5); // pas de signe et num regle sur 16 bits : 5 chiffres
if(tmp->mInternal != DYN_OK)
pos = 0;
}
return pos;
}
struct {
long blanc, nomregle, debut, fin, occ, infini, commentaire, intervalle, hexa, car, reste;
} r;
void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
{
r.blanc = rg(e, regles, "blanc", tmp); // 1
r.nomregle = rg(e, regles, "nomregle", tmp); // 2
r.debut = rg(e, regles, "debut", tmp); // 3
r.fin = rg(e, regles, "fin", tmp); // 4
r.occ = rg(e, regles, "occ", tmp); // 5
r.infini = rg(e, regles, "infini", tmp); // 6
r.commentaire = rg(e, regles, "commentaire", tmp); // 7
r.intervalle = rg(e, regles, "intervalle", tmp); // 8
r.hexa = rg(e, regles, "hexa", tmp); // 9
r.car = rg(e, regles, "car", tmp); // 10
r.reste = rg(e, regles, "reste", tmp); // 11
}
long parse(Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic * trav, Dynamic * encours)
{
#define nreg(x) ((x)*2 > trav->mLg ? 0 : *(ent16 *)(trav->mPtr + (x)*2 - 2))
/* */
static int numlig = 0;
numlig++;
/* */
if(valex->mLg == 0)
return OK; /* ligne vide */
/* */
int nbres = dynDcount(&e, resultat, 10, DYN_NONE, DYN_NONE);
int nbval = dynDcount(&e, valex, cVM, 2, cFM);
ent16 regle;
dynSetLen(&e, trav, 0);
dynSetLen(&e, encours, 0);
for(int ival = nbval; ival > 0; ival--)
{
/* suppression des regles 1 et 7 (blanc et commentaire) */
dynField(&e, valex, tmp, 2, ival, cFM, cVM, 1);
regle = dynToNum(&e, tmp, DYN_FALSE, 0);
if(regle == r.blanc || regle == r.commentaire)
{
dynDel(&e, valex, 1, ival, cFM, cVM, 1);
dynDel(&e, valex, 2, ival, cFM, cVM, 1);
dynDel(&e, valex, 3, ival, cFM, cVM, 1);
}
else
{
if(dynCtrl(&e, trav, trav->mLg + 2, TRUE) != DYN_OK)
return DYN_ERR;
if(trav->mLg > 0)
memcopie(trav->mPtr + 2, trav->mPtr, trav->mLg);
*(ent16 *)(trav->mPtr) = regle;
dynSetLen(&e, trav, trav->mLg + 2);
}
}
//dynDel(&e, valex, 2, DYN_NONE, cFM, DYN_NONE, 1);
if(trav->mLg == 0)
return OK; /* blancs et/ou commentaire seuls */
/* */
//for(int i=1;i<=trav->mLg/2;i++) printf("%d,",nreg(i)); printf("\n");
/* debut d'analyse des tokens : nomregle */
if(nreg(1) != r.nomregle)
{
dynField(&e, valex, tmp, 3, 1, cFM, cVM, 1);
printf("Erreur ligne %dc%s : nom regle attendu\n", numlig, tmp->mPtr);
return DYN_ERR;
}
/* liste de et/ou */
for(ent16 n = 2;;)
{
if((regle = nreg(n)) == 0)
break;
/* */
if(regle == r.debut || regle == r.car) ; else
{
dynField(&e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : car ou debut et/ou attendu\n", numlig, tmp->mPtr);
return DYN_ERR;
}
/* et */
if(n == 2)
dynStoreSz(&e, valex, 4, DYN_NONE, "", 0, cFM, DYN_NONE);
else
dynConcatSz(&e, valex, ";", 1);
/* */
if(regle == r.car)
{
/* 1 caractere = (1,1,car) (raccourci d'ecriture) */
dynConcatSz(&e, valex, "1,1,", 4);
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
dynConcat(&e, valex, tmp);
n++;
continue;
}
if(nreg(n+1) == r.occ && (nreg(n+2) == r.occ || nreg(n+2) == r.infini)) ; else
{
dynField(&e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : occurence min/max attendue %d\n", numlig, tmp->mPtr, n);
return DYN_ERR;
}
n++;
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
dynIconv(&e, tmp, encours, "X");
dynConcat(&e, valex, encours); // occmin
n++;
if(nreg(n) == r.infini)
dynConcatSz(&e, valex, "-1,", 3);
else
{
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
dynIconv(&e, tmp, encours, "X");
dynConcat(&e, valex, encours); // occmax
}
ent16 n1,n2,n3; char unefois[2] = {0};
n1 = nreg(n+1);
n2 = nreg(n+2);
n3 = nreg(n+3);
while(n1 == r.car || n1 == r.hexa || ((n1 == r.car || n1 == r.hexa) && n2 == r.intervalle && (n3 == r.car || n3 == r.hexa)))
{
dynConcatSz(&e, valex, unefois, DYN_LGNONE);
if((n1 == r.car || n1 == r.hexa) && n2 == r.intervalle && (n3 == r.car || n3 == r.hexa))
{
n++;
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
if(n1 == 10)
dynConcat(&e, valex, tmp);
else
{
dynIconv(&e, tmp, encours, "X");
dynConcatSz(&e, valex, encours->mPtr + 1, DYN_LGNONE); // copier apres le #
}
dynConcatSz(&e, valex, "-", 1);
n += 2;
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
if(n3 == r.car)
dynConcat(&e, valex, tmp);
else
{
dynIconv(&e, tmp, encours, "X");
dynConcatSz(&e, valex, encours->mPtr + 1, DYN_LGNONE); // copier apres le #
}
}
else if(n1 == r.car)
{
n++;
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
dynConcat(&e, valex, tmp);
}
else if(n1 == r.hexa)
{
n++;
dynField(&e, valex, tmp, 1, n, cFM, cVM, 1);
dynIconv(&e, tmp, encours, "X");
dynConcatSz(&e, valex, encours->mPtr + 1, DYN_LGNONE); // copier apres le #
}
n1 = nreg(n+1);
n2 = nreg(n+2);
n3 = nreg(n+3);
unefois[0] = ':';
}
if(unefois[0] == 0)
{
dynField(&e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : caractere/intervalle attendu\n", numlig, tmp->mPtr);
return DYN_ERR;
}
if(n1 == r.fin) ; else
{
dynField(&e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : fin et/ou attendue\n", numlig, tmp->mPtr);
return DYN_ERR;
}
n += 2;
}
/* lecture nom regle en hexa */
dynField(&e, valex, tmp, 1, 1, cFM, cVM, 1);
dynIconv(&e, tmp, trav, "X");
trav->mPtr[trav->mLg - 1] = ','; /* exemple : begin,1,comment,2,... permet de faire un locate */
dynConcatSz(&e, trav, Int64ToSz(&e, nbres == 0 ? 1 : nbres, DYN_FALSE, 0), DYN_LGNONE);
dynStore(&e, resultat, 1, nbres == 0 ? 1 : nbres*2-1, trav, 10, ',');
/* */
dynField(&e, valex, tmp, 4, DYN_NONE, cFM, DYN_NONE, 1);
nbres = (nbres == 0 ? 2 : nbres + 1);
dynStoreSz(&e, resultat, nbres, DYN_NONE, tmp->mPtr, tmp->mLg, 10, DYN_NONE);
/* */
#undef nreg
return OK;
}
long gen_c(Dynamic * resultat, Dynamic * elem1, Dynamic * elem2, Dynamic * elem3)
{
dynSetLen(&e, elem2, 0); // token
@@ -350,13 +147,12 @@ int main(int argc, char * argv[])
}
else
{
if(lire_regles_lex(&e, &regles, NULL) != DYN_OK)
if(lire_regles_lex(&e, &regles, "lexlex") != DYN_OK)
ret = -3;
}
if(ret == 0)
{
init_reg(&e, &regles, &elem1);
//printf("commentaire : %ld nomregle : %ld\n", r.commentaire, r.nomregle);
init_reg_lex(&e, &regles, &elem1); // elem1 = var tmp
//
dynErase(&e, &fichier, "\r");
dynRemove(&e, &fichier, NULL, 0, DYN_TRUE);
@@ -364,7 +160,7 @@ int main(int argc, char * argv[])
{
lex(&e, &regles, &ligne, &valex);
/* */
ret = parse(&valex, &resultat, &elem1, &elem2, &elem3);
ret = parse_lex(&e, &valex, &resultat, &elem1, &elem2, &elem3);
/* */
//dynConvert(&e, &valex, sFM sVM, "\n|");
//printf("valex %s\n", valex.mPtr);//
+165 -53
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.
@@ -30,7 +30,7 @@
#include "langage.h"
#include "dynamic.h"
#include "lex.c"
#include "lex.h"
#include "instr.h"
#include "rep.h"
#include "arg.c"
@@ -98,7 +98,12 @@ 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 */
Dynamic forend,forinc; /* variables pour le code asm des boucles foreach numeriques */
Dynamic varparam; /* contient les variables passees en parametre a une sub : interdire ceratins formes d'appel pour eviter plus tard des erreurs de pointeur */
int doVarParam; /* booleen pour activer dans variable() la memo des variables dans varparam */
int typeof_; /* gestion du cas "typeof var" dans terme() */
/* -------------------- */
ent64 lap = 0; /* calcul temps du programme (hors init, alloc et free), en ms */
@@ -139,11 +144,13 @@ long init(env * e)
dynInit(e, &srcdbg, 0);
dynInit(e, &forend, 0);
dynInit(e, &forinc, 0);
dynInit(e, &varparam, 0);
iPrio = 0;
iImbriPrio = 1;
numNiv = 0;
idNiv = 0;
numlig = 0;
doVarParam = 0;
return OK; /* TODO controles */
}
@@ -160,6 +167,7 @@ void fin(env * e)
dynFree(e, &srcdbg);
dynFree(e, &forend);
dynFree(e, &forinc);
dynFree(e, &varparam);
}
long rg(env * e, Dynamic * regles, char * nom, Dynamic * tmp)
@@ -182,11 +190,11 @@ sub,11,endsub,12,if,13,then,14,else,15,elseif,16,endif,17,do,18,call,19,invoke,2
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
neg,51,round,52,type,53,len,54,count,55,dcount,56,field,57,index,58,search,59,sortedsearch,60
change,61,format,62,insert,63,remove,64,tonum,65,tostring,66,equal,67,diff,68,gt,69,lt,70
gte,71,lte,72,and,73,or,74,not,75,beginpar,76,endpar,77,beginh,78,endh,79,begins,80
ends,81,indirect,82,typeof,83,stringdq,84,stringq,85,ident,86,varsys,87,numberdec,88,numberint,89,minus,90
plus,91,multiply,92,divide,93,divident,94,modulo,95,concat,96,listesep,97,identsep,98,modsep,99,other,100
*/
struct {
ent16 blank,comment,begin,background,library,end,except,throw,catch,include;
@@ -194,11 +202,11 @@ struct {
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,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;
ent16 indirect,typeof_,stringdq,stringq,ident,varsys,numberdec,numberint,minus,plus;
ent16 multiply,divide,divident,modulo,concat,listesep,identsep,modsep,other;
ent16 neg,round,type,len,count,dcount,field,index,search,sortedsearch;
ent16 change,format,insert,remove,tonum,tostring,equal,diff,gt,lt;
ent16 gte,lte,and,or,not,beginpar,endpar,beginh,endh,begins;
ent16 ends,indirect,typeof_,stringdq,stringq,ident,varsys,numberdec,numberint,minus;
ent16 plus,multiply,divide,divident,modulo,concat,listesep,identsep,modsep,other;
} r;
/* les 2 fonctions fictives ci dessous doivent avoir un numero < 512 et > au max de "r" ci-dessus */
/* servent a gerer la notation x{1,2}[3,4] */
@@ -276,8 +284,9 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.field = rg(e, regles, "field", tmp);
r.index = rg(e, regles, "index", tmp);
r.search = rg(e, regles, "search", tmp);
r.change = rg(e, regles, "change", tmp);
r.sortedsearch = rg(e, regles, "sortedsearch", tmp);
/* */
r.change = rg(e, regles, "change", tmp);
r.format = rg(e, regles, "format", tmp);
r.insert = rg(e, regles, "insert", tmp);
r.remove = rg(e, regles, "remove", tmp);
@@ -287,8 +296,8 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.diff = rg(e, regles, "diff", tmp);
r.gt = rg(e, regles, "gt", tmp);
r.lt = rg(e, regles, "lt", tmp);
r.gte = rg(e, regles, "gte", tmp);
/* */
r.gte = rg(e, regles, "gte", tmp);
r.lte = rg(e, regles, "lte", tmp);
r.and = rg(e, regles, "and", tmp);
r.or = rg(e, regles, "or", tmp);
@@ -298,8 +307,8 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.beginh = rg(e, regles, "beginh", tmp);
r.endh = rg(e, regles, "endh", tmp);
r.begins = rg(e, regles, "begins", tmp);
r.ends = rg(e, regles, "ends", tmp);
/* */
r.ends = rg(e, regles, "ends", tmp);
r.indirect = rg(e, regles, "indirect", tmp);
r.typeof_ = rg(e, regles, "typeof", tmp);
r.stringdq = rg(e, regles, "stringdq", tmp);
@@ -309,8 +318,8 @@ void init_reg(env * e, Dynamic * regles, Dynamic * tmp)
r.numberdec = rg(e, regles, "numberdec", tmp);
r.numberint = rg(e, regles, "numberint", tmp);
r.minus = rg(e, regles, "minus", tmp);
r.plus = rg(e, regles, "plus", tmp);
/* */
r.plus = rg(e, regles, "plus", tmp);
r.multiply = rg(e, regles, "multiply", tmp);
r.divide = rg(e, regles, "divide", tmp);
r.divident = rg(e, regles, "divident", tmp);
@@ -400,6 +409,9 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
if(tok != r.ident && tok != r.this && tok != r.parent)
return VAR_ERR;
//
if(typeof_)
dynConcatSz(e, resultat, "TYPO\n", 5); // aGauche vaut toujours 0 en mode typeof
//
dynField(e, valex, tmp, 1, norig(n), cFM, cVM, 1);
dynIconv(e, tmp, encours, "X");
dynConcatSz(e, resultat, "PVAR ", 5);
@@ -412,6 +424,11 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
//printf("ident:%s niv:%ld liste:%s\n", encours->mPtr, nbNivIdent, nivIdent.mPtr);
return VAR_ERR; // creer une erreur specifique
}
if(doVarParam)
{
dynConcatSz(e, &varparam, sFM, 1);
dynConcat(e, &varparam, encours);
}
/* */
n++;
for(;;)
@@ -428,6 +445,8 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
{
if(tok2 == r.count)
{
if(typeof_)
return VAR_ERR; // pas de hash.count en mode typeof : non autorise
dynConcatSz(e, resultat, "HCOU", 4);
}
else
@@ -435,8 +454,18 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
if(tok == r.identsep)
dynConcatSz(e, resultat, "PVAH ", 5);
else
{
dynConcatSz(e, resultat, "PVAI ", 5);
if(doVarParam)
doVarParam = 2; // indique au moins une indirection dans les vars
}
dynConcat(e, resultat, encours);
/* */
if(doVarParam)
{
dynConcatSz(e, &varparam, sVM, 1);
dynConcat(e, &varparam, encours);
}
}
dynConcatSz(e, resultat, "\n", 1);
}
@@ -454,6 +483,8 @@ long variable(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynam
/* */
n++;
}
if(typeof_)
dynConcatSz(e, resultat, "PSHT\n", 5);
return VAR_OK;
}
@@ -521,7 +552,7 @@ long terme(env * e, ent16 t, Dynamic * valex, Dynamic * tmp, Dynamic * encours)
}
if((t == r.abs || t == r.int_ || t == r.frac || t == r.neg ||
t == r.type || t == r.round || t == r.tonum || t == r.tostring ||
t == r.len || t == r.count || t == r.not || t == r.typeof_ ||
t == r.len || t == r.count || t == r.not || t == r.sortedsearch ||
t == r.dcount || t == r.field || t == r.index || t == r.search ||
t == r.change || t == r.format || t == r.insert || t == r.remove ) && nreg(n+1) == r.beginpar)
{
@@ -551,13 +582,22 @@ long terme(env * e, ent16 t, Dynamic * valex, Dynamic * tmp, Dynamic * encours)
tok = nreg(n);
return TERM_ENDS;
}
typeof_ = FALSE;
if(t == r.typeof_)
{
typeof_ = TRUE;
n++;
tok = nreg(n);
}
dynSetLen(e, &trav, 0);
if(variable(e, &trav, valex, tmp, encours, &aGauche) == VAR_OK)
{
typeof_ = FALSE;
/* var ; n et tok sont deja a jour (positionne sur le prochain token) */
return TERM_VAR;
}
/* sinon erreur */
typeof_ = FALSE;
return ret;
}
@@ -660,9 +700,6 @@ long stack_fn(env * e, Dynamic * resultat, long fn, long nbParam)
if(fn == r.count)
return nbParam != 2 ? -1 : dynConcatSz(e, resultat, "COUN\n", DYN_LGNONE);
if(fn == r.typeof_)
return nbParam != 1 ? -1 : dynConcatSz(e, resultat, "TEST\n", DYN_LGNONE); /* TODO dans langage.c !! */
if(fn == r.dcount)
{
if(nbParam == 1)
@@ -691,6 +728,14 @@ long stack_fn(env * e, Dynamic * resultat, long fn, long nbParam)
else
return dynConcatSz(e, resultat, (nbParam == 2 ? "SRCH\n" : "SCHS\n"), DYN_LGNONE);
}
if(fn == r.sortedsearch)
{
if(nbParam != 3 && nbParam != 4)
return -1;
else
return dynConcatSz(e, resultat, (nbParam == 3 ? "SSRC\n" : "SSCS\n"), DYN_LGNONE);
}
if(fn == r.change)
return nbParam != 3 ? -1 : dynConcatSz(e, resultat, "CHNG\n", DYN_LGNONE);
@@ -907,9 +952,12 @@ long expr(env * e, Dynamic * resultat, Dynamic * valex, Dynamic * tmp, Dynamic *
else if(termType == TERM_STR)
{
/* empiler le terme en assembleur <string> */
dynConcatSz(e, resultat, "PVAT\nDSET \"", DYN_LGNONE); /* TODO pbm " dans la chaine : quid ?? */
dynChange(e, encours, (char *)"\"", "#22", DYN_ALL);
dynChange(e, encours, (char *)" ", "#20", DYN_ALL); // car dans assembler.c, "trim(3)" de chaque ligne...
dynConcatSz(e, resultat, "PVAT\nDSET \"", DYN_LGNONE);
//dynChange(e, encours, (char *)"\"", "#22", DYN_ALL);
//dynChange(e, encours, (char *)" ", "#20", DYN_ALL);
/* mettre en hexa les cars "speciaux", dont <espace> 32/#20 car assembleur.c fait un trim,
" 34/#22 car instr DSET utilise les guillements - ne pas convertir # 35/#23 car sert a coder un car en hexa, mettre #35 pour utiliser le # !! */
dynCleanString(e, encours, (octet)35, (octet)126, TRUE); // TRUE convertit les octets hors intervalle en hexa #xx
dynConcat(e, resultat, encours);
dynConcatSz(e, resultat, "\"\nPSHV\n", DYN_LGNONE);
/* chercher ENDPAR */
@@ -1384,6 +1432,8 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
printf("Erreur ligne %dc%s : nom fichier include incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
/* ne garder que les cars entre 33 et 126, car INCL n'est que informatif ici */
dynCleanString(e, encours, (octet)33, (octet)126, FALSE); // FALSE pour supprimer et ne pas convertir en hexa #xx
// include deja mis dans <source>, mis ici pour info dans le compile
dynConcatSz(e, resultat, "SRCL ", DYN_LGNONE);
dynConcatSz(e, resultat, Int64ToSz(e, numlig, FALSE, 0), DYN_LGNONE);
@@ -1422,6 +1472,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
ent64s numb;
if(tok2number(e, &numb, valex, tmp, encours) != TERM_NUM)
{
/* TODO : tester une variable + modif langage.c/assembler */
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : numero exception throw incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -1507,6 +1558,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
ent64s numb;
if(tok2number(e, &numb, valex, tmp, encours) != TERM_NUM)
{
/* TODO : tester une variable + modif langage.c/assembler */
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : numero part incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -2024,6 +2076,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
/* -------------------------------------------------------------------------------------- */
if(tok == r.do_ || tok == r.call || tok == r.invoke)
{
//ent16 toksub = tok; // si besoin pour differencier do/call/invoke
dynSetLen(e, &envers, 0);
/* 3 formes : do var ; do ident@ident ; do library@ident
invoke ident&ident call ident */
@@ -2032,7 +2085,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
dynConcatSz(e, resultat, "\nCRAZ\n", DYN_LGNONE);
if(tok == r.call || tok == r.invoke)
{
/* appel de module ou de library **FINIR** */
/* appel de module ou de library */
if(tok == r.call)
{
tok2 = nreg(n+1);
@@ -2134,6 +2187,8 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
tok = nreg(n);
if(tok != r.endpar)
{
dynSetLen(e, &varparam, 0);
doVarParam = 1;
/* au moins 1 var en parametre */
for(;;)
{
@@ -2141,6 +2196,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
aGauche = 0;
if(variable(e, &trav, valex, tmp, encours, &aGauche) == VAR_ERR)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : parametre do/call/invoke incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -2151,12 +2207,52 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
break;
if(tok != r.listesep)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : parametre do/call/invoke incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
n++;
}
/* TODO => controler certaines formes de variables passees en parametre (varparam) :
(a, a) (a, a.b) (a.b, a.b.c) (a!c) : sont interdites
*/
if(doVarParam == 2)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : parametre do/call/invoke avec indirection non autorisee\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
doVarParam = 0;
long i, j, nbi, nbj, nb = dynDcount(e, &varparam, cFM, DYN_NONE, DYN_NONE);
for(i = 2; i < nb; i++)
for(j = i + 1; j <= nb; j++)
{
// comparer i et j
dynField(e, &varparam, tmp, i, DYN_NONE, cFM, DYN_NONE, 1);
dynField(e, &varparam, encours, j, DYN_NONE, cFM, DYN_NONE, 1);
if(dynCompare(e, tmp, CMP_EQ, encours->mPtr, encours->mLg))
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : parametres do/call/invoke identiques non autorises\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
nbi = dynDcount(e, tmp, cVM, DYN_NONE, DYN_NONE);
nbj = dynDcount(e, encours, cVM, DYN_NONE, DYN_NONE);
if(nbi == nbj)
continue;
if(nbi > nbj)
nbi = nbj; // nbi est le min de var enchainees : comparer sur le min, si egal : non autorise
dynField(e, &varparam, tmp, i, 1, cFM, cVM, nbi);
dynField(e, &varparam, encours, j, 1, cFM, cVM, nbi);
if(dynCompare(e, tmp, CMP_EQ, encours->mPtr, encours->mLg))
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : parametres do/call/invoke imbriques, de meme base, non autorises\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
}
}
if(nreg(n+1) != 0)
{
@@ -2178,8 +2274,11 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
dynConcatSz(e, resultat, "\n", DYN_LGNONE);
n++;
aGauche = 1;
dynSetLen(e, &varparam, 0);
doVarParam = 1; // pour ctrl new : "classe.membre = new classe" non autorise
if(variable(e, &envers, valex, tmp, encours, &aGauche) == VAR_ERR)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : variable let incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -2187,6 +2286,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
setfld = 0; // 1 pour x{1} et 2 pour x{1,1}
if(tok == r.beginh)
{
doVarParam = 0;
if(expr(e, resultat, valex, tmp, encours, 0, r.let) != 0) // var{ is followed by 1 or 2 expr, comma separated
{
/* erreur dans l'expression */
@@ -2198,6 +2298,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
setsubstr = 0; // 1 pour x[1,1]
if(tok == r.begins)
{
doVarParam = 0;
if(expr(e, resultat, valex, tmp, encours, 0, r.change) != 0) // var[ is followed by 2 expr, comma separated
{
/* erreur dans l'expression */
@@ -2208,6 +2309,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
}
if(tok != r.equal)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : let incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -2216,6 +2318,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
tok = nreg(n);
if(tok == r.beginh)
{
doVarParam = 0;
if(setfld != 0 || setsubstr != 0)
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
@@ -2325,6 +2428,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
{
if(setfld != 0 || setsubstr != 0)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : creation objet incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -2336,6 +2440,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
/* TODO : indirection sur le nom de la classe : var a la place de ident dans ce cas la */
if(tok == r.ident && tok2 == 0) ; else
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : new incorrect\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
@@ -2344,11 +2449,21 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
dynIconv(e, &envers, tmp, "X");
if(tmp->mLg < 1 || tmp->mLg > 24)
{
doVarParam = 0;
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
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...
doVarParam = 0;
/* si "tmp" (la classe) est le premier element de varparam : non autorise */
dynField(e, &varparam, &envers, 2, 1, cFM, cVM, 1);
if(dynCompare(e, &envers, CMP_EQ, tmp->mPtr, tmp->mLg))
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : new, classe non autorise quand mise a jour membre pour elle meme\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
// pbm test suivant si new appele dans library et classe declaree dans le prog principal (ou inversement)... donc plus de controle
if(IdentInconnu(e, tmp))
{
//dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
@@ -2358,7 +2473,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
}
if(aGauche == 2)
{
// TODO dercode avec une var a creer : PHDN/PIDN - TODO
// dercode avec une var a creer : PHDN/PIDN
dercode.mPtr[3] = 'N';
dynConcat(e, resultat, &dercode);
}
@@ -2369,6 +2484,7 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
else
{
/* expression "simple" */
doVarParam = 0;
if(expr(e, resultat, valex, tmp, encours, 0, 0) != 0)
{
/* erreur dans l'expression */
@@ -2530,37 +2646,33 @@ long parse(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic
if(tok == r.echo) strcpy(instr, "WRIT\n"); else strcpy(instr, "WRLN\n");
/* */
n++;
tok = nreg(n);
tok2 = nreg(n+1);
/* temporaire pour tests, A FINIR */
if(tok == r.ident && tok2 == 0) // enlever tok2 == 0 FINIR
{
aGauche = 0;
if(variable(e, resultat, valex, tmp, encours, &aGauche) == VAR_ERR)
{
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : variable echo incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR; /* TODO numeroter les erreurs */
}
dynConcatSz(e, resultat, instr, 5);
}
else if((tok == r.stringdq || tok == r.stringq) && tok2 == 0)
{
dynConcatSz(e, resultat, "PVAT\nDSET \"", DYN_LGNONE); /* TODO pbm " dans la chaine : quid ?? */
tok2string(e, valex, tmp, encours);
dynChange(e, encours, "\"", "#22", DYN_ALL);
dynChange(e, encours, " ", "#20", DYN_ALL);
dynConcat(e, resultat, encours);
dynConcatSz(e, resultat, "\"\n", DYN_LGNONE);
dynConcatSz(e, resultat, instr, 5);
}
else
/* expression "simple" */
doVarParam = 0;
if(expr(e, resultat, valex, tmp, encours, 0, 0) != 0)
{
/* erreur dans l'expression */
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : fin echo/echonl incorrect\n", numlig, tmp->mPtr);
printf("Erreur ligne %dc%s : expression let incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR;
}
if(tok != 0)
{
/* erreur en fin d'expression */
dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
printf("Erreur ligne %dc%s : fin d'expression let incorrecte\n", numlig, tmp->mPtr);
return DYN_ERR;
}
dynConcatSz(e, resultat, instr, 5);
return OK;
/* */
//aGauche = 0;
//if(variable(e, resultat, valex, tmp, encours, &aGauche) == VAR_ERR)
//{
// dynField(e, valex, tmp, 3, norig(n), cFM, cVM, 1);
// printf("Erreur ligne %dc%s : variable echo incorrecte\n", numlig, tmp->mPtr);
// return DYN_ERR; /* TODO numeroter les erreurs */
//}
//dynConcatSz(e, resultat, instr, 5);
}
/* -------------------------------------------------------------------------------------- */
if(tok == r.delet)
+1 -4
View File
@@ -52,7 +52,7 @@ static int setError(modEtat * p, int err)
{
if(p != NULL)
p->error = err;
return EX_MODERR;
return err == OK ? OK : EX_MODERR;
}
static void encodageMD2(env * e, var * entree, var * sortie)
@@ -618,7 +618,6 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
/* ============================================================================================= */
else if(modFnIs(e, "MD2", 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;
@@ -634,7 +633,6 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
/* ----------------------------------------------------------------------------------------------- */
else if(modFnIs(e, "MD4", 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;
@@ -650,7 +648,6 @@ long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
/* ----------------------------------------------------------------------------------------------- */
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;
+5 -1
View File
@@ -48,7 +48,7 @@ char libInstr[256 * 4] ={"VERS" "JUMP" "DECL" "SRCL" "BEXC" "EXCE" "CATC" "THRW"
"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" "PHDN" "PIDN" "SADV" "VLET" /* 110-119 */
"PHDV" "PIDV" "HCOU" "PVHD" "PVID" "xxxx" "xxxx" "xxxx" "xxxx" "xxxx" /* 124 */
"PHDV" "PIDV" "HCOU" "PVHD" "PVID" "SSRC" "SSCS" "xxxx" "xxxx" "xxxx" /* 126 */
"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"
@@ -326,6 +326,10 @@ char libComp[10 * 3] = {"EQ " "NE " "LT " "GT " "LE " "GE " "AND" "OR " "NOT" "F
#define IN_PVHD 123
#define IS_PVID "\x7C"
#define IN_PVID 124
#define IS_SSRC "\x7D"
#define IN_SSRC 125
#define IS_SSCS "\x7E"
#define IN_SSCS 126
#define IS_LIBR "\xFB"
#define IN_LIBR 251
+174 -66
View File
@@ -81,9 +81,7 @@ void dyn_printdebug(env * e, var * v, int detail)
}
}
#include "lex.c"
//#include "reseau.c"
#include "lex.h"
/* seules variables globales : celle indiquant un signal de terminaison du programme et celles pour basculer en mode debug on/off ! */
octet ctx_env_kill = 0; /* mis a 255 si signal de terminaison */
@@ -1258,14 +1256,28 @@ void nfmt(env * e, int fn)
stack_num(e, pns4); // length
if(e->exception == EX_NOTNUM)
return;
if(pns2->num != NUM_DEUX && pns2->num != NUM_TROIS && pns2->num != NUM_QUATRE)
long cr = DYN_OK;
if(pns2->num == FORMAT_LEFT * NUM_FACTEUR)
{
stack_str(e, pns2); // garde le pns2->num ok et cree la var string pns2->str (resultat)
cr = dynFmt(e, pns->str, pns2->str, 'L', *pns3->str->mPtr, pns4->num / NUM_FACTEUR);
}
else if(pns2->num == FORMAT_RIGHT * NUM_FACTEUR)
{
stack_str(e, pns2); // garde le pns2->num ok et cree la var string pns2->str (resultat)
cr = dynFmt(e, pns->str, pns2->str, 'R', *pns3->str->mPtr, pns4->num / NUM_FACTEUR);
}
else if(pns2->num == FORMAT_CENTER * NUM_FACTEUR)
{
stack_str(e, pns2); // garde le pns2->num ok et cree la var string pns2->str (resultat)
cr = dynFmt(e, pns->str, pns2->str, 'C', *pns3->str->mPtr, pns4->num / NUM_FACTEUR);
}
else
{
e->exception = EX_FORMAT_KO;
return;
}
//
stack_str(e, pns2); // garde le pns2->num ok et cree la var string pns2->str (resultat)
if(dynFmt(e, pns->str, pns2->str, (pns2->num == NUM_DEUX ? 'L' : (pns2->num == NUM_TROIS ? 'R' : 'C')), *pns3->str->mPtr, pns4->num / NUM_FACTEUR) == DYN_OK)
if(cr == DYN_OK)
{
pns->str = pns2->str;
pns2->str = NULL;
@@ -1294,7 +1306,7 @@ void nfmt(env * e, int fn)
stack_num(e, pns2);
if(e->exception == EX_NOTNUM)
return;
if(pns2->num != NUM_UN)
if(pns2->num != FORMAT_TRIM * NUM_FACTEUR)
{
e->exception = EX_FORMAT_KO;
return;
@@ -1332,7 +1344,7 @@ void nfmt(env * e, int fn)
stack_str(e, pns3);
if(e->exception == EX_NOTNUM)
return;
if(pns2->num != NUM_CINQ)
if(pns2->num != FORMAT_SURROUND * NUM_FACTEUR)
{
e->exception = EX_FORMAT_KO;
return;
@@ -1443,6 +1455,82 @@ void nsearchs(env * e)
}
}
void nsortedsearchf(env * e)
{
if(e != NULL)
{
/* ok pour depiler */
if(e->numstr_stack.read < 3 * sizeof(numstr))
{
/* depassement capacite buffer */
e->exception = EX_BUFOVF;
return;
}
else
{
numstr * pns, * pns2, * pns3;
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));
/* search(var, chaine) */
stack_str(e, pns);
stack_str(e, pns2);
stack_num(e, pns3);
if(e->exception == EX_NOTNUM)
return;
if(pns3->num != SORTEDSEARCH_ASC * NUM_FACTEUR && pns3->num != SORTEDSEARCH_DESC * NUM_FACTEUR)
{
e->exception = EX_SORTEDSEARCH_KO;
return;
}
//
pns->num = dynSortLocateSz(e, pns->str, pns2->str->mPtr, e->sep_field, pns3->num / NUM_FACTEUR, DYN_NONE, DYN_NONE) * NUM_FACTEUR;
pns->str = NULL;
}
}
}
void nsortedsearchs(env * e)
{
if(e != NULL)
{
/* ok pour depiler */
if(e->numstr_stack.read < 4 * sizeof(numstr))
{
/* depassement capacite buffer */
e->exception = EX_BUFOVF;
return;
}
else
{
numstr * pns, * pns2, * pns3, * pns4;
e->numstr_stack.write = e->numstr_stack.read - 4 * sizeof(numstr);
e->numstr_stack.read -= 3 * 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));
pns4 = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.read + 2 * sizeof(numstr));
/* search(var, chaine, fieldnumber) */
stack_str(e, pns);
stack_str(e, pns2);
stack_num(e, pns3);
stack_num(e, pns4);
if(e->exception == EX_NOTNUM)
return;
if(pns4->num != SORTEDSEARCH_ASC * NUM_FACTEUR && pns4->num != SORTEDSEARCH_DESC * NUM_FACTEUR)
{
e->exception = EX_SORTEDSEARCH_KO;
return;
}
//
pns->num = dynSortLocateSz(e, pns->str, pns2->str->mPtr, e->sep_subfield, pns4->num / NUM_FACTEUR, pns3->num / NUM_FACTEUR, e->sep_field) * NUM_FACTEUR;
pns->str = NULL;
}
}
}
void nfldf(env * e)
{
if(e != NULL)
@@ -1775,7 +1863,7 @@ void ntostring(env * e)
numstr * pns;
e->numstr_stack.write = e->numstr_stack.read - sizeof(numstr);
pns = (numstr *)(e->numstr_stack.ptr + e->numstr_stack.write);
/* tostring (utilite ?) */
/* tostring */
stack_str(e, pns);
}
}
@@ -2196,7 +2284,8 @@ void instr_011(env * e)
void instr_012(env * e)
{
/* SUBR */
pointeur ad = e->si - 1;
pointeur ad = e->si - 1; // sauvegarde, pour sauter apres la sub
//
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; }
@@ -2232,6 +2321,7 @@ void instr_012(env * e)
e->si = ad + lgs;
e->v.lg = e->si - e->v.ptr - 1; // ok : e->ptr + e->lg pointe sur le dernier octet de la sub
hashtable_do(e, HASH_WRITE, lg == 0 ? e->ad_var : &e->g, e->nom, &v);
//
}
/* */
void instr_013(env * e)
@@ -2547,13 +2637,17 @@ void instr_028(env * e)
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
/* */
if(e->mode_typeof && e->typeof_ == -1) return; /* derniere var inconnue : mode typeof, continuer en attendant le PSHT */
if(e->mode_typeof && e->typeof_ == VAR_UNDECLARED) return; /* derniere var inconnue : mode typeof, continuer en attendant le PSHT */
/* */
var_search(e, &e->ad_var);
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 */
if(e->mode_typeof)
{
e->typeof_ = VAR_UNDECLARED;
e->exception = OK;
}
return;
}
if(e->ad_var->type == VAR_PARAM)
@@ -2565,7 +2659,7 @@ void instr_028(env * e)
e->typeof_ = e->ad_var->type;
else if(e->exception == EX_NOVAR)
{
e->typeof_ = -1;
e->typeof_ = VAR_UNDECLARED;
e->exception = OK;
}
else
@@ -2608,12 +2702,16 @@ void instr_029(env * e)
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
/* */
if(e->mode_typeof && e->typeof_ == -1) return; /* derniere var inconnue : mode typeof, continuer en attendant le PSHT */
if(e->mode_typeof && e->typeof_ == VAR_UNDECLARED) 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 */
if(e->mode_typeof)
{
e->typeof_ = VAR_UNDECLARED;
e->exception = OK;
}
return;
}
if(e->ad_var->type == VAR_PARAM)
@@ -2623,7 +2721,7 @@ void instr_029(env * e)
e->exception = EX_NAVAR;
if(e->mode_typeof)
{
e->typeof_ = -1;
e->typeof_ = VAR_UNDECLARED;
e->exception = OK;
}
return;
@@ -2646,7 +2744,7 @@ void instr_029(env * e)
e->typeof_ = e->ad_var->type;
else if(e->exception == EX_NOVAR)
{
e->typeof_ = -1;
e->typeof_ = VAR_UNDECLARED;
e->exception = OK;
}
else
@@ -2661,16 +2759,18 @@ void instr_030(env * e)
/* WRIT / echo dans le langage */
if(e->demon)
return; /* en mode "phantom", pas de printf */
if(e->ad_var == NULL)
/* */
var * res = NULL;
ntostring(e); // forcer en chaine
npopv(e, &res); // lire le resultat de l'expression depuis la pile : chaine forcement ici
if(e->exception != OK)
return;
if(res == NULL)
e->exception = EX_NOADVAR;
else
{
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_NUMBER)
printf("%s", NumberToSz(e, e->ad_var->num, NULL, NULL));
else if(e->ad_var->type == VAR_DYNAMIC)
printf("%s", e->ad_var->ptr);
if(res->type == VAR_DYNAMIC)
printf("%s", res->ptr);
else
e->exception = EX_NAVAR;
}
@@ -2679,8 +2779,6 @@ void instr_030(env * e)
void instr_031(env * e)
{
/* WRLN / echonl dans le langage */
if(e->demon)
return; /* en mode "phantom", pas de printf */
instr_030(e);
if(!e->exception)
printf("\n");
@@ -2978,24 +3076,16 @@ void instr_040(env * e)
e->exception = EX_NOADVAR;
return;
}
//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);
//}
/* TODO : si sub, ok, si class, ne pas faire ?? */
/* 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);
}
/* */
void instr_041(env * e)
{
// HLET - A FINIR - ajouter un mode "declarehash" en plus du mode typeof... pour pouvoir creer des vars dans des hash (idem autres types) => PHDH/PIDH
// HLET - PHDH/PIDH pour creer des hash dans des hash
// lit de la pile le modulo et separateur (val. par defaut si 0 au non empile) et cree une hash table
// premier depilage : separateur, deuxieme : modulo. Si pas de 2eme, le premier devient le modulo !
ent64s modulo, separateur = npope(e);
@@ -3267,8 +3357,8 @@ void instr_056(env * e)
1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,10 ,11
@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
@fm,@vm,@svm,@tm,@currfm,@currvm,@number,@dynamic,@empty,@trim,@left,@right,@center,@surround,@asc,@desc
31 ,32 ,33 ,34 ,35 ,36 ,40 ,41 ,42 ,50 ,51 ,52 ,53 ,54 ,55 ,56
*/
char sep[2] = {0};
switch(varsys)
@@ -3418,19 +3508,25 @@ void instr_056(env * e)
npushc(e, VAR_EMPTY); /* type */
break;
case 50:
npushc(e, NUM_UN); /* trim */
npushc(e, FORMAT_TRIM * NUM_FACTEUR); /* trim */
break;
case 51:
npushc(e, NUM_DEUX); /* left */
npushc(e, FORMAT_LEFT * NUM_FACTEUR); /* left */
break;
case 52:
npushc(e, NUM_TROIS); /* right */
npushc(e, FORMAT_RIGHT * NUM_FACTEUR); /* right */
break;
case 53:
npushc(e, NUM_QUATRE); /* center */
npushc(e, FORMAT_CENTER * NUM_FACTEUR); /* center */
break;
case 54:
npushc(e, NUM_CINQ); /* surround */
npushc(e, FORMAT_SURROUND * NUM_FACTEUR); /* surround */
break;
case 55:
npushc(e, SORTEDSEARCH_ASC * NUM_FACTEUR); /* asc */
break;
case 56:
npushc(e, SORTEDSEARCH_DESC * NUM_FACTEUR); /* desc */
break;
}
}
@@ -3646,7 +3742,7 @@ void instr_060(env * e)
strncpy(e->nom, (char *)e->si, lg);
e->si += lg;
/* */
if(e->mode_typeof && e->typeof_ == -1) return; /* derniere var inconnue : mode typeof, continuer en attendant le PSHT */
if(e->mode_typeof && e->typeof_ == VAR_UNDECLARED) return; /* derniere var inconnue : mode typeof, continuer en attendant le PSHT */
/* */
var_search(e, &v);
if(e->exception != OK)
@@ -3654,7 +3750,7 @@ void instr_060(env * e)
if(e->mode_typeof)
{
e->exception = OK;
e->typeof_ = -1;
e->typeof_ = VAR_UNDECLARED;
}
return; /* pas trouve */
}
@@ -3666,7 +3762,7 @@ void instr_060(env * e)
if(e->mode_typeof)
{
e->exception = OK;
e->typeof_ = -1;
e->typeof_ = VAR_UNDECLARED;
}
return;
}
@@ -3698,7 +3794,7 @@ void instr_060(env * e)
e->typeof_ = e->ad_var->type;
else if(e->exception == EX_NOVAR)
{
e->typeof_ = -1;
e->typeof_ = VAR_UNDECLARED;
e->exception = OK;
}
else
@@ -3769,13 +3865,17 @@ void instr_065(env * e)
{
/* TYPO */
e->mode_typeof = TRUE;
e->typeof_ = 0; /* pour traiter les PVAR/PVAH/PVAI */
e->typeof_ = VAR_NB + 1; /* pour traiter les PVAR/PVAH/PVAI */
}
/* */
void instr_066(env * e)
{
/* PSHT */
npushc(e, e->typeof_ * NUM_FACTEUR);
if(! e->mode_typeof || e->typeof_ > VAR_NB)
e->typeof_ = VAR_UNDECLARED;
/* PSHV sera a suivre, forcement : maj ad_var pour que PSHV soit ok */
e->int_number.num = e->typeof_ * NUM_FACTEUR;
e->ad_var = &e->int_number;
e->mode_typeof = FALSE;
}
/* */
@@ -4682,7 +4782,7 @@ void instr_106(env * e)
e->exception = EX_NOVAR;
return;
}
/* v pointe sur la var dans la hashtable : maj est "directe" si même type, sinon ?? */
/* v pointe sur la var dans la hashtable : maj est "directe" si même type, sinon ? => si NUMBER, convertir en chaine ! => creer une instruction ? */
if(v->type != VAR_DYNAMIC)
{
e->exception = EX_NAVAR;
@@ -5516,14 +5616,13 @@ void instr_121(env * e)
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 */
/* compter le nb d'elem de la hash/objet en cours <ad_var> (equiv. a PVAH/PVAI)
pas de mode "typeof" possible sur HCOU (bloque a la compilation)
*/
/* */
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)
@@ -5531,11 +5630,6 @@ void instr_122(env * e)
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;
@@ -5650,6 +5744,18 @@ void instr_124(env * e)
}
}
/* */
void instr_125(env * e)
{
/* SSRC field */
nsortedsearchf(e);
}
/* */
void instr_126(env * e)
{
/* SSCS field */
nsortedsearchs(e);
}
/* */
/* */
void instr_251(env * e)
{
@@ -5902,7 +6008,7 @@ void (*instr[256])(env * e) = {instr_000,instr_001,instr_002,instr_003,instr_004
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_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_120,instr_121,instr_122,instr_123,instr_124,instr_125,instr_126,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,
@@ -6047,6 +6153,8 @@ void (*instr[256])(env * e) = {instr_000,instr_001,instr_002,instr_003,instr_004
; 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)
; 125 7D SSRC 1 sortedsearch(var) search sorted string in field
; 126 7E SSCS 1 search(var, numField) search sorted string in subfield of the field given
;
; 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
@@ -6370,7 +6478,7 @@ int CreateContext(env ** ctx, int useSignal, int argc, char *argv[])
e->endianess = *(char *)(&endian);
/* */
e->mode_typeof = FALSE;
e->typeof_ = 0;
e->typeof_ = VAR_NB + 1;
/* */
#ifdef UNIX
e->path_sep[0] = '/';
+19 -4
View File
@@ -87,9 +87,9 @@ enum {
VAR_OBJECT = 7, /* idem hashtable mais en objet : seule diff. element "_class" cree dans la table (interne) */
VAR_BUFFER = 8, /* usage interne : pile calcul + pile appel sub (autre ? buffer circulaire ptr read/write) */
VAR_NB = 8,
VAR_EMPTY = 0, /* retour @empty */
VAR_EMPTY = 0, /* retour @empty fonction type(expr) */
VAR_UNDECLARED = -1,
VAR_UNDECLARED = 0, /* cas de retour si pas de var dans "typeof var1.var2.var3" */
WCP_WIN1252 = 1252,
WCP_8859_1 = 28591,
@@ -253,7 +253,8 @@ enum {
EX_CHILD_FORK = 38, /* erreur de fork sur nouveau process */
EX_CHILD_EXEC = 39, /* erreur execution nouveau process */
EX_ZERO_FOR_INCR = 40, /* erreur increment a zero dans une boucle foreach numerique */
EXNB = 40 /* MEMO !!!! */
EX_SORTEDSEARCH_KO = 41, /* erreur de parametre (type de tri incorrect) */
EXNB = 41 /* MEMO !!!! */
};
typedef struct {
@@ -362,6 +363,20 @@ enum {
CMP_FOR = 10
};
enum {
FORMAT_TRIM = 1,
FORMAT_LEFT = 2,
FORMAT_RIGHT = 3,
FORMAT_CENTER = 4,
FORMAT_SURROUND = 5
};
enum {
SORTEDSEARCH_NONE = 0,
SORTEDSEARCH_ASC = 1, // = DYN_SORT_ASC
SORTEDSEARCH_DESC = 2 // = DYN_SORT_DESC
};
#define GUV_CLASS "_class"
#define GUV_BINADDR "_binaddr"
#define GUV_LOCAL "_local"
@@ -375,7 +390,7 @@ enum {
#define GUV_BIN "_bin"
#define GUV_WDIR "_wdir"
#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"
#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,@asc,@desc;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,55,56"
#include "global.h"
+286 -51
View File
@@ -2,7 +2,7 @@
__ __ __
\ \/ \/ / W language
\ /\ /
\/ \/ Copyright 2024 lanisys.fr
\/ \/ Copyright 2024-2026 lanisys.fr
This file is part of W language.
@@ -47,69 +47,253 @@ reste: (1,1,#00-#FF) ;11; 1,1,00-FF
[] est remplace par () car cela revient au meme !
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "langage.h"
#include "dynamic.h"
#include "lex.h"
// force exporting
#ifdef WINLIB
#undef WAPIDECL
#define WAPIDECL __declspec(dllexport)
#else
#undef WAPIDECL
#define WAPIDECL
#endif
static struct {
long blanc, nomregle, debut, fin, occ, infini, commentaire, intervalle, hexa, car, reste;
} rlex;
static long rg_lex(env * e, Dynamic * regles, char * nom, Dynamic * tmp)
{
// renvoie le numero de la regle a partir de son nom, 0 si non trouvee ou erreur conversion en numerique
long pos = dynLocateSz(e, regles, nom, ',', 1, 10);
if(pos > 0)
{
dynField(e, regles, tmp, 1, pos + 1, 10, ',', 1);
pos = dynToNum(e, tmp, DYN_FALSE, 5); // pas de signe et num regle sur 16 bits : 5 chiffres
if(tmp->mInternal != DYN_OK)
pos = 0;
}
return pos;
}
WAPIDECL void init_reg_lex(env * e, Dynamic * regles, Dynamic * tmp)
{
rlex.blanc = rg_lex(e, regles, "blanc", tmp); // 1
rlex.nomregle = rg_lex(e, regles, "nomregle", tmp); // 2
rlex.debut = rg_lex(e, regles, "debut", tmp); // 3
rlex.fin = rg_lex(e, regles, "fin", tmp); // 4
rlex.occ = rg_lex(e, regles, "occ", tmp); // 5
rlex.infini = rg_lex(e, regles, "infini", tmp); // 6
rlex.commentaire = rg_lex(e, regles, "commentaire", tmp); // 7
rlex.intervalle = rg_lex(e, regles, "intervalle", tmp); // 8
rlex.hexa = rg_lex(e, regles, "hexa", tmp); // 9
rlex.car = rg_lex(e, regles, "car", tmp); // 10
rlex.reste = rg_lex(e, regles, "reste", tmp); // 11
}
WAPIDECL long parse_lex(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic * trav, Dynamic * encours)
{
#define nreg(x) ((x)*2 > trav->mLg ? 0 : *(ent16 *)(trav->mPtr + (x)*2 - 2))
/* */
static int numlig = 0;
numlig++;
/* */
if(valex->mLg == 0)
return OK; /* ligne vide */
/* */
int nbres = dynDcount(e, resultat, 10, DYN_NONE, DYN_NONE);
int nbval = dynDcount(e, valex, cVM, 2, cFM);
ent16 regle;
dynSetLen(e, trav, 0);
dynSetLen(e, encours, 0);
for(int ival = nbval; ival > 0; ival--)
{
/* suppression des regles 1 et 7 (blanc et commentaire) */
dynField(e, valex, tmp, 2, ival, cFM, cVM, 1);
regle = dynToNum(e, tmp, DYN_FALSE, 0);
if(regle == rlex.blanc || regle == rlex.commentaire)
{
dynDel(e, valex, 1, ival, cFM, cVM, 1);
dynDel(e, valex, 2, ival, cFM, cVM, 1);
dynDel(e, valex, 3, ival, cFM, cVM, 1);
}
else
{
if(dynCtrl(e, trav, trav->mLg + 2, TRUE) != DYN_OK)
return DYN_ERR;
if(trav->mLg > 0)
memcopie(trav->mPtr + 2, trav->mPtr, trav->mLg);
*(ent16 *)(trav->mPtr) = regle;
dynSetLen(e, trav, trav->mLg + 2);
}
}
//dynDel(e, valex, 2, DYN_NONE, cFM, DYN_NONE, 1);
if(trav->mLg == 0)
return OK; /* blancs et/ou commentaire seuls */
/* */
//for(int i=1;i<=trav->mLg/2;i++) printf("%d,",nreg(i)); printf("\n");
/* debut d'analyse des tokens : nomregle */
if(nreg(1) != rlex.nomregle)
{
dynField(e, valex, tmp, 3, 1, cFM, cVM, 1);
printf("Erreur ligne %dc%s : nom regle attendu\n", numlig, tmp->mPtr);
return DYN_ERR;
}
/* liste de et/ou */
for(ent16 n = 2;;)
{
if((regle = nreg(n)) == 0)
break;
/* */
if(regle == rlex.debut || regle == rlex.car) ; else
{
dynField(e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : car ou debut et/ou attendu\n", numlig, tmp->mPtr);
return DYN_ERR;
}
/* et */
if(n == 2)
dynStoreSz(e, valex, 4, DYN_NONE, "", 0, cFM, DYN_NONE);
else
dynConcatSz(e, valex, ";", 1);
/* */
if(regle == rlex.car)
{
/* 1 caractere = (1,1,car) (raccourci d'ecriture) */
dynConcatSz(e, valex, "1,1,", 4);
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
dynConcat(e, valex, tmp);
n++;
continue;
}
if(nreg(n+1) == rlex.occ && (nreg(n+2) == rlex.occ || nreg(n+2) == rlex.infini)) ; else
{
dynField(e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : occurence min/max attendue %d\n", numlig, tmp->mPtr, n);
return DYN_ERR;
}
n++;
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
dynIconv(e, tmp, encours, "X");
dynConcat(e, valex, encours); // occmin
n++;
if(nreg(n) == rlex.infini)
dynConcatSz(e, valex, "-1,", 3);
else
{
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
dynIconv(e, tmp, encours, "X");
dynConcat(e, valex, encours); // occmax
}
ent16 n1,n2,n3; char unefois[2] = {0};
n1 = nreg(n+1);
n2 = nreg(n+2);
n3 = nreg(n+3);
while(n1 == rlex.car || n1 == rlex.hexa || ((n1 == rlex.car || n1 == rlex.hexa) && n2 == rlex.intervalle && (n3 == rlex.car || n3 == rlex.hexa)))
{
dynConcatSz(e, valex, unefois, DYN_LGNONE);
if((n1 == rlex.car || n1 == rlex.hexa) && n2 == rlex.intervalle && (n3 == rlex.car || n3 == rlex.hexa))
{
n++;
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
if(n1 == 10)
dynConcat(e, valex, tmp);
else
{
dynIconv(e, tmp, encours, "X");
dynConcatSz(e, valex, encours->mPtr + 1, DYN_LGNONE); // copier apres le #
}
dynConcatSz(e, valex, "-", 1);
n += 2;
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
if(n3 == rlex.car)
dynConcat(e, valex, tmp);
else
{
dynIconv(e, tmp, encours, "X");
dynConcatSz(e, valex, encours->mPtr + 1, DYN_LGNONE); // copier apres le #
}
}
else if(n1 == rlex.car)
{
n++;
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
dynConcat(e, valex, tmp);
}
else if(n1 == rlex.hexa)
{
n++;
dynField(e, valex, tmp, 1, n, cFM, cVM, 1);
dynIconv(e, tmp, encours, "X");
dynConcatSz(e, valex, encours->mPtr + 1, DYN_LGNONE); // copier apres le #
}
n1 = nreg(n+1);
n2 = nreg(n+2);
n3 = nreg(n+3);
unefois[0] = ':';
}
if(unefois[0] == 0)
{
dynField(e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : caractere/intervalle attendu\n", numlig, tmp->mPtr);
return DYN_ERR;
}
if(n1 == rlex.fin) ; else
{
dynField(e, valex, tmp, 3, n, cFM, cVM, 1);
printf("Erreur ligne %dc%s : fin et/ou attendue\n", numlig, tmp->mPtr);
return DYN_ERR;
}
n += 2;
}
/* lecture nom regle en hexa */
dynField(e, valex, tmp, 1, 1, cFM, cVM, 1);
dynIconv(e, tmp, trav, "X");
trav->mPtr[trav->mLg - 1] = ','; /* exemple : begin,1,comment,2,... permet de faire un locate */
dynConcatSz(e, trav, Int64ToSz(e, nbres == 0 ? 1 : nbres, DYN_FALSE, 0), DYN_LGNONE);
dynStore(e, resultat, 1, nbres == 0 ? 1 : nbres*2-1, trav, 10, ',');
/* */
dynField(e, valex, tmp, 4, DYN_NONE, cFM, DYN_NONE, 1);
nbres = (nbres == 0 ? 2 : nbres + 1);
dynStoreSz(e, resultat, nbres, DYN_NONE, tmp->mPtr, tmp->mLg, 10, DYN_NONE);
/* */
#undef nreg
return OK;
}
#include "lex_files.h"
long regles_lex(env * e, Dynamic * r)
WAPIDECL long lire_regles_lex(env * e, Dynamic * regles, char * fichier_lex)
{
dynLet(e, r, "", 0);
dynConcatSz(e, r, "blanc,1,nomregle,2,debut,3,fin,4,occ,5,infini,6,commentaire,7,intervalle,8,hexa,9,car,10,reste,11\n", DYN_LGNONE);
dynConcatSz(e, r, "1,-1,20:09\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,61-7A;0,-1,30-39:61-7A;1,1,3A\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,28\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,29\n", DYN_LGNONE);
dynConcatSz(e, r, "1,9,30-39;1,1,2C\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,2A;1,1,2C\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,3B;0,-1,09-7E\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,2D\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,23;2,2,30-39:41-46\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,21-7E\n", DYN_LGNONE);
dynConcatSz(e, r, "1,1,00-FF", DYN_LGNONE);
return DYN_OK;
}
//
long lire_regles_lex(env * e, Dynamic * regles, char * fichier_lex)
{
long cr;
long cr = DYN_ERR;
if(fichier_lex != NULL)
{
/* selon fichier_lex, lire directement depuis le source */
if(strncmp(fichier_lex, "debuglex", 8) == 0)
{
if(*file_debuglex == 0)
#ifdef WINLIB
cr = dynRead(e, regles, "C:\\Users\\Poupougne42\\source\\repos\\win_w_src\\lex\\debuglex"); // lire les regles depuis le fichier sur disque
#else
cr = dynRead(e, regles, "/etc/wlanguage/debuglex"); // lire les regles depuis le fichier sur disque
#endif
else
cr = dynLet(e, regles, file_debuglex, DYN_LGNONE);
cr = dynLet(e, regles, file_debuglex, DYN_LGNONE);
}
else if(strncmp(fichier_lex, "wlex", 4) == 0)
{
if(*file_wlex == 0)
#ifdef WINLIB
cr = dynRead(e, regles, "C:\\Users\\Poupougne42\\source\\repos\\win_w_src\\lex\\wlex"); // lire les regles depuis le fichier sur disque
#else
cr = dynRead(e, regles, "/etc/wlanguage/wlex"); // lire les regles depuis le fichier sur disque
#endif
else
cr = dynLet(e, regles, file_wlex, DYN_LGNONE);
cr = dynLet(e, regles, file_wlex, DYN_LGNONE);
}
else if(strncmp(fichier_lex, "lexlex", 6) == 0)
{
cr = dynLet(e, regles, file_lexlex, DYN_LGNONE);
}
else
cr = dynRead(e, regles, fichier_lex); // lire les regles depuis le fichier sur disque
}
else
cr = regles_lex(e, regles); // par defaut, charger les regles lex des fichiers "lex" (?!)
//
if(cr == DYN_OK)
{
dynErase(e, regles, "\r"); /* nettoyage au cas ou fichier Windows */
//dynDel(e, regles, 1, DYN_NONE, 10, DYN_NONE, 1); /* la premiere ligne contient le <numero,nom> des regles, separe par "," */
}
//dynErase(e, regles, "\r"); /* nettoyage au cas ou fichier Windows */
return cr;
}
//
long concorde_h(env * e, Dynamic * chaine, Dynamic * regle, Dynamic * elem, Dynamic * detail)
static long concorde_h(env * e, Dynamic * chaine, Dynamic * regle, Dynamic * elem, Dynamic * detail)
{
long conc = 1, lgconc = 0, fin = FALSE, ichaine = 0, nch, t1, t2, trouve;
long occmin, occmax, occtrouve, occsuiv;
@@ -208,8 +392,8 @@ long concorde_h(env * e, Dynamic * chaine, Dynamic * regle, Dynamic * elem, Dyna
conc = lgconc;
return conc;
}
//
void lex(env * e, Dynamic * regles, Dynamic * saisie, Dynamic * valex)
WAPIDECL void lex(env * e, Dynamic * regles, Dynamic * saisie, Dynamic * valex)
{
/* vars Dynamic :
regles (en entree) : liste des regles ; etregle : regle ET en cours
@@ -361,6 +545,57 @@ void lex(env * e, Dynamic * regles, Dynamic * saisie, Dynamic * valex)
dynFree(e, &motencours);
dynFree(e, &trouvemot);
}
WAPIDECL long compile_lex(env * e, Dynamic * fichier_lex, Dynamic * compile)
{
// "compile" les regles lex fournies dans <fichier_lex> et renvoi le resultat dans <compile>
// <1> = nom et numeros des regles, <2> a <n> = regles lex
long cr = DYN_OK, ret = 0;
Dynamic regles, tmp, ligne, tmp1, tmp2, tmp3;
//
dynInit(e, &regles, 0);
dynInit(e, &tmp, 0);
dynInit(e, &ligne, 0);
dynInit(e, &tmp1, 0);
dynInit(e, &tmp2, 0);
dynInit(e, &tmp3, 0);
//
dynSetLen(e, compile, 0);
//
cr = lire_regles_lex(e, &regles, "lexlex"); // <regles> = regles lex compiles
if(cr == DYN_OK)
{
init_reg_lex(e, &regles, &tmp);
dynErase(e, fichier_lex, "\r");
dynRemove(e, fichier_lex, NULL, 0, DYN_TRUE);
while(dynRemove(e, fichier_lex, &ligne, 10, DYN_FALSE) > -1 && ret == 0)
{
lex(e, &regles, &ligne, &tmp); // tmp au format "valex" : chaine/noregle/position
ret = parse_lex(e, &tmp, compile, &tmp1, &tmp2, &tmp3);
}
if(ret != 0)
cr = DYN_ERR;
}
//
dynFree(e, &regles);
dynFree(e, &tmp);
dynFree(e, &ligne);
dynFree(e, &tmp1);
dynFree(e, &tmp2);
dynFree(e, &tmp3);
//
return cr;
}
/*
pour utiliser lex :
- compiler les regles 1 fois : compile_lex(e, regles, compile)
- analyser du contenu : lex(e, compile, contenu, valex)
le resultat est dans valex : <1> chaine hexa en VM, <2> no regle en VM, <3> position origine contenu en VM
le nom de la regle <no regle> se trouve comme cela : dynField(e, compile, nom, 1, noregle*2-1, 10, ',', 1)
la conversion en clair de la chaine hexa trouvee : dynIconv(e, hexa, clair, "X");
*/
/* source OK :
* LEX.REGLE = regles Lex, valeurs ET separees par "," ; liste de cars en OU pour chaque partie ET
LEX.REGLE = ""
+38
View File
@@ -0,0 +1,38 @@
/* **********************************************
__ __ __
\ \/ \/ / 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/>.
********************************************** */
#ifndef LEX_H
#define LEX_H
#include "apidecl.h"
/* utilise par genlex */
WAPIDECL void init_reg_lex(env * e, Dynamic * regles, Dynamic * tmp);
WAPIDECL long parse_lex(env * e, Dynamic * valex, Dynamic * resultat, Dynamic * tmp, Dynamic * trav, Dynamic * encours);
/* */
WAPIDECL long lire_regles_lex(env * e, Dynamic * regles, char * fichier_lex);
WAPIDECL void lex(env * e, Dynamic * regles, Dynamic * saisie, Dynamic * valex);
WAPIDECL long compile_lex(env * e, Dynamic * fichier_lex, Dynamic * compile);
#endif
+168
View File
@@ -0,0 +1,168 @@
/* **********************************************
__ __ __
\ \/ \/ / 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 "lex.h"
typedef struct {
int error; // dernier code erreur specifique au module
//*** a completer selon le besoin du module
} modEtat;
/* mettre ici les codes d'erreurs specifiques au module */
/* codes a passer a la fonction setError */
#define EXMOD_COMPILE -1
static int setError(modEtat * p, int err)
{
if(p != NULL)
p->error = err;
return err == OK ? OK : EX_MODERR;
}
#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 ** );
#endif
long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
{
modEtat * p_etat;
long exc = OK;
// init/end/vers/error sont obligatoires pour tout module
// - - - - - - - - - - - - - - - - - - - -
if(etat == NULL)
return EX_MODPARAM;
else
p_etat = (modEtat *)(*etat); /* evite de la faire a chaque fonction */
//
if(param1 != NULL)
if(param1->type == VAR_PARAM)
param1 = (var *)param1->ptr; /* evite de le faire a chaque fonction */
if(param2 != NULL)
if(param2->type == VAR_PARAM)
param2 = (var *)param2->ptr; /* evite de le faire a chaque fonction */
if(param3 != NULL)
if(param3->type == VAR_PARAM)
param3 = (var *)param3->ptr; /* evite de le faire a chaque fonction */
//
/* ----------------------------------------------------------------------------------------------- */
/* les 4 fonctions suivantes doivent toujours exister dans chaque module */
if(modFnIs(e, "init", 4))
{
// alloc ptr sur zone memoire pour memoriser l'etat du module
*etat = memalloc(e, sizeof(modEtat));
if(*etat == NULL)
exc = EX_MODETAT;
else
{
p_etat = (modEtat *)(*etat);
p_etat->error = 0;
//*** code specifique ici
//
}
}
else if(modFnIs(e, "end", 3))
{
//*** code specifique ici
//
// liberation specifique au module avant arret process
if(p_etat != NULL)
memfree(e, p_etat);
}
else if(modFnIs(e, "vers", 4))
{
if(param1 == NULL)
exc = EX_MODPARAM;
else
{
// renvoie la version du module/plugins
if(param1->type == VAR_DYNAMIC)
dynLet(e, param1, "1", 1); //*** version en alpha
else if(param1->type == VAR_NUMBER)
param1->num = NUM_UN; //*** version en numerique
else
exc = EX_MODPARAM; // variable en parametre du mauvais type
}
}
else if(modFnIs(e, "error", 5))
{
// renvoie la derniere erreur specifique au module
if(p_etat == NULL)
exc = EX_MODETAT;
else if(param1 == NULL)
exc = EX_MODPARAM;
else
{
if(param1->type == VAR_NUMBER)
param1->num = (ent64)(NUM_FACTEUR * p_etat->error);
else
exc = EX_MODPARAM; // bad type of parameter
}
}
/* ============================================================================================= */
else if(modFnIs(e, "compile", 7))
{
// 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
{
exc = setError(p_etat, compile_lex(e, param1, param2));
}
}
/* ============================================================================================= */
else if(modFnIs(e, "analyze", 7))
{
// 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) // rules
exc = EX_MODPARAM;
else if(param2->type != VAR_DYNAMIC) // input
exc = EX_MODPARAM;
else if(param3->type != VAR_DYNAMIC) // result
exc = EX_MODPARAM;
else
{
lex(e, param1, param2, param3);
}
}
/* ----------------------------------------------------------------------------------------------- */
else
{
setError(p_etat, 0); // evite un warning de compil
exc = EX_MODFUNC; // fonction non prise en charge
}
//
return exc;
}
+41 -5
View File
@@ -1,8 +1,44 @@
//static char file_debuglex[] = "";
// !! ne pas mettre de caracteres \r dans les constantes ci-dessous !!
// fichiers lex
static char file_lexlex[] = "blanc,1,nomregle,2,debut,3,fin,4,occ,5,infini,6,commentaire,7,intervalle,8,hexa,9,car,10,reste,11\n"
"1,-1,20:09\n"
"1,1,61-7A;0,-1,30-39:61-7A;1,1,3A\n"
"1,1,28\n"
"1,1,29\n"
"1,9,30-39;1,1,2C\n"
"1,1,2A;1,1,2C\n"
"1,1,3B;0,-1,09-7E\n"
"1,1,2D\n"
"1,1,23;2,2,30-39:41-46\n"
"1,1,21-7E\n"
"1,1,00-FF";
// debugger w
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";
"1,-1,20:09:0A:0D\n"
"1,2,61-7A:41-5A\n"
"1,1,3F\n"
"1,9,30-39\n"
"1,1,2B\n"
"1,1,2D\n"
"1,1,3A;1,1,61-7A:41-5A:5F;0,23,61-7A:41-5A:30-39\n"
"1,1,2E;1,1,61-7A:41-5A;0,23,61-7A:41-5A:30-39\n"
"1,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,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";
// langage W
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,sortedsearch,60,"
"change,61,format,62,insert,63,remove,64,tonum,65,tostring,66,equal,67,diff,68,gt,69,lt,70,gte,71,lte,72,and,73,or,74,not,75,beginpar,76,endpar,77,beginh,78,endh,79,begins,80,ends,81,indirect,82,typeof,83,stringdq,84,stringq,85,ident,86,varsys,87,numberdec,88,numberint,89,minus,90,"
"plus,91,multiply,92,divide,93,divident,94,modulo,95,concat,96,listesep,97,identsep,98,modsep,99,other,100"
"\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\n"
"1,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\n"
"1,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\n"
"1,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\n"
"1,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\n"
"1,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\n"
"1,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,73;1,1,6F;1,1,72;1,1,74;1,1,65;1,1,64;1,1,73;1,1,65;1,1,61;1,1,72;1,1,63;1,1,68\n"
"1,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\n"
"1,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,74;1,1,79;1,1,70;1,1,65;1,1,6F;1,1,66\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\n"
"1,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";
+1 -2
View File
@@ -41,7 +41,7 @@ static int setError(modEtat * p, int err)
{
if(p != NULL)
p->error = err;
return EX_MODERR;
return err == OK ? OK : EX_MODERR;
}
#ifdef WINLIB
@@ -51,7 +51,6 @@ __declspec(dllexport) long execModule(env * , var * , var * , var * , void ** );
long execModule(env * e, var * param1, var * param2, var * param3, void ** etat)
{
/* TODO : gestion des 3 parametres (au lieu d'un seul) */
modEtat * p_etat;
long exc = OK;
// init/end/vers/error sont obligatoires pour tout module
+14 -10
View File
@@ -120,11 +120,11 @@ WAPIDECL int varptrtbl_ctrl(env * e, var * v)
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.
v[1] = nb, v[2] = ad var param, v[3] = ptr de la var param, v[4] = ad var param2, etc.
*/
pointeur * beg = (pointeur *)e->varptrtbl.ptr;
ent64 nb = *((ent64 *)beg); // ok si sizeof(pointeur) = sizeof(ent64)
pointeur * curr = ++beg;
pointeur * curr = beg + 2;
while(nb--)
if((pointeur *)(*curr) == (pointeur *)v->ptr)
return TRUE; // deja existant
@@ -134,7 +134,7 @@ WAPIDECL int varptrtbl_ctrl(env * e, var * v)
return FALSE;
}
WAPIDECL void varptrtbl_add(env * e, var * v)
WAPIDECL void varptrtbl_maj(env * e, var * v)
{
// ajoute a e->varptrtbl la var si de type "pointeur" : VAR_PARAM, objet...
if(v == NULL)
@@ -143,15 +143,19 @@ WAPIDECL void varptrtbl_add(env * e, var * v)
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.
v[1] = nb, v[2] = ad var param, v[3] = ptr de la var param, v[4] = ad var param2, 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
if((pointeur *)(*curr) == (pointeur *)v)
{
curr++;
*curr = (pointeur)v->ptr;
return; // deja existant : maj ptr vraie var
}
else
curr += 2;
// pas trouve : ajout a la fin
@@ -160,14 +164,14 @@ WAPIDECL void varptrtbl_add(env * e, var * v)
beg = (pointeur *)e->varptrtbl.ptr; // au cas ou realloc memoire
*((ent64 *)beg) = addnb;
curr = beg + addnb * 2;
*curr-- = (pointeur)v;
*curr = (pointeur)v->ptr;
*curr-- = (pointeur)v->ptr;
*curr = (pointeur)v;
}
}
WAPIDECL void varptrtbl_del(env * e, var * v)
{
// supprime de e->varptrtbl la var v
// supprime de e->varptrtbl la var param v
if(v == NULL)
return;
/*
@@ -179,7 +183,7 @@ WAPIDECL void varptrtbl_del(env * e, var * v)
pointeur * curr = ++beg;
ent64 savnb = nb;
while(nb--)
if((pointeur *)(*curr) == (pointeur *)v->ptr)
if((pointeur *)(*curr) == (pointeur *)v)
{
// trouve : mettre le dernier a la place de celui en cours, sauf si c'est le dernier
*((ent64 *)beg) = savnb - 1;
+1 -1
View File
@@ -31,7 +31,7 @@ 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_maj(env * e, var * v);
WAPIDECL void varptrtbl_del(env * e, var * v);
/* ********************************************** */