oplang: Stack-based esoteric programming language

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/aionescu/oplang#readme


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.0.0, 0.3.0.1, 0.4.0.0, 0.4.0.1
Change log CHANGELOG.md
Dependencies base (>=4.14 && <5), containers (>=0.6.5 && <0.7), directory (>=1.3.7 && <1.4), filepath (>=1.4.2 && <1.5), megaparsec (>=9.2 && <9.3), mtl (>=2.3 && <2.4), optparse-applicative (>=0.17 && <0.18), process (>=1.6.14 && <1.7), text (>=2 && <2.1), text-builder-linear (>=0.1 && <0.2), transformers (>=0.6 && <0.7) [details]
License GPL-3.0-only
Copyright Copyright (C) 2019-2022 Alex Ionescu
Author Alex Ionescu
Maintainer alxi.2001@gmail.com
Category Compilers/Interpreters, Language
Home page https://github.com/aionescu/oplang#readme
Bug tracker https://github.com/aionescu/oplang/issues
Source repo head: git clone https://github.com/aionescu/oplang
Uploaded by aionescu at 2022-08-12T22:22:57Z

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for oplang-0.3.0.0

[back to package description]

oplang

Hackage

OpLang is a stack-based esoteric programming language based on Brainfuck.

Installing

The compiler is available on Hackage, and can be installed via cabal (which can itself be installed via ghcup).

cabal install oplang

Usage

To compile an OpLang file with default options, use:

oplang code.op
./code.out

For a list of available command-line options, use oplang --help.

Building from source

Prerequisites:

(Both can be installed via ghcup)

cabal build
cabal run . -- <args>

Language Features

OpLang is a strict superset of Brainfuck.

Its main improvement is the addition of user-defined operators, which are analogous to user-defined functions in languages like C or Python.

The "memory tape" in OpLang is specific to each operator invocation (akin to the stack space allocated for functions in C), and there is a separate "stack" which persists across operator invocations.

Each cell in the tape(s) and stack is 1 byte, and overflow/underflow is allowed.

The default size of the stack is 4KB, and the default size for each memory tape is 64KB. These can be modified via the command-line.

Syntax

OpLang has 10 "intrinsic" operators, 8 of which are the Brainfuck operators, with the same semantics:

And 2 of them are new operators that modify the stack:

An OpLang program consists of a series of custom operator definitions, followed by the "toplevel" (similar to a main() function in other languages).

An operator definition consists of the operator's name, followed by the operator's body, enclosed in {/}.

Single-line comments are supported, and are introduced by the # character.

Here's a simple program that reads a character from stdin, adds 3 to it, and prints it back:

a { ; +++ : }
,: a ;.

For more example programs, see the examples folder.

License

This repository is licensed under the terms of the GNU General Public License v3.

For more details, see the license file.