Download the PHP package m3m0r7/rubyvm-on-php without Composer
On this page you can find all versions of the php package m3m0r7/rubyvm-on-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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 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
- https://github.com/ruby/ruby/blob/master/compile.c
- https://github.com/ruby/ruby/blob/master/vm.c
- https://github.com/ruby/ruby/blob/master/vm_exec.c
DEMO
Requirement
- PHP 8.2+
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
-
Install via composer as following
-
Save the below code as
HelloWorld.rb
-
Output
.yarv
file as following -
Create PHP file with below code and save as
HelloWorld.php
- Run
php HelloWorld.php
and you will get outputtedHelloWorld!
from RubyVM.
Call defined ruby method on PHP
- Create ruby code as below:
And then, save file as test.rb
-
Compile to YARV as below:
- Call ruby method on PHP as below:
You will get to output Hello World from Ruby!
.
In addition case, maybe you want to pass arguments. of course, it is available on.
First time, to modify previous code as below.
Second time, to modify PHP code $executed->context()->callFromPHP()
as following:
You will get to output Hello World! Here is passed an argument from PHP
.
Use an executor debugger
The RubyVM on PHP is provided an executor debugger that can display processed an INSN and anymore into a table as following:
If you want to display above table then add below code from the Quick start.
_Notice: The executor debugger is using a lot of memories. We recommend to use disabling ordinarily. In depending on the case, may be using -d memory_limit=NEEDING_MEMORY_BYTES
parameters to be working when calling php
command_
Step by step debugging
The RubyVM on PHP is providing step by step debugger. It is available to confirm to process a sequence step by step. Which collect previous stacks, registered local tables and so on. this is required debugging this project.
When you enabled it, displays as below:
Custom method
The RubyVM on PHP has custom method in the main context.
Try to call phpinfo
as below Ruby code on the RubyVM on PHP:
Then you got displayed PHP Version: 8.2.7
Test
Linter
How to contribute
1) Build your ruby environment from source code with -DIBF_ISEQ_DEBUG
flag
See: https://docs.ruby-lang.org/en/master/contributing/building_ruby_md.html
2) When you built ruby environment, you will got vm.inc
file which is wrote how to execute each INSN commands
3) You can get logging at ibf_load_**
when running ruby code as following
The above logs is created below example code:
4) Refer it and now you can contribute to implement INSN command in the RubyVM on PHP
Other my toys
- PHPJava - Implement a JVM written in PHP
- nfc-for-php - A NFC Reader (Control a NFC hardware) written in PHP
- PHPPython - Implement a PYC executor written in PHP