Discussion:
[Swig-devel] New HHVM module
Nishant Gupta
2016-06-02 13:38:43 UTC
Permalink
Hi, My name is Nishant Gupta. I'm currently working on extending swig to
support HHVM <http://hhvm.com>, as part of Google Summer of Code 2016,
under the guidance of Olly. HHVM is a JIT compiler for PHP developed by
Facebook. I am using the extension API
<https://github.com/facebook/hhvm/wiki/Extension-API> provided by HHVM for
this purpose. (N.B. This mail is in HTML, so I request you to turn on html.
The mail only contains hyperlinks, nothing creepy)

I have implemented parts of wrapping constants and functions, and would
kindly request you to please review these parts (especially the function
wrapper). The repo is located at github.com/ng420/swig-hhvm . The module
can be found at Source/Modules/hhvm.cxx
<https://github.com/ng420/swig-hhvm/blob/master/Source/Modules/hhvm.cxx>

I'm currently facing a few problems while implementing overloaded
functions. I have implemented code to wrap each variant of the overloaded
function. Now, I wish to add a 'switching function' as done by other
modules. However, the format of my function is functionname(arg1, arg2..),
and I couldn't find how to dispatch
<https://github.com/ng420/swig-hhvm/blob/master/Source/Modules/hhvm.cxx#L202>
in this format. Thanks to Olly, I came to know there is $commaargs
<https://github.com/ng420/swig-hhvm/blob/master/Source/Modules/overload.cxx#L389>,
which is only used by chicken (module). However, it generates a leading
comma
<https://github.com/ng420/swig-hhvm/blob/master/sample/ext_example.cpp#L243>,
and I'm not sure how to get rid of it. Should I go for creating a similar
$commaargs (call it $printedargs), or should I just amend the existing one
and reflect the changes in checken.cxx? Simply adding a leading comma at
$commaargs in chicken.cxx
<https://github.com/ng420/swig-hhvm/blob/master/Source/Modules/chicken.cxx#L1308>
can break things in case of zero arguments, and I am not sure if by
customizing the format string I can achieve the desired effect.

Another issue is returning result. When the overloaded function is selected
(by the switching function), I wish to return the result of non-void
functions. How can I achieve that?

A simple fall-back to above issues is to completely discard the generation
of switching function, which, as I understand, java and C# do. What are
your thoughts?

Thanks
Nishant
William S Fulton
2016-06-04 12:02:16 UTC
Permalink
Post by Nishant Gupta
Hi, My name is Nishant Gupta. I'm currently working on extending swig to
support HHVM, as part of Google Summer of Code 2016, under the guidance of
Olly. HHVM is a JIT compiler for PHP developed by Facebook. I am using the
extension API provided by HHVM for this purpose. (N.B. This mail is in HTML,
so I request you to turn on html. The mail only contains hyperlinks, nothing
creepy)
I have implemented parts of wrapping constants and functions, and would
kindly request you to please review these parts (especially the function
wrapper). The repo is located at github.com/ng420/swig-hhvm . The module can
be found at Source/Modules/hhvm.cxx
I'm currently facing a few problems while implementing overloaded functions.
I have implemented code to wrap each variant of the overloaded function.
Now, I wish to add a 'switching function' as done by other modules. However,
the format of my function is functionname(arg1, arg2..), and I couldn't find
how to dispatch in this format. Thanks to Olly, I came to know there is
$commaargs, which is only used by chicken (module). However, it generates a
leading comma, and I'm not sure how to get rid of it. Should I go for
creating a similar $commaargs (call it $printedargs), or should I just amend
the existing one and reflect the changes in checken.cxx? Simply adding a
leading comma at $commaargs in chicken.cxx can break things in case of zero
arguments, and I am not sure if by customizing the format string I can
achieve the desired effect.
Another issue is returning result. When the overloaded function is selected
(by the switching function), I wish to return the result of non-void
functions. How can I achieve that?
A simple fall-back to above issues is to completely discard the generation
of switching function, which, as I understand, java and C# do. What are your
thoughts?
First question is what do you mean by the term 'switching function'? I
presume you mean the 'dispatch function' which is the terminology used
in SWIG for overloaded functions?

Regarding $commaargs, I would prefer you amended it and make the
necessary changes in chicken.cxx to generate the same output (if
possible).

I don't believe php 7 supports function overloading like Java and C#,
so I don't see how you can take that approach. Correct me if I'm
wrong, but that means you have to provide a dispatch function like the
other scripting languages.

Good luck and thanks for the pending contributions to SWIG! Feel free
to ask any more questions here.

William
Nishant Gupta
2016-06-04 15:35:56 UTC
Permalink
Hi,

Yes, I mean the dispatch function. Regarding $commaargs, I found that I
couldn't use it because of few issues. HNI equivalent of mixed data-type is
called variant. Now, assume that we receive all the arguments as an array
of variants (similar to void **argv[]), and we wish to call the appropriate
wrapped function. The issue is, variant cannot be casted automatically. For
example, assume that we wish to call a function f(int x, int y). It cannot
be called by two variant variables, say v1 and v2, and f(v1,v2) is an
invalid call. Variants have their own casting methods. So, an acceptable
call would be f(v1.toInt64Val(), v2.toInt64Val())

The existing mechanism just checks the type. So, I'm able to check the
types of parameters, but I cannot assign them to new variables of
appropriate types, e.g. int64_t targ0 = arg[0].toInt64Val(); nor I can cast
them at the time of call e.g. f(arg[0].toInt64Val(), arg[1].toInt64Val())

As I had mentioned in my last mail, another issue is, returning results
from the overloaded function. We cannot add 'return func_name(args)' in the
template because of void-returning functions. So, for a function which
returns a value, we wish to return it, otherwise, we have to return null.

My current approach is to copy and modify the existing dispatch function to
meet my requirements. Since the requirements are quite different from
requirements of the current modules, I didn't modify the common functions.
I'll return to change these in due course, if you see a need to do so.

By the way, I feel that you are confusing between hhvm and php. HHVM is a
compiler for php. It supports both, php 5 and (major features of) php 7.
However, it has a different extension api than php, that is where the need
of this module arises.

Thanks
Nishant
Post by Nishant Gupta
Post by Nishant Gupta
Hi, My name is Nishant Gupta. I'm currently working on extending swig to
support HHVM, as part of Google Summer of Code 2016, under the guidance
of
Post by Nishant Gupta
Olly. HHVM is a JIT compiler for PHP developed by Facebook. I am using
the
Post by Nishant Gupta
extension API provided by HHVM for this purpose. (N.B. This mail is in
HTML,
Post by Nishant Gupta
so I request you to turn on html. The mail only contains hyperlinks,
nothing
Post by Nishant Gupta
creepy)
I have implemented parts of wrapping constants and functions, and would
kindly request you to please review these parts (especially the function
wrapper). The repo is located at github.com/ng420/swig-hhvm . The
module can
Post by Nishant Gupta
be found at Source/Modules/hhvm.cxx
I'm currently facing a few problems while implementing overloaded
functions.
Post by Nishant Gupta
I have implemented code to wrap each variant of the overloaded function.
Now, I wish to add a 'switching function' as done by other modules.
However,
Post by Nishant Gupta
the format of my function is functionname(arg1, arg2..), and I couldn't
find
Post by Nishant Gupta
how to dispatch in this format. Thanks to Olly, I came to know there is
$commaargs, which is only used by chicken (module). However, it
generates a
Post by Nishant Gupta
leading comma, and I'm not sure how to get rid of it. Should I go for
creating a similar $commaargs (call it $printedargs), or should I just
amend
Post by Nishant Gupta
the existing one and reflect the changes in checken.cxx? Simply adding a
leading comma at $commaargs in chicken.cxx can break things in case of
zero
Post by Nishant Gupta
arguments, and I am not sure if by customizing the format string I can
achieve the desired effect.
Another issue is returning result. When the overloaded function is
selected
Post by Nishant Gupta
(by the switching function), I wish to return the result of non-void
functions. How can I achieve that?
A simple fall-back to above issues is to completely discard the
generation
Post by Nishant Gupta
of switching function, which, as I understand, java and C# do. What are
your
Post by Nishant Gupta
thoughts?
First question is what do you mean by the term 'switching function'? I
presume you mean the 'dispatch function' which is the terminology used
in SWIG for overloaded functions?
Regarding $commaargs, I would prefer you amended it and make the
necessary changes in chicken.cxx to generate the same output (if
possible).
I don't believe php 7 supports function overloading like Java and C#,
so I don't see how you can take that approach. Correct me if I'm
wrong, but that means you have to provide a dispatch function like the
other scripting languages.
Good luck and thanks for the pending contributions to SWIG! Feel free
to ask any more questions here.
William
William S Fulton
2016-06-18 12:11:13 UTC
Permalink
Post by Nishant Gupta
Hi,
Yes, I mean the dispatch function. Regarding $commaargs, I found that I
couldn't use it because of few issues. HNI equivalent of mixed data-type is
called variant. Now, assume that we receive all the arguments as an array of
variants (similar to void **argv[]), and we wish to call the appropriate
wrapped function. The issue is, variant cannot be casted automatically. For
example, assume that we wish to call a function f(int x, int y). It cannot
be called by two variant variables, say v1 and v2, and f(v1,v2) is an
invalid call. Variants have their own casting methods. So, an acceptable
call would be f(v1.toInt64Val(), v2.toInt64Val())
The existing mechanism just checks the type. So, I'm able to check the types
of parameters, but I cannot assign them to new variables of appropriate
types, e.g. int64_t targ0 = arg[0].toInt64Val(); nor I can cast them at the
time of call e.g. f(arg[0].toInt64Val(), arg[1].toInt64Val())
As I had mentioned in my last mail, another issue is, returning results from
the overloaded function. We cannot add 'return func_name(args)' in the
template because of void-returning functions. So, for a function which
returns a value, we wish to return it, otherwise, we have to return null.
Take a look at the Java approach. It uses a special variable called
$null which is usually expanded to NULL or empty space for void
returns.

In this instance, I'd rather you used common code rather than copying
this rather large dispatch code base which should be used by all
languages implementing dispatch functions. Aim to implement special
variable tweaks like $null in hhvm.cxx.
Post by Nishant Gupta
My current approach is to copy and modify the existing dispatch function to
meet my requirements. Since the requirements are quite different from
requirements of the current modules, I didn't modify the common functions.
I'll return to change these in due course, if you see a need to do so.
Are you sure you need a dispatch function, or can you use true
overloaded methods like in the case of Java? Are you generating PHP or
HACK code for use on HHVM? Is overloading supported by any of these
languages on HHVM? If so, it'll be much better than writing dispatch
functions.

William

Loading...