+
Skip to content

dmah42/mrdo

Repository files navigation

Rust

mrdo

mrdo is a language in which variables may be either a:

  • real (mutable 64-bit floating point)
  • integer (mutable 32-bit integer)
  • coll (an immutable collection of reals)
  • TODO: dict (key-value immutable collection of reals)

usage

bash $ ./mrdo

will start a repl. Use :h in the repl to get a list of meta-commands.

bash $ ./mrdo <filename> [-o <output>]

will compile the program provided and run it, optionally outputting the bytecode. If the provided program is already bytecode, it will be run directly.

for other flags, see bash $ ./mrdo --help

submodules

compiler compiles from high-level to assembly

asm compiles from assembly to bytecode

vm runs the bytecode

repl understands both assembly and high level code

language features

variables

Variables can be defined and have values assigned using the = operator. Assignment is a copy operation, ie:

foo = 42.0
bar = foo

will copy the value from foo to bar, resulting in two instances being defined.

Also note that while the variable type is inferred, it is also immutable. Once a variable is a type, it can't be reassigned to a new type.

functions

TODO (not implemented in the new rust world yet)

builtins

TODO (not implemented in the new rust world yet)

Builtins are called using the do(<builtin>, <args...>) syntax.

collection builtins

TODO These operate on collections in parallel and are either a:

  • map (convert each element in the input collection to one element in the output collection)
  • filter (conditionally output each element in the input collection)
  • fold (accumulate a collection to a single element)

For map, the input and output collections may be different types.

More function types may be added later.

io builtins

Anything can be read or written to stdin/stdout using the builtins

  • TODO: read
  • write

operations

The usual operations are available:

  • arithmetical: +, -, /, *
  • comparitive: gt, gte, lt, lte, eq, ne
  • TODO: logical: and, or, not, xor Logical operations treat 0.0 as false and all other values as true.

arithmetical operations

if left and right are real or integer, arithmetical operations work as expected.

if both are coll, they must be the same size and the operations are applied pairwise.

if one is real or integer and one is coll, the real or integer is applied to every element in the coll.

comparitive operations

for coll types, comparisons follow the rustlang model. specifically, if any element of a collection compares true for the operation, then the operation as a whole will return true (or 1, actually).

collection-specific operations

Collections themselves have the following operations defined:

  • TODO: flatten: takes multiple collections and combines them into a single collection.
  • TODO: sort: takes a collection and returns a seq of the elements in an order governed by a given comparison operation.
  • TODO: first: returns the first 'n' elements of a collection in the same
  • collection type.

assembly language

for details of all the opcodes and what they do, see opcodes.md

old

-- There's an original version of this project that is more feature rich and uses LLVM to compile to a binary, but that restricted what could be done at runtime so it's been moved to old.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载