partialruby - Ruby partial interpreter written in pure ruby
What I trying to say with “partial” ? Well, the ruby interpreter is composed by a few main conceptual “components”: parser, api, VM and execution environment. A partial interpreter will be a library implementing only one or even only part of one of these basic components. In this case, partialruby only implements part of the VM (e.g. partialruby DOESN’T implement a GC), use the excenllent ruby_parser gem (github.com/seattlerb/ruby_parser) to parse ruby code and use the real interpreter to the rest (api, environment, etc…).
Goals:
Implement a alternative VM which export services that is not exported by the original VM without implementing a entire ruby interpreter or fork an existing ruby interpreter
- Control of execution flow via hooking for sandboxing (see evalhook and shikashi projects) - Fast DSL (over ruby, and faster than ruby itself!)
Proof of Concept of interpreter and partial interpreter development
- Hyper-portability: microruby - Search for a faster ruby
Installation
Gem Installation (pending)
sudo gem install partialruby
OR
-
Download the last version of the gem from github.com/tario/partialruby/downloads
-
Install the gem with the following;
sudo gem install partialruby-X.X.X.gem.
Documentation (pending)
Full API documentation can be found on: tario.github.com/partialruby/doc/
Usage (pending)
Basically, partialruby export two APIs:
-
A alernative eval function with context. Example:
require “partialruby”
context = PartialRuby::Context.new context.eval(‘print “hello worldn”’)
Or
require "partialruby"
PartialRuby.eval('print "hello world\n"')
-
A flexible node handling. Example
require “partialruby”
class MyPartialRubyContext < PartialRuby::Context
def ruby_emul_call(tree) object_tree = tree[1] method_name = tree[2] arglist = tree[3] argsstr = arglist[1..-1]. map{|subtree| "(" + emul(subtree, frame) + ")" }. join(",") if (object_tree) "((#{emul(object_tree)}).#{method_name}(#{argsstr})" else if arglist.count == 0 "#{method_name}(#{argsstr})" else "#{method_name}" end end end
end
context = MyPartialRubyContext.new context.eval(‘print “hello worldn”’)
Copying
Copyright © 2010-2011 Dario Seminara, released under the GPL License (see LICENSE)