Git Product home page Git Product logo

natalie's Introduction

Natalie

github build status MIT License justforfunnoreally.dev badge

Natalie is a very early-stage work-in-progress Ruby implementation.

It provides an ahead-of-time compiler using C++ and gcc/clang as the backend. Also, the language has a REPL that performs incremental compilation.

demo screencast

There is much work left to do before this is useful. Please let me know if you want to help!

Helping Out

Contributions are welcome! You can learn more about how I work on Natalie via the hacking session videos on YouTube.

The easiest way to get started right now would be to find a method on an object that is not yet implemented and make it yourself! Also take a look at good first issues. (See the 'Building' and 'Running Tests' sections below for some helpful steps.)

We have a very quiet Discord server -- come and hang out!

Building

Natalie is tested on macOS, OpenBSD, and Ubuntu Linux. Windows is not yet supported.

Natalie requires a system Ruby (MRI) to host the compiler, for now.

Prerequisites:

  • git
  • autoconf
  • automake
  • libtool
  • GNU make
  • gcc or clang
  • Ruby 3.0 or higher with dev headers
    • Using rbenv to install Ruby is preferred.
    • Installing rbenv-aliases along with rbenv helps with matching Ruby versions like 3.0 to the latest patch release.
    • If not using rbenv or another version manager, you'll need the ruby and ruby-dev package from your system.
  • ccache (optional, but recommended)
  • compiledb (optional, but recommended)

Install the above prerequisites on your platform, then run:

git clone https://github.com/natalie-lang/natalie
cd natalie
rake

Troubleshooting Build Errors

  • Don't use sudo! If you already made that mistake, then you should sudo rm -rf build and try again.
  • If you get an error about file permissions, e.g. unable to write a file to somewhere like /usr/lib/ruby, or another path that would require root, then you have a couple options:
    • Use a tool like rbenv to install a Ruby verison in your home directory. Gems will also be installed there. Run rbenv version to see which version is currently selected. Run rbenv shell followed by a version to select that version.
    • Specify where to install gems with something like:
      mkdir -p ~/gems
      export GEM_HOME=~/gems
      
      You'll just have to remember to do that every time you open a new terminal tab.
  • If you get an error about missing bundler, then your operating system probably didn't install it alongside Ruby. You can run gem install bundler to get it.

NOTE: Currently, the default build is the "debug" build, since Nataile is in active development. But you can build in release mode with rake build_release.

Usage

REPL:

bin/natalie

Run a Ruby script:

bin/natalie examples/hello.rb

Compile a file to an executable:

bin/natalie -c hello examples/hello.rb
./hello

Using With Docker

docker build -t natalie .                                            # build image
docker run -it --rm natalie                                          # repl
docker run -it --rm natalie -e "p 2 * 3"                             # immediate
docker run -it --rm -v$(pwd)/myfile.rb:/myfile.rb natalie /myfile.rb # execute a local rb file
docker run -it --rm --entrypoint bash natalie                        # bash prompt

Running Tests

To run a test (or spec), you can run it like a normal Ruby script:

bin/natalie spec/core/string/strip_spec.rb

This will run the tests and tell you if there are any failures.

If you want to run all the tests that we expect to pass, you can run:

rake test

Lastly, if you need to run a handful of tests locally, you can use the test/runner.rb helper script:

bin/natalie test/runner.rb test/natalie/if_test.rb test/natalie/loop_test.rb

What's the difference between the 'spec/' and 'test/' directories?

The files in spec/ come from the excellent ruby/spec project, which is a community-curated repo of test files that any Ruby implementation can use to compare its conformance to what MRI (Matz's Ruby Interpreter) does. We copy specs over as we implement the part of the language that they cover.

Everything in test/ is stuff we wrote while working on Natalie. These are tests that helped us bootstrap certain parts of the language and/or weren't covered as much as we would like by the official Ruby specs. We use this to supplement the specs in spec/.

Copyright & License

Natalie is copyright 2023, Tim Morgan and contributors. Natalie is licensed under the MIT License; see the LICENSE file in this directory for the full text.

Some parts of this program are copied from other sources, and the copyright belongs to the respective owner. Such copyright notices are either at the top of the respective file, in the same directory with a name like LICENSE, or both.

file(s) copyright license
big_int.* Syed Faheel Ahmad MIT
dtoa.c David M. Gay, Lucent Technologies custom permissive
fiber_object.* Evan Jones MIT
spec/* Engine Yard, Inc. MIT
version.rb Engine Yard, Inc. MIT
zlib Jean-loup Gailly and Mark Adler zlib license

See each file above for full copyright and license text.

natalie's People

Contributors

seven1m avatar herwinw avatar richardboehme avatar thegrizzlydev avatar timcraft avatar nanobowers avatar fncontroloption avatar ryangjchandler avatar hendiadyoin1 avatar andrykonchin avatar davidot avatar alimpfard avatar imustafin avatar borisromanov avatar ai-mozi avatar kddnewton avatar robertbendun avatar jcs avatar ohadrau avatar mateusdeap avatar stevegeek avatar tekknolagi avatar linusg avatar watzon avatar g-flat avatar duncan-britt avatar cian911 avatar awesomekling avatar crystalsage avatar kuzux 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.