1 unstable release

0.1.0 Mar 9, 2020

#206 in #scripting-language


Used in oxlex

BSD-3-Clause

11KB
212 lines

OxyScript

A slightly oxidizing scripting language

! This is all very heavily WIP. Does not work properly yet !

CURRENTLY SWITCHING FROM A STACK VM TO A REGISTER VM. NON-FUNCTIONAL ATM

What is this?

OxyScript is a small scripting language i implemented myself
as a learning exercise, and because i wanted a language where i can control all
design variables myself.

Why?

For no real reason, except the following:

  • As a learning exercise
  • To make it easily embeddable in Rust
  • As an alternative to Python for shell scripting (as i detest Python)
  • For the lolz

Goals

Some of my goals with this are:

  • Should be able to run basic algorithms (eg, fibonacci)
  • Should be able to call rust functions
  • Should offer an easy API for embedding
  • Replace languages like Python for shell scripting
  • Be reasonably fast

Current status/TODO

  • Handles integer arithmetic
  • Handles float arithmetics
  • Structure scripts into (sub)modules
  • Supports calling functions
  • Supports string handling
  • Supports simple conditionals (if without else)
  • Supports complex conditionals (if/elseif/else, switch/case...)
  • PARTIAL: Supports loops (loop, while, for etc...) (see FN#1)
  • PARTIAL: Supports custom types (Containers) (see FN#2)
  • Supports calling rust functions
  • Supports embedding/exposing rust native types

Design

This is what a simple .oxs script could look like:

mod: inner_module {
    fn: add(lhs: int, rhs: int) ~ int {
        return lhs + rhs;
    }
}

import: core::Destroy;

// This is basically a struct.
cont: Vector {
    x: float;
    y: float;
}

impl: Destroy for Vector {
    fn: destroy(&this) {
        // Special handling for destruction of this property
    }
}

// Struct implementation
impl: Vector {
    fn: length() ~ float {
        return float::sqrt((x*x)+(y*y));
    }
}

import: inner_module::add = add_fn;

fn: main() ~ int {
    var lhs: int = 1;
    var rhs: int = 2;
    return add_fn(lhs, rhs);
}

Footnotes

  1. Only while loops are implemented for now.
  2. Container member functions are currently broken.

Dependencies

~1.5MB
~32K SLoC