Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic hack language support #123

Merged
merged 6 commits into from
Jan 24, 2016

Conversation

thekid
Copy link
Member

@thekid thekid commented Jan 24, 2016

See xp-framework/rfc#308

Scope

This pull request supersedes #57 and implements the following Hack features in XP:

  • Running hack code alongside PHP - seamless
  • The short hack lambdas inside regular code - seamless
  • Hack parameter and return types, including void, this, noreturn, the num and arraykey unions, function types and typed arrays array<T> and maps array<?, T> - via changes to type system
  • Hack enums to be recognized as enum types correctly - by checking for HH\BuiltinEnum

Hack generics and attributes are not supported. See this comment on #122: We only cover the very basics to make reflection work consistently with PHP and Hack. Other features need to be implemented (or already are) in libraries such as https://github.com/xp-forge/mirrors!

Example

Test.class.php:

<?hh

use util\cmd\Console;

class Test {

  public static function main(array<string> $args): int {
    Console::writeLine('Hello World');
    return 0;
  }
}

Load and run:

vagrant@vagrant-ubuntu-vivid-64:/devel/xp/core$ XP_RT=hhvm xp Test
Hello World

Reflect:

vagrant@vagrant-ubuntu-vivid-64:/devel/xp/core$ XP_RT=hhvm xp -w \
  '\lang\XPClass::forName("Test")->getMethods()'
[public static int main(array<string> $args)]
vagrant@vagrant-ubuntu-vivid-64:/devel/xp/core$ XP_RT=hhvm xp -w \
  '\lang\XPClass::forName("Test")->getMethods ()[0]->getParameters()[0]->getType()'
lang.ArrayType<string[]>

* [x] Hack enums
* [x] Hack parameter and return types
* [x] Hack typed arrays array<T> and maps array<?, T>
@thekid thekid mentioned this pull request Jan 24, 2016
5 tasks
@thekid thekid added this to the 7.0.0 milestone Jan 24, 2016
@thekid thekid added the rfc label Jan 24, 2016
thekid added a commit that referenced this pull request Jan 24, 2016
@thekid thekid merged commit 4f19999 into xp-framework:master Jan 24, 2016
@thekid thekid deleted the infrastructure/hack-basic-support branch January 24, 2016 16:19
@thekid thekid mentioned this pull request Jan 24, 2016
11 tasks
@thekid thekid mentioned this pull request Sep 29, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant