All Projects → sysprog21 → rubi

sysprog21 / rubi

Licence: other
Ruby-like high-performance script programming language with JIT compilation

Programming Languages

c
50402 projects - #5 most used programming language
lua
6591 projects
ruby
36898 projects - #4 most used programming language
Makefile
30231 projects

Rubi

Rubi is a high-level, high-performance script programming language, with syntax that is familiar to users of Ruby. Rubi is implemented via just-in-time compilation.

Syntax

Anyone who is familiar to Ruby programming language should learn Rubi quickly. Sample programs can be found in the directory progs.

  • Syntax
# Statement => write in the function.

# output the string and number
# puts is output and \n
# output is output only.
puts "Hello world!!" # => Hello world!!\n
puts "number = ", 65536 # => number = 65536\n
output "not new line" # => not new line

# declaration is not required
# support only integer
i = 10
i = i + 43
i = i % 5
i = i - 32
sum = i * (12 / 5)
12 / 5 # => 2

# loop and if
for i = 1, i < 100, i = i + 1
    if i % 15 == 0
        puts "fizzbuzz"
    elsif i % 5 == 0
        puts "buzz"
    elsif i % 3 == 0
        puts "fizz"
    else
        puts i
    end
end

# create function
def sum(n)
    sm = 0
    for = 1, i <= n, i = i + 1
        sm = sm + i
    end
    sm
    # "return sm" is OK
end
  • Implement Fibonacci in Rubi:
def fib(n)
    if n < 2
        n
    else
        fib(n - 1) + fib(n - 2)
    end
end

puts fib(39)
  • Implement recursive quick sort in Rubi
def sort(a, left, right)
    l = left; r = right; pv = a[(l + r) / 2]
    while 1
        while a[l] < pv; l++; end
        while pv < a[r]; r--; end
        if l >= r; break end
        tmp = a[l]; a[l] = a[r]; a[r] = tmp
        l++; r--;
    end
    l--; r++
    if left < l; sort(a, left, l); end
    if r < right; sort(a, r, right); end
end

Licensing

Rubi is freely redistributable under the two-clause BSD License. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Portability

The compiler and JIT is highly dependant on the Intel x86 Instruction Set Architecture (ISA) and Linux style calling convention.

Quick Start

  • Install development packages for Ubuntu Linux Ubuntu 14.04 LTS:
sudo apt-get install gcc-multilib libc6-dev-i386
  • Build and run
$ make
$ ./rubi [filename]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].