RE: Arithmetic Expression Compiler
January 3, 2019 at 12:35 pm
(This post was last modified: January 3, 2019 at 1:31 pm by FlatAssembler.)
I don't think I am doing it the hard way, I think it's that x86 assembly and especially ARM assembly just aren't easy compilation targets.
The x86 Assembly language doesn't appear to follow the principle of least surprise at all. ARM assembly is said to be significantly more consistent, but that comes at a price of not having useful directives (such as the basic trigonometric functions, basic logarithmic and exponential functions, basic cyclometric functions...) built in. If you target those, you need to spend hours and hours debugging the assembly (and perhaps the easiest way to do that is to repeatedly call C functions such as "printf" from assembly code, which is itself very error prone) instead of implementing new features to your compiler.
That's why almost every compiler collection has its own byte code (GIMPLE in GCC, LLVM IR in CLANG...), which is intended to be easier to compile to than assembly, but it's still supposed to be easy to translate into any particular assembly. WebAssembly is also designed to be extremely easy to compile into.
By the way, what do you guys here think, what is the best compiler for C if you are just targeting the common Windows on Intel architecture? I think it's by far the Tiny C Compiler. It compiles the entire Duktape in an imperceptible amount of time on my 12-year-old laptop, while GCC takes more than 10 seconds to do the same. It's said that TCC produces inferior assembly code than GCC does, but, for the Duktape-based compiler I've made, the difference is imperceptible. I value being able to quickly modify my C program when debugging it more than being able to produce assembly optimized for the super-modern 64-bit processors (which my 12-year-old laptop can't execute anyway).
BTW, let me be clear, I am not planning to continue developing it. I've made it just in case somebody asks me "Do you know anything about how the compilers work?", that I can shut them up by saying "Sure, I've made one! From scratch, in JavaScript. For my own simple programming language that compiles into Assembly.".
The x86 Assembly language doesn't appear to follow the principle of least surprise at all. ARM assembly is said to be significantly more consistent, but that comes at a price of not having useful directives (such as the basic trigonometric functions, basic logarithmic and exponential functions, basic cyclometric functions...) built in. If you target those, you need to spend hours and hours debugging the assembly (and perhaps the easiest way to do that is to repeatedly call C functions such as "printf" from assembly code, which is itself very error prone) instead of implementing new features to your compiler.
That's why almost every compiler collection has its own byte code (GIMPLE in GCC, LLVM IR in CLANG...), which is intended to be easier to compile to than assembly, but it's still supposed to be easy to translate into any particular assembly. WebAssembly is also designed to be extremely easy to compile into.
By the way, what do you guys here think, what is the best compiler for C if you are just targeting the common Windows on Intel architecture? I think it's by far the Tiny C Compiler. It compiles the entire Duktape in an imperceptible amount of time on my 12-year-old laptop, while GCC takes more than 10 seconds to do the same. It's said that TCC produces inferior assembly code than GCC does, but, for the Duktape-based compiler I've made, the difference is imperceptible. I value being able to quickly modify my C program when debugging it more than being able to produce assembly optimized for the super-modern 64-bit processors (which my 12-year-old laptop can't execute anyway).
BTW, let me be clear, I am not planning to continue developing it. I've made it just in case somebody asks me "Do you know anything about how the compilers work?", that I can shut them up by saying "Sure, I've made one! From scratch, in JavaScript. For my own simple programming language that compiles into Assembly.".