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

furia (fir's proto-c compiler)

187 views
Skip to first unread message

fir

unread,
Apr 19, 2022, 5:00:34 PM4/19/22
to
I dont remember if i already wrote on this and how

Last year i practically was not coding spending my time for more like sociology thinking and being sick.. I wonder if not to get back for coding few days, though i must say my eyesight noticably get worse and this is unexpected problem, if letters 'blur' (though blur is not proper word maybe, its more like overlap shifted images maybe) from a meter or so it makes coding much troublesome and i feel pain

hovever recently i wrote elements of my compiler, it takes for now such form of proto-c as i call it...i mean i only take that kind of expression which is extremly easy to translate to assembly (and assembly i assemble with my own assembler)

so it is like thet for example

int mouse_x = 0
int mouse_y = 0

void ProcessMouseMove()
asm mov eax (esp+4);
asm mov (mouse_x) eax;
asm mov eax (esp+8);
asm mov (mouse_y) eax
return


int last_key_pressed = 0
int PAGE_UP = 33

void ProcessKeyDown()
asm mov eax (esp+4);
asm mov (last_key_pressed) eax
if last_key_pressed = PAGE_UP
cdecl "green_fire.dll" ToggleFullscreen()
end
return



void RunFrame()
int background_color = 0

background_color = background_color + 1
cdecl "green_fire.dll" ClearFrameData(background_color);

int r = 10
for r from 10 to 250 step 3
cdecl "green_fire.dll" DrawCircle( mouse_x, mouse_y, r, 0xff00);
end
cdecl "green_fire.dll" DrawSomeText2( 0xffffff, 10, 30, "this app is compiled by furia \x00");
cdecl "green_fire.dll" DrawSomeText2( 0xffffff, 30, 130, "mouse %d %d\x00", mouse_x, mouse_y);
return

void OnResize()
return


void main()
cdecl "green_fire.dll" RegisterRunFrame( &RunFrame );
cdecl "green_fire.dll" RegisterMouseMove( &ProcessMouseMove );
cdecl "green_fire.dll" RegisterKeyDown( &ProcessKeyDown );
cdecl "green_fire.dll" RegisterOnResize( &OnResize );
cdecl "green_fire.dll" SetSleepValue(30)
cdecl "green_fire.dll" SetScaleOnResize(1)
cdecl "green_fire.dll" SetupWindow3(" compiled by fir's furia proto c compiler \x00", 10, 10, 600, 400, 300, 200 );
return

i got a lack ov very fundamental things - one of troublesome things was
the "compilation" (translation to assembly) free-length and free nested of
arithmetic expressions (which may combine ints and floats also logic operators array indexing and more - even simple free arithmetic expresions on ints are troublesome for me)

i got no specific question or topic for discusion for the moment but i post it an possibly i invent some if i get deeper in some problems if i again will wrap my head around it (if thay say that in english)

fir
compiler for test (worx on windows, as i generaty my own exe and i not fulfilled for some PE standards or so some antivirs may raport false alarmn that gnerated exe is a virus..its not)

http://minddetonator.htw.pl/furia11.zip

fir

unread,
Apr 19, 2022, 6:04:21 PM4/19/22
to
i wander what i can add (as this case gives some observations)

i may say that all this stetements are strightforward to translate, some just take statement and flush the piece of asm one by one linearly in one pass... no need to collect data in arrays etc... for and if only needed to store number of if/for met to use when end of for if is met to use it in flushed piece of asm (in case of for also limit of counting and step also noted

what i think is what else i could add in that very simple stream-lined approach.. i need to think what else could be added

it also makes thinking in this more complex design in languages is kinda justified (needed)..ofc its kinda needed but maybe not so much as some think.. maybe i will try to insight some of it (i mean notice some things a bit more on this - what can be obtained in simple way)

other problem is i woule dlike to code something in halfway between expressions like c=a*b and unlimited nested expressions (not to torment myself with code for compiling the latter), but problem is i cant see what this halfway thing could be

also as expression mix ints and floats it seem it cant go without building a table on the fly what is int and what is float, it is quite easy ofc to build that table but i wonder what can i obtain in most simple way

expressions are pain, so maybe i will code anything else first


fir

unread,
Apr 20, 2022, 1:14:46 PM4/20/22
to
i updated it slightly (put 12 in link)

what i was thinking on it is to make all variables global..it gives nice cut-off of things - on compiler side when you acces variable you just need to emit a piece of assembly that uses given identifier/label and thats all, no wory of anything else..
.hovever this is a problem that you cant repeat local names even like x y or i (unless you declare them global) but for now as to proto c i think its standable

second topic is that imports, right now i precede all imported calls like

cdecl "green_fire.dll" DrawCircle( mouse_x, mouse_y, r, 0xff00);
cdecl "msvcrt.dll" printf(" dipa \x00")
stdcall " user32.dll" MessageBoxA(0,"caption\x00","title\x00",0)

to get rid of it i either would need add import "green_fire.dll" and in compiler code read into this dll build an arrays names it contains and then in my compiled code look up in this array to check what dll it possibly belongs other way is to add

import "green_fire.dll: cdecl name1, cdecl name2, cdecl name3" and this i probably will do, its not perfact but as kinda practical stub i think its standable (allows to compile without presence of dll you compile for)

fir

unread,
Apr 20, 2022, 1:48:42 PM4/20/22
to
incidentally the ftp site i use to upload linx stopped working (i use free one so mayb they cut me off, though it worked for years, i dont know)

Kaz Kylheku

unread,
Apr 20, 2022, 1:59:27 PM4/20/22
to
On 2022-04-20, fir <profes...@gmail.com> wrote:
> i updated it slightly (put 12 in link)
>
> what i was thinking on it is to make all variables global..it gives
> nice cut-off of things - on compiler side when you acces variable you
> just need to emit a piece of assembly that uses given identifier/label
> and thats all, no wory of anything else.. .hovever this is a problem
> that you cant repeat local names even like x y or i (unless you
> declare them global) but for now as to proto c i think its standable

That is false. You can have locally scoped variables that are globally
accessed via names at the assembly language level.

You just have to allocate machine-generated names for them, and map from
the declared names to the machine-generated names.

Have you heard of this declaration specifier called static? E.g

static int x;
{
static int x;


}

this could compile to something like: the outer x is $g0027
and the inner x is $g0028.

The disadvantage of global/static variables isn't that you cannot
reuse names, but that you don't have reentrancy. Even under
simple recursion, you have to save and restore important
variables. (And where to? You need a stack for that.)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

fir

unread,
Apr 20, 2022, 2:16:26 PM4/20/22
to
i dont quite understand what you mean
whay i meen is i that if i make all variables global - even those who are scoped in function body,
and even those who are function arguments, like

int x;
void foo(int y, int z)
{
int w;
}

simply be like
int x;
int y;
int z;
int w;

- this makes nice "cut off" in simplicity of compiler becouse i dont need check literally
nothing ... when i encounted declaration like above i just emit

.data x (int)

(which my assembler just assembles by reserving adres in statioc data section and thats all)
and when i found acces like x=2 i also need to emit just two lines of blind assembly

mov eax 2
mov (x) eax

and dont bother for nothing..it simply makes it dat simple...this is not handy (as it not allows to reuse names) but it ois possible to write programs this way.. one may just declare global int i and reuse it in all loops or sometimes make convention that for example will put functionname_variable name to not make clash (the first just reuse is probably standable as kinda by definition that local names you use in normal c are not meant to preserve value)

as to recursion i dont care it is so rarely used i literally use it once a 10 years and could live without it
(also note im writing proto-c compiler when i realize some stages i will revrite it bot for given 'milestones' i kinda find it interesting to hold to some simplifications - and the question is qhat simplifications are good compromise for very strong simplicity and standable usability)


fir

unread,
Apr 20, 2022, 2:29:14 PM4/20/22
to
as what you probbaly say i know it i may just add functionname__ prefix (making functionname_x) before locals and arguments and in case of compiling x check if functionname_x is present and if so emit functionname_x it is standably easy (its very wasy in fact) but i wanted this "total globalisation" more for sake of it than that i cant handle that prefixing - prefixin i always can do, so its not matter maybe of ding it but the order of doing this...and i need yet to compile that damn nested expressions and some side things i yet not even thinkd

fir

unread,
Apr 20, 2022, 2:38:53 PM4/20/22
to
as those zip links dont work i may put the source it compiles in this example and teh assembly
it generates (if someone would read into it i think it may be somewhat educational )

the proto-c code


void ProcessMouseMove(int mouse_x, int mouse_y)
return

void ProcessKeyDown(int last_key_pressed)
int PAGE_UP = 33
if last_key_pressed = PAGE_UP
cdecl "green_fire.dll" ToggleFullscreen()
end
return

void RollBackgroundColor()
int background_color = 0
background_color = background_color + 1
cdecl "green_fire.dll" ClearFrameData(background_color);
return

void RunFrame()
RollBackgroundColor()
int r = 10
for r from 10 to 250 step 3
cdecl "green_fire.dll" DrawCircle( mouse_x, mouse_y, r, 0xff00);
end
cdecl "green_fire.dll" DrawSomeText2( 0xffffff, 10, 30, "this app is compiled by furia \x00");
cdecl "green_fire.dll" DrawSomeText2( 0xffffff, 30, 130, "mouse %d %d\x00", mouse_x, mouse_y);
return

void OnResize()
return


void main()
cdecl "green_fire.dll" RegisterRunFrame( &RunFrame );
cdecl "green_fire.dll" RegisterMouseMove( &ProcessMouseMove );
cdecl "green_fire.dll" RegisterKeyDown( &ProcessKeyDown );
cdecl "green_fire.dll" RegisterOnResize( &OnResize );
cdecl "green_fire.dll" SetSleepValue(30)
cdecl "green_fire.dll" SetScaleOnResize(1)
cdecl "green_fire.dll" SetupWindow3(" compiled by fir's furia proto c compiler \x00", 10, 10, 600, 400, 300, 200 );
return

emited asm (im my own syntax fpr example by ?? i denote data directive to declare data (i also allowed it to intermix it with code not like some assemblers who keep .code and .data directives in separate)

// this is assembly generated by fir's furia compiler
// at Apr 20 2022 18:46:17
// use organic assembler to assemble it into exe

jmp main

ProcessMouseMove:
?? mouse_x: 0i
mov eax (esp+4)
mov (mouse_x) eax
?? mouse_y: 0i
mov eax (esp+8)
mov (mouse_y) eax

ret



ProcessKeyDown:
?? last_key_pressed: 0i
mov eax (esp+4)
mov (last_key_pressed) eax
?? PAGE_UP: 33i

mov eax (last_key_pressed)
cmp eax (PAGE_UP)
jne __if__0__end

call ("green_fire.dll"->ToggleFullscreen)
__if__0__end:

ret



RollBackgroundColor:
?? background_color: 0i
mov eax (background_color)
add eax 1
mov (background_color) eax

push (background_color)
call ("green_fire.dll"->ClearFrameData)
pop eax

ret



RunFrame:

call RollBackgroundColor
?? r: 10i

// compiling for r from 10 to 250 step 3

mov ecx 10
__for__0__start:
push ecx
mov (r) ecx

push 65280
push (r)
push (mouse_y)
push (mouse_x)
call ("green_fire.dll"->DrawCircle)
pop eax
pop eax
pop eax
pop eax

pop ecx
add ecx 3
cmp ecx 251
jl __for__0__start

?? str_label_0: "this app is compiled by furia \x00"
push str_label_0
push 30
push 10
push 16777215
call ("green_fire.dll"->DrawSomeText2)
pop eax
pop eax
pop eax
pop eax

push (mouse_y)
push (mouse_x)
?? str_label_1: "mouse %d %d\x00"
push str_label_1
push 130
push 30
push 16777215
call ("green_fire.dll"->DrawSomeText2)
pop eax
pop eax
pop eax
pop eax
pop eax
pop eax

ret



OnResize:

ret



main:

push RunFrame
call ("green_fire.dll"->RegisterRunFrame)
pop eax

push ProcessMouseMove
call ("green_fire.dll"->RegisterMouseMove)
pop eax

push ProcessKeyDown
call ("green_fire.dll"->RegisterKeyDown)
pop eax

push OnResize
call ("green_fire.dll"->RegisterOnResize)
pop eax

push 30
call ("green_fire.dll"->SetSleepValue)
pop eax

push 1
call ("green_fire.dll"->SetScaleOnResize)
pop eax

push 200
push 300
push 400
push 600
push 10
push 10
?? str_label_2: " compiled by fir's furia proto c compiler \x00"
push str_label_2
call ("green_fire.dll"->SetupWindow3)
pop eax
pop eax
pop eax
pop eax
pop eax
pop eax
pop eax

ret


fir

unread,
Apr 20, 2022, 4:24:17 PM4/20/22
to
i may yet share some side thought i noticed yesterday (as this is discussion goroup and that thoughts are suitable for discussion groups i think)
what i genarate with thic compilation is a vwry simple assembly, in fact i even could generate allembly that uses only eax ;c (and esp sporadically) no other registers - though i may add some also
this assembly that uses only eax may be overprimitive but eventually i could generate a bit better that uses more registers but still it wouldnt be nothing elabiorate like those heavily optimised assembly outputs that are generated for specific models of x86 family

the quesrtion is if people SHOULD generate such elaborate optimised assembly outputs..in fact it seem to me that most probably NO...assembly should be imo rather most clean and strightforward and if talking of optimisation it could be rather more for size (shortnmess( and clarity

its probably cpu designers that should optimise, the fact that compiler optimise in different ways for different mnodels is rather fault (not that i bother on details how it today look assembly level of cpus, 20 years ago it seemd interesting to me but now seem things seem to changed..kinda sad as this golden era computing i remember the best)

bart c

unread,
Apr 21, 2022, 9:11:19 AM4/21/22
to
On Tuesday, 19 April 2022 at 22:00:34 UTC+1, fir wrote:

> fir
> compiler for test (worx on windows, as i generaty my own exe and i not fulfilled for some PE standards or so some antivirs may raport false alarmn that gnerated exe is a virus..its not)
>
> http://minddetonator.htw.pl/furia11.zip

My OS said this ZIP was unsafe. When I bypassed that, all it contained was a PDF of a slide, in Polish, containing some bullet points.

Is that as far as you got?

Joe Pfeiffer

unread,
Apr 21, 2022, 11:45:06 AM4/21/22
to
I got a 403 when I tried to download it.

fir

unread,
Apr 21, 2022, 12:07:48 PM4/21/22
to
i noticed i needed not to click on this here but to copy and paset it in adres field of browser and it worked - untin next day it stoped working at all (i suspecty that this site which i use as ftp to put various files i link maybe decided to turn it off for me as they will prefer if i put calasic www page there and thay can show ugly advertisments)

if you know some page i may put this 200 KB zip to download say and i may upload there)

fir

unread,
Apr 21, 2022, 12:13:23 PM4/21/22
to
yuh, sorry - it worked for me 10 years or so but it was a day when it stopped working (i still got acces to ftp in total commender but links dont work now,)
if some know site to upload zip i may use it but say me which one

fir

unread,
Apr 21, 2022, 12:28:01 PM4/21/22
to
admin answered to me "Mechanizmy bezpieczeństwa google - safe browser uznały, że strona zawiera szkodliwe skrypty." which stands for probably "The google - safe browser security mechanisms have decided that the website contains malicious scripts."

dont you know what i can do with this?

fir

unread,
Apr 21, 2022, 12:40:31 PM4/21/22
to
czwartek, 21 kwietnia 2022 o 15:11:19 UTC+2 bart c napisał(a):
ok try this

https://file.io/s39Qw9YoC8OK

this is a protocompiler and my assembler (and my dll library something like sfml/sdl i wrote for my own usage) ..i didnt spend a lot of time on both - the 'gross' of the work was writing the assembler which i already wrote on - the 'gross' of thios work on assembler was two weeks of work, (but after half a year of being slightly stunned by pe format) the work on compiler was even shorter (like week of work - speaking maybe a bit in reduced way as i dont remember correctly but thas was this type of amounts - not included resting and time for thinking ;c)

fir

unread,
Apr 21, 2022, 1:17:05 PM4/21/22
to
here also,

https://filebin.net/u9hkfyr8llptnwj3#

i post it in case of somebody would like to discuss related things as its kinda interesting in fact for example i discovered that the compiler is in fact like 20 maybe 30 lines of code - you only need to add next lines to compile next functionalities

problem is i recantli like have lack of motivation and even though i could upbuild the compiler to compile reasonable c and more i find this lack of motivation (in fact maybe im getting old ..especially this eyesight makes a problem)


bart c

unread,
Apr 21, 2022, 1:25:03 PM4/21/22
to
This worked. Already it did say the file would be deleted after downloading (you may need to re-upload?).

The two EXEs worked fine this time, and that was pretty good demo.

fir

unread,
Apr 21, 2022, 1:49:03 PM4/21/22
to
czwartek, 21 kwietnia 2022 o 19:17:05 UTC+2 fir napisał(a):
>
> i post it in case of somebody would like to discuss related things as its kinda interesting in fact for example i discovered that the compiler is in fact like 20 maybe 30 lines of code - you only need to add next lines to compile next functionalities
>

wanna see that lines? it is

FILE *out_asm_file = NULL ;

int main(int argc, char* argv[])
{
char* input_file_name = "program.c"; char* output_file_name = "program.asm";
if (argc==3) { input_file_name = argv[1]; output_file_name = argv[2]; }
chunk d = LoadChunk(input_file_name);
out_asm_file = fopen(output_file_name, "wb");

chunks lines = SplitAfterCharacterOrCharacter(d, 0x0a, ';');
int n = ChunksLength(lines);
for(int i=0; i<n; i++) {
if(ChunkIsEmpty(lines.first[i])) continue;
chunks atoms = SplitChunkOnAtoms(current_line);
int atoms_len = ChunksLength(atoms);
if(atoms_len<1) continue; //skip emty lines
if( atoms_len>=2 ) if( CCS(a0, "/") ) if( CCS(a1, "/") ) continue; //skip commentary lines
if(atoms_len>=4) // compile aaa+=222
if( CCL (a0) ) if( CCS (a1, "+") ) if( CCS (a2, "=") ) if( CCI (a3) ) {
FlushOutAsmChunkPE("\n mov eax (", a0, ")");
FlushOutAsmChunkPE("\n add eax ", a3, " ");
FlushOutAsmChunkPE("\n mov (", a0, ") eax "); }

if(atoms_len>=6) //compile tab[a] = b
{ if( CCL( a0 ) ) if( CCS( a1, "[" ) ) if( CCL( a2 ) ) if( CCS( a3, "]" ) ) if( CCS( a4, "=" ) ) if( CCL( a5 ) )
{
FlushOutAsmChunkPE("\n mov ebx (", a5, ") ");
FlushOutAsmChunkPE("\n mov eax ", a0, " ");
FlushOutAsmChunkPE("\n add eax (", a2, ") ");
FlushOutAsmChunkPE("\n mov (eax) ebx ", Chunk(" "), " ");
continue;
}
}
if(atoms_len >= 5) // compile stdcall "modulename" foo()
{
if( CCS(a0, "stdcall") || CCS(a0, "cdecl")) if( CCS(a1, "\"" ) ) if( CCL(a2) ) if( CCS(a3, "." ) ) if( CCL(a4) ) if( CCS(a5, "\"" ) ) if( CCL(a6) ) {
FlushOutAsm("\n ");
int args_len = GenerateOPushesForArgumentsOfFunction( current_line);
FlushOutAsm("\n call (\"%.*s.%.*s\"->%.*s) ", ChunkLength(a2) , a2.beg, ChunkLength(a4) , a4.beg, ChunkLength(a6) , a6.beg );
if( CCS(a0, "cdecl") )
for(int i=args_len-1; i>=0; i--) { FlushOutAsm("\n pop eax "); }
}
}

/////
rest here
/////
}
fclose(out_asm_file);
printf("\n COMPILATION DONE ");
return 0;
}

done, compiler written

fir

unread,
Apr 21, 2022, 1:49:09 PM4/21/22
to
this demo you like probebly becouse my green fire dll which allows do some easy window
pixelbased apps

you could use it in c like

#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#include <windows.h>
#include <math.h>
#include "green-fire.h"


void RunFrame(int advance)
{
ClearFrameData(0x333300);
//draw here

///code here , may poll keyboard and draw by DrawLine DrawCircle
if(space_pressed) {}

}

void ProcessMouseMove(int x, int y)
{
//mouse movement event
}

void ProcessKeyDown(int key) {
if(key==VK_UP ) { } ///key events
}

void OnResize() {}

int main(void)
{
RegisterMouseMove( ProcessMouseMove ); //set callbacks
RegisterKeyDown( ProcessKeyDown );
RegisterOnResize( OnResize );
RegisterRunFrame( RunFrame );
SetSleepValue(12);
SetupWindow2(" my app ", 20, 20, 700/1, 500/1 );
return 0;
}

fir

unread,
Apr 21, 2022, 2:10:16 PM4/21/22
to
sorry i missed few lines like


chunk a0 = atoms.first[0];
chunk a1 = atoms.first[1];
chunk a2 = atoms.first[2];
chunk a3 = atoms.first[3];
chunk a4 = atoms.first[4];
chunk a5 = atoms.first[5];
chunk a6 = atoms.first[6];
chunk a7 = atoms.first[7];
chunk a8 = atoms.first[8];
chunk a9 = atoms.first[9];

the trick is i use my sickle.c library it loads text file (chunk is my invention i already written a lot struct chunk {char* beg; char* end;}

chunk d = LoadChunk(input_file_name);
chunks lines = SplitAfterCharacterOrCharacter(d, 0x0a, ';');

chunks is an array of chunks (chich is based on reallock seed so it may be internaly resized by this function above, the function breaks initial text into chunk into lines and also breaks after ";" so it is broken on logical lines

this below makes loop on each such logical line

int n = ChunksLength(lines);
for(int i=0; i<n; i++)
{
chunks atoms = SplitChunkOnAtoms(current_line);

this in turn break each line on atoms for example " void foo (int a, float b);"
would return such atoms
"void"
"foo"
"("
"int"
"a"
","
"float"
"b"
")"
";"

regardles of amount of whitespaces beetween - it not touches oryginal data only fu produses atams array which is filled with pointers to begins and ends of such atoms

i got few functions like CCL CCS CCI which stands for compare /cehck if chunk is alphanumeric label, symbol or number/integer so if i will write
if(CCS(atoms.first[0], "int"))
if(CCL(atoms.first[1])
if(CCS(atoms.first[2], "=")
if(CCI(atoms.first[3])
{

}
i know i catched every line like

int aa = -2888;
int something = 0x7777aa;

so i may generate assembly by FlushOutAsm("......") routines;

and thats all compiler done

(its all thnx to my concepts of chunk/chunks spliter and atomizer i wrote on this group already

fir

unread,
Apr 21, 2022, 2:19:54 PM4/21/22
to
czwartek, 21 kwietnia 2022 o 20:10:16 UTC+2 fir napisał(a):
must say i find it cool/fine as i think i got some talent in simplyfing things like that
thsi code of the compiler i tinker in ad pasted has some simple errors (i mean things i would
slightly rewrite to make it cleaner) but this is becouse i clarify some things when working on this
(like how exactly sickle.c library should contain) so it is working state...but this scheme of compilation i find quite cool bot liek dam recursive codes or bison yaxx whopse i dont know but seem rather horrible approach (yawn)

fir

unread,
Apr 21, 2022, 2:32:10 PM4/21/22
to
czwartek, 21 kwietnia 2022 o 20:10:16 UTC+2 fir napisał(a):
>
ye i probbaly sjpould write cleaner example from this above, so the compiler its like

chunk d = LoadChunk(input_file_name);
chunks lines = SplitAfterCharacterOrCharacter(d, 0x0a, ';');
int n = ChunksLength(lines);
for(int i=0; i<n; i++)
{
chunks atoms = SplitChunkOnAtoms(current_line);
//translate all type int xxx = 1111
if(CCS(atoms.first[0], "int")) if(CCL(atoms.first[1]) if(CCS(atoms.first[2], "=") if(CCI(atoms.first[3]) {
FlushOutAsmStr("\n .data "); FlushOutAsmChunk(atoms.first[1); FlushOutAsmStr(" "); FlushOutAsmChunk(atoms.first[3); FlushOutAsmStr("i "); }
}

this above is a compiler and its kinda general one, some just needed to put more translation blocks, error checking etc

fir

unread,
Apr 21, 2022, 2:41:22 PM4/21/22
to
czwartek, 21 kwietnia 2022 o 20:32:10 UTC+2 fir napisał(a):
> >
> > (its all thnx to my concepts of chunk/chunks spliter and atomizer i wrote on this group already
> ye i probbaly sjpould write cleaner example from this above, so the compiler its like
> chunk d = LoadChunk(input_file_name);
> chunks lines = SplitAfterCharacterOrCharacter(d, 0x0a, ';');
> int n = ChunksLength(lines);
> for(int i=0; i<n; i++)
> {
> chunks atoms = SplitChunkOnAtoms(current_line);
> //translate all type int xxx = 1111
> if(CCS(atoms.first[0], "int")) if(CCL(atoms.first[1]) if(CCS(atoms.first[2], "=") if(CCI(atoms.first[3]) {
> FlushOutAsmStr("\n .data "); FlushOutAsmChunk(atoms.first[1); FlushOutAsmStr(" "); FlushOutAsmChunk(atoms.first[3); FlushOutAsmStr("i "); }
> }

current_line should be lines.first[i]
or
chunk current_line = lines.first[i];
should be added

i got slight conceptual problem if i should use the word first,
as chunk is chunk {char* beg; char* end; }
i decided to use other names than beg end in chunks structure , becouse if i would use the same it is confusing not only for chunk newbs , so i used first and last
chunks {chunk* first; chunk* last; }
but the first not fully fits, as for example in atoms.first[4] this titles the chunk number 4 in array so
the word first not fully fits imo, maybe it should be atoms.chunk[4] there for example 2nd letter of 5th chunk yu acces by atoms[4].chunk.beg[1] the last probably can stay

fir

unread,
Apr 21, 2022, 7:09:59 PM4/21/22
to
środa, 20 kwietnia 2022 o 20:29:14 UTC+2 fir napisał(a):
>.and i need yet to compile that damn nested expressions and some side things i yet not even thinkd

in fact it seem i forgot what i already got

(its becouse i coded this 2 or 3 tears ago.. it seem in fact that as to this expresion i write some a bit weird code which takes soem wxpresion which have parentheses and work on it like it would be the data, scans and takes things like "a*b" and replaces it by t1 puting aside t1=a*b and do that in loop top this extend it puts out all operators... it seem weird to me as its slow etc but i forgot it in fact at least work, code it produces is also far from good but for now for me its standable, so in fact i could say i got those expressions mostly done... more good i seen to forget that extending it to the extemnt it would contain some things like array indexing or function calls seem in fact strightforward, so in fact im not sure what i was worying about (maybe becouse this is not optymal but i realized i dont care for optimal at this stage)
still it is yet few days of work esp i would need add floats

fir

unread,
Apr 21, 2022, 10:12:41 PM4/21/22
to
czwartek, 21 kwietnia 2022 o 19:25:03 UTC+2 bart c napisał(a):
> This worked. Already it did say the file would be deleted after downloading (you may need to re-upload?).
>
the first site seemd to be designed to share something only for one download... this filebin hosts
for 6 days

i found 2 years ago i also made i may call functions in what i call naked form (what i was writing bac then i found viable alternative

foo(a,b,c);
foo a b c ; //naked form

https://filebin.net/33fxpjsgk846ymb2

also gave alternative for initialisation

int a = 10;
int a{10}


so now it can compile

import "green_fire.dll" cdecl DrawSomeText2
import "green_fire.dll" cdecl ToggleFullscreen
import "green_fire.dll" cdecl ClearFrameData
import "green_fire.dll" cdecl DrawCircle
import "green_fire.dll" cdecl RegisterRunFrame
import "green_fire.dll" cdecl RegisterMouseMove
import "green_fire.dll" cdecl RegisterKeyDown
import "green_fire.dll" cdecl RegisterOnResize
import "green_fire.dll" cdecl SetSleepValue
import "green_fire.dll" cdecl SetScaleOnResize
import "green_fire.dll" cdecl SetupWindow3

void ProcessMouseMove(int mouse_x, int mouse_y)
return

void ProcessKeyDown(int last_key_pressed)
int PAGE_UP{33}
if last_key_pressed = PAGE_UP
ToggleFullscreen(); .
return

void RollBackgroundColor()
int background_color {0x00000001}
background_color += 1;
ClearFrameData background_color
return

void RunFrame()
RollBackgroundColor()
int r{10}
for r from 10 to 250 step 3
DrawCircle mouse_x mouse_y r 0xff00
.
DrawSomeText2 0xffffff 10 30 "this app is compiled by furia \x00"
DrawSomeText2 0xffffff 30 130 "mouse %d %d\x00" mouse_x mouse_y
int b {2} ; int c {10}
b = 2;c = 10; b = c/(b-1)+c*(c-2);
DrawSomeText2 0xffffff 20 140 " %d \x00" b
b = 2; c = 10; lisplike b = c+b*7/4+3-12 ;
DrawSomeText2 0xffffff 20 150 " %d \x00" b
return

void OnResize()
return

void main()
RegisterRunFrame &RunFrame
RegisterMouseMove &ProcessMouseMove
RegisterKeyDown &ProcessKeyDown
RegisterOnResize &OnResize
SetSleepValue 30
SetScaleOnResize 1
SetupWindow3 " compiled by fir's furia proto c compiler \x00" 10 10 600 400 300 200
return


fir

unread,
Apr 22, 2022, 7:03:04 AM4/22/22
to
i wouldnt call it especially readable but at least its proof as it work if it compiles and runs
as to readability i think if i should drop semicolons ":" and use "'," (commas) instead (thought it the first is semocolon the second should be named colon)

this makes me to coment out the code that compiles clothed/dressed form foo(a,b,c) untill i will revrite it to not break on logical lines on commas inside parenthesis (and i dont want to smend my time on such things) but bessides comma form seem interesting to me

DrawSomeText2 0xffffff 10 30 "this app is compiled by furia \x00" , DrawSomeText2 0xffffff 30 130 "mouse %d %d\x00" mouse_x mouse_y ,
int b {2}, ; int c {10} , b = 2, c = 10, b = c/(b-1)+c*(c-2), DrawSomeText2 0xffffff 20 140 " %d \x00" b , b = 2; c = 10, lisplike b = c+b*7/4+3-12 , DrawSomeText2 0xffffff 20 150 " %d \x00" b, return

worth change i guess.. i will coment out the dressed form compilation then

fir

unread,
Apr 22, 2022, 9:02:52 AM4/22/22
to
sorry for posting a lot of post (in the mode of adding remarks as post below my own posts as i like to do)
i find it somewhat interesting besides after writing few days i will probably wanish for another half a year or so

as to this above replacing ; by , dont changed like to much though imo , looks slightly better ..so i couldnt be sure worthing to do this but another argument is that typing , is easier than : so i think it may stay

fir

unread,
Apr 22, 2022, 5:13:13 PM4/22/22
to
i made yet some additions

https://filebin.net/c7cns125ysfca8d2

i repaired splitter, now it i dont made mistake its poroof on beraking
on logical lines becouse it splits on "," not after ","

aa aa,aaa ,a s s,s,s,ss ->
aa aa
aaa
a s s
s
s
ss

befoe it was
aa aa,
aaa ,
a s s,
s,
s,
ss
and those additional atoms could interfere with interpretation insade lines

also i made braking on logical lines on 3 values 0x0a "," and ":"

the code it compiles

import "green_fire.dll" cdecl DrawSomeText2 ToggleFullscreen
import "green_fire.dll" cdecl ClearFrameData DrawCircle
import "green_fire.dll" cdecl RegisterRunFrame RegisterMouseMove
import "green_fire.dll" cdecl RegisterKeyDown RegisterOnResize
import "green_fire.dll" cdecl SetSleepValue SetScaleOnResize SetupWindow3
import "green_fire.dll" variable frame_size_x frame_size_y

void ProcessMouseMove(int mouse_x; int mouse_y): return

void ProcessKeyDown(int last_key_pressed)
int PAGE_UP{33}
if last_key_pressed = PAGE_UP: ToggleFullscreen() :.
return

void RollBackgroundColor()
int background_color {0x00000001}
background_color += 1
ClearFrameData background_color
return

void RunFrame()
RollBackgroundColor()
int r, int wx = 0, int wy = 0, wx = frame_size_x, wy = frame_size_y, wx /= 2, wy /= 2
for r from 20 to 100 step 2: DrawCircle wx wy r 0xff4455 :.
for r from 20 to 200 step 2: DrawCircle mouse_x mouse_y r 0xff00 :.

DrawSomeText2 0xffffff 10 30 "this app is compiled by furia \x00"
DrawSomeText2 0xffffff 30 130 "mouse %d %d\x00" mouse_x mouse_y
int b {2},int c {10}
b = 2, c = 10, b = c/(b-1)+c*(c-2), DrawSomeText2 0xffffff 20 150 " %d \x00" b
b = 2, c = 10, lisplike b = c+b*7/4+3-12 , DrawSomeText2 0xffffff 20 170 " %d \x00" b
return

void OnResize(): return

void main()
RegisterRunFrame &RunFrame,
RegisterMouseMove &ProcessMouseMove
RegisterKeyDown &ProcessKeyDown,

fir

unread,
Apr 23, 2022, 8:35:11 AM4/23/22
to
https://filebin.net/7nvpszd5eru4o4uf

i added yet some syntax changes ment to maybe try later to put this some c little programs meant to be
stripped for size and see in what syntax i could obtain the possible minimum (though for now i got yet many things yet not implemented for examlple no float expressions (need to put stubs in assembly)
acces to array is obtainalble only thru a = b[i] and c[i]=d etc) now it compiles

import "green_fire.dll" cdecl DrawSomeText2 ToggleFullscreen
import "green_fire.dll" cdecl ClearFrameData DrawCircle
import "green_fire.dll" cdecl RegisterRunFrame RegisterMouseMove
import "green_fire.dll" cdecl RegisterKeyDown RegisterOnResize
import "green_fire.dll" cdecl SetSleepValue SetScaleOnResize SetupWindow3
import "green_fire.dll" variable frame_size_x frame_size_y

void ProcessMouseMove(int mouse_x; int mouse_y): return

.PAGE_UP{33}

void ProcessKeyDown(int last_key_pressed)
? last_key_pressed=PAGE_UP: ToggleFullscreen() :.
return

.background_color{0x00000001}

void RollBackgroundColor()
background_color += 1, ClearFrameData background_color
return

void RunFrame()
RollBackgroundColor()
.wx=frame_size_x, .wy=frame_size_y, wx/=2, wy/=2
20/100/2 .r: DrawCircle wx wy r 0xff4455:.
20/200/2 r: DrawCircle mouse_x mouse_y r 0xff00:.
DrawSomeText2 0xffffff 10 30 "this app is compiled by furia \x00",
DrawSomeText2 0xffffff 30 130 "mouse %d %d\x00" mouse_x mouse_y
.b=2, .c=10, b = c/(b-1)+c*(c-2), DrawSomeText2 0xffffff 20 150 " %d \x00" b
b=2, c=10, lisplike b = c+b*7/4+3-12 , DrawSomeText2 0xffffff 20 170 " %d \x00" b
return

void OnResize(): return

void main(): RegisterRunFrame &RunFrame, RegisterMouseMove &ProcessMouseMove
RegisterKeyDown &ProcessKeyDown, RegisterOnResize &OnResize
SetSleepValue 30, SetScaleOnResize 1
SetupWindow3 " compiled by fir's furia proto c compiler \x00" 20 20 640 480 320 240
return

i got a little weary already but it is potential fun..potentially if i would implement more and rise quality of source i can give the c source of this compiler too (though taking my kinda novative (i guess) hints how to write it esp if someone would target nasm or something and not write his own asm it not so hard) but this is yet to be seen

fir

unread,
Apr 30, 2022, 5:01:29 AM4/30/22
to
somewhat upgraded version

https://filebin.net/pethf87gfgorfuz7

takes code like

//////////////////////////////
import "green_fire.dll" (cdecl) DrawSomeText2 ToggleFullscreen ...
ClearFrameData DrawCircle RegisterRunFrame RegisterMouseMove ...
RegisterKeyDown RegisterOnResize SetSleepValue SetScaleOnResize ...
SetupWindow3 (var) frame_size_x frame_size_y
import "user32.dll" (stdcall) MessageBoxA
import "msvcrt.dll" (cdecl) printf

void ProcessMouseMove(int mouse_x int mouse_y), return

void foo(int z1 int z2 int z3 int z4 )
printf " %d %d %d %d \x00" z1 z2 z3 z4, return

void AddBackgrounColor(int addX)
background_color = background_color + addX , return

void ProcessKeyDown(int last_key_pressed)
int PAGE_UP=33, int keyR = 0x52, int keyG = 0x47, int keyB = 0x42
last_key_pressed?=PAGE_UP: ToggleFullscreen().
last_key_pressed?=0x41: foo(frame_size_x frame_size_y/2 3 4).
last_key_pressed?=0x53: foo(2 3 4 5), foo(6 7 8 9).
last_key_pressed?=0x43: MessageBoxA 0 "captionC\x00" "title\x00" 0 .
last_key_pressed?=keyR: AddBackgrounColor(0x10).
last_key_pressed?=keyG: AddBackgrounColor(0x1000).
last_key_pressed?=keyB: AddBackgrounColor(0x100000).


return

void RollBackgroundColor(), int background_color += 0x01, ClearFrameData background_color,
return
double aa = 1111.111111111, double bb = 7.22, int cc = 2, int dd = 3
void RunFrame(),
RollBackgroundColor(),
30;.r;100;2: DrawCircle frame_size_x/4 frame_size_y/3 r 0xff4455 .
20; r;100;3: DrawCircle frame_size_x/5*4 frame_size_y/4 r 0xff00 .
10; r;70;2: DrawCircle frame_size_x/2 frame_size_y/5*4 r 0xffff00 .

20; r;200;2: DrawCircle mouse_x mouse_y r 0xffff .
DrawSomeText2 0xffffff 10 30 "this app is compiled by furia \x00",
DrawSomeText2 0xffffff 30 180 "mouse %d %d\x00" mouse_x mouse_y
cc+=1, aa+=0.01, aa-=0.00001,
DrawSomeText2 0xffffff 30 100 "cc %d aa %f \x00" cc aa,
return
void OnResize(), return
void main()
RegisterRunFrame &RunFrame, RegisterMouseMove &ProcessMouseMove
RegisterKeyDown &ProcessKeyDown, RegisterOnResize &OnResize, SetSleepValue 30, SetScaleOnResize 1
SetupWindow3 " compiled by fir's furia proto c compiler \x00" 20 20 640 480 320 240
return


now some can put expresions as argument of functions,,it doesnt seem a big upgrade but
in fact the core things in the inner layer/ring of compilers are those two: microcompiler of expressions and code that compiles-in this expressions in given place (here for me it is those arguments of functions)

those two things emmn most thing done, probably teh harded thing in thic compiler, so when i done it i may feel like 51% of compiler done
(my expresions are errorouns and simple (only +-*/) but extending it is easy work... sadly i myself feel like emeritus so harder parts was wearing me...its a doom of my life, need to do work when began to feel really old)

fir

unread,
Apr 30, 2022, 4:11:32 PM4/30/22
to
yet i may add some remarks:
the compiler is now, i checked 100k bytes source )including commented and not needed parts_
which gave 5k lines (which in turn stands for 2 weeks of crazy work, as for me month of crazy work
is 10k lines - this was whan i was younger and able to code 10k lines a month) ... for me it took
probably like about 5-6 weeks of coding (i dont remember exactly, proably about 5)

i will need to add things yet but overally it seems in 10k lines one could build basic proto-c compiler
if one could try to not get too long it also can go in few k lines possinly (like 5k) hovever i skipped some things so if add some it probably will go up to 20 k maybe (but 20k seem a lot)

as to how hard it is i seen easier thibgs to code but also is not so hard, hovever i found a trouble
of writing it stright from begin to end good way, it rather put my head of state when i just added and added those ifs (as its damn many ifs) and not being sure if it all packs together and forget precise
code flow..it seems to pack together though

overally when i see on code i can compile i see: logical lines containing
- function call
- function definition (header)
- expression
- if-header
- for-header
and thats mostly all (yet i may add ends of if/for.function blocks)

from those 6 mentioned 4 are easy, expression and function calls are those that are harder...
still i dont see all that things to much clear i may say bot some experience here i got... i eventually suspect that investing more in that could give some good vision of things here (but its yet to see)

fir

unread,
May 1, 2022, 5:00:56 AM5/1/22
to
i added yet new version https://filebin.net/hhwx77gjc4zmeyax

this compiles a bit cleanised syntax

//////////////////////////////
import "green_fire.dll" (cdecl) DrawSomeText2 ToggleFullscreen ClearFrameData DrawCircle RegisterRunFrame RegisterMouseMove RegisterKeyDown RegisterOnResize SetSleepValue SetScaleOnResize SetupWindow3 (var) frame_size_x frame_size_y
import "user32.dll" (stdcall) MessageBoxA
import "msvcrt.dll" (cdecl) printf
////////////////////////////////////

void ProcessMouseMove int mouse_x int mouse_y
return

void foo int z1 int z2 int z3 int z4
printf " %d %d %d %d \x00" z1 z2 z3 z4
return

void AddBackgrounColor int addX
background_color += addX
return


void ProcessKeyDown int last_key_pressed :
int PAGE_UP{33}, int keyR{0x52}, int keyG{0x47}, int keyB{0x42}
last_key_pressed?=PAGE_UP: ToggleFullscreen .
last_key_pressed?=0x41: foo frame_size_x frame_size_y/2 3 4 .
last_key_pressed?=0x53: foo 2 3 4 5, foo 6 7 8 9 .
last_key_pressed?=0x43: MessageBoxA 0 "captionC\x00" "title\x00" 0 .
last_key_pressed?=keyR: AddBackgrounColor 0x10 .
last_key_pressed?=keyG: AddBackgrounColor 0x1000 .
last_key_pressed?=keyB: AddBackgrounColor 0x100000 .
return

void RollBackgroundColor: int background_color += 0x01
ClearFrameData background_color
return

double aa {21111.111111111},double bb{7.22},int cc{2}, int dd{3}

void RunFrame
RollBackgroundColor,
30;.r;100;2: DrawCircle frame_size_x/4 frame_size_y/3 r 0xff4455 .
20; r;100;3: DrawCircle frame_size_x/5*4 frame_size_y/4 r 0xff00 .
10; r;70 ;4: DrawCircle frame_size_x/6*5 frame_size_y/5*4 r 0xffff00 .
11; r;70 ;4: DrawCircle frame_size_x/6*5 frame_size_y/5*4 r 0x00ffff .

30; r;200;2: DrawCircle mouse_x mouse_y r 0xffff .
DrawSomeText2 0xffffff 10 30 "this app is compiled by furia \x00"
DrawSomeText2 0xffffff 30 180 "mouse %d %d\x00" mouse_x mouse_y
DrawSomeText2 0xffffff 10 220 "test cc %d test aa %f \x00" cc+=1 aa+=0.111111
return

void OnResize, return

void main()
RegisterRunFrame &RunFrame, RegisterMouseMove &ProcessMouseMove
RegisterKeyDown &ProcessKeyDown, RegisterOnResize &OnResize, SetSleepValue 30, SetScaleOnResize 1
SetupWindow3 " compiled by fir's furia proto c compiler \x00" 20 20 640 480 320 240
return

though still it has a bunch of small syntax holes and wrongings
most possibly i will get a break and return to it some other day hovever as i said i think
wthe worst of this is done and 52% of it is done, the rest is just easy typing

fir

unread,
May 8, 2022, 12:43:23 PM5/8/22
to
some newer version

https://filebin.net/qg6zad6s27xb80vt

i upgraded those 'vector' separation code and
allowed both use ; or | separators or none
like
foo a b c
foo a|b|c

i throwed old reducer code to trash bin and wrote one notably cleaner though
still i didnt wanted even to test that (probably not all works but may be mended)

possibly i could go on and add something more
0 new messages