All Projects → rhysd → 8cc.vim

rhysd / 8cc.vim

C Compiler written in Vim script

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to 8cc.vim

Vifm.vim
Vim plugin that allows use of vifm as a file picker
Stars: ✭ 197 (-3.9%)
Mutual labels:  viml, vim-plugin
Learn Vim
无废话极简版Vim学习笔记!文章按主题分拆为多个章节,并尽量控制每节的信息量;通过文字色彩和字体,将命令、快捷键突出显示;在每节结尾,提供一个命令列表,以便回顾文中介绍的重要命令。如果这些文章能对喜欢Vim的朋友有所益处,我将不胜荣幸。
Stars: ✭ 83 (-59.51%)
Mutual labels:  viml, vim-plugin
Viki vim
A personal wiki for Vim
Stars: ✭ 52 (-74.63%)
Mutual labels:  viml, vim-plugin
Vim Hexedit
Hexedit is a plug-in under VIM, which is used to strengthen the hex editing ability of VIM.
Stars: ✭ 42 (-79.51%)
Mutual labels:  viml, vim-plugin
Quickfixsigns vim
Mark quickfix & location list items with signs
Stars: ✭ 126 (-38.54%)
Mutual labels:  viml, vim-plugin
Vim Grepper
👾 Helps you win at grep.
Stars: ✭ 1,030 (+402.44%)
Mutual labels:  viml, vim-plugin
Incsearch Easymotion.vim
Stars: ✭ 82 (-60%)
Mutual labels:  viml, vim-plugin
Vim Gnupg
This script implements transparent editing of gpg encrypted files.
Stars: ✭ 566 (+176.1%)
Mutual labels:  viml, vim-plugin
Vim Todo Lists
Vim plugin for TODO lists
Stars: ✭ 126 (-38.54%)
Mutual labels:  viml, vim-plugin
Vim Youdao Translater
vim的有道取词翻译插件
Stars: ✭ 116 (-43.41%)
Mutual labels:  viml, vim-plugin
Tskeleton vim
File Templates and Code Skeletons/Snippets for VIM
Stars: ✭ 33 (-83.9%)
Mutual labels:  viml, vim-plugin
Vim Markbar
Display all accessible marks and their surrounding lines in a collapsible sidebar.
Stars: ✭ 159 (-22.44%)
Mutual labels:  viml, vim-plugin
Vim Diff Toggle
🛠 Vim plugin to speed up editing diff files
Stars: ✭ 17 (-91.71%)
Mutual labels:  viml, vim-plugin
Vim Lookup
Jump to the definition of variables or functions in VimL code.
Stars: ✭ 51 (-75.12%)
Mutual labels:  viml, vim-plugin
Vimcompletesme
You don't Complete Me; Vim Completes Me! A super simple, super minimal, super light-weight tab completion plugin for Vim.
Stars: ✭ 752 (+266.83%)
Mutual labels:  viml, vim-plugin
Vim Plugin Viewdoc
Vim plugin: flexible viewer for any documentation
Stars: ✭ 79 (-61.46%)
Mutual labels:  viml, vim-plugin
Pear Tree
A Vim auto-pair plugin that supports multi-character pairs, intelligent matching, and more
Stars: ✭ 327 (+59.51%)
Mutual labels:  viml, vim-plugin
Vim Startify
🔗 The fancy start screen for Vim.
Stars: ✭ 4,479 (+2084.88%)
Mutual labels:  viml, vim-plugin
Incsearch Fuzzy.vim
Stars: ✭ 116 (-43.41%)
Mutual labels:  viml, vim-plugin
Tlib vim
Some utility functions for VIM
Stars: ✭ 147 (-28.29%)
Mutual labels:  viml, vim-plugin

8cc.vim: Pure Vim script C Compiler

Build Status

This is a Vim script port of 8cc built on ELVM. In other words, this is a complete C compiler written in Vim script.

8cc is a nicely-written small C compiler for x86_64 Linux. It's C11-aware and self-hosted.

ELVM is a Eso Lang Virtual Machine. ELVM retargets 8cc to emit its own intermediate representation, EIR. ELVM compiles C code into EIR with the retargeted 8cc as frontend. And then translates EIR into various targets (Python, Ruby, C, BrainFxxk, Piet, Befunge, Emacs Lisp, ...) in backend. The architecture resembles LLVM. This presentation is a good stuff to know ELVM architecture further (though in Japanese).

ELVM can compile itself into various targets. So I added a new 'Vim script' backend and use it to translate C code of 8cc into Vim script.

Now 8cc.vim is written in pure Vim script. 8cc.vim consists of frontend (customized 8cc) and backend (ELC). It can compile C code into Vim script. And of course Vim can evaluate the generated Vim script code.

Note that this is a toy project. 8cc.vim is much much slower. It takes 824 (frontend: 430 + backend: 396) seconds to compile the simplest putchar() program on MacBook Pro Early 2015 (2.7 GHz Intel Core i5). But actually it works!

As VM runs on Vim script, 8cc.vim works on Linux, OS X and (hopefully) Windows.

Installation

Please clone this repository and :packadd (please see :help pack-add).

Or please use your favorite plugin manager (vim-plug, dein.vim and so on).

Usage

  • Commands
    • :EccCompile
    • :EccRun
  • Functions
    • eightcc#compile()
    • eightcc#run()

Compile C Code

Prepare your C code in the current buffer. Following is a 'Hello world' example.

int putchar(int x);

int main() {
  const char* p = "Hello, world!\n";
  for (; *p; p++)
    putchar(*p);
  return 0;
}

Then execute :EccCompile command. Note that you can use several options such as --verbose for this. Please see :EccCompile --help for more detail.

It takes a long time 20 minutes or more. Let's take a rest and get some ☕️.

As the result, new buffer is opened with Vim script code which was compiled from C code. Load it by :w putchar.vim and :source putchar.vim.

Finally, execute below Vim script code by your hand. The compiled code is run on VM on Vim script. The SetupVM() function creates a VM instance.

:let vm = SetupVM()
:call vm.run()

result screen shot

If you want to see only the result of running Vim script, you can use :EccRun to skip above process.

Corresponding to :EccCompile and :EccRun, you can use eightcc#compile() and eightcc#run() functions. They can take one dictionary for execution options.

License

MIT License

Copyright (c) 2016 rhysd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].