DEV Community

bored duck
bored duck

Posted on

Arcable: The language that fits your coding style/grammar

Downloads:

Download Arcable 1.0.0

Arcable

Arcable is a programming language for writing C++-targeted programs in a style
that can feel Python-like, C-like, assembly-like, or a practical hybrid of
those forms. Arcable source files use the .arc extension.

The reference implementation is a small compiler written in C. It lowers
Arcable code into temporary C++, invokes clang++, deletes the temporary
<basename>.arcable.cpp file, and leaves the compiled application behind.

Build

cmake -S . -B build
cmake --build build --config Debug
Enter fullscreen mode Exit fullscreen mode

This builds both arcable.exe and the compatibility command acomp.exe.
On Windows it also builds install.exe, a GUI installer that contains the
Arcable command binaries, LSP, source snapshot, and VS Code extension files.

Install

Install the command line tools, language server helper, and local VS Code
extension:

.\build\Debug\install.exe
Enter fullscreen mode Exit fullscreen mode

The GUI installer extracts arcable.exe and acomp.exe to
%LOCALAPPDATA%\Arcable\bin, writes the LSP and bundled source/support files
under %LOCALAPPDATA%\Arcable, installs the VS Code extension into the user's
VS Code extension folder, and sets ARCABLE_HOME, ARCABLE_TOOLS,
ARCABLE_LSP, and the user PATH.

You can also run the script installer directly:

powershell -ExecutionPolicy Bypass -File .\tools\install.ps1
Enter fullscreen mode Exit fullscreen mode

The installer builds the project, copies acomp.exe and arcable.exe to
%LOCALAPPDATA%\Arcable\bin, adds that directory to your user PATH, copies
tools\arcable_lsp.py to %LOCALAPPDATA%\Arcable\tools, and sets
ARCABLE_HOME, ARCABLE_TOOLS, and ARCABLE_LSP for editor integrations.

Open a new terminal after installing, then run:

acomp .\examples\python_like.arc -o .\build\Debug\python_like.exe -- -Wall
Enter fullscreen mode Exit fullscreen mode

Use -SkipVSCodeExtension if you only want the CLI and LSP files installed.

Compile A Program

.\build\Debug\arcable.exe .\examples\python_like.arc -o .\build\Debug\python_like.exe -- -Wall
Enter fullscreen mode Exit fullscreen mode

Everything after -- is forwarded to clang++. On Windows, arcable
automatically initializes the Visual Studio Build Tools environment before
launching Clang when it can find vcvars64.bat. Set ARCABLE_VCVARS64 to a
custom vcvars64.bat path if Visual Studio is installed somewhere unusual.

Language Styles

Python-like:

def main() -> int:
    message: string = "hello"
    print(message)
    return 0
Enter fullscreen mode Exit fullscreen mode

C-like:

int main() {
    print("hello");
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Assembly-like:

.var value int 41
add value 1
print value
ret 0
Enter fullscreen mode Exit fullscreen mode

Hybrid styles are allowed when they are unambiguous. For example, Python-style
def and print can be mixed with C-style braces:

def main() {
    print("hello")
}
Enter fullscreen mode Exit fullscreen mode

Imports:

import <math.h>
from <stdint.h> import *
Enter fullscreen mode Exit fullscreen mode
#include <math.h>
import "my_header.hpp";
Enter fullscreen mode Exit fullscreen mode
.import <math.h>
%include "my_header.hpp"
Enter fullscreen mode Exit fullscreen mode

Import targets become C++ #include lines in the generated file. They must use
angle brackets for system headers or quotes for local headers.

Smoke Tests

powershell -ExecutionPolicy Bypass -File .\tests\run_smoke.ps1
Enter fullscreen mode Exit fullscreen mode

Language Server

Arcable includes a dependency-free Language Server Protocol server:

python .\tools\arcable_lsp.py
Enter fullscreen mode Exit fullscreen mode

Configure your editor's LSP client to launch that command for .arc files. The
server provides:

  • diagnostics for malformed imports, block syntax, braces, and assembly-like instructions
  • completions for Arcable keywords, C++ keywords/types/standard headers, imports, and assembly-like instructions
  • hover text for common Arcable and C++ language forms
  • full-document sync for unsaved editor buffers

For VS Code, use any generic LSP client extension and set the server command to:

{
  "command": "python",
  "args": ["C:/Users/devel/Downloads/adaptablecpp/tools/arcable_lsp.py"],
  "filetypes": ["arc"]
}
Enter fullscreen mode Exit fullscreen mode

VS Code Extension

VS Code does not need a separate LSP client for Arcable. This repo includes
a local extension with syntax coloring, diagnostics, quick fixes, hover, and
dropdown completions for .arc files.

Install it:

powershell -ExecutionPolicy Bypass -File .\tools\install_vscode_extension.ps1
Enter fullscreen mode Exit fullscreen mode

Then reload VS Code and open a .arc file. The extension contributes the
Arcable language mode for .arc files and runs entirely inside VS Code.

The extension lives in vscode-extension/ if you want to inspect or edit it.

History

Arcable started under the name AdaptableCPP. That name described the first
implementation idea: a compiler that adapted different code styles into C++.

The name was dropped because the project had grown beyond being just an
"adaptable C++ compiler." Once .arc files, a syntax model, diagnostics,
imports, editor support, and reusable language rules existed, it made more
sense to treat it as its own programming language. Arcable is shorter,
works better as a language name, and leaves room for the language to evolve
without sounding like only a C++ wrapper.

Top comments (0)