News for hackers. Stuff that matters.
Re:C Is Not a Low-level Language (2018) by junon on Tuesday December 28, 2021 @08:02AM (#29713362)
Err... what? Did you make these terms up yourself, or are these established in some literature already? Because they make no sense.

C isn't converted into assembler language unless you ask the compiler to. For example, LLVM lowers IR AST structures into target specific machine code. Assembler is never involved.

ASM is just a human readable representation of machine code for a particular ISA. So in your mental model, C and ASM exist at the same level.

Further, Java bytecode would exist above the the machine code level (again, alongside C then, since the VM is compiled to machine code) and Java on top of that.

It just doesn't make any sense to define languages like this. I don't see any benefit, and I don't even see it as being correct.

Re:C Is Not a Low-level Language (2018) by rezaprima on Tuesday December 28, 2021 @08:57AM (#29713790)
perhaps he/she meant 3rd generation language. https://en.wikipedia.org/wiki/Third-generation_programming_l...
Re:C Is Not a Low-level Language (2018) by drran on Tuesday December 28, 2021 @10:25AM (#29714588)
3 generation of languages were powered by increased level of abstraction, which was enabled by increased capabilities of hardware. 4th generation can (will?) be powered by AI.
Re:C Is Not a Low-level Language (2018) by junon on Tuesday December 28, 2021 @09:01AM (#29713821)
Just because it's on Wikipedia doesn't mean it's a real thing. The only source for that page is some bizarro, circa-1998 website about "computer jargon". These are not academic terms that I've personally ever heard of. Happy to be wrong, but I'm not going to pretend they have any utility or legs.
Re:C Is Not a Low-level Language (2018) by uxp100 on Tuesday December 28, 2021 @09:12AM (#29713930)
3gl 4gl 5gl were common terms 30 years ago or so. More industry and advertising terms than academic. And 5gl was more like a Japanese government grant program than any particular set of language features IIRC.
Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @09:25AM (#29714052)
My memory of the whole "nGL" language thing was that it was more a marketing term than anything you would find in an academic paper. It was particularly common in the IBM world, for example in books[1] and advertisements[2]

[1] https://www.oldcomputerbooks.com/pages/books/R504/james-mart...

[2] I can't find a good example, but I remember seeing ads for "4GL" tools in Dr Dobbs regularly in the mid-90s.

Re:C Is Not a Low-level Language (2018) by int_19h on Wednesday December 29, 2021 @03:13AM (#29722932)
On PC, I remember platforms such as dBase were often referred to as 4GL. In retrospect, it feels like was a short way to say "very high-level domain-specific language for databases".
Re:C Is Not a Low-level Language (2018) by resonious on Tuesday December 28, 2021 @10:27AM (#29714605)
The "high-level lang, assembly, machine code" model is pretty much how it's taught in schools and random internet tutorials. As usual, the real world is a little more nuanced.
Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @09:16AM (#29713975)
> C isn't converted into assembler language unless you ask the compiler to. For example, LLVM lowers IR AST structures into target specific machine code. Assembler is never involved

That depends on the compiler. GCC, for instance, most certainly emits assembler code as part of its standard compilation process.

Re:C Is Not a Low-level Language (2018) by vlovich123 on Tuesday December 28, 2021 @09:57AM (#29714339)
GCC to my knowledge has long-switched to IR as well. It’s called GIMPLE [1]. Can you please substantiate your claim?

[1]. https://gcc.gnu.org/wiki/GIMPLE

Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @10:51AM (#29714829)
Well, there this[1] page that describes the GCC architecture:

"The SSA form is also used for optimizations. GCC performs more than 20 different optimizations on SSA trees. After the SSA optimization pass, the tree is converted back to the GIMPLE form which is then used to generate a register-transfer language (RTL) form of a tree. RTL is a hardware-based representation that corresponds to an abstract target architecture with an infinite number of registers. An RTL optimization pass optimizes the tree in the RTL form. *Finally, a GCC back-end generates the assembly code for the target architecture using the RTL representation.* Examples of back-ends are x86 back end, mips back end, etc."

Then, there's the official GCC documentation[2]:

"Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file."

You can also just run GCC -- either with --verbose or --save-temps -- and observe what the compiler toolchain is doing.

[1] https://en.m.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU...

[2] https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Overall-Option...

Re:C Is Not a Low-level Language (2018) by vlovich123 on Tuesday December 28, 2021 @02:19PM (#29716921)
Not really sure what you’re arguing for. All optimization passes operate on GIMPLE.

> SSA GIMPLE is low level GIMPLE rewritten in SSA form.

I’m by no means a compiler internals expert, but to my knowledge there’s no translation from RTL to assembly. The compiler is directly emitting the machine code directly without first emitting assembler. You have to ask the compiler to serialize to assembly explicitly.

> several assembler input files, or into one assembler input file; then each assembler input file produces an object file,

That doesn’t sound right. Seems more like an abstract description. You can’t dump assembly out of an object file either. You have to do a conversion from an intermediary form to get back out a form of the assembly.

I think at this point it’s splitting hairs but assembly is not used as an intermediary at any point, even for generating machine code.

Re:C Is Not a Low-level Language (2018) by marcus0x62 on Tuesday December 28, 2021 @03:52PM (#29718010)
> Not really sure what you’re arguing for. All optimization passes operate on GIMPLE.

You asked me for a citation. I provided two, as well as a means by which you could see for yourself that what I am saying is correct.

Believe what you want, but all of the GCC documentation, as well as the output of the compiler if you run with --verbose or --save-temps supports what I have described of GCC's operation.

The compiler internals manual[1] also describes the backend machine descriptions, and how they are used in detail:

"There are three main conversions that happen in the compiler:

1. The front end reads the source code and builds a parse tree.

2. The parse tree is used to generate an RTL insn list based on named instruction patterns.

3. The insn list is matched against the RTL templates to produce assembler code."

[1] - https://gcc.gnu.org/onlinedocs/gccint/Overview.html