8cc.vim: Pure Vim script C Compiler

(github.com)

162 points | by JNRowe 378 days ago

6 comments

  • WalterBright 377 days ago
    Back in the 1970s, I was told that somebody had written a FORTRAN compiler as a TECO macro just to prove it could be done.

    (TECO means Text Editor Charactor Oriented, a line editor that had a macro capability. EDLIN was a line editor for MS-DOS.)

    • mhh__ 376 days ago
      Sometimes I worry that software, because you can do this, also let's you do similarly bizarre things obfuscated under a layer of complexity.

      Imagine a car company announcing they'd built a perfectly cuboidal car entirely out of (say) tungsten — it only does 3mph and is expensive but we value engineering time over performance!

  • timando 377 days ago
    Can you use the ELVM backend to compile Emacs into Vim script?
    • zorrn 377 days ago
      An operating system inside a text editor inside an operating system maybe inside a vm inside another operating system. Wait I forgot nested virtualization.
  • INTPenis 378 days ago
    It looks like they're just taking the entire eightcc compiler and stuffed into vim buffer memory.
    • rhysd 378 days ago
      No. It is a C compiler compiled to Vim script. So it is actually a C compiler written in Vim script.
      • munificent 378 days ago
        I think a more accurate way to describe it is that it's a C compiler written in C and then automatically transpiled to VimScript.

        No human hand-authored this giant pile of VimScript: https://raw.githubusercontent.com/rhysd/8cc.vim/master/autol...

        • rhysd 378 days ago
          Yes. It is compiled to Vim script using ELVM[1]. Though the author of Vim script backend of ELVM is me :)

          [1]: https://github.com/shinh/elvm

          • nequo 378 days ago
            That is very cool! So with ELVM one could put together a C compiler in TeX too? Or transpile Vim into Vim script to self-host it?
          • krick 377 days ago
            Cool. Why, though? I mean, it's not like this project has any practical value anyway, but wouldn't it be actually easier and more efficient to actually implement a C compiler in VimScript? Or is the vimscript ELVM backend the actual end-goal here, and C-compiler at question is basically just a proof that it works?
        • metadat 377 days ago
          Thanks, at first I thought someone had written it in vim script, then I inspected the README in detail and learned it's only transpiled from C to vim script, which is not particularly exciting or impressive compared to a human wielding such a degree of vim script fu.
        • gsuuon 377 days ago
          Ah - my impression went from 'this is pure masochism' to just 'this is slightly insane'.
      • flohofwoe 378 days ago
        I wonder how much faster a manually written C compiler in Vim script would be.

        The current code is essentially assembly instructions running as Vim script, this gotta be incredibly slow, probably not much faster than an x86 emulator written in Vim script:

        https://raw.githubusercontent.com/rhysd/8cc.vim/master/autol...

        • actionfromafar 378 days ago
          Time for JIT-compiled vimscript, I guess? Why should Javascript have all the fun.
        • svlasov 378 days ago
          I wonder how much faster it would be if it was written in Vim9 script.
        • aghastnj 378 days ago
          There's only one way to find out, bubba! You're gonna have to write an x86 emulator in vimscript for us, and tell us how it compares...
  • flying_sheep 378 days ago
    I'd love to use vim to compile vim lolz
    • queuebert 378 days ago
      I always suspected Emacs would achieve sentience before vim. Maybe I'll be wrong.
      • zelphirkalt 378 days ago
        The difference is, that with Vim script it will either happen unexpectedly or unexplicably, while in Elisp it will/might happen later, but will be in the realm of understandable things.
        • tambourine_man 378 days ago
          Just keep adding closing parenthesis to the end of the file. Eventually Emacs will greet you in HAL 9000 style.
  • riddley 378 days ago
    Checkmate, athiests.