We want to talk about C Compiler written in Vim script `rhysd/8cc.vim`. Folders and files Latest commit History Repository files navigation 8cc.vim: Pure Vim script C Compiler
This is a complete C compiler written entirely in Vim script. This novel compiler, 8cc.vim, is a port from the original 8cc, a minimal C compiler tailored for x86_64 Linux. Traditionally self-hosted and compliant with C11 standards, 8cc has been adeptly modified to function through Vim script by leveraging the power of ELVM (Eso Lang Virtual Machine). ELVM allows 8cc to emit its unique intermediate representation, EIR, which forms the backbone for compiling C code into various end languages, including Python, Ruby, C, and even more esoteric languages like BrainFxxk and Befunge.
ELVM Architecture
The ELVM's architecture is reminiscent of LLVM, setting up a sophisticated system where the frontend (8cc) processes C code and the backend (ELVM) translates that into many target languages. This opens a world of possibilities as the system can self-compile into numerous targets through the addition of specific backends, such as the new 'Vim script' backend incorporated by the creator.
8cc.vim Composition and Capabilities
8cc.vim combines a customized 8cc as its frontend and ELC for the backend, allowing it to compile C code into Vim script. This powerful combination enables Vim to evaluate and execute the generated Vim script code, albeit gradually. For instance, compiling the simplest `putchar()` program takes a noticeable 824 seconds on a relatively recent MacBook Pro, highlighting that this is more of a fun exploratory project rather than a practical compiler due to its performance constraints.
Practical Use and Installation
Installating 8cc.vim is straightforward:
Clone the repository and employ `:packadd` (refer to `:help pack-add` within Vim).
Alternatively, choose your preferred plugin manager like vim-plug or dein.vim.
Compiling C Code
Preparing your C code is simplistic within the current buffer. Here's how you can compile:
Place your C code, like the 'Hello world' example, in the buffer.
Execute the `:EccCompile` command.
Explore available options through `:EccCompile --help`.
After a lengthy compilation time, typically exceeding 20 minutes, a new buffer opens revealing the translated Vim script, which you save (`:w putchar.vim`) and source (`:source putchar.vim`).
Subsequently, executing the resulting Vim script involves creating an instance via the `SetupVM()` function and running the script manually.
Command Utilities
For added convenience, the system provides `:EccRun` to witness the result of running Vim script directly. Corresponding functions like `eightcc#compile()` and `eightcc#run()` simplify the compilation and execution process by supporting dictionary parameters to customize execution options.
Licensing
The software is distributed under the MIT License, guaranteeing freedom of usage, modification, distribution, and commercialization with the necessary attribution. The creators and contributors bear no liability for any claims or damages arising from the software's use.
Image to Illustrate Vim Script Compilation

Description: Example showcasing Vim editing environment where the 8cc.vim compiler could be utilized.
Visual of Compilation Process in Vim Buffer

Description: Example of Vim buffer, illustrating how C code is compiled into Vim script.
Remember these 3 key ideas for your startup:
Leveraging Multi-Language Backend:
By adopting a multi-language backend approach like ELVM, you can extend the functionality of your software to support various programming languages, widening its applicability and user base. This modular and flexible architecture could be crucial for achieving interoperability and reach in a diverse developer community.Innovative Project Exploration:
Engaging in innovative and fun projects, even if they're not immediately practical, allows your team to experiment and learn. Projects like 8cc.vim can spark curiosity and foster a culture of continuous improvement and creativity within your startup, encouraging the exploration of new tools and methodologies.Efficiency in Development Tools:
Utilizing tools like Vim script for tasks seemingly unusual for them can streamline development processes, providing unique solutions and improving productivity. Even simple tools can achieve extraordinary results with thoughtful application, potentially offering cost-effective and flexible development workflows. For more insights, see task automation: how and why you should use it.
Edworking is the best and smartest decision for SMEs and startups to be more productive. Edworking is a FREE superapp of productivity that includes all you need for work powered by AI in the same superapp, connecting Task Management, Docs, Chat, Videocall, and File Management. Save money today by not paying for Slack, Trello, Dropbox, Zoom, and Notion.
For more details, see the original source.