My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Sunday, March 8, 2020

Typechecker in hhvm and running Hack program

Let's start with writing a sample program of printing cubes of numbers. eg:

Using the editor of your choice (e.g., VSCode or vim), let's create a file called first.hack with the following code:
<<__entrypoint>> function main(): void { echo "Welcome to Hack! \n\nTutorial by Anwar Faiz\n\n"; \printf("Table of Cubes\n" . "----------------\n"); for ($i = -5; $i <= 5; ++$i) { \printf(" %2d %2d \n", $i, $i * $i * $i); } \printf("----------------\n"); exit(0); }
To see the result of Typechecking:
$ hh_client first.hack
You should see:
No errors!
* Note that however, you might get following error - Error: /Users/mfaiz/ECPCP/hhvm-hack/first.hack is not a directory
But that is other issue. i will explain in next post.

To run the program on client side:
$hhvm first.hack 
You will get following as result.

By the way by now I am already feeling like using Node like application for PHP. This is looking cool. Hurray! 
Take care readers. And pour in your thoughts :)




Friday, March 6, 2020

First Hello World using Hack & HHVM from Facebook

1. Install HHVM on MacOS via Homebrew:
brew tap hhvm/hhvm
brew install hhvm

The out-of-the-box HHVM configuration won't need tweaking by most new users. Notably, the JIT compiler that gives HHVM its speed is on by default. If you want to take a look at the configuration used, it's at /usr/local/etc/hhvm/php.ini in MacOS.



2. Test: After installing HHVM, change to the directory where your code lives, and start up HHVM:

hhvm -m server -p 8080
-m represents the mode and here indicates that HHVM is running in HTTP server mode.
-p configures the TCP port that HHVM uses to listen to HTTP requests. The default port is 80, the standard HTTP port. However, that port requires root access, so for this example, we will use port 8080.

This will start the server as follows and then you can test on browser.


3. Write a simple "Hello World" program named hello.hack:

<<__entrypoint>> function main(): noreturn{ echo "Hello World in Hack Language! \nThis is Anwar Jamal Faiz"; exit(0); }

Save this hello.hack in the same directory that you ran the hhvm command from above. Then, load http://localhost:8080/hello.hack in your browser and verify you see "Hello World!" appear.


See in browser:
You may also write the program as:
<<__entrypoint>>
function main(): noreturn{
  echo "Hello World in Hack Language! \nThis is Anwar Jamal Faiz";
  exit(0);
}




4.  You can directly run file using hhvm itself.

$ hhvm hello.hack




Note: You can configure HHVM too. Running HHVM automatically at boot as a service (instead of just on the command line as above) unfortunately does require some configuration. See the proxygen documentation for details. However, default settings are okay for any average usecase.