My first open source program, Vampirio Code, why I developed it and how I did it



This content originally appeared on DEV Community and was authored by Gabriel Frasca

Hi everyone! I’m new here, I’m from Argentina, and I’m excited to be part of this community. I’ve been working for a long time on Vampirio Code, a project I’d love to share with you.

Vampirio Code is a code editor with syntax highlighting and multi-language support. Its main goal is to allow you to compile and run code quickly, so you can test algorithms without having to build large projects that take forever just to see if something works.

With Ctrl + N, you can open a new document, select your language, and compile or interpret it without even saving the file. The output appears directly in the console. I developed this editor because I needed something fast like Notepad++ or Sublime Text, but that could also compile code immediately.

As the project grew, I added features that turned it into a full IDE, including linking multiple files, libraries, DLLs, and controlling output types like creating .exe or .dll for C++ projects.

The project is open-source and available on GitHub: https://github.com/leirbag4/VampirioCode

This is a project that arose from a personal need to have something fast, efficient, and that would allow me to accelerate the development process of my projects and work. I wrote it entirely in C# and since I was going to rewrite the entire graphical interface, I opted to use WinForms. It’s a technology that has been around for thousands of years, and if I don’t keep up with it, I can easily port the code. The main library I use for code formatting is Scintilla, which I’ve used several times in the past.

Technical Overview

Vampirio Code’s core structure is in the Command namespace, where each compiler or interpreter is represented abstractly and can be called from code.

Each command inherits from BaseCmd.cs and returns a BaseResult, which indicates whether the execution was successful and handles errors.

Builders

We also have a Builder namespace. There are Simple Builders and Custom Builders:

Simple Builders: The first ones I programmed. They handle basic compilation tasks, like passing file paths to the compiler.

Custom Builders: Added later with IDE capabilities. They let you configure menus, select libraries, files to compile, output type, etc.

Here’s an example of a Simple C++ Builder for Clang:


// Just comment this define in case you don't need libclang.dll
#define USE_LIBCLANG

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VampirioCode.Command.Clang;
using VampirioCode.Command.Clang.Result;
using VampirioCode.SaveData;
using VampirioCode.UI;

namespace VampirioCode.Builder.Simple
{
    public class SimpleClangCppBuilder : Builder
    {
        //private string objsDir;
        private string outputDir;

        public SimpleClangCppBuilder()
        {
            Name = "Clang++";
            Type = BuilderType.SimpleClangCpp;
        }

        public override void Prepare()
        {
            TempDir = AppInfo.TemporaryBuildPath;               // temporary directory ->   \temp_build\
            BaseProjDir = TempDir + projectName + "\\";         // temporary project dir -> \temp_build\proj_name\
            ProjectDir = BaseProjDir;                           // temporary project dir -> \temp_build\proj_name\
            ProgramFile = ProjectDir + projectName + ".cpp";    // .cpp program file ->     \temp_build\proj_name\proj.cpp
            //objsDir =               ProjectDir + "obj\\";     // output binaries dir ->   \temp_build\proj_name\obj\
            outputDir = ProjectDir + "bin\\";                   // output binaries dir ->   \temp_build\proj_name\bin\
            OutputFilename = outputDir + projectName + ".exe";  // output binaries dir ->   \temp_build\proj_name\bin\proj.exe
        }

        protected override async Task OnBuildAndRun()
        {
            var result = await _Build();
            RunResult runResult;

            if (result.IsOk)
            {
                XConsole.Clear();
                Clang clang = new Clang();

                List<string> libPaths = new List<string>();
#if USE_LIBCLANG                
                //libPaths.Add(@"C:\programs_dev\clang_llvm_18_1_0\lib");
                libPaths.Add(Config.BuildersSettings.CLang.clang_lib_dir);
#endif
                runResult = await clang.RunAsync(result.OutputFilename, libPaths);
                //return runResult;
            }

            runResult = new RunResult();
            runResult.SetError(result.ErrorInfo);
            //return runResult;
            CheckResult(result);
        }


        public async Task<BuildResult> _Build()
        {
            Prepare();

            CreateProjectStructure();

            if (!Directory.Exists(outputDir))
                Directory.CreateDirectory(outputDir);

            // write all code to '\temp_build\proj_name\proj.cpp' main program file
            File.WriteAllText(ProgramFile, code);


            // [ COMPILATION PROCESS ]
            List<string> sourceFiles = new string[] { ProgramFile }.ToList();

            List<string> includes = new List<string>();
            List<string> libPaths = new List<string>();
            List<string> libFiles = new List<string>();

#if USE_LIBCLANG
            includes.Add(Config.BuildersSettings.CLang.clang_include_dir);
            libPaths.Add(Config.BuildersSettings.CLang.clang_lib_dir);
            libFiles.Add("libclang.lib");
#endif

            Clang clang = new Clang();
            var result = await clang.BuildAsync(sourceFiles, OutputFilename, includes, libPaths, libFiles);
            result.OutputFilename = OutputFilename;

            return result;
        }

    }
}



With this introduction, I’d like to tell you that I’m so excited about this project that I decided to create a website to showcase all the projects I upload. I named it Vampirio Studio and created a page to host it here: Vampirio Code. I thank you all for letting me use your space, and if you can or want to use it and give your feedback, that would be great. A big hello to everyone.


This content originally appeared on DEV Community and was authored by Gabriel Frasca