Coder Social home page Coder Social logo

satanson / asteria Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lhmouse/asteria

0.0 2.0 0.0 11.13 MB

The Asteria Programming Language

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.13% M4 0.10% C++ 94.57% Shell 4.50% C 0.07% Python 0.36% SWIG 0.28%

asteria's Introduction

The Asteria Programming Language

README

CI Category Build on OS Host OS Build Status Remarks
Travis CI 🥇Primary Linux (Ubuntu) Linux (Ubuntu) Build Status
AppVeyor 🥈Secondary Windows (MSYS2) Windows (MSYS2) Build Status Standard I/O not in UTF-32.
LGTM Alerts
Compiler Category Remarks
GCC 10 🥇Primary
GCC 9 🥇Primary
GCC 8 🥇Primary
GCC 7 🥈Secondary Faulty strict overflow warnings.
GCC 6 🥇Primary
GCC 5 🥇Primary
Clang 8 🥈Secondary Unknown warning options. A number of meaningless warnings.
Clang 7 🥈Secondary Unknown warning options. A number of meaningless warnings.
MSVC 19 ⛔Abandoned Little build system support. Internal compiler errors.

GNU nano for the win!

Concepts

I started learning programming from ActionScript since Flash 5 days. It was no sooner (and not strange, either) than I learned JavaScript, because they are so similar. I admit that JavaScript is a fascinating language, but it also has quite a few drawbacks when we look at it today:

  1. There is no 64-bit integer type. While some data exchange formats (such as Protocol Buffers) do have 64-bit integers, they cannot be stored as Numbers safely. Some implementations split 64-bit integers into higher and lower parts, which is not very handy, as the lower part suddenly becomes signed and may be negative.
  2. There are no binary strings. Strings are in UCS-2 (rather than UTF-16), while ArrayBuffers are not resizable.
  3. NaN and Infinity are neither keywords nor constants. They are properties of the global object and may be overwritten. Moreover, Boolean(NaN) yields false unlike other languages.

Here is an issue that is shared by almost all common languages, including C and Python:

let a = [ ];
let b = [ ];

function test(x, y) {
  x.length = 0, x[0] = "hello";  // modifies the array that `x` would reference
  y = [ "hello" ];               // modifies `y` instead of the argument
}
test(a, b);  // arguments are in effect pointers

console.log("a = ", a);   // [ 'hello' ]
console.log("b = ", b);   // []

However, compared with typed languages such as Java, JavaScript has a few advantages:

  1. A number is always a Number. There are no integer types of varieties of widths, which simplifies programming. Unlike integers, Numbers never overflow.
  2. Being untyped, a function can be passed around like objects without knowing its parameters.

Asteria has been highly inspired by JavaScript but has been designed to address such issues.

Features

  1. Sane and clean.
  2. Self-consistent.
  3. Simple to use.
  4. Lightweight.
  5. Procedural.
  6. Dynamically typed.
  7. Easy to integrate in a C++ project. (C++14 and hexadecimal floating-point literals are required.)
  8. Native to C++ exceptions, particularly std::bad_alloc.

Characteristics

  1. First-class functions.
  2. Closure functions.
  3. Exceptions.
  4. Flexible syntax similar to C++ and JavaScript.
  5. Regular grammar.
  6. Argument passing (by value or reference) determined by the argument rather than the parameter.
  7. Idempotently copyable values basing on copy-on-write.
  8. Minimal garbage collection support.
  9. Structured binding similar to C++17.

Data Types

Asteria is untyped. Variables do not have types. Only values (which can be stored in in variables) do. In this sense functions are considered opaque data.

There are 9 data types:

Asteria JavaScript Java C++ Remarks
null undefined N/A std::nullptr_t
boolean Boolean boolean bool
integer N/A long std::int64_t signed 64-bit integer in two's complement
real Number double double IEEE-754 double-precision floating-point number
string N/A byte[] std::string octet string, commonly refered as byte string
opaque N/A Object std::any opaque value used by bindings
function Function N/A N/A functions and closures
array Array N/A std::vector<
std::any>
object Object N/A std::unordered_map<
std::string,
std::any>
order of elements not preserved

Expression Categories

var foo;
// `foo` refers to a "variable" holding `null`.

const inc = 42;
// `inc` refers to an "immutable variable" holding an `integer` of `42`.

var bar = func() { return ->inc;  };      // return by reference
// `bar` refers to an "immutable variable" holding a function.
// `bar()` refers to the same "variable" as `inc`.

func add(x) { return x + inc;  };   // return by value
// `add` refers to an "immutable variable" holding a function.
// `add(5)` refers to a "temporary" holding an `integer` of `47`.

How to Build

$ autoreconf -i  # requires autoconf, automake and libtool
$ ./configure
$ make -j$(nproc)

The REPL

$ ./bin/asteria

WIP

License

BSD 3-Clause License

asteria's People

Contributors

lhmouse avatar maskray avatar peaceshi avatar

Watchers

 avatar  avatar

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.