Skip to content

vixcpp/vixpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vix++

Vix++ is a thin language layer for Vix-powered C++ applications.

It keeps your code close to standard C++, but removes some of the friction around includes, build flow, and runtime usage.

use vix.core;
use std.iostream;

int main()
{
  std::cout << "Hello from Vix++\n";
  return 0;
}

Vix++ transpiles .vix files into standard C++ files, then delegates the build and execution to the existing vix CLI.

main.vix
  ↓
vix++ transpiler
  ↓
.vix/build/vixpp/main.generated.cpp
  ↓
vix run/build/check
  ↓
binary

Why Vix++ exists

C++ is powerful, fast, and explicit. But the developer experience around includes, build systems, compiler flags, dependency wiring, and project setup can become heavy very quickly.

Vix already makes C++ easier to run:

vix run main.cpp

Vix++ adds a small language layer on top:

vix++ run main.vix

The goal is simple: cleaner source, standard C++ output, Vix-powered build.

Vix++ does not replace C++. It improves the way you write and run C++ applications with Vix.

Vix vs Vix++

Vix and Vix++ have separate responsibilities.

Vix     = runtime and build engine for standard C++
Vix++   = language frontend for .vix files

Vix++ depends on the vix command being installed and available in your PATH. It does not link against the internal Vix CLI code.

Example

Create main.vix:

use std.iostream;

int main()
{
  std::cout << "Hello from Vix++\n";
  return 0;
}

Run it:

vix++ run main.vix

Vix++ generates:

// Generated by Vix++. Do not edit directly.
#include <iostream>

int main()
{
  std::cout << "Hello from Vix++\n";
  return 0;
}

Then it calls:

vix run .vix/build/vixpp/main.generated.cpp

Imports

Vix++ uses use declarations:

use vix.core;
use vix.json;
use std.vector;
use local.config;

They are converted to C++ includes:

#include <vix/core.hpp>
#include <vix/json.hpp>
#include <vector>
#include "config.hpp"

Vix imports

use vix.core;         // → #include <vix/core.hpp>
use vix.http.server;  // → #include <vix/http/server.hpp>

Standard library imports

use std.iostream;  // → #include <iostream>
use std.vector;    // → #include <vector>
use std.string;    // → #include <string>

Local imports

use local.config;         // → #include "config.hpp"
use local.services.user;  // → #include "services/user.hpp"

Basic syntax

A .vix file is mostly normal C++. Only use declarations are special in the MVP.

use vix.core;
use std.string;

int main()
{
  vix::App app;
  return app.run();
}

Rules:

  • use declarations must appear before regular C++ code
  • blank lines are allowed
  • // comments are allowed before and between imports
  • duplicate imports are emitted only once
  • the rest of the file remains standard C++

CLI

vix++ run main.vix        # run a .vix file
vix++ main.vix            # shortcut for run
vix++ build main.vix      # build a .vix file
vix++ check main.vix      # check a .vix file
vix++ help                # show help
vix++ version             # show version

Use a custom Vix binary:

vix++ run main.vix --vix /usr/local/bin/vix

Use a custom generated output directory:

vix++ run main.vix --build-dir .vix/generated

Forward arguments to Vix:

vix++ build main.vix --out app

Build from source

git clone https://github.com/vixcpp/vixpp
cd vixpp
vix build
ctest --test-dir build --output-on-failure

The binary is generated as build/vix++. Run an example:

./build/vix++ run examples/hello.vix

Examples

Hello world

use std.iostream;

int main()
{
  std::cout << "Hello from Vix++\n";
  return 0;
}

JSON

use vix.json;
use std.iostream;

int main()
{
  using namespace vix::json;

  auto user = o(
      "id", 42,
      "name", "Ada",
      "tags", a("pro", "admin"));

  std::cout << dumps(user, 2) << "\n";
  return 0;
}

HTTP

use vix.core;

int main()
{
  vix::App app;

  app.get("/", [](vix::Request &, vix::Response &res){
    res.json({"message", "Hello from Vix++"});
  });

  app.run(8080);
  return 0;
}

Project status

Vix++ is experimental. The first version focuses on:

  • .vix files
  • use imports
  • portable transpilation
  • diagnostics
  • generated standard C++
  • delegation to Vix
  • basic tests

It does not try to become a full new language yet.

What Vix++ does not do yet

  • fn syntax
  • let syntax
  • automatic package imports
  • C++20 module generation
  • project import maps
  • formatting / linting
  • watch mode
  • REPL

Architecture

vixpp/
├── include/vixpp/
│   ├── Diagnostic.hpp
│   ├── ImportResolver.hpp
│   ├── SourceFile.hpp
│   ├── Transpiler.hpp
│   ├── Runner.hpp
│   └── Version.hpp
│
├── src/
│   ├── Diagnostic.cpp
│   ├── ImportResolver.cpp
│   ├── SourceFile.cpp
│   ├── Transpiler.cpp
│   ├── Runner.cpp
│   └── main.cpp
│
├── examples/
├── tests/
├── docs/
└── cmake/

Core parts: SourceFile loads .vix files, ImportResolver maps use declarations to C++ includes, Transpiler generates standard C++, Runner calls the installed vix CLI, and Diagnostics reports clear errors.

Design principles

  • Stay close to C++
  • Generate readable C++
  • Do not hide the runtime
  • Do not replace Vix
  • Keep imports predictable
  • Make the build flow simpler

The developer should always be able to understand what Vix++ generates. Vix++ should make C++ easier to write without making it mysterious.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Created by Gaspard Kirira
Vix.cpp: [https://github.com/vixcpp/vixpp]

About

Vix++ is a thin language layer for Vix-powered C++ applications.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors