Pure Vim Script C Compiler: Introducing 8cc.vim

BY Mark Howell 1 years ago4 MINS READ
article cover

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:

  1. Clone the repository and employ `:packadd` (refer to `:help pack-add` within Vim).

  2. 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:

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

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

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

article cover
About the Author: Mark Howell Linkedin

Mark Howell is a talented content writer for Edworking's blog, consistently producing high-quality articles on a daily basis. As a Sales Representative, he brings a unique perspective to his writing, providing valuable insights and actionable advice for readers in the education industry. With a keen eye for detail and a passion for sharing knowledge, Mark is an indispensable member of the Edworking team. His expertise in task management ensures that he is always on top of his assignments and meets strict deadlines. Furthermore, Mark's skills in project management enable him to collaborate effectively with colleagues, contributing to the team's overall success and growth. As a reliable and diligent professional, Mark Howell continues to elevate Edworking's blog and brand with his well-researched and engaging content.

Trendy NewsSee All Articles
CoverEdit PDFs Securely & Freely: Breeze PDF In-Browser SolutionBreeze PDF is a free, offline browser-based PDF editor ensuring privacy. It offers text, image, and signature additions, form fields, merging, page deletion, and password protection without uploads.
BY Mark Howell 4 May 2025
CoverDecoding R1: The Future of AI Reasoning ModelsR1 is an affordable, open-source AI model emphasizing reasoning, enabling innovation and efficiency, while influencing AI advancements and geopolitical dynamics.
BY Mark Howell 26 January 2025
CoverSteam Brick: A Minimalist Gaming Console Redefines PortabilitySteam Brick: A modified, screenless Steam Deck for travel, focusing on portability by using external displays and inputs. A creative yet impractical DIY project with potential risks.
BY Mark Howell 26 January 2025
CoverVisual Prompt Injections: Essential Guide for StartupsThe Beginner's Guide to Visual Prompt Injections explores vulnerabilities in AI models like GPT-4V, highlighting security risks for startups and offering strategies to mitigate potential data compromises.
BY Mark Howell 13 November 2024
CoverGraph-Based AI: Pioneering Future Innovation PathwaysGraph-based AI, developed by MIT's Markus J. Buehler, bridges unrelated fields, revealing shared complexity patterns, accelerating innovation by uncovering novel ideas and designs, fostering unprecedented growth opportunities.
BY Mark Howell 13 November 2024
CoverRevolutionary Image Protection: Watermark Anything with Localized MessagesWatermark Anything enables embedding multiple localized watermarks in images, balancing imperceptibility and robustness. It uses Python, PyTorch, and CUDA, with COCO dataset, under CC-BY-NC license.
BY Mark Howell 13 November 2024
CoverJungle Music's Role in Shaping 90s Video Game SoundtracksJungle music in the 90s revolutionized video game soundtracks, enhancing fast-paced gameplay on PlayStation and Nintendo 64, and fostering a cultural revolution through its energetic beats and immersive experiences.
BY Mark Howell 13 November 2024
CoverMastering Probability-Generating Functions: A Guide for EntrepreneursProbability-generating functions (pgfs) are mathematical tools used in probability theory for data analysis, risk management, and predictive modeling, crucial for startups and SMEs in strategic decision-making.
BY Mark Howell 31 October 2024
Try EdworkingA new way to work from  anywhere, for everyone for Free!
Sign up Now