GithubHelp home page GithubHelp logo

al1-ce / ion Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 39 KB

A simple c-style interpreted programming language

License: MIT License

D 99.65% Assembly 0.35%
compiler interpreter language programming-language

ion's Introduction

Ion (NOT READY TO USE. CURRENTLY IN PRE-ALPHA STAGES)

A simple c-style interpreted programming language

Ion language specification

File extension: .i or .ion (i.e helloworld.i or helloworld.ion)

Example code:

Hello world:

import std.stdio: writeln;

void main() {
    writeln("hello world");
}

or:

import std.stdio: writeln;

writeln("hello world");

Type mix:

import std.type: var;
import std.stdio;

alias println = writeln;

function add(int a, var b) {
    return a + b;
}

println(add(3, "2"));

if (true) {
    println(true.toString);
}

/* Expected result:
 * 5
 * true
 */

Definition

Ion is an interpreted scripting languade written in D. Main points of Ion are:

  • Dynamic typing (with ability to inforce certain types by writing type instead of var)
  • Familliar syntax to such languages as: c, c++, c#, d, java, javion, typescript
  • Acessibility in tearms of definitions (i.e. var count: number, var count, var count: int and int count are all valid definitions of a variable). Which allows for broader appeal
  • Powerful alias system that allows for overloading function names alias a = b;, variable names, types (alias let = std.type.var;), imports (import io = std.stdio;) and keywords (keyword alias fn = function;)

Keywords:

void
int
bool
char
real
double
float
keyword
alias
true
false

Types

Numeric:

int, float, double, real

String:

string, char

Boolean:

bool

Other:

void, var

Aliases

Basic aliases

Basic alias create a name that refers to another symbol.

Examples:

Type alias:

alias mytype = proj.types.StructType;
alias i = int;

Method alias:

void doStuff() {}
alias ds = doStuff;

Template alias:

void doTempl(T)() {}
alias t1 = doTempl!(int);

Variable alias:

int d = 0;
alias id = d;

Keyword aliases

Keyword alias must be a statement, attribute, keyword or sum of all above. It cannot be expression and will not behave like macro.

Examples:

Variant type aliases, defined in core.styles.js:

keyword alias var = public core.type.variant;
keyword alias let = private core.type.variant;
keyword alias constructor = this;

Or TS style in core.styles.ts:

keyword alias number = float;
keyword alias boolean = bool;

Rust-like code, defined in core.styles.rust:

keyword alias fn = function; // function serves two purposes. Declaration & pointers
keyword alias let = immutable core.type.variant;
keyword alias mut = mutable;
keyword alias var = mut core.type.variant;
keyword alias i8 = byte;
...
keyword alias i64 = long;
keyword alias str = string;
keyword alias mod = module;
keyword alias imp = import; // you need that too
keyword alias pub = public;
keyword alias priv = private; // removed from rust but necessary here
keyword alias self = this;

Which produces:

// module.i
mod hello_sayer;

priv fn private_print(text: str) {
    print(str);
}

pub fn public_print(text: str, num: i32) {
    private_print(text);
    println(num);
}
// main.i
imp module;

fn main() {
    let i: i8 = 1;
    var num: i32 = 42;
    num += i;
    // private_print("Throws error because it's visible only in module");
    public_print("Hello world ", num); // prints "Hello world 43"
}

Not exactly one to one conversion, but still a nice transition.

ion's People

Contributors

al1-ce avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

ion's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.