Giter Club home page Giter Club logo

nelua-lang's Introduction

Nelua Logo

nelua.io

Nelua Programming Language

Build Status Coverage Status Discord Try on Repl.it

Nelua is a minimal, simple, efficient, statically typed, compiled, meta programmable, safe and extensible systems programming language with a Lua flavor. It uses ahead of time compilation to compile to native code. Nelua stands for Native Extensible Lua.

NOTE: The language is in development and in alpha state.

About

Nelua is a systems programming language for performance sensitive applications where Lua would not be efficient, like operational systems, real-time applications and game engines. It has syntax and semantics similar to Lua, but is designed to be able to work free from a Lua interpreter, instead it takes advantage of ahead of time compilation. When coding using Nelua idioms such as type notations, records, arrays, manual memory management, pointers the performance should be efficient as C. But when using Lua idioms such as tables, metatables and untyped variables the compiler uses a runtime library to provide the dynamic functionality.

Nelua can do compile-time meta programming because it has a Lua preprocessor capable to cooperate with the compiler as it compiles, this is only possible because the compiler is fully made in Lua and is fully accessible or modifiable by the preprocessor on the fly. Therefore it's possible to implement higher constructs such as classes, generics and polymorphism at compile time without having to make them into the language specification, thus keeping the language simpler and compact. For example in Lua classes don't exist but you can implement yourself using metatables, in Nelua they don't exist neither but you can implement more efficiently at compile time by meta programming or at runtime just like in Lua.

Nelua can do extensible programming as the programmer may add extensions to the language such as new grammars, AST definitions, semantics, type checkers, code generation and behaviors to the compiler at compile time via the preprocessor.

Nelua has two choices for memory management, it's the developer choice to use garbage collection or manual memory management depending on his use case.

Nelua compiles to C first then to the target native code, this way existing C libraries and APIs can be reused and new C libraries can be created. Any platform that a C99 compiler targets the language is capable of targeting so the language can take advantage of highly optimized compilers such as GCC and Clang, thus generating very efficient native code.

The motivation of the language is to replace C/C++ part of projects that uses Lua today with a language that have syntax and semantics similar to Lua, but without loosing performance or the ability to go low level. Therefore unifying the syntax and semantics across both compiled and dynamic language.

Goals

  • Be minimal with a small syntax, manual and API, but powerful
  • Be efficient by compiling to optimized C code then native code
  • Have syntax, semantics and features similar to Lua
  • Optionally statically typed with type checking
  • Achieve classes, generics, polymorphism and other higher constructs by meta programming
  • Have an optional garbage collector
  • Make possible to create clean DSLs by extending the language grammar
  • Make programming safe for non experts by doing run/compile-time checks and avoiding undefined behavior
  • Possibility to emit low level code (C, assembly)
  • Be modular and make users capable of creating compiler plugins to extended
  • Generate readable, simple and efficient C code
  • Possibility to output freestanding code (dependency free, for kernel dev or minimal runtime)
  • No single memory management model, choose for your use case GC or manual

Why?

  • We love to script in Lua.
  • We love C performance.
  • We want best of both worlds in a single language and with a unified syntax.
  • We want to reuse or mix existing C/C++/Lua code.
  • We want type safety and optimizations.
  • We want to have efficient code while maintaining readability and safety.
  • We want the language features and manual to be minimal and fit our brain.
  • We want to deploy anywhere C runs.
  • We want to extended the language features by meta programming or modding the compiler.
  • We want to code with or without garbage collection depending on our use case.
  • We want to abuse of static dispatch instead of dynamic dispatch to gain performance and correctness.

Learning

More details about the language can be read on the following links:

  • Check out the language overview to get a quick view of the language syntax, features and usage.
  • Check out the language tutorial for learning the basics.
  • Join the language discord chat in case you have questions or need help.

Quick Installation

In a system with build tools and a C compiler do:

git clone https://github.com/edubart/nelua-lang.git && cd nelua-lang
make
sudo make install

The Nelua compiler should be available in /usr/local/bin/nelua, now run the hello world example:

nelua examples/helloworld.nelua

For complete instructions on how to install see the installing tutorial.

Examples

The folder examples contains some examples in Nelua, including some games, most of the examples currently work only with the default C generator backend.

To run the Snake demo for example run:

nelua examples/snakesdl.nelua

Benchmarks

Some benchmarks can be found in benchmarks folder, it contains nelua benchmarks and pure C benchmark as reference. The Lua code of the benchmarks are generated by nelua compiler, as it can compile to Lua too.

The benchmarks can be run with make benchmark, this is my last results:

benchmark lua 5.3 luajit 2.1 nelua c
ackermann 2448.2 ms 145.2 ms 47.8 ms 47.4 ms
fibonacci 2612.4 ms 951.7 ms 279.9 ms 280.9 ms
mandel 2549.6 ms 97.0 ms 88.5 ms 88.2 ms
sieve 1240.4 ms 265.3 ms 88.7 ms 60.1 ms
heapsort 2602.1 ms 274.0 ms 170.9 ms 127.5 ms

NOTE: Nelua can match C speed if all benchmarks were coded using optimized structures, however to make the benchmarks comparisons fair with Lua/LuaJIT they were coded in Lua style (using sequence tables and a garbage collector).

Environment that this benchmark was run: LuaJIT 2.1.0-beta3, GCC 9.3.0, Lua 5.3.5, CPU Intel Core i7-3770K CPU @ 3.50GHz, OS ArchLinux CFLAGS -O3 -fno-plt -march=native -flto

Previous test runs on the master branch can be seen in the github's actions tab.

Roadmap

Language planned features and history of accomplished features can be seen in the github's projects tab.

Contributing

You can support or contribute to Nelua in many ways, giving the project a star on github, testing out its features, reporting bugs, discussing ideas, spreading it to the world, sharing projects made with it on github, creating tutorials or blog posts, creating wiki pages that could be useful for newcomers, improving its documentation or through a donation or sponsorship,

Become a Patron

License

MIT License

nelua-lang's People

Contributors

bjornbytes avatar dependabot[bot] avatar edubart avatar

Watchers

 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.