Run code from many programming languages!

Related tags

Command-line langbot
Overview

Langbot

Creating an image

  1. Install podman
  2. Build an image: podman build -t langbot .

Running a language

Run podman run --rm -i langbot ./scripts/run.sh <language>. It will read source code from stdin and execute it.

Adding your own language

  1. Create a directory langs/yourlang/.
  2. Create a file langs/yourlang/compile.sh.
    • This file is responsible for downloading sources for, compiling and installing your programming language.
    • It will be run using the command bash -x -euo pipefail compile.sh, in a temporary working directory which is populated with the content of langs/yourlang.
    • When downloading sources, always make sure that what you're downloading won't change. E.g with git, always git checkout a particular commit.
    • Install all build artifacts to the directory that's passed in as the $DEPLOYDIR environment variable.
    • When everything is done, run touch "$DEPLOYDIR/.done" as a final sanity check.
  3. Create a file langs/yourlang/run.sh.
    • run.sh is copied to the deployment directory (what was $DEPLOYDIR in compile.sh)
    • It will be run using the command bash -euo pipefail run.sh, in the deployment directory. It should read its source code from stdin, and do whatever is necessary to execute that code.
    • If everything goes okay, exit with exit code 0; if something goes wrong, exit with a non-zero exit code.
    • You can assume that only one execution happens at a time, meaning you shouldn't worry about creating random file names for the input files.
  4. Add your language to the list in scripts/compile-all.sh to make it run as part of building the podman container.

In some cases, you may also need to add dependencies to the Containerfile.

A simple example language you can take inspiration from is Osyris.

langs/osyris/compile.sh is:

git clone https://github.com/mortie/osyris.git
cd osyris
git checkout 2db1f2c1746dbda2451d8cc888921a0f518aaf78

cargo build --release
cp target/release/osyris "$DEPLOYDIR"

touch "$DEPLOYDIR/.done"

And langs/osyris/run.sh is:

cat >input.os
exec ./osyris input.os

Some development tips

  • During development, it might help to remove all other languages than yours from the list of languages in scripts/compile-all.sh, so that podman build -t langbot . only needs to run your language.
  • Don't be afraid to re-build the container; podman caches all the steps it can, so podman build -t langbot . doesn't start from scratch every time.
  • You may want to investigate the compiler interactively, which can be done with podman run --rm -it langbot.
  • In fact, I find it helpful to manually run my shell commands in an interactive container and write the compile.sh script by writing down my commands there as I go.
You might also like...
Code implementation of DDIA, primarily using Rust and Go languages.

Let's implement DDIA in rust and golang (with some Java and Cpp). This repository contains code implementations for 'Designing Data-Intensive Applicat

High-performance and normalised trading interface capable of executing across many financial venues

High-performance and normalised trading interface capable of executing across many financial venues. Also provides a feature rich simulated exchange to assist with backtesting and dry-trading.

 (Pre-Release Software) Secure, Encrypted, P2P chat written atop Warp, IPFS, LibP2P, Dioxus and many more awesome projects and protocols.
(Pre-Release Software) Secure, Encrypted, P2P chat written atop Warp, IPFS, LibP2P, Dioxus and many more awesome projects and protocols.

Uplink Privacy First, Modular, P2P messaging client built atop Warp. Uplink is written in pure Rust with a UI in Dioxus (which is also written in Rust

🕺 Run React code snippets/components from your command-line without config

Run React code snippets/components from your command-line without config.

A toy example showing how to run Rust code in Python for speed and progress.

PoC: Integrating Rust in Python A toy example showing how to run Rust code in Python for speed and progress. Requirements Python 3.6+ Rust 1.44+ Cargo

Example to run Rust code on the MCH2022 badge.
Example to run Rust code on the MCH2022 badge.

Rust on the MCH2022 badge This repo contains instructions and code to run Rust on the MCH2022 badge. There are two approaches regarding environment: I

 ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK
ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK

ClangQL - Clang AST Query Language ClangQL is a tool that allow you to run SQL-like query on C/C++ Code instead of database files using the GitQL SDK.

Turbine is a toy CLI app for converting Rails schema declarations into equivalent type declarations in other languages.

Turbine Turbine is a toy CLI app for converting Rails schema declarations into equivalent type declarations in other languages. It’s described as a to

Growing languages with interpreters and staging.

language-greenhouse This is a small collection of interpreters/compilers focused on the technique of compilation by staging. For more information, ple

Comments
  • Added Phosphor

    Added Phosphor

    I added the Phosphor programming language. The version used is the latest release (0.2.1) which I published today.

    Note that Node.js, binutils and NASM are needed as dependencies for the compiler to work. The additionally added installation of lsb-release is used for making the node installation platform-agnostic and could theoretically be removed if DISTRO="$(lsb_release -s -c)" is replaced with DISTRO=jammy (for Ubuntu 22.04) and maintained to match the used image.

    opened by BenediktMagnus 4
Owner
Martin Dørum
Martin Dørum
Programming language made by me to learn other people how to make programming languages :3

Spectra programming language Programming language made for my tutorial videos (my youtube channel): Syntax Declaring a variable: var a = 3; Function

Adi Salimgereyev 3 Jul 25, 2023
A CLI for analyzing the programming languages and how much code written in a project.

projlyzer A CLI for analyzing the programming languages and how much code written in a project. New features are on the way... Example Screenshot Buil

null 10 Apr 10, 2022
Catch Tailwindcss Errors at Compile-Time Before They Catch You, without making any change to your code! Supports overriding, extending, custom classes, custom modifiers, Plugins and many more 🚀🔥🦀

twust Twust is a powerful static checker in rust for TailwindCSS class names at compile-time. Table of Contents Overview Installation Usage Statement

null 15 Nov 8, 2023
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.

This repository lists static analysis tools for all programming languages, build tools, config files and more. The official website, analysis-tools.de

Analysis Tools 10.7k Jan 2, 2023
Generate Soufflé Datalog types, relations, and facts that represent ASTs from a variety of programming languages.

treeedb treeedb makes it easier to start writing a source-level program analysis in Soufflé Datalog. First, treeedb generates Soufflé types and relati

Langston Barrett 16 Nov 30, 2022
tmplt is a command-line interface tool that allows you to quickly and easily set up project templates for various programming languages and frameworks

tmplt A User Friendly CLI Tool For Creating New Projects With Templates About tmplt is a command-line tool that lets users quickly create new projects

Humble Penguin 35 Apr 8, 2023
🎄 Advent of Code written in various languages. (2015-2022)

?? Advent of Code This repository contains my solutions to the Advent of Code puzzles. Every year, I will try to solve the puzzles in a different lang

Tommy 2 Dec 15, 2022
Trying to solve Advent of Code 2022 in 25 different languages (1 day = 1 language)

Advent of Code 2022: 15/25 langs I’ll try to solve this Advent of Code using different language for each day. Any programs needed to run the code will

Max “Goldstein” Siling 2 Dec 15, 2022
Advent of Code, this year I will attempt the 25 different languages challenge

Advent of Code 2022 As this is my third year doing Advent of Code, this time I will try the 25 Different Languages Challenge, which is solving the pro

Andreu Vall Hernàndez 7 Dec 27, 2022
Demo app duplicated in 5 languages (Go/JavaScript/Python/Ruby/Rust) showing how to go from source code to container image using melange+apko

hello-melange-apko ?? This repo contains an example app duplicated across 5 languages showing how to: Package source code into APKs using melange Buil

Chainguard 16 Jan 23, 2023