GithubHelp home page GithubHelp logo

doytsujin / ruruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sisshiki1969/ruruby

0.0 1.0 0.0 2.84 MB

An alternative Ruby implementation by Rust.

Rust 97.15% Ruby 2.31% Shell 0.18% Dockerfile 0.36%

ruruby's Introduction

ruruby ruruby

An alternative Ruby implementation by Rust.

Feature

  • Purely implemented with Rust. No dependency on any other Ruby implementation such as CRuby(MRI), mruby, .. etc.
  • Hand-written original parser.
  • Virtual machine execution.

Related article

Qiita: Rust でつくる(つくれるかもしれない)Ruby

Implementation status

  • Literals
    • Bool
    • Integer
    • Float
    • String literal
    • String literal with interpolation
    • Array literal
    • Hash literal
    • Lambda literal
    • Block literal
    • Regular expression
  • Objects
    • Integer
    • Float
    • Symbol
    • String
    • Range
    • Array
    • Hash
    • Proc
    • Method
    • Regexp
    • Struct
    • Enumerator
    • Fiber
  • Variables
    • Local variable
    • Instance variable
    • Class variable
    • Global variable
  • Constants
    • Constant
  • Branch and Loop
    • If-then-elsif-else
    • Unless-then-else
    • Postfix if / unless
    • For-in
    • Break / Continue
    • While
    • Until
    • Postfix while / until
    • Case-when
    • Return
  • Methods
    • Instance Method
    • Class Method
    • Singleton Method
  • Class and Module
    • Subclass / Inheritance
    • Initializer
    • Attribute accessor
    • Open class (Ad-hoc class definition)
    • Module

How to run ruruby

To build ruruby, You'll need installation of Rust. Be aware that only nightly version of Rust works for ruruby.

To run ruby program file on ruruby,

% cargo run tests/sample.rb

or

% cargo run --release -- tests/sample.rb

You can launch irb-like interactive shell, omitting file name.

% cargo run

Option: Bytecode Trace execution

% cargo run --features trace -- tests/sample.rb
   Compiling ruruby v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 1.83s
     Running `target/debug/ruruby tests/sample.rb`
---> MethodRef(198)
   0:PUSH_STRING     stack:0
   5:SET_LOCAL       stack:1
   e:PUSH_STRING     stack:0
  13:PUSH_STRING     stack:1
  18:CONCAT_STR      stack:2
  19:GET_LOCAL       stack:1
  22:TO_S            stack:2
  23:CONCAT_STR      stack:2
  24:PUSH_STRING     stack:1
  29:CONCAT_STR      stack:2
  2a:SEND_SELF       stack:1
Hello world!
  3b:END             stack:1
<--- Ok(nil)

Option: Emit ByteCode

% cargo run --features emit-iseq -- tests/sample.rb
   Compiling ruruby v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 6.72s
     Running `target/debug/ruruby tests/sample.rb`
-----------------------------------------
MethodRef(198)
local var: 0:w
block: None
  00000 PUSH_STRING 181
  00005 SET_LOCAL outer:0 LvarId:0
  00014 PUSH_STRING 182
  00019 PUSH_STRING 183
  00024 CONCAT_STR
  00025 GET_LOCAL outer:0 LvarId:0
  00034 TO_S
  00035 CONCAT_STR
  00036 PUSH_STRING 184
  00041 CONCAT_STR
  00042 SEND_SELF 'puts' 1 items
  00059 END
Hello world!

Option: Performance analysis per VM instruction

% cargo run --features perf -- tests/sample.rb
   Compiling ruruby v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 3.53s
     Running `target/debug/ruruby tests/sample.rb`
Hello world!
Performance analysis for Inst:
------------------------------------------
Inst name         count    %time     nsec
                                    /inst
------------------------------------------
PUSH_STRING           4     6.48    25993
SET_LOCAL             1     0.19     3756
GET_LOCAL             1     0.00      382
SEND_SELF             1     2.58    41261
CONCAT_STR            3     0.19     1166
TO_S                  1     0.25     4707
END                   1     0.06     1044
CODEGEN               1    87.48  1391588
EXTERN                1     2.45    39834
------------------------------------------

ruruby's People

Contributors

sisshiki1969 avatar grosser 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.