News for hackers. Stuff that matters.
Re:Tiny-C Compiler by unwind on Monday March 13, 2023 @08:55AM (#35135059)
It's probably better to call it an interpreter, since it will also run the program and print the values of all non-zero variables afterward.

Calling it a compiler is (to me) really stretching things, I can't see any code to emit any other form of the code, it's all aimed at evaluating (executing) it.

Edit: oops, I didn't read the code closely enough, it does emit code but only internally, that code is what gets executed. Thanks for the corrections!

Re:Tiny-C Compiler by userbinator on Monday March 13, 2023 @09:32AM (#35135477)
It is a compiler rather than a direct evaluator, since it generates bytecode for a stack VM --- and also includes the interpreter for that (look at the bottom).
Re:Tiny-C Compiler by masklinn on Monday March 13, 2023 @09:38AM (#35135564)
That’s more or less every interpreter. CPython compiles to bytecode before interpreting that, yet nobody would call it a compiler.
Re:Tiny-C Compiler by shadowfox on Monday March 13, 2023 @11:35AM (#35137167)
In contrast, Java also did that and I doubt if most people think of Java as interpreted. So, using a byte-code interpreter may not be the criteria most people are using to decide on this. Truthfully, I think it is all a bit arbitrary.
Re:Tiny-C Compiler by Mike_12345 on Monday March 13, 2023 @05:12PM (#35142754)
That is definitely a compiler and anyone with a CS degree would call it that if they were discussing its functionality, because that's technically what it is. (Referring specifically to the part which compiles Python to bytecode)

Your SQL database also has a compiler. SQL is compiled to an execution plan. Compile doesn't only mean "create a machine code executable file".

Re:Tiny-C Compiler by masklinn on Monday March 13, 2023 @05:33PM (#35143104)
> That is definitely a compiler and anyone with a CS degree would call it that if they were discussing its functionality because that's technically what it is.

None of these assertions is correct.

> (Referring specifically to the part which compiles Python to bytecode)

So referring specifically to something different than what I explicitly specified, it's called something else.

By that reasoning, a cow is a muscle and you are an acid.

> Your SQL database also has a compiler.

"Has a" and "is a" are rather different relationships.

> Compile doesn't only mean "create a machine code executable file".

You're the only person who made that assertion.

Re:Tiny-C Compiler by Mike_12345 on Monday March 13, 2023 @08:47PM (#35145661)
> None of these assertions is correct.

https://en.wikipedia.org/wiki/CPython

"CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it."

Re:Tiny-C Compiler by userbinator on Monday March 13, 2023 @09:20PM (#35146007)
I think this is a question of interface vs. implementation.

Python, JavaScript, and other languages which are traditionally considered interpreted but may do (JIT) compilation in their implementation are used as if they were interpreters: to the user, there's no separate compilation step. You run python somefile.py or node somefile.js (or refresh a browser holding a page), and editing the source code causes the next invocation to take those changes immediately. Contrast this with C/C++ and Java where there is definitely an explicit compilation step in nearly all implementations.

The program in this article thus is an implementation of a compiler, but has the interface of an interpreter.

Re:Tiny-C Compiler by northernskys30 on Monday March 13, 2023 @09:21AM (#35135334)
It compiles to a sort of byte code that is executed by a stack based virtual machine.