/uwu-toolkit

An UwU source-to-source compilation library for Node.js, Deno & web browsers.

Primary LanguageTypeScriptMIT LicenseMIT

UwU Toolkit

GitHub license npm version Tests codecov

An UwU source-to-source compilation library for web-browsers, Node.js & Deno.

Contents

  1. What is Uwu
  2. Installation
  3. Usage
  4. Supported output languages
  5. Examples

What is UwU?

UwU is an esoteric programming language created by Kira Rose. It is a member of the Brainfuck trivial substitution family of programming languages. An example program written in UwU, and a list of commands can be found here.

Installation

Run npm i uwu-toolkit or yarn add uwu-toolkit.

Usage

  • Use compileTo[LANGUAGE]() where [LANGUAGE] is a supported output language/variant ( e.g. compileToJsWeb()).
  • The web variant of the JavaScript transpiler generates a function that returns an object containing two members:
    1. output - The output of the program.
    2. cells - The array of cells that were used by the program.
  • See the documentation for more information.

Supported Output Languages

  • Brainfuck.
  • C.
  • C++.
  • JavaScript.
  • Python.

Table 1: Supported Commands by Output Language

Language OwO °w° UwU QwQ @w@ >w< ~w~ ¯w¯ Memory Size
Brainfuck Not Applicable
C 30,000
C++ 30,000/Dynamic
JavaScript (Web) 30,000/Dynamic
JavaScript (Node.js) 30,000/Dynamic
JavaScript (Deno) 30,000/Dynamic
Python 30,000/Dynamic

Examples

CommonJS (Node)

const uwuTK = require('uwu-toolkit');

const helloUwu = 'UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO'
  + 'UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU'
  + 'UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯'
  + 'OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°'
  + 'QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@'
  + '@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@'
  + 'OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°'
  + '°w° QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ @w@ OwO OwO'
  + 'UwU @w@ OwO OwO UwU UwU @w@';

try {
  const helloJS = uwuTK.compileToJsWeb(helloUwu);
  const hello = new Function(`${helloJS}return main().output;`);

  console.log(hello());
} catch (err) {
  console.error(`Error: ${err.message}`);
}

Program Validation - CommonJS (Node)

const uwuTK = require('uwu-toolkit');

const helloUwu = 'UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO'
  + 'UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU'
  + 'UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯'
  + 'OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°'
  + 'QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@'
  + '@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@'
  + 'OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°'
  + '°w° QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ @w@ OwO OwO'
  + 'UwU @w@ OwO OwO UwU UwU @w@';

const invalidUwu = 'UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO'
  + 'UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU'
  + 'UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯'
  + 'OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°'
  + 'QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@'
  + '@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@'
  + 'OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°'
  + '°w° QwQ QwQ QwQ QwQ QwQ QwQ ¯w¯ QwQ QwQ QwQ QwQ @w@ OwO OwO'
  + 'UwU @w@ OwO OwO UwU UwU @w@';

const validSourceArray = uwuTK.tokenizeUwuSource(helloUwu);
const invalidSourceArray = uwuTK.tokenizeUwuSource(invalidUwu);

console.log(uwuTK.isValidProgram(validSourceArray)); // true
console.log(uwuTK.isValidProgram(invalidSourceArray)); // false

ESM (Node)

import * as uwuTK from 'uwu-toolkit';

const helloUwu = 'UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO'
  + 'UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU'
  + 'UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯'
  + 'OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°'
  + 'QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@'
  + '@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@'
  + 'OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°'
  + '°w° QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ @w@ OwO OwO'
  + 'UwU @w@ OwO OwO UwU UwU @w@';

try {
  const helloJS = uwuTK.compileToJsWeb(helloUwu);
  const hello = new Function(`${helloJS}return main().output;`);

  console.log(hello());
} catch (err) {
  console.error(`Error: ${err.message}`);
}

ESM (Deno)

import * as uwuTK from "https://jspm.dev/uwu-toolkit";

const helloUwu = "UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO"
  + "UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU"
  + "UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯"
  + "OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°"
  + "QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@"
  + "@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@"
  + "OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°"
  + "°w° QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ @w@ OwO OwO"
  + "UwU @w@ OwO OwO UwU UwU @w@";

try {
  const helloJS = uwuTK.compileToJsWeb(helloUwu);
  const hello = new Function(`${helloJS}return main().output;`);

  console.log(hello());
} catch (err) {
  console.error(`Error: ${err.message}`);
}

TypeScript (Deno)

import * as uwuTK from "https://cdn.jsdelivr.net/gh/synthetic-borealis/uwu-toolkit/deno/index.ts";

const helloUwu = "UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO" +
  "UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU" +
  "UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯" +
  "OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°" +
  "QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@" +
  "@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@" +
  "OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°" +
  "°w° QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ @w@ OwO OwO" +
  "UwU @w@ OwO OwO UwU UwU @w@";

try {
  const helloJS = uwuTK.compileToJsWeb(helloUwu);
  const hello = new Function(`${helloJS}return main().output;`);

  console.log(hello());
} catch (err) {
  console.error(`Error: ${err.message}`);
}

Web

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hewwo Wowwd!</title>
    <script src="https://unpkg.com/uwu-toolkit@2.0.1/dist/uwu-toolkit.js"></script>
  </head>
  <body>
    <p>
      <textarea id="output-box" readonly rows="8" style="width: 90%;"></textarea>
    </p>
    <button id="run-button">Run</button>

    <script>
      const runButton = document.getElementById('run-button');
      const outputBox = document.getElementById('output-box');
      const helloUwu = 'UwU UwU UwU UwU UwU UwU UwU UwU ~w~ OwO'
        + 'UwU UwU UwU UwU ~w~ OwO UwU UwU OwO UwU UwU UwU OwO UwU UwU'
        + 'UwU OwO UwU OwO UwU UwU UwU UwU °w° °w° °w° °w° °w° QwQ ¯w¯'
        + 'OwO UwU OwO UwU OwO QwQ OwO OwO QwQ OwO UwU ~w~ °w° ¯w¯ °w°'
        + 'QwQ ¯w¯ OwO OwO @w@ OwO QwQ QwQ QwQ @w@ OwO OwO OwO QwQ @w@'
        + '@w@ °w° °w° °w° UwU UwU UwU UwU UwU UwU UwU UwU UwU UwU @w@'
        + 'OwO OwO @w@ °w° QwQ @w@ °w° @w@ OwO OwO OwO @w@ @w@ °w° °w°'
        + '°w° QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ QwQ @w@ OwO OwO'
        + 'UwU @w@ OwO OwO UwU UwU @w@';

      outputBox.value = '';
      runButton.addEventListener('click', () => {
        try {
          const helloWorldProgram = uwuTK.compileToJsWeb(helloUwu);
          const helloWorld = new Function(`${helloWorldProgram} return main().output;`);

          outputBox.value += helloWorld();
        } catch (err) {
          outputBox.value += `Error: ${err.message}`;
        }
      });
    </script>
  </body>
</html>