Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

harder problem i encountered

53 views
Skip to first unread message

fir

unread,
May 5, 2022, 6:38:05 AM5/5/22
to
back then i wrote code which i found initially silly (it was taken
becouse i found some text on it (i mean compilng expressions with operators and parenthesis ) herdly readable and i wanted something quick

now when i run it i found it quite okay in some sense, what it is
it is a machine that treats expression as data it takes something like

(a*b+c*d)/e

as an input and reduce operator exchanging a*b into t1
and emiting "mov eax (a); mul eax (b); mov (t1) eax;"

(t1+c*d)/e //emit "mov eax (a); mul eax (b); mov (t1) eax;"
and so on
(t1+t2)/e //emit "mov eax (c); mul eax (d); mov (t2) eax;"
(t3)/e //emit "mov eax (t1); mul eax (t2); mov (t3) eax;"
t3/e
t4 //emit emit "mov eax (t3); mul eax (e); mov (t4) eax;"

and done (i may add any operators easily to this also)

yesterday i also added reduction for t[a] which puts t(N) and emits what
it need to emit

the code looks like that

void compile_expression_particule(chunks atoms)
{
temp_register = 1;
for(;;)
{
while( reduce_operator(atoms, '/'));
while( reduce_operator(atoms, '*'));
while( reduce_operator(atoms, '-'));
while( reduce_operator(atoms, '+'));
while( reduce_operator2(atoms, Chunk("<or>")));
while( reduce_operator2(atoms, Chunk("<and>")));
while( reduce_operator2(atoms, Chunk("<xor>")));
//.. may have more here

while( reduce_unefective_parentheses(atoms));
while( reduce_mellow_array_acces(atoms));

int live = CountStillexistingAtomsInExpression(atoms);

if(live==1) break;
}

it has some problem becouse it reducess all divisions until cann then reduces all multiplies until cann etc (problem is it not resolves div and mul in equal priority from left to right so the result is other than in c, but i find it as a problem i may resolve later)

worse problem i encountered is thet that i only used it in that form as above and it i get such expression

x = (a*b+c*d)/e

tle liftside i just take by if cut it to (a*b+c*d)/e and assign result to x
("mov eax (t_n); mov (x) t_n;")

problem is i need to get it more general able to reduce such things as
t[ (x*y+1*2)/f ] = (a*b+c*d)/e
and on this level of exhaustion i cannot focus enough...on some level of exhaustion tocus qualities drop down and also practical errors when
implementing rise up

does maybe someone who is less tired see what based on this code above should i add to be able to compile such more general form?



fir

unread,
May 5, 2022, 10:39:49 AM5/5/22
to
maybe lets think whay would happan if i would treat = as an normal operator to be reduced, maybe thats the way (obviously this pack of loops abowe as i said reduces things in wrong, almost random, order but as i said i dont wory for now for that)
generally when i reduce particule it yealds as i said to stream of t1 t2 t3 t4 t5... variables, what i return is generally hold in eax but in fact when i would need to save to that last t-somthing., i colud..though this probably has no sense
well if i would have a=2 it seems i should modify the sheme mov eax (left), op eax (right), mov (tN ) eax
into mov eax left, mov ebx (right), mov (eax) ebx
but what in case i get tab[i]=a.. i couldnt reduce tab[i] to tN value so maybe i should ad special reducing routine that treats tab[i]=x as a whole?
i get a bit weary and in taht state slements dont stick that well in my hed..its common case obviously..someone needs to force himself to rest it seems

fir

unread,
May 5, 2022, 5:31:24 PM5/5/22
to
the assign operator i added and it seem to work, the a[b]=c reduction i wrote but not even tested getting to weary... good scheme for work for me seem to be intense 2-3 weeks and then a longer break (asm i wrote in one such session in 2017 iirc later added sse mnemonics in shorter one in 2018 iirc) furia i began in one such session in 2019 now it was second in 2022.. so it maybe seems i need to break few months again...geel free to continue your talk

fir

unread,
May 7, 2022, 4:33:33 AM5/7/22
to
czwartek, 5 maja 2022 o 16:39:49 UTC+2 fir napisał(a):
> czwartek, 5 maja 2022 o 12:38:05 UTC+2 fir napisał(a):

in fact this topic is a mess, i stopped coding for 2 days becouse of this cognitive drop down
but i feel like im bori9ng so maybe yet will try to mend it a bit

i wonder if i turn this into

again:
ReduceMulsAndDivs1Pass(); //like a*b*(c+d) -> t1*(c+d)
ReduceAddsAndSubbs1Pass(); // like t1*(c+d) -> t1*(t2)
int pr = ReduceUneffectiveParenthesis // t1*t2
if(pr) goto again:

will be generall it is not ships something

i need to add yet this assign reduction, array acces and array assign, how?
array accec (i mean reduction for read) i could do when ready ,
say
frame_bitmap[4*(mouse_x+frame_size_x*mouse_y)]*b*(c+d)
after that loop will be
frame_bitmap[4*(mouse_x+t1)]*b*(c+d)
frame_bitmap[4*(t2)]*b*(t3)
frame_bitmap[4*t2]*b*t3
frame_bitmap[t4]*t5 //cant go
so reduce array acces
i see some problem
becouse if i would have
frame_bitmap[t4]*t5+6 the code will add sum before i would be able to reduce multiply

doeas this mean this method is wrong, can be easy repaired and i need do domething other
this is found final nested parenthesis and firstly reduce them with the assumption there is no more parenthesis in it? seems so
0 new messages