Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming

CJIT - C, Just In Time! (dyne.org) 28

Long-time Slashdot reader jaromil writes: As a fun project, we hacked together a C interpreter (based on Tiny C Compiler) that compiles C code in-memory and runs it live.

CJIT today is a 2MB executable that can do a lot, including call functions from any installed library on Linux, Windows, and MacOSX.

Slashdot reader oliwer points out "they are also including a REPL, which could be interesting." And the CJIT web page promises there's "no EULA to sign, no IDE to install... 100% Free and open source!"

It also says the project was inspired by Terry Davis (TempleOS) and Fabrice Bellard (Tiny C Compiler).

CJIT - C, Just In Time!

Comments Filter:
  • by flyingfsck ( 986395 ) on Sunday December 01, 2024 @01:45PM (#64983555)
    C is my favourite most hated computer language and I use it for everything. I would certainly look into this new tool and will probably hate it just the same.
    • C interpreters aren't new.

      I first used one back in the 1980s.

      They don't work very well. C isn't designed to be an interpreted language.

      • It's compiled "in-memory." It is not "interpreted" per se.

        • Re: My favourite (Score:4, Insightful)

          by ShanghaiBill ( 739463 ) on Sunday December 01, 2024 @02:51PM (#64983657)

          It's compiled "in-memory." It is not "interpreted" per se.

          The problem is that small changes, such as tweaking a header file, can have global effects.

          So, incremental compilation doesn't work very well.

          You can kinda sorta make it work most of the time but with lots of limitations.

          Languages designed for interpretation, such as Python, or for incremental compilation, such as Java, don't have the same problems (although they have different problems).

        • by dfghjk ( 711126 )

          But t's value-add is presumably interactive development because it is used like an interpreter. It's a modified interpreter with better performance, something of value to no one these days.

          • Or custom plugins in other products, just like what you can do with Lua on nginx, or custom rules in firewalls or other similar engines. Throw in some sandboxing and you have a very powerful/dangerous tool.
        • by tlhIngan ( 30335 )

          It's compiled "in-memory." It is not "interpreted" per se.

          Many interpreted languages are compiled in memory. Python, for example, isn't executed line by line, but compiled for a virtual machine bytecode and that bytecode is executed.

          But it's still considered an interpreted language because you just run the code directly even though there's an implicit compile and link step that happens when you run the code.

          It's a very fine distinction these days

          • by narcc ( 412956 )

            We often use the term 'compile' informally to refer to programs that translate programs to a machine code, but, strictly speaking, a compiler is a program that translates a program written in one language into another. An interpreted language that didn't use some intermediate representation would be very odd. The only one I could come up with off-hand was Lisp, but it seems silly to draw a distinction on that basis when all we could say is "we have compiled languages and an interpreted language called Lis

            • by ebh ( 116526 )

              Even those old BASIC interpreters in ROM on your home micro used an intermediate form, generated as you typed, to save memory and improve performance.

              I wouldn't call that either compiling or interpreting. That's front-end lexical analysis and parsing, which for BASIC was not exactly a conventional parse tree, but close. It remained in memory, and that's what was read when you typed RUN. I'd have to fire up my old Apple ][ to be able to tell you for certain what the on-disk format of a saved BASIC program looked like, but it was probably stored in some hybrid of the tokenized format plus the REM comments. (I probably knew the answer to that 45 years ago.)

              • by narcc ( 412956 )

                I wouldn't call that either ...

                That's my whole point, really. It's silly to try to draw a hard line. The claim that there is "a very fine distinction" is equally silly, for the same reasons.

                The rest of this is wildly off-topic, but I feel compelled to reply anyway:

                not exactly a conventional parse tree, but close

                Not even remotely close, as it happens. Quite a few, at least of those I'm familiar with, were little more than a tokenization, not even bothering to do so much as evaluating constant expressions or converting infix expressions to postfix, I assume to simplify the conversion

              • by stripes ( 3681 )

                I wouldn't call that either compiling or interpreting. That's front-end lexical analysis and parsing, which for BASIC was not exactly a conventional parse tree, but close. It remained in memory, and that's what was read when you typed RUN. I'd have to fire up my old Apple ][ to be able to tell you for certain what the on-disk format of a saved BASIC program looked like, but it was probably stored in some hybrid of the tokenized format plus the REM comments. (I probably knew the answer to that 45 years ago.)

          • by batkiwi ( 137781 )

            Would you consider typescript a compiler since it converts it to javascript?

      • by ceoyoyo ( 59147 ) on Sunday December 01, 2024 @05:50PM (#64983931)

        The hair on all the Java people's backs just went up and now they're hissing at you.

    • by gweihir ( 88907 )

      C is the worst language available, except for all others that have been tried.

      Well, not quite. But essentially all programming languages suck. The right tool for the right task makes them suck a bit less and for many tasks, C is it.

  • Seem to recall this product from the 80's, worked really well with better diagnostics than the c compilers of the era...
  • Flappy Bird is bigger than that...

    Anyway, great job! It's fun to see news about a good old-fashioned "we did it because we could" open-source nerd project.

  • Dr. Dobb's 1989 (Score:5, Informative)

    by laughingskeptic ( 1004414 ) on Sunday December 01, 2024 @02:50PM (#64983653)
    Herbert Schildt, "Building your own C interpreter", Dr. Dobb's Journal, 1989, Volume 14, Issue 8 pp. 38 - 49
  • by geekprime ( 969454 ) on Sunday December 01, 2024 @02:58PM (#64983667)
    I still have my original copy on floppy disk. According to the internet archive, Run/C 1.20 by Age of Reason Co. Publication date 1985-04-26
  • by TheSync ( 5291 ) on Sunday December 01, 2024 @06:29PM (#64984025) Journal

    Where is the Javascript version so it can run in the browser window?

  • by eniac42 ( 1144799 ) on Monday December 02, 2024 @08:32AM (#64984827) Journal
    Fabrice Bellards Tiny C Compiler is a brilliant piece of work, a very fast, light, full featured C99 compiler for x86-32/64 or Arm in about 400k or so. I still use it from time to time.
  • I could have used this when I was writing a lot of C...

To communicate is the beginning of understanding. -- AT&T

Working...