go-php icon indicating copy to clipboard operation
go-php copied to clipboard

Toy Golang interpreter written in PHP

Go-PHP

Golang interpreter written in PHP.

Example

use GoPhp\Interpreter;

$interp = Interpreter::create(<<<GO
    package main
    
    type person struct {
        name string
        age  int
    }
    
    func newPerson(name string) *person {
        p := person{name: name}
        p.age = 42

        return &p
    }

    func main() {
        s := newPerson("John Doe")
    
        println("Hello, " + s.name)
    }
GO);

$result = $interp->run();

See examples for more. To run examples:

cd ./examples/{name}
php main.php

WIP

This is a toy project, currently work-in-progress.

To see what is already implemented, refer to tests.

Development

install dependencies:

composer install

run tests:

make test

run make help for more commands.