Live data from Hacker News

Tiny-C Compiler (2001)

iro.umontreal.ca

41–50 of 82 posts

Re: Tiny-C Compiler (2001)

#41
This doesn't have types, functions, arrays or much error checking. It has one char identifiers. I don't think we should read into this any more than a tiny example or experiment by the author.

Re: Tiny-C Compiler (2001)

#42
post #41

This doesn't have types, functions, arrays or much error checking. It has one char identifiers. I don't think we should read into this any more than a tiny example or experiment by the author.

So, it's the C equivalent of Tiny BASIC?

So, a Tiny C?

Re: Tiny-C Compiler (2001)

#43

This is an interpreter for a super restricted subset of C and it looks well written from a pedagogical standpoint (keeps thing pretty simple, fairly easy to read). But it's slightly awk to strip-down a language (what features do you keep, what do you lose?). I think it's more fun to build an interpreter for an actual tiny language. In my next book I have interpreters for Brainfuck [0], an obfuscated kind of joke of a…

FORTH is another language that's quick and easy to write from scratch, where you need a couple of dozen words written in assembler and then the rest of FORTH can be written in FORTH.

Re: Tiny-C Compiler (2001)

#44

Earlier quoted context omitted.

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).

That’s more or less every interpreter. CPython compiles to bytecode before interpreting that, yet nobody would call it a compiler.

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 (2001)

#45

Not to be confused with https://bellard.org/tcc/ , which is a tiny compiler for the C language.

It is sad that tcc is unmaintained as it would be really useful in small embedded systems. I just tried it on Debian and compilation fails without #undefining CONFIG_TCC_MALLOC_HOOKS in lib/bcheck.c. After compilation it passes tests, but they warn that it could be unreliable.

While Fabrice Bellard is no longer working on TCC [0] and an official release tarball hasn't been packaged since version 0.9.27 (5 years ago) the project is by no means unmaintained.

For details, check their current working repository [1] and mailing list [2].

[0]: https://bellard.org/tcc/

[1]: https://repo.or.cz/tinycc.git

[2]: https://lists.nongnu.org/archive/html/tinycc-devel/

Re: Tiny-C Compiler (2001)

#46
post #14

Oh, Marc Feeley. Wonder if we'll see a Tiny-C target for Gambit?

That's not on my TODO! But Gambit does have support for TCC. For example you can use TCC to compile a file to a dynamically loadable object file (aka shared library). The compilation is faster than gcc and the code size is typically smaller too:

  $ cat hello.scm
  (display "hello!\n")
  $ gsc hello.scm
  $ gsi hello.o1
  hello!
  $ ls -l hello.o1   # this is generated by gcc
  -rwxrwxr-x 1 feeley feeley 18152 Mar 13 17:16 hello.o1
  $ rm hello.o1
  $ gsc -cc "tcc -shared" hello.scm
  $ gsi hello.o1
  hello!
  $ ls -l hello.o1   # this is generated by tcc
  -rwxrwxr-x 1 feeley feeley 4432 Mar 13 17:17 hello.o1

Re: Tiny-C Compiler (2001)

#47
post #41

This doesn't have types, functions, arrays or much error checking. It has one char identifiers. I don't think we should read into this any more than a tiny example or experiment by the author.

So, it's the C equivalent of Tiny BASIC? So, a Tiny C?

Not even that as it doesn't have function calls or even print!

See Feeley's response for the proper context.

Re: Tiny-C Compiler (2001)

#48

Earlier quoted context omitted.

That’s more or less every interpreter. CPython compiles to bytecode before interpreting that, yet nobody would call it a compiler.

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".

> 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 (2001)

#49
Sigh. I wish people would teach compilers using Oberon as an example. One can write a small yet complete compiler for (what turns out to be not-so-tiny) a language.
Post reply on HN