Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-02-27 Thread rempas via Tinycc-devel
24 Φεβ 2022, 18:51 Από ivo...@gmail.com:

> On Thu, 24 Feb 2022 11:16:54 -0500 Christopher Conforti
>  wrote:
>
>> I hope I got this all straight, and I hope it helps!
>>
>
> Yes, you basically nailed it. If you have a parser for language, you
> can either execute it directly in the language your parser
> is written in (interpreter), or output intermediate code or assembly or
> object code directly (like tcc does).
>
> Writing a compiler starts with writing a parser for your language. What
> you do after that (interpret or generate code) is of second concern.
> Hope the OP understands that.
>
> Regards,
> Ivo
>
Thanks, I do understand that and I already knew. However, this doesn't answer 
my original question at all...

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-02-27 Thread rempas via Tinycc-devel
24 Φεβ 2022, 18:16 Από christop...@conforti.xyz:

> On Sat, 29 Jan 2022 10:08:11 +0100 (CET)
> rempas via Tinycc-devel  wrote:
>
>>
>> 29 Ιαν 2022, 03:20 Από s...@conman.org:
>>
>> > It was thus said that the Great rempas via Tinycc-devel once stated:
>> >
>> >> Thanks! However, I don't understand how this will help me. I mean, I don't
>> >> even want to create an intepreter to begin with. So this has nothing to do
>> >> with what I want to make. Unless you are referring to the frontend so in
>> >> this case, It will probably be a good idea to read this book. Or maybe I
>> >> should make an intepreter in the end? Hm
>> >> 
>> > It's interpreters all the way down (what do you think CPUs do with machine
>> > code?  They interpret it).  Also, if you have parsed code into a form you
>> > can interpret, you have enough information to generate machine code.
>> > 
>> I know that the CPU interprets the instructions but an interpreter will use
>> a programming language to interpret.
>>
>
> Mind that I'm still very new (and usually a lurker), but I think I can help.
>
> Machine instructions are just another programming language, and programming
> languages are fancier machine instructions. Compilers and interpreters both
> do the same thing--interpret higher-level languages into lower-level 
> languages.
> All the way from shell scripts (or batch files, for the Winders users) down to
> assembler, until at the bottom is machine code.
>
> The difference between a "compiler" and "interpreter" is that the 
> "interpreter"
> is usually running (like 'tcc -run') and passing its results directly to
> another interpreter (usually the CPU, but could be, for example, a JRE
> (spit-balling)) for execution NOW, while the "compiler" runs once (like 'tcc
> -o') typically puts its results in a file, to be read at an arbitrary time by
> another interpreter (again, usually the CPU but could be something like a JVM)
> for execution LATER.
>
> Further, an "interpreter" can pass its results to a "compiler" for
> immediate compilation, and a "compiler" can pass its results directly to an
> "interpreter" for immediate execution. Taking Python as an example: an
> "interpreter" could be written that translates Python into C, the output
> of which could be redirected into something like 'tcc -run' in real time; an
> "interpreter" could be written that translates C into Python, the results of
> which could be redirected into a Python interpreter in real time. "Compilers"
> could be written to "compile" C into a Python source file, and vice-versa, for
> later execution by an appropriate interpreter.
>
> This, by the way, is essentially how Java works: a Java source file is
> "compiled" into Java Virtual Machine code (kinda like CPU instructions), which
> is interpreted by the Java Runtime Environment, which passes the results to 
> your
> CPU. I've always found this aspect of the Java system very interesting.
>
> I hope I got this all straight, and I hope it helps!
>
> -- 
> Christopher Conforti
> Independent Cutco Sales Representative
> +1-717-281-6059 
> christop...@conforti.xyz 
>
Thank you, you got everything straight except for one thing. In your example on 
converting "C" to "Python" and vice versa. You cannot create an "interpreter" 
that will have an output because interpreters don't have an output. This is 
what we call a "compiler".

The front-end is the same bad interpreters execute the code rather than output 
a (or multiple) file.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-02-24 Thread Ivo van Poorten
On Thu, 24 Feb 2022 11:16:54 -0500 Christopher Conforti
 wrote:
> I hope I got this all straight, and I hope it helps!

Yes, you basically nailed it. If you have a parser for language, you
can either execute it directly in the language your parser
is written in (interpreter), or output intermediate code or assembly or
object code directly (like tcc does).

Writing a compiler starts with writing a parser for your language. What
you do after that (interpret or generate code) is of second concern.
Hope the OP understands that.

Regards,
Ivo

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-02-24 Thread Christopher Conforti
On Sat, 29 Jan 2022 10:08:11 +0100 (CET)
rempas via Tinycc-devel  wrote:
>
> 29 Ιαν 2022, 03:20 Από s...@conman.org:
> 
> > It was thus said that the Great rempas via Tinycc-devel once stated:
> >
> >> Thanks! However, I don't understand how this will help me. I mean, I don't
> >> even want to create an intepreter to begin with. So this has nothing to do
> >> with what I want to make. Unless you are referring to the frontend so in
> >> this case, It will probably be a good idea to read this book. Or maybe I
> >> should make an intepreter in the end? Hm
> >> 
> > It's interpreters all the way down (what do you think CPUs do with machine
> > code?  They interpret it).  Also, if you have parsed code into a form you
> > can interpret, you have enough information to generate machine code.
> >  
> I know that the CPU interprets the instructions but an interpreter will use
> a programming language to interpret.
>

Mind that I'm still very new (and usually a lurker), but I think I can help.

Machine instructions are just another programming language, and programming
languages are fancier machine instructions. Compilers and interpreters both
do the same thing--interpret higher-level languages into lower-level languages.
All the way from shell scripts (or batch files, for the Winders users) down to
assembler, until at the bottom is machine code.

The difference between a "compiler" and "interpreter" is that the "interpreter"
is usually running (like 'tcc -run') and passing its results directly to
another interpreter (usually the CPU, but could be, for example, a JRE
(spit-balling)) for execution NOW, while the "compiler" runs once (like 'tcc
-o') typically puts its results in a file, to be read at an arbitrary time by
another interpreter (again, usually the CPU but could be something like a JVM)
for execution LATER.

Further, an "interpreter" can pass its results to a "compiler" for
immediate compilation, and a "compiler" can pass its results directly to an
"interpreter" for immediate execution. Taking Python as an example: an
"interpreter" could be written that translates Python into C, the output
of which could be redirected into something like 'tcc -run' in real time; an
"interpreter" could be written that translates C into Python, the results of
which could be redirected into a Python interpreter in real time. "Compilers"
could be written to "compile" C into a Python source file, and vice-versa, for
later execution by an appropriate interpreter.

This, by the way, is essentially how Java works: a Java source file is
"compiled" into Java Virtual Machine code (kinda like CPU instructions), which
is interpreted by the Java Runtime Environment, which passes the results to your
CPU. I've always found this aspect of the Java system very interesting.

I hope I got this all straight, and I hope it helps!

-- 
Christopher Conforti
Independent Cutco Sales Representative
+1-717-281-6059 
christop...@conforti.xyz 

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread rempas via Tinycc-devel
29 Ιαν 2022, 17:16 Από nikla...@gmail.com:

> To answer the original question: Yes. TCC is very readable even for someone 
> who is not an expert C programmer.
>
That's great to hear. I tried to start from "main" and go thought the code and 
it indeed seems good.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread Niklas Rosencrantz
To answer the original question: Yes. TCC is very readable even for someone
who is not an expert C programmer.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread rempas via Tinycc-devel
29 Ιαν 2022, 12:10 Από eli...@orange.fr:

>
> I suggest you start with something simple:
>
>
>  
>
>
> A language that implement 4 arithmetic integer operations, has integer 
> variables, allows to define functions and includes print function as library 
> function.
>
>
> Chose the syntax you like and start to write you own compiler that generate 
> intermediate internal code, then choose a backend (for example C) that 
> generates code corresponding to your intermediate code.
>
>
>  
>
>
> You’ll learn of lot of things and you’ll get 80% of the knowledge you’ll need 
> to write serious things.
>
>
>  
>
>
> This globally how works my Lisp compiler from Lisp files up to standalone 
> executable.
>
>
>  
>
>
> See https://en.wikipedia.org/wiki/OpenLisp#Compiler
>
>
>  
>
>
> From:>  Tinycc-devel 
> [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] > On Behalf Of > ian
> Sent:>  Saturday, January 29, 2022 10:43
> To:>  rempas via Tinycc-devel
> Subject:>  Re: [Tinycc-devel] Can a biggener (and idiot) like me read and 
> understand TCC's backend so I can create my own frontend with it?
>
>
Hi! Thank you for your answer but I really have a hard time to understand what 
you are saying In the second paragraph.

When saying to choose a backend the generates code, you mean a compiler right? 
Also, how will this generate code corresponding to mine? Isn't the code 
specific to the backend/compiler? And some compilers (like TCC) imidiatly 
create object files or assembly and don't generate an Intermediate 
representation file. But even If I could make an IR that would mimic the IR of 
another compiler (let's say Clang/LLVM), how would this help me understand how 
this translates this to a sequence of bytes and how the instructions are 
represented as bytes?

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread rempas via Tinycc-devel
29 Ιαν 2022, 12:06 Από crae...@gmail.com:

> Hi,
>
> If you want something more practical, take a look at Thomas Ball's
> "Writing an Interpreter in Go" and "Writing a compiler in Go".
> It doesn't focus much on theory. It's simply about writing a compiler.
> Of course, theory is very important, but it might help you to understand the
> theory afterwards if you've already written a compiler.
>
> You would have to rewrite the Go code in C. But think of it as a small
> task to improve your C.
>
> --
> craekz
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
Thanks a lot!!! This will probably help! I also agree with your take. I have 
seen SOOO much in theory but I need to see some code in practice. I don't know 
go so I'll have to look up whatever I don't understand but I'm pretty sure this 
will be a great start. And after the basics, I can look up official references 
and documents and I can look how compilers generate code for specific things!

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread rempas via Tinycc-devel
29 Ιαν 2022, 11:43 Από sibian0...@gmail.com:

>
> Hi
>
>
> One thing or the other :
>
>
> - you wanna learn asm or algorithmics, and it's not the best  place; but 
> you obviously need to have to know them a "few",
>
>
> - or, you already know how to code something in ASM, and then the  
> suggested book about how to make an interpreter is the good  starting 
> point for you.
>
>
> Rgds
>
>
Thank you! It's the first thing for sure and probably the book can teach me 
some good algorithms and practices for my frontend. I will look into it!

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread Samir Ribić via Tinycc-devel
I have already sent a tutorial to rempas to make a simple compiler using
parser generator Coco/r, but there is one extremely simple tutorial to
learn writing compilers from scratch: Let's build a compiler by Jack
Crenshaw  Let's Build a Compiler (iecc.com)
 . It is Pascal and Motorola 68000
target based. Do not discard it as obsolete. Pascal is a very readable
programming language, and MC 68000 has a quite good instruction set.

On Sat, Jan 29, 2022 at 11:11 AM Christian Jullien  wrote:

> I suggest you start with something simple:
>
>
>
> A language that implement 4 arithmetic integer operations, has integer
> variables, allows to define functions and includes print function as
> library function.
>
> Chose the syntax you like and start to write you own compiler that
> generate intermediate internal code, then choose a backend (for example C)
> that generates code corresponding to your intermediate code.
>
>
>
> You’ll learn of lot of things and you’ll get 80% of the knowledge you’ll
> need to write serious things.
>
>
>
> This globally how works my Lisp compiler from Lisp files up to standalone
> executable.
>
>
>
> See https://en.wikipedia.org/wiki/OpenLisp#Compiler
>
>
>
> *From:* Tinycc-devel [mailto:tinycc-devel-bounces+eligis=
> orange...@nongnu.org] *On Behalf Of *ian
> *Sent:* Saturday, January 29, 2022 10:43
> *To:* rempas via Tinycc-devel
> *Subject:* Re: [Tinycc-devel] Can a biggener (and idiot) like me read and
> understand TCC's backend so I can create my own frontend with it?
>
>
>
> Hi
>
> One thing or the other :
>
> - you wanna learn asm or algorithmics, and it's not the best place; but
> you obviously need to have to know them a "few",
>
> - or, you already know how to code something in ASM, and then the
> suggested book about how to make an interpreter is the good starting point
> for you.
>
> Rgds
>
> Le 29/01/2022 à 10:08, rempas via Tinycc-devel a écrit :
>
> 29 Ιαν 2022, 03:20 Από s...@conman.org:
>
>
>
> It was thus said that the Great rempas via Tinycc-devel once stated:
>
>
>
> I would advice you to start with this 
> https://craftinginterpreters.com/contents.html first.
>
>
>
> The rest will follow before you know it.
>
>
>
> Thanks! However, I don't understand how this will help me. I mean, I don't
>
> even want to create an intepreter to begin with. So this has nothing to do
>
> with what I want to make. Unless you are referring to the frontend so in
>
> this case, It will probably be a good idea to read this book. Or maybe I
>
> should make an intepreter in the end? Hm
>
>
>
>
>
> It's interpreters all the way down (what do you think CPUs do with machine
>
> code?  They interpret it).  Also, if you have parsed code into a form you
>
> can interpret, you have enough information to generate machine code.
>
>
>
>  -spc
>
>
>
> ___
>
> Tinycc-devel mailing list
>
> Tinycc-devel@nongnu.org
>
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
>
>
> I don't know if I'm that stupid but I really don't understand. I know that 
> the CPU interprets the instructions but an interpreter will use a programming 
> language to interpret. For example, the following statement:
>
>
>
> `println("Hello from my lang: {}", "BestLang")`
>
>
>
> will be translated to (suppose the interpreted is written in C) and then be 
> executed:
>
>
>
> `printf("Hello from my lang: %s", "BestLang);`
>
>
>
> So how is this going to teach my assembly and how the instructions are 
> represented in binary? The book specifically says that it won't work with 
> teaching assembly. The interpreted is a binary that takes source code and 
> executes it. It doesn't create a binary. So I really don't understand what's 
> going on here...
>
>
>
> ___
>
> Tinycc-devel mailing list
>
> Tinycc-devel@nongnu.org
>
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
> --
> -- sibian0...@gmail.com
> -- Développeur compulsif
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread Christian Jullien
I suggest you start with something simple:

 

A language that implement 4 arithmetic integer operations, has integer 
variables, allows to define functions and includes print function as library 
function.

Chose the syntax you like and start to write you own compiler that generate 
intermediate internal code, then choose a backend (for example C) that 
generates code corresponding to your intermediate code.

 

You’ll learn of lot of things and you’ll get 80% of the knowledge you’ll need 
to write serious things.

 

This globally how works my Lisp compiler from Lisp files up to standalone 
executable.

 

See https://en.wikipedia.org/wiki/OpenLisp#Compiler 

 

From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On 
Behalf Of ian
Sent: Saturday, January 29, 2022 10:43
To: rempas via Tinycc-devel
Subject: Re: [Tinycc-devel] Can a biggener (and idiot) like me read and 
understand TCC's backend so I can create my own frontend with it?

 

Hi

One thing or the other :

- you wanna learn asm or algorithmics, and it's not the best place; but you 
obviously need to have to know them a "few",

- or, you already know how to code something in ASM, and then the suggested 
book about how to make an interpreter is the good starting point for you.

Rgds

Le 29/01/2022 à 10:08, rempas via Tinycc-devel a écrit :

29 Ιαν 2022, 03:20 Από s...@conman.org:
 

It was thus said that the Great rempas via Tinycc-devel once stated:
 

I would advice you to start with this 
https://craftinginterpreters.com/contents.html first.
 
The rest will follow before you know it.

 
Thanks! However, I don't understand how this will help me. I mean, I don't
even want to create an intepreter to begin with. So this has nothing to do
with what I want to make. Unless you are referring to the frontend so in
this case, It will probably be a good idea to read this book. Or maybe I
should make an intepreter in the end? Hm
 

 
It's interpreters all the way down (what do you think CPUs do with machine
code?  They interpret it).  Also, if you have parsed code into a form you
can interpret, you have enough information to generate machine code.
 
 -spc
 
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
 

I don't know if I'm that stupid but I really don't understand. I know that the 
CPU interprets the instructions but an interpreter will use a programming 
language to interpret. For example, the following statement:
 
`println("Hello from my lang: {}", "BestLang")`
 
will be translated to (suppose the interpreted is written in C) and then be 
executed:
 
`printf("Hello from my lang: %s", "BestLang);`
 
So how is this going to teach my assembly and how the instructions are 
represented in binary? The book specifically says that it won't work with 
teaching assembly. The interpreted is a binary that takes source code and 
executes it. It doesn't create a binary. So I really don't understand what's 
going on here...
 
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

-- 
-- sibian0...@gmail.com
-- Développeur compulsif

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread craekz
Hi,

If you want something more practical, take a look at Thomas Ball's
"Writing an Interpreter in Go" and "Writing a compiler in Go".
It doesn't focus much on theory. It's simply about writing a compiler.
Of course, theory is very important, but it might help you to understand the
theory afterwards if you've already written a compiler.

You would have to rewrite the Go code in C. But think of it as a small
task to improve your C.

--
craekz

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread ian
Hi

One thing or the other :

- you wanna learn asm or algorithmics, and it's not the best place; but
you obviously need to have to know them a "few",

- or, you already know how to code something in ASM, and then the
suggested book about how to make an interpreter is the good starting
point for you.

Rgds

Le 29/01/2022 à 10:08, rempas via Tinycc-devel a écrit :
> 29 Ιαν 2022, 03:20 Από s...@conman.org:
>
>> It was thus said that the Great rempas via Tinycc-devel once stated:
>>
 I would advice you to start with this 
 https://craftinginterpreters.com/contents.html first.

 The rest will follow before you know it.
>>> Thanks! However, I don't understand how this will help me. I mean, I don't
>>> even want to create an intepreter to begin with. So this has nothing to do
>>> with what I want to make. Unless you are referring to the frontend so in
>>> this case, It will probably be a good idea to read this book. Or maybe I
>>> should make an intepreter in the end? Hm
>>>
>> It's interpreters all the way down (what do you think CPUs do with machine
>> code?  They interpret it).  Also, if you have parsed code into a form you
>> can interpret, you have enough information to generate machine code.
>>
>>  -spc
>>
>> ___
>> Tinycc-devel mailing list
>> Tinycc-devel@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
> I don't know if I'm that stupid but I really don't understand. I know that 
> the CPU interprets the instructions but an interpreter will use a programming 
> language to interpret. For example, the following statement:
>
> `println("Hello from my lang: {}", "BestLang")`
>
> will be translated to (suppose the interpreted is written in C) and then be 
> executed:
>
> `printf("Hello from my lang: %s", "BestLang);`
>
> So how is this going to teach my assembly and how the instructions are 
> represented in binary? The book specifically says that it won't work with 
> teaching assembly. The interpreted is a binary that takes source code and 
> executes it. It doesn't create a binary. So I really don't understand what's 
> going on here...
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
-- 
-- sibian0...@gmail.com
-- Développeur compulsif
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread rempas via Tinycc-devel
29 Ιαν 2022, 03:20 Από s...@conman.org:

> It was thus said that the Great rempas via Tinycc-devel once stated:
>
>> > I would advice you to start with this 
>> > https://craftinginterpreters.com/contents.html first.
>> >
>> > The rest will follow before you know it.
>>
>> Thanks! However, I don't understand how this will help me. I mean, I don't
>> even want to create an intepreter to begin with. So this has nothing to do
>> with what I want to make. Unless you are referring to the frontend so in
>> this case, It will probably be a good idea to read this book. Or maybe I
>> should make an intepreter in the end? Hm
>>
>
> It's interpreters all the way down (what do you think CPUs do with machine
> code?  They interpret it).  Also, if you have parsed code into a form you
> can interpret, you have enough information to generate machine code.
>
>  -spc
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
I don't know if I'm that stupid but I really don't understand. I know that the 
CPU interprets the instructions but an interpreter will use a programming 
language to interpret. For example, the following statement:

`println("Hello from my lang: {}", "BestLang")`

will be translated to (suppose the interpreted is written in C) and then be 
executed:

`printf("Hello from my lang: %s", "BestLang);`

So how is this going to teach my assembly and how the instructions are 
represented in binary? The book specifically says that it won't work with 
teaching assembly. The interpreted is a binary that takes source code and 
executes it. It doesn't create a binary. So I really don't understand what's 
going on here...

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-28 Thread Sean Conner
It was thus said that the Great rempas via Tinycc-devel once stated:
> > I would advice you to start with this 
> > https://craftinginterpreters.com/contents.html first.
> >
> > The rest will follow before you know it.
>
> Thanks! However, I don't understand how this will help me. I mean, I don't
> even want to create an intepreter to begin with. So this has nothing to do
> with what I want to make. Unless you are referring to the frontend so in
> this case, It will probably be a good idea to read this book. Or maybe I
> should make an intepreter in the end? Hm

  It's interpreters all the way down (what do you think CPUs do with machine
code?  They interpret it).  Also, if you have parsed code into a form you
can interpret, you have enough information to generate machine code.

  -spc

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-28 Thread Ekaitz Zarraga
Hi there,

> I tried to read the Tiger Book with examples. I tried to learn Bison. I
> tried to learn Lemon Parser. I could not write the grammar for a for-loop.
> I don't know if that's because if stupid, if it wasn't well explained or if
> it's difficult.

There are various books that explain grammars very well but with pretty
different approaches. A very practical (and old-ish!) one is this:

https://compilers.iecc.com/crenshaw/

Also Niklaus Wirth's lessons include EBNF (which was invented by him btw)
and some practical examples of it for OBERON:

https://people.inf.ethz.ch/wirth/

There are tons of books and references but these ones are probably
underestimated and they may worth a look.
I hope you enjoy them.

Cheers,
Ekaitz

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-28 Thread rempas via Tinycc-devel
28 Ιαν 2022, 22:35 Από ssofr...@cytanet.com.cy:

> On Fri, 28 Jan 2022 20:25:08 +0100
> Niklas Rosencrantz  wrote:
>
>> I tried to read the Tiger Book with examples. I tried to learn Bison. I
>> tried to learn Lemon Parser. I could not write the grammar for a for-loop.
>> I don't know if that's because if stupid, if it wasn't well explained or if
>> it's difficult.
>>
>> What I could learn from was to take the instruction sheet for MIPS assembly
>> and find out how statements in C can translate to assembly. That was easy
>> to learn. What a real compiler will generate is always 5 times more than
>> what the instruction manual says it should translate to. I tried with GCC
>> and a MIPS compiler, looked at the generated assembly which was very
>> different from what I could run directly from e.g. the MARS MIPS
>> environment by writing it by hand.
>>
>> I'm out on deep water but this was my experience with trying to learn. I
>> found that TCC is very good for learning and trying ideas.
>>
>> /Niklas
>>
>
> I would advice you to start with this 
> https://craftinginterpreters.com/contents.html first.
>
> The rest will follow before you know it.
>
Thanks! However, I don't understand how this will help me. I mean, I don't even 
want to create an intepreter to begin with. So this has nothing to do with what 
I want to make. Unless you are referring to the frontend so in this case, It 
will probably be a good idea to read this book. Or maybe I should make an 
intepreter in the end? Hm

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-28 Thread rempas via Tinycc-devel
28 Ιαν 2022, 21:25 Από nikla...@gmail.com:

> I tried to read the Tiger Book with examples. I tried to learn Bison. I tried 
> to learn Lemon Parser. I could not write the grammar for a for-loop. I don't 
> know if that's because if stupid, if it wasn't well explained or if it's 
> difficult.
>
Don't say that! You don't seem to be stupid to me and the fact that you kept 
trying shows that your can do hard work with is more important the been genius 
and lazy (like some people are).

> What I could learn from was to take the instruction sheet for MIPS assembly 
> and find out how statements in C can translate to assembly. That was easy to 
> learn. What a real compiler will generate is always 5 times more than what 
> the instruction manual says it should translate to. I tried with GCC and a 
> MIPS compiler, looked at the generated assembly which was very different from 
> what I could run directly from e.g. the MARS MIPS environment by writing it 
> by hand.
>
> I'm out on deep water but this was my experience with trying to learn. I 
> found that TCC is very good for learning and trying ideas.
>
> /Niklas
>
TCC is probably heaven compared to GCC or probably anything else. However, I'm 
not so worried about how C translates to assembly but about the structure of 
the header file (sections, sectors, addresses, offsets etc.) and how the 
instructions translate to binary (does the CPU uses GCC or NASM syntax under 
the hood? Or maybe none of them)? This will be a huge pain in the ass to do 
this way. It will require hours and hours just to properly learn a few of them. 
So it can't be, there must be a better way to do this in 2022...

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-28 Thread Stefanos via Tinycc-devel
On Fri, 28 Jan 2022 20:25:08 +0100
Niklas Rosencrantz  wrote:

> I tried to read the Tiger Book with examples. I tried to learn Bison. I
> tried to learn Lemon Parser. I could not write the grammar for a for-loop.
> I don't know if that's because if stupid, if it wasn't well explained or if
> it's difficult.
> 
> What I could learn from was to take the instruction sheet for MIPS assembly
> and find out how statements in C can translate to assembly. That was easy
> to learn. What a real compiler will generate is always 5 times more than
> what the instruction manual says it should translate to. I tried with GCC
> and a MIPS compiler, looked at the generated assembly which was very
> different from what I could run directly from e.g. the MARS MIPS
> environment by writing it by hand.
> 
> I'm out on deep water but this was my experience with trying to learn. I
> found that TCC is very good for learning and trying ideas.
> 
> /Niklas

I would advice you to start with this 
https://craftinginterpreters.com/contents.html first.

The rest will follow before you know it.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-28 Thread Niklas Rosencrantz
I tried to read the Tiger Book with examples. I tried to learn Bison. I
tried to learn Lemon Parser. I could not write the grammar for a for-loop.
I don't know if that's because if stupid, if it wasn't well explained or if
it's difficult.

What I could learn from was to take the instruction sheet for MIPS assembly
and find out how statements in C can translate to assembly. That was easy
to learn. What a real compiler will generate is always 5 times more than
what the instruction manual says it should translate to. I tried with GCC
and a MIPS compiler, looked at the generated assembly which was very
different from what I could run directly from e.g. the MARS MIPS
environment by writing it by hand.

I'm out on deep water but this was my experience with trying to learn. I
found that TCC is very good for learning and trying ideas.

/Niklas

Den tors 27 jan. 2022 20:50  skrev:

> 26 Ιαν 2022, 22:55 Από nikla...@gmail.com:
>
> > I'm not an expert C programmer. I could find my way, read and learn from
> the TCC source code. It reminded me of reading the source of SASH (the
> stand-alone shell) which is readable compared to DASH for example.
> >
> > 2. What I would do to learn more but it's not guaranteed to work
> >
> > a) I would try and learn how statements (in C) translate to assembly for
> a target platform. Maybe start with ARM or MIPS that is supposed to be
> easier than x86 asm.
> >
> > b) I would try and write a disassembler because I heard it's a good
> exercise.
> >
> > My experience is that compilers or how to write an interpreter is not a
> learn-by-doing ability. I would need to read and practice a lot before
> trying to do it.
> >
> > /Niklas
> >
>
> Thanks you! Yeah, trying to test things yourself is a way to learn but
> apart from been very very hard, inappropriate and annoying to do, this is
> another way. You see, let's say that you want to see how a statement
> translates to assembly from C ok? Now, let's say that you use GCC for that
> (which produces more bloated code than TCC hence why I picked it for the
> example) to see how it translates C code to assembly. Now the problem with
> this is that, why should we take the way it does it as "the right way?"
> Maybe the way GCC does it is not the best possible way or maybe there are
> better practices that have been found through the years. So I think I will
> ultimately waste my time and challenge my patience doing it this way.
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-27 Thread rempas via Tinycc-devel
27 Ιαν 2022, 00:13 Από tinycc-devel@nongnu.org:

> If your language is quite different from C, and you wish to make a fast 
> compiler, I would suggest building  the compiler yourself. If you can make 
> EBNF of the langage syntax, your frontend is almost done. Take some fast 
> parser generator. I strongly recommend Coco/R because it generates easy to 
> understand and fast parser code and suipports different programming languages.
> The Compiler Generator Coco/R (jku.at) 
> 
>
Thank you! I will look it out!

> What is here interesting, you can add code in your favorite language to be 
> executed after any syntax element is recognized inside (.    .)  brackets. It 
> may be storing new variables during the declaration into the table , 
> recognizing the variable already in the table or machine code 
> generating. It is relatively easy to generate assembly code, but it is not 
> the fastest way to execute
>
I'm sorry but I don't understand what you are talking about here. Can you 
please explain me?

> In a case of machine code, you need to know also about executable format 
> (headers and sections), instruction encoding and code patching in case of 
> jumps.
>
Yeah, that's what I'm thinking and I would like to find a book or something 
that will show how to do that properly. At least the basic ones cause like I 
said, it is very very hard to read references when you don't know anything in 
this topic!

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-27 Thread rempas via Tinycc-devel
26 Ιαν 2022, 22:55 Από nikla...@gmail.com:

> I'm not an expert C programmer. I could find my way, read and learn from the 
> TCC source code. It reminded me of reading the source of SASH (the 
> stand-alone shell) which is readable compared to DASH for example.
>
> 2. What I would do to learn more but it's not guaranteed to work
>
> a) I would try and learn how statements (in C) translate to assembly for a 
> target platform. Maybe start with ARM or MIPS that is supposed to be easier 
> than x86 asm.
>
> b) I would try and write a disassembler because I heard it's a good exercise.
>
> My experience is that compilers or how to write an interpreter is not a 
> learn-by-doing ability. I would need to read and practice a lot before trying 
> to do it.
>
> /Niklas
>

Thanks you! Yeah, trying to test things yourself is a way to learn but apart 
from been very very hard, inappropriate and annoying to do, this is another 
way. You see, let's say that you want to see how a statement translates to 
assembly from C ok? Now, let's say that you use GCC for that (which produces 
more bloated code than TCC hence why I picked it for the example) to see how it 
translates C code to assembly. Now the problem with this is that, why should we 
take the way it does it as "the right way?" Maybe the way GCC does it is not 
the best possible way or maybe there are better practices that have been found 
through the years. So I think I will ultimately waste my time and challenge my 
patience doing it this way.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-26 Thread Joshua Scholar
I assume that the backends are built on in-memory assemblers.
If those assemblers are relatively complete they could be very useful for
someone wanting to start their own compiler.

How easy are those to understand/use/separate from the rest of the program?

On Wed, Jan 26, 2022 at 2:14 PM Samir Ribić via Tinycc-devel <
tinycc-devel@nongnu.org> wrote:

> If your language is quite different from C, and you wish to make a fast
> compiler, I would suggest building  the compiler yourself. If you can make
> EBNF of the langage syntax, your frontend is almost done. Take some fast
> parser generator. I strongly recommend Coco/R because it generates easy to
> understand and fast parser code and suipports different programming
> languages.
> The Compiler Generator Coco/R (jku.at)
> 
>
> What is here interesting, you can add code in your favorite language to be
> executed after any syntax element is recognized inside (..)  brackets.
> It may be storing new variables during the declaration into the table ,
> recognizing the variable already in the table or machine code generating.
> It is relatively easy to generate assembly code, but it is not the fastest
> way to execute. In a case of machine code, you need to know also about
> executable format (headers and sections), instruction encoding and code
> patching in case of jumps.
>
> On Wed, Jan 26, 2022 at 10:09 PM Niklas Rosencrantz 
> wrote:
>
>> I'm not an expert C programmer. I could find my way, read and learn from
>> the TCC source code. It reminded me of reading the source of SASH (the
>> stand-alone shell) which is readable compared to DASH for example.
>>
>> 2. What I would do to learn more but it's not guaranteed to work
>>
>> a) I would try and learn how statements (in C) translate to assembly for
>> a target platform. Maybe start with ARM or MIPS that is supposed to be
>> easier than x86 asm.
>>
>> b) I would try and write a disassembler because I heard it's a good
>> exercise.
>>
>> My experience is that compilers or how to write an interpreter is not a
>> learn-by-doing ability. I would need to read and practice a lot before
>> trying to do it.
>>
>> /Niklas
>>
>> Den ons 26 jan. 2022 20:28rempas via Tinycc-devel <
>> tinycc-devel@nongnu.org> skrev:
>>
>>> **Huge post incoming!!!**
>>>
>>> Hi! I'm a beginner with low level programming and assembly. I'm
>>> interested in learning
>>> assembly so I can create my own (non-toy) compiler. Now, I'm a huge
>>> fanatic for
>>> TCC!!! I LOVE IT!!! I love it so much that it inspired my to create my
>>> own compiler that
>>> will output C code and then use TCC (or any C compiler to compile) it.
>>> However, I thought about some things.
>>>
>>> 1. Compile times. TCC is the fastest non-toy compiler but my compiler
>>> will add up to the compilation time because it will need to create
>>> these C files. On top on that, the C programming language doesn't
>>> use the best practices when it comes to header files as you have to
>>> re-write the files end up on becoming slower not because of the
>>> compiler
>>> or the backend because because of the design of the language itself.
>>>
>>> 2. Having to deal with C. A lot of things of my language will not
>>> translate to C
>>> with the best possible way so it will be harder and I will need to
>>> sacrifice the
>>> compilation times and maybe runtime performance.
>>>
>>> 3. Optimizations. As we know, TCC doesn't make optimizations (or does
>>> it?) so
>>> the resulting code can run slower that GCC or Clang some times. This
>>> means
>>> that we will need to use 2 compilers in some projects to get the
>>> best possible
>>> performance while keeping the amazing fast compilation times of TCC.
>>>
>>> So what I thought was... "You know what? We don't I make a compiler that
>>> will
>>> create binaries itself? I will have the best possible compilation times
>>> and I will
>>> be able to apply the optimizations that I want!". Well that's a great
>>> idea but there
>>> are some problems.
>>>
>>> 1. This is HARD!!! Not only I must first learn assembly but I must also
>>> read
>>> the manufacturer manual for each CPU that I want to support. Also,
>>> even
>>> across the same instruction set, Each operating system needs
>>> different
>>> work to be done (I don't know, I suppose even OSes that use something
>>> common like ELF will not work out of the box without any small
>>> change right?).
>>> So even for people that know assembly NOW and are very experienced
>>> with it,
>>> this will be very hard to do and maintain unless you are a genius
>>> and I am NOT
>>> one for sure (the exact opposite probably).
>>>
>>> 2. Where do I learn? I mean, resources about creating binary files in
>>> ELF format
>>> (or whatever each OS is using) and learning the CPU instructions
>>> don't exist here
>>> and there and even in the places where they exist, it is most of the
>>> 

Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-26 Thread Samir Ribić via Tinycc-devel
If your language is quite different from C, and you wish to make a fast
compiler, I would suggest building  the compiler yourself. If you can make
EBNF of the langage syntax, your frontend is almost done. Take some fast
parser generator. I strongly recommend Coco/R because it generates easy to
understand and fast parser code and suipports different programming
languages.
The Compiler Generator Coco/R (jku.at)


What is here interesting, you can add code in your favorite language to be
executed after any syntax element is recognized inside (..)  brackets.
It may be storing new variables during the declaration into the table ,
recognizing the variable already in the table or machine code generating.
It is relatively easy to generate assembly code, but it is not the fastest
way to execute. In a case of machine code, you need to know also about
executable format (headers and sections), instruction encoding and code
patching in case of jumps.

On Wed, Jan 26, 2022 at 10:09 PM Niklas Rosencrantz 
wrote:

> I'm not an expert C programmer. I could find my way, read and learn from
> the TCC source code. It reminded me of reading the source of SASH (the
> stand-alone shell) which is readable compared to DASH for example.
>
> 2. What I would do to learn more but it's not guaranteed to work
>
> a) I would try and learn how statements (in C) translate to assembly for a
> target platform. Maybe start with ARM or MIPS that is supposed to be easier
> than x86 asm.
>
> b) I would try and write a disassembler because I heard it's a good
> exercise.
>
> My experience is that compilers or how to write an interpreter is not a
> learn-by-doing ability. I would need to read and practice a lot before
> trying to do it.
>
> /Niklas
>
> Den ons 26 jan. 2022 20:28rempas via Tinycc-devel 
> skrev:
>
>> **Huge post incoming!!!**
>>
>> Hi! I'm a beginner with low level programming and assembly. I'm
>> interested in learning
>> assembly so I can create my own (non-toy) compiler. Now, I'm a huge
>> fanatic for
>> TCC!!! I LOVE IT!!! I love it so much that it inspired my to create my
>> own compiler that
>> will output C code and then use TCC (or any C compiler to compile) it.
>> However, I thought about some things.
>>
>> 1. Compile times. TCC is the fastest non-toy compiler but my compiler
>> will add up to the compilation time because it will need to create
>> these C files. On top on that, the C programming language doesn't
>> use the best practices when it comes to header files as you have to
>> re-write the files end up on becoming slower not because of the
>> compiler
>> or the backend because because of the design of the language itself.
>>
>> 2. Having to deal with C. A lot of things of my language will not
>> translate to C
>> with the best possible way so it will be harder and I will need to
>> sacrifice the
>> compilation times and maybe runtime performance.
>>
>> 3. Optimizations. As we know, TCC doesn't make optimizations (or does
>> it?) so
>> the resulting code can run slower that GCC or Clang some times. This
>> means
>> that we will need to use 2 compilers in some projects to get the best
>> possible
>> performance while keeping the amazing fast compilation times of TCC.
>>
>> So what I thought was... "You know what? We don't I make a compiler that
>> will
>> create binaries itself? I will have the best possible compilation times
>> and I will
>> be able to apply the optimizations that I want!". Well that's a great
>> idea but there
>> are some problems.
>>
>> 1. This is HARD!!! Not only I must first learn assembly but I must also
>> read
>> the manufacturer manual for each CPU that I want to support. Also,
>> even
>> across the same instruction set, Each operating system needs different
>> work to be done (I don't know, I suppose even OSes that use something
>> common like ELF will not work out of the box without any small change
>> right?).
>> So even for people that know assembly NOW and are very experienced
>> with it,
>> this will be very hard to do and maintain unless you are a genius and
>> I am NOT
>> one for sure (the exact opposite probably).
>>
>> 2. Where do I learn? I mean, resources about creating binary files in ELF
>> format
>> (or whatever each OS is using) and learning the CPU instructions
>> don't exist here
>> and there and even in the places where they exist, it is most of the
>> times, references
>> or things like manufacturer manuals which are not the best things to
>> study if you
>> don't have years of experience and you are already confident enough
>> with this topic.
>>
>> Ok this is getting too big, I will be sort. So after all that, I either
>> do my original idea
>> and output C code or I'm writing this email and hope for a reply. So what
>> I wanted
>> to ask from people that have work with TCC's code and know how assembly
>> works,
>> is TCC's backed tied 

Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-26 Thread Niklas Rosencrantz
I'm not an expert C programmer. I could find my way, read and learn from
the TCC source code. It reminded me of reading the source of SASH (the
stand-alone shell) which is readable compared to DASH for example.

2. What I would do to learn more but it's not guaranteed to work

a) I would try and learn how statements (in C) translate to assembly for a
target platform. Maybe start with ARM or MIPS that is supposed to be easier
than x86 asm.

b) I would try and write a disassembler because I heard it's a good
exercise.

My experience is that compilers or how to write an interpreter is not a
learn-by-doing ability. I would need to read and practice a lot before
trying to do it.

/Niklas

Den ons 26 jan. 2022 20:28rempas via Tinycc-devel 
skrev:

> **Huge post incoming!!!**
>
> Hi! I'm a beginner with low level programming and assembly. I'm interested
> in learning
> assembly so I can create my own (non-toy) compiler. Now, I'm a huge
> fanatic for
> TCC!!! I LOVE IT!!! I love it so much that it inspired my to create my own
> compiler that
> will output C code and then use TCC (or any C compiler to compile) it.
> However, I thought about some things.
>
> 1. Compile times. TCC is the fastest non-toy compiler but my compiler
> will add up to the compilation time because it will need to create
> these C files. On top on that, the C programming language doesn't
> use the best practices when it comes to header files as you have to
> re-write the files end up on becoming slower not because of the
> compiler
> or the backend because because of the design of the language itself.
>
> 2. Having to deal with C. A lot of things of my language will not
> translate to C
> with the best possible way so it will be harder and I will need to
> sacrifice the
> compilation times and maybe runtime performance.
>
> 3. Optimizations. As we know, TCC doesn't make optimizations (or does it?)
> so
> the resulting code can run slower that GCC or Clang some times. This
> means
> that we will need to use 2 compilers in some projects to get the best
> possible
> performance while keeping the amazing fast compilation times of TCC.
>
> So what I thought was... "You know what? We don't I make a compiler that
> will
> create binaries itself? I will have the best possible compilation times
> and I will
> be able to apply the optimizations that I want!". Well that's a great idea
> but there
> are some problems.
>
> 1. This is HARD!!! Not only I must first learn assembly but I must also
> read
> the manufacturer manual for each CPU that I want to support. Also, even
> across the same instruction set, Each operating system needs different
> work to be done (I don't know, I suppose even OSes that use something
> common like ELF will not work out of the box without any small change
> right?).
> So even for people that know assembly NOW and are very experienced
> with it,
> this will be very hard to do and maintain unless you are a genius and
> I am NOT
> one for sure (the exact opposite probably).
>
> 2. Where do I learn? I mean, resources about creating binary files in ELF
> format
> (or whatever each OS is using) and learning the CPU instructions don't
> exist here
> and there and even in the places where they exist, it is most of the
> times, references
> or things like manufacturer manuals which are not the best things to
> study if you
> don't have years of experience and you are already confident enough
> with this topic.
>
> Ok this is getting too big, I will be sort. So after all that, I either do
> my original idea
> and output C code or I'm writing this email and hope for a reply. So what
> I wanted
> to ask from people that have work with TCC's code and know how assembly
> works,
> is TCC's backed tied with TCC's frontend? Will it be strain-forward If I
> was trying to learn
> some assembly and then trying to read TCC backend and then try to
> understand how
> it works and add my own frontend to it? What are your thoughts?
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-26 Thread rempas via Tinycc-devel
**Huge post incoming!!!**

Hi! I'm a beginner with low level programming and assembly. I'm interested in 
learning
assembly so I can create my own (non-toy) compiler. Now, I'm a huge fanatic for
TCC!!! I LOVE IT!!! I love it so much that it inspired my to create my own 
compiler that
will output C code and then use TCC (or any C compiler to compile) it.
However, I thought about some things.

1. Compile times. TCC is the fastest non-toy compiler but my compiler
    will add up to the compilation time because it will need to create
    these C files. On top on that, the C programming language doesn't
    use the best practices when it comes to header files as you have to
    re-write the files end up on becoming slower not because of the compiler
    or the backend because because of the design of the language itself.

2. Having to deal with C. A lot of things of my language will not translate to C
    with the best possible way so it will be harder and I will need to 
sacrifice the
    compilation times and maybe runtime performance.

3. Optimizations. As we know, TCC doesn't make optimizations (or does it?) so
    the resulting code can run slower that GCC or Clang some times. This means
    that we will need to use 2 compilers in some projects to get the best 
possible
    performance while keeping the amazing fast compilation times of TCC.

So what I thought was... "You know what? We don't I make a compiler that will
create binaries itself? I will have the best possible compilation times and I 
will
be able to apply the optimizations that I want!". Well that's a great idea but 
there
are some problems.

1. This is HARD!!! Not only I must first learn assembly but I must also read
    the manufacturer manual for each CPU that I want to support. Also, even
    across the same instruction set, Each operating system needs different
    work to be done (I don't know, I suppose even OSes that use something
    common like ELF will not work out of the box without any small change 
right?).
    So even for people that know assembly NOW and are very experienced with it,
    this will be very hard to do and maintain unless you are a genius and I am 
NOT
    one for sure (the exact opposite probably).

2. Where do I learn? I mean, resources about creating binary files in ELF format
    (or whatever each OS is using) and learning the CPU instructions don't 
exist here
    and there and even in the places where they exist, it is most of the times, 
references
    or things like manufacturer manuals which are not the best things to study 
if you
    don't have years of experience and you are already confident enough with 
this topic.

Ok this is getting too big, I will be sort. So after all that, I either do my 
original idea
and output C code or I'm writing this email and hope for a reply. So what I 
wanted
to ask from people that have work with TCC's code and know how assembly works,
is TCC's backed tied with TCC's frontend? Will it be strain-forward If I was 
trying to learn
some assembly and then trying to read TCC backend and then try to understand how
it works and add my own frontend to it? What are your thoughts?

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel