PHPackages                             m3m0r7/rubyvm-on-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. m3m0r7/rubyvm-on-php

ActiveLibrary

m3m0r7/rubyvm-on-php
====================

0.3.3.0(2y ago)258MITPHPPHP &gt;=8.2

Since Sep 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/m3m0r7/rubyvm-on-php)[ Packagist](https://packagist.org/packages/m3m0r7/rubyvm-on-php)[ RSS](/packages/m3m0r7-rubyvm-on-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

RubyVM on PHP
=============

[](#rubyvm-on-php)

The RubyVM on PHP is implementation RubyVM written in PHP 100%. Completely documentation not exists how to implement RubyVM, and I was referred [Ruby source code](https://github.com/ruby/ruby) when contributing this project.

*Notice: This project is very ultra super hyper maximum experimental implementation*

*Notice: I tested Ruby version 3.2 and 3.3 only*

### See also

[](#see-also)

-
-
- [https://github.com/ruby/ruby/blob/master/vm\_exec.c](https://github.com/ruby/ruby/blob/master/vm_exec.c)

DEMO
----

[](#demo)

[![](./docs/demo.gif)](./docs/demo.gif)

Requirement
-----------

[](#requirement)

- PHP 8.2+

Currently status
----------------

[](#currently-status)

- Implemented general syntax (define local variables, global variables, classes, methods, booleans, hashes, arrays and so on)
- Implemented arithmetics (`+`, `-`, `*`, `/`), bit calculating (`|`, `&`, ``), some operator (`**`, `%`) and available overwrite it
- Implemented the block syntax (`[].each do | var | ... end`) and non block syntax (`[].push`)
- Implemented keyword arguments when calling a method (`keyword_argument(a: "Hello", c: "!", b: "World")`)
- Implemented variadic arguments when using an array and calling a method (`[*var1, *var2]`, `keyword_argument(a, b, *c)`)
- Implemented partially ruby methods (`to_s`, `to_i`, `[].push`, `foobar.nil?`)
- Implemented case-when syntax
- Implemented regexp syntax (`p /Hello/ =~ "Hello World"`)
- Implemented raise/rescue
- and anymore (see the tests' directory)

Quick start
-----------

[](#quick-start)

1. Install via composer as following

```
$ composer require m3m0r7/rubyvm-on-php

```

2. Save the below code as `HelloWorld.rb`

```
puts RubyVM::InstructionSequence.compile("puts 'HelloWorld!\n'", "HelloWorld.rb").to_binary
```

3. Output `.yarv` file as following

```
$ ruby HelloWorld.rb > HelloWorld.yarv
```

3. Create PHP file with below code and save as `HelloWorld.php`

```
