hhvm issues \nFatal error: Uncaught Error: unknown class xhp_x__element in :\nStack trace:\n#0 /Users/user/code/xhp-js-example/example.php(12) - hhvm

I'm trying to play with xhp and I'm finding that running the one xhp example I could find https://github.com/hhvm/xhp-js-example is issuing an error \nFatal error: Uncaught Error: Found top-level code in :\nStack trace:\n#0 {main} when following the README as is on HHVM 4.71. Removing require_once(__DIR__.'/vendor/autoload.php'); resolves the top-level code error but I'm now stuck with the error \nFatal error: Uncaught Error: unknown class xhp_x__element in :\nStack trace:\n#0 /Users/user/code/xhp-js-example/example.php(12): <unknown>()\n#1 {main}. I've tried to change the code in example.php to the one found here:
class :introduction extends :x:element {
protected function render(): \XHPRoot {
return <strong>Hello!</strong>;
}
}
class :intro-plain-str extends :x:element {
protected function render(): \XHPRoot {
// Since this function returns an XHPRoot, if you want to return a primitive
// like a string, wrap it around <x:frag>
return <x:frag>Hello!</x:frag>;
}
}
echo <introduction />;
echo PHP_EOL.PHP_EOL;
echo <intro-plain-str />;
since that didn't work, I also tried the simple example from here:
<?hh // strict
$user_name = 'Fred';
echo <tt>Hello <strong>{$user_name}</strong></tt>;
but altered to resolve the top-level error by wrapping it in a function and annotating it as follows:
<?hh // strict
<<__EntryPoint>>
function main(): void {
$user_name = 'Fred';
echo <tt>Hello <strong>{$user_name}</strong></tt>;
}
I'd get a very similar error \nFatal error: Uncaught Error: Class undefined: xhp_tt in /Users/user/code/xhp-js-example/example.php:6\nStack trace:\n#0 (): main()\n#1 {main}
Any help with getting these seemingly simple examples to work would be much appreciated since it's very painful and discouraging for trying this tech when the basic examples don't seem to run. this is using the macos package of hhvm on Catalina.
EDIT: I've also tried this without the use of xhp-js, which is included in the example repo and am getting the same error message.

There are a few roadblocks that the OP encountered to get XHP running with HHVM 4.62, as discussed in the comments.
xhp-js and xhp-js-example are both outdated by a few years so they can't compile due to breaking changes to HHVM itself, as the OP saw.
While the XHP syntax is built into Hack, all the standard implementations are provided by xhp-lib, so it is necessary to autoload that in order to use the standard library of tags and tag classes.
New to HHVM 4.62 is mandatory FIXME whitelisting, which requires package writers to explicitly specify allowed HH_FIXME codes in the .hhconfig. These were added to XHP-lib in 4.0.0rc1, so this version is necessary when running on HHVM 4.62.
Therefore, a minimal project with XHP on 4.62 looks like this:
composer.json
{
"require": {
"hhvm": "~4.62",
"hhvm/hhvm-autoload": "^3.1.3",
"facebook/xhp-lib": "~4.0.0rc1"
}
}
hh_autoload.json
{ "roots": [ "src/" ] }
src/example.hack
require_once(__DIR__ . "/../vendor/hh_autoload.hh");
<<__EntryPoint>>
function main(): void {
echo <div>{1 + 2}</div>;
}

Related

Is there a way to call extension methods from debug console?

Debugging with extension methods seems to be a bit problematic currently.
Consider the following code:
import 'dart:developer';
void main() {
final a = A();
workaround = a.extMethod;
debugger();
a.normalMethod();
a.extMethod();
}
class A {
String normalMethod() => 'hello from class';
}
extension AX on A {
String extMethod() => 'hello from extension';
}
When debugging this, stepping into both methods (normalMethod() and extMethod()) will work fine, the only difference is that this isn't available for extMethod() for some reason (there is #this instead, but it can't be used anyhow).
The extension method (extMethod()) is impossible to use for evaluations in the debug console, though.
a.normalMethod()
"hello from class"
a.extMethod()
Unhandled exception:
NoSuchMethodError: Class 'A' has no instance method 'extMethod'.
Receiver: Instance of 'A'
Tried calling: extMethod()
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1 Eval ()
workaround()
"hello from extension"
I have found kind of a workaround as you can see, but it has to be in place before running the program so I'd definitely prefer a better method that can be used on fly without any preparation.
I have found two very old issues describing this exact problem but both are closed and from what I understand, unresolved.
https://github.com/dart-lang/sdk/issues/44801
https://github.com/dart-lang/sdk/issues/44472
I'm using Dart 2.18.6 (latest stable).

Error when using MvxAppCompatActivity

I am writing an application with Xamarin.Android with MvvmCross. I want my Activity to inherit from MvxAppCompatActivity so that I can use fragments. Here is my base class:
public class BaseActivity<TViewModel> : MvxAppCompatActivity<TViewModel> where TViewModel : MvxViewModel
{
public new TViewModel ViewModel
{
get { return base.ViewModel; }
set { base.ViewModel = value; }
}
}
I get this error on the OnCreate of my Activity:
Failed resolution of: Landroid/support/v7/appcompat/R$drawable; Didn't
find class "android.support.v7.appcompat.R$drawable" on path:
DexPathList...
But if I change MvxAppCompatActivity to MvxActivity it works fine...why?
I downloaded your solution and tried to build the Android project. It fails with 18 occurrences of the same error:
error: No resource identifier found for attribute 'loginButtonBackgroundColor' in package ...
So after a little inspection of your solution, I did the following steps to solve your issue:
1) In login_screen.axml I saw you had this line:
xmlns:[YOURNAMESPACE]="http://schemas.android.com/apk/res/[YOUR PACKAGE]"
Which is unnecessary. After removing it, and changing the lines [YOURNAMESPACE]:loginButtonBackgroundColor=... to local:loginButtonBackgroundColor=... the build succeeds.
2) I saw some layout files are located inside the /drawable folder (button_round_corner.xml, input_box.xml and login_button.xml). I moved them to the /layout folder and fixed the issues the change produced (only two).
3) Made Setup class inherit from MvxAppCompatSetup.
4) Added a RegisterAttribute over the LoginButton control. So the class definition looks like this:
using Android.Runtime;
...
namespace Xxx.Droid.Components
{
[Register(nameof(LoginButton))]
public class LoginButton : FrameLayout, IMvxNotifyPropertyChanged
{
...
}
}
And that's it! Probably (2) was not necessary, but leaving it here just in case.
It could be several things but it is probably the lack of some android support packages. Mainly the lack of Xamarin.Android.Support.Design gives that error. So check if you have that added and if not add it and it should solve your problem.
If it doesn't it's highly likely you lack some other android support packages

POJO compilation fails (Algo: GBM, H2o-Version 3.8.1.3, Javac: 1.8.0_45, Mac OSX 10.11.3 / Fedora 23)

I try to locally compile a POJO of a GBM prediction model generated with H2o 3.8.1.3; I follow the instructions in the POJO class:
create a folder
Download the h2o-genmodel.jar into the folder with:
curl http://myh2oinstancesurl:myh2oinstancesport/3/h2o-genmodel.jar > h2o-genmodel.jar
Download the successfully trained GBM model named 154 into the folder with:
curl http://myh2oinstancesurl:myh2oinstancesport/3/Models/154/java > 154.java
Compile the sources in the folder with javac 1.8.0_45 under Max OSX 10.11.3 or Fedora 23:
javac -cp h2o-genmodel.jar 154.java
Result are a bunch of compilation errors:
154.java:24: error: <identifier> expected
public class 154 extends GenModel {
^
154.java:24: error: illegal start of type
public class 154 extends GenModel {
^
154.java:24: error: ';' expected
public class 154 extends GenModel {
^
154.java:25: error: illegal start of expression
public hex.ModelCategory getModelCategory() { return hex.ModelCategory.Binomial; }
^
154.java:25: error: ';' expected
public hex.ModelCategory getModelCategory() { return hex.ModelCategory.Binomial; }
^
154.java:27: error: illegal start of expression
public boolean isSupervised() { return true; }
^
154.java:27: error: ';' expected
public boolean isSupervised() { return true; }
^
154.java:28: error: illegal start of expression
public int nfeatures() { return 14; }
^
154.java:28: error: ';' expected
public int nfeatures() { return 14; }
^
154.java:29: error: illegal start of expression
public int nclasses() { return 2; }
^
...
100 errors
Is there an issue with my procedure? Or is this a bug with my setup? Is there anybody who currently can compile GBM POJOs? Thanks for your responses!
Solved: The problem was that the POJO class name obviously has to be a valid java class name; a purely numeric name is not allowed. Changing the model name resolves the issue.
[ This is not a direct answer to the question, but hopefully a helpful pointer to anyone that finds this question... ]
Since this question was asked, H2O has also added the ability to export a MOJO and use it for making predictions.
An H2O POJO is a code representation of a model, and an H2O MOJO is a data representation of a model.
A MOJO can be used in the same way as a POJO, and MOJOs do not need to be compiled (they are interpreted instead). This is especially useful for very large tree models, where trying to compile them has various technical challenges around gigabytes of code size. So in many cases, the best way to address a compilation issue is to not compile at all.
The online documentation for both H2O POJOs and MOJOs can be found here:
http://docs.h2o.ai/h2o/latest-stable/h2o-genmodel/javadoc/index.html
I hope people find this (delayed) answer helpful.

grails shell and closures

Trying to run the following command in grails console:
Family.where() {password =~ "%qw%"}
A very simple query on a stored object. I'm getting back:
ERROR groovy.lang.MissingMethodException:
No signature of method: com.babyboom.Family.where() is applicable for argument types: (groovysh_evaluate$_run_closure1) values: [groovysh_evaluate$_run_closure1#34356294]
Possible solutions: where(groovy.lang.Closure), merge(), every(), grep(), merge(com.babyboom.Family), merge(java.util.Map)
I understand that the closure I created is a different than the expected one.
Couple of questions:
Why there are 2 types of closures ?
Found Why am I getting a "No signature of method"" error when running the closure recursion example in the Groovy shell? tried it and it didn't help, still getting the same error
It works well when using grails console
This is likely a classloader bug with the grails shell. To reproduce, add dependency to BuildConfig.gradle:
runtime "org.grails:grails-datastore-simple:3.1.2.RELEASE"
then run
import org.grails.datastore.mapping.simple.SimpleMapDatastore
import org.grails.datastore.gorm.GormStaticApi
class Bar {}
class Foo extends GormStaticApi<Bar> {
Foo() {
super(Bar, new SimpleMapDatastore(), [], null)
}
}
def f = new Foo()
In grails console yields:
Result: Foo#699c0395
In grails shell yields:
groovy:000> def f = new Foo()
ERROR java.lang.LinkageError:
loader constraint violation: when resolving overridden method "Foo.$getStaticMetaClass()Lgroovy/lang/MetaClass;" the class loader (instance of groovy/lang/GroovyClassLoader$InnerLoader) of the current class, Foo, and its superclass loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader), have different Class objects for the type ()Lgroovy/lang/MetaClass; used in the signature

Using Groovy Library in Grails and getting 'No suitable ClassLoader found for grab'

I'm playing around with Grails/Groovy and have some straight Groovy code working that utilizes groovy-wslite. That code starts as such
send-request.groovy
#Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.0')
import wslite.soap.*
When I implement that into my Grails code and view the controller/action I get this
Error 500: Internal Server Error
URI: /FormProj/hello/trigger
Class: java.lang.RuntimeException
Message: No suitable ClassLoader found for grab
And here's the code in it's current state (I've tried a LOT of different things)
HelloController.groovy
package com.demo
import groovy.grape.Grape
class HelloController {
def index() { }
def sayHi() {
return [
greeting : "Hi there, ${ params.name }"
]
}
def trigger() {
Grape.grab(group:'com.github.groovy-wslite', module:'groovy-wslite', version:'1.1.0')
…
}
}
As I'm sure you notice I'm very green with Grails/Groovy and really all things Java. I do know there is a wslite plugin for Grails, but surely this can work too right?
Grails: 2.3.8
Groovy: 2.2.2
UPDATE
Based on Ian Robert's advice I have updated my BuildConfig file by adding this line to the dependencies block
compile 'com.github.groovy-wslite:groovy-wslite:1.1.0'
And updated my controller to look like this
HelloController.groovy
package ws.thejspot
import wslite.soap.*
class HelloController {
def index() { }
def sayHi() {
return [
greeting : "Hi there, ${ params.name }"
]
}
def trigger() {
def client = new SOAPClient('URL')
}
}
Unfortunately now the IDE, GGTS, shows an error in the controller 'unable to resolve class SOAPClient'
Rather than trying to download the dependencies with #Grab, you should use the standard Grails dependency mechanism - edit grails-app/conf/BuildConfig.groovy and look for the grails.project.dependency.resolution closure. Inside that, in the dependencies block you should add
compile 'com.github.groovy-wslite:groovy-wslite:1.1.0'
and remove anything Grape-related from the controller, leaving just the import wslite.soap.*
You will probably need to run
grails compile --refresh-dependencies
at least once to ensure that Grails picks up your change to BuildConfig - it deliberately doesn't do a full dependency resolve every time you compile, so as not to slow down the build too much, so you need to tell it to refresh when you know it needs to.

Resources