Sitelet https://github.com/xp-framework/rfc/issues/327
Skip to content

Compile-time metaprogramming #327

Description

@thekid

Scope of Change

The XP Compiler will be extended to support compile-time metaprogramming

Rationale

Build libraries like xp-forge/partial into compiler.

Functionality

<<value>>
class Person {
  private int $id;
  private string $name;
}

The compiler finds an implementation which was previously registered via Transformations::register() for class nodes. The function gets executed and transforms the above to the following PHP:

class Person implements \lang\Value {
  private $id;
  private $name;

  public function __construct(int $id, string $name) {
    $this->id= $id;
    $this->name= $name;
  }

  public function id() { return $this->id; }

  public function name() { return $this->name; }

  // toString(), hashCode() and compareTo() omitted for brevity
}

Security considerations

Speed impact

Dependencies

xp-framework/compiler#19

Related documents

https://dzone.com/articles/compile-time-metaprogramming
http://groovy-lang.org/metaprogramming.html#_available_ast_transformations
http://groovy-lang.org/metaprogramming.html#developing-ast-xforms
http://notatube.blogspot.de/2010/12/project-lombok-creating-custom.html
xp-framework/compiler#15
https://wiki.php.net/rfc/parser-extension-api
microsoft/TypeScript#5595

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions