6 ms·
It’s worth noting that this is a compiler for the Tiny-C language, and not as one might think a tiny compiler for the C language.
by netgusto 4y ago
It’s worth noting that this is a compiler for the Tiny-C language, and not as one might think a tiny compiler for the C language.
- unwind 4y agoIt'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!
- northernskys30 4y agoIt compiles to a sort of byte code that is executed by a stack based virtual machine.
- userbinator 4y agoIt 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).
- masklinn 4y agoThat’s more or less every interpreter. CPython compiles to bytecode before interpreting that, yet nobody would call it a compiler.
- shadowfox 4y agoIn 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.
- Mike_12345 4y agoThat 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".
- masklinn 4y ago> 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.
- Mike_12345 4y ago> None of these assertions is correct. You should fix the Wikipedia article: https://en.wikipedia.org/wiki/CPython 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."
- userbinator 4y agoI 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.
- susam 4y agoYes, a better title would be: Compiler for the Tiny-C Language (2001) In fact, that is exactly how the source code describes itself in the comments.