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

«Error: Died: method not found: seq_build_by in class Games::Solitaire::Verify::VariantParams» after building expand-solitaire-multi-card-moves #27

Closed
shlomif opened this issue Nov 2, 2014 · 13 comments

Comments

@shlomif
Copy link
Collaborator

shlomif commented Nov 2, 2014

Running this script:

#!/bin/bash

git_repo="$HOME/progs/freecell/git"
gsv="$git_repo/fc-solve/cpan/Games-Solitaire-Verify"

inc()
{
    local path="$1"
    shift
    echo "-I" "$gsv/$path/lib"
}

BASE="MyDir"
BASE_LIB="MyDir/lib"

for bn in "Games-Solitaire-Verify" "POSIX--replacement" "Exception-Class--replacement" "Getopt-Long--replacement" "List-Util--replacement" "Class-XSAccessor--replacement" ; do
    p="$gsv/$bn/lib"
    find "$p" -name '*.pm' | (while read fn ; do
        g="${fn##$p/}"
        mkdir -p "$BASE_LIB/$(dirname "$g")"
        perl -lp -MSQ -e 's#\Ause parent $sq([^$sq]+)$sq;#use $1 (); use vars qw(\@ISA); \@ISA = (qw($1));#' < "$fn" > "$BASE_LIB/$g"
    done)
done

# perl -MCarp::Always perlito5.pl -Cjs -I src5/lib/ $(inc "Games-Solitaire-Verify") $(inc "POSIX--replacement") $(inc "Exception-Class--replacement") $(inc "Getopt-Long--replacement") $(inc "List-Util--replacement") $(inc "Class-XSAccessor--replacement")  "$gsv"/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves
perl -MCarp::Always perlito5.pl -Cjs -I src5/lib/ -I "$BASE_LIB" "$gsv"/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves

gives me this:

shlomif@telaviv1:~$ node ~/expand-solitaire-multi-card-moves.js 

/home/shlomif/expand-solitaire-multi-card-moves.js:931
                throw(err)
                      ^
Error: Died: method not found: seq_build_by in class Games::Solitaire::Verify::VariantParams
Error
    at CORE.die (/home/shlomif/expand-solitaire-multi-card-moves.js:1907:24)
    at p5call (/home/shlomif/expand-solitaire-multi-card-moves.js:181:20)
    at /home/shlomif/expand-solitaire-multi-card-moves.js:3780:8
    at p5for_lex (/home/shlomif/expand-solitaire-multi-card-moves.js:922:13)
    at tmp179 [as _init] (/home/shlomif/expand-solitaire-multi-card-moves.js:3774:5)
    at p5call (/home/shlomif/expand-solitaire-multi-card-moves.js:156:44)
    at tmp106 (/home/shlomif/expand-solitaire-multi-card-moves.js:2248:5)
    at p5call (/home/shlomif/expand-solitaire-multi-card-moves.js:160:20)
    at p5pkg.POSIX.List_ISA (/home/shlomif/expand-solitaire-multi-card-moves.js:3881:60)
    at /home/shlomif/expand-solitaire-multi-card-moves.js:3926:4

Seems like the method is not constructed in run time.

@shlomif
Copy link
Collaborator Author

shlomif commented Nov 2, 2014

Some more progress - got rid of a string eval, but seems like ->mk_acc_ref is not getting called in the first place:

#!/bin/bash

git_repo="$HOME/progs/freecell/git"
gsv="$git_repo/fc-solve/cpan/Games-Solitaire-Verify"

inc()
{
    local path="$1"
    shift
    echo "-I" "$gsv/$path/lib"
}

BASE="MyDir"
BASE_LIB="MyDir/lib"

for bn in "Games-Solitaire-Verify" "POSIX--replacement" "Exception-Class--replacement" "Getopt-Long--replacement" "List-Util--replacement" "Class-XSAccessor--replacement" ; do
    p="$gsv/$bn/lib"
    find "$p" -name '*.pm' | (while read fn ; do
        g="${fn##$p/}"
        mkdir -p "$BASE_LIB/$(dirname "$g")"
        perl -lp -MSQ -e 's#\Ause parent $sq([^$sq]+)$sq;#use $1 (); use vars qw(\@ISA); \@ISA = (qw($1));#' < "$fn" > "$BASE_LIB/$g"
    done)
done
cat <<'EOF' > 'mk_acc_ref.pl'
sub mk_acc_ref
{
    my $pkg = shift;
    my $names = shift;

    my $mapping = +{ map { $_ => $_ } @$names };

    {
        foreach my $meth_name (keys %$mapping)
        {
            my $slot = $mapping->{$meth_name};

            {
                no strict;
                *{"${pkg}::$meth_name"} = sub {
                    my $self = shift;

                    if (@_)
                    {
                        $self->{$slot} = shift;
                    }
                    return $self->{$slot};
                };
            }
        }
    }
}
EOF
perl -lp -i -0777 -MSQ -MIO::All -E 's#^sub mk_acc_ref\n(.*?)\n}\n#io()->file("mk_acc_ref.pl")->all#ems' "$BASE_LIB"/Games/Solitaire/Verify/Base.pm

# perl -MCarp::Always perlito5.pl -Cjs -I src5/lib/ $(inc "Games-Solitaire-Verify") $(inc "POSIX--replacement") $(inc "Exception-Class--replacement") $(inc "Getopt-Long--replacement") $(inc "List-Util--replacement") $(inc "Class-XSAccessor--replacement")  "$gsv"/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves
perl -MCarp::Always perlito5.pl -Cjs -I src5/lib/ -I "$BASE_LIB" "$gsv"/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves

@fglock
Copy link
Owner

fglock commented Nov 3, 2014

running the script, I get this message:
Global symbol "$REQUIRE_ORDER" requires explicit package name
I'm investigating

@fglock
Copy link
Owner

fglock commented Nov 3, 2014

Exporting scalars is not yet implemented.
I'll see how it could be done.

@fglock
Copy link
Owner

fglock commented Nov 6, 2014

I've made a few fixes, now I get:

$ . shlomif.sh 
Error in BEGIN block: Can't locate object method "mk_classdata" via package "Exception::Class::Base" at (eval 24) line 3.
    eval 'package Exception::Class::Base;
{
    __PACKAGE__->mk_classdata(\'Trace\');
    __PACKAGE__->mk_classdata(\'NoRefs\');
    __PACKAGE__->NoRefs(1);

    __PACKAGE__->mk_classdata(\'NoContextInfo\');
    __PACKAGE__->NoContextInfo(0);

    __PACKAGE__->mk_classdata(\'RespectOverload\');
    __PACKAGE__->RespectOverload(0);

    __PACKAGE__->mk_classdata(\'MaxArgLength\');
    __PACKAGE__->MaxArgLength(0);

    sub Fields { () }
}' called at perlito5.pl line 5421

@fglock
Copy link
Owner

fglock commented Nov 6, 2014

Do you think it would be a good idea to copy your
fc-solve/cpan/Games-Solitaire-Verify/*--replacement
files to
src5/lib/src5/lib/Perlito5X/

See also the %Perlito_internal_module table in
src5/lib/Perlito5/Grammar/Use.pm

2014-11-02 14:41 GMT+01:00 Shlomi Fish notifications@github.com:

Some more progress - got rid of a string eval, but seems like ->mk_acc_ref
is not getting called in the first place:

#!/bin/bash

git_repo="$HOME/progs/freecell/git"
gsv="$git_repo/fc-solve/cpan/Games-Solitaire-Verify"
inc()
{
local path="$1"
shift
echo "-I" "$gsv/$path/lib"
}

BASE="MyDir"
BASE_LIB="MyDir/lib"
for bn in "Games-Solitaire-Verify" "POSIX--replacement" "Exception-Class--replacement" "Getopt-Long--replacement" "List-Util--replacement" "Class-XSAccessor--replacement" ; do
p="$gsv/$bn/lib"
find "$p" -name '.pm' | (while read fn ; do
g="${fn##$p/}"
mkdir -p "$BASE_LIB/$(dirname "$g")"
perl -lp -MSQ -e 's#\Ause parent $sq([^$sq]+)$sq;#use $1 (); use vars qw(@isa); @isa = (qw($1));#' < "$fn" > "$BASE_LIB/$g"
done)done
cat <<'EOF' > 'mk_acc_ref.pl'sub mk_acc_ref{ my $pkg = shift; my $names = shift; my $mapping = +{ map { $
=> $_ } @$names }; { foreach my $meth_name (keys %$mapping) { my $slot = $mapping->{$meth_name}; { no strict; *{"${pkg}::$meth_name"} = sub { my $self = shift; if (@) { $self->{$slot} = shift; } return $self->{$slot}; }; } } }}EOF
perl -lp -i -0777 -MSQ -MIO::All -E 's#^sub mk_acc_ref\n(.
?)\n}\n#io()->file("mk_acc_ref.pl")->all#ems' "$BASE_LIB"/Games/Solitaire/Verify/Base.pm

perl -MCarp::Always perlito5.pl -Cjs -I src5/lib/ $(inc "Games-Solitaire-Verify") $(inc "POSIX--replacement") $(inc "Exception-Class--replacement") $(inc "Getopt-Long--replacement") $(inc "List-Util--replacement") $(inc "Class-XSAccessor--replacement") "$gsv"/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves

perl -MCarp::Always perlito5.pl -Cjs -I src5/lib/ -I "$BASE_LIB" "$gsv"/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves


Reply to this email directly or view it on GitHub
#27 (comment).

@shlomif
Copy link
Collaborator Author

shlomif commented Nov 6, 2014

@fglock: don't know - they are really incomplete and ad-hoc.

@fglock
Copy link
Owner

fglock commented Nov 7, 2014

The context in which Perlito5 executes BEGIN blocks is incomplete, this is a bug.
This patch demonstrates the problem: it forces the materialization of the code at the right time, such that mk_classdata() can execute.

diff --git a/cpan/Games-Solitaire-Verify/Exception-Class--replacement/lib/Class/Data/Inheritable.pm b/cpan/Games-Soli
index df2aabb..95b54fb 100644
--- a/cpan/Games-Solitaire-Verify/Exception-Class--replacement/lib/Class/Data/Inheritable.pm
+++ b/cpan/Games-Solitaire-Verify/Exception-Class--replacement/lib/Class/Data/Inheritable.pm
@@ -4,6 +4,8 @@ use strict qw(vars subs);
 use vars qw($VERSION);
 $VERSION = '0.08';

+BEGIN {
+
 use Carp ();

 sub mk_classdata {
@@ -28,6 +30,8 @@ sub mk_classdata {
     *{$declaredclass.'::'.$alias}     = $accessor;
 }

+}
+
 1;

 __END__
diff --git a/cpan/Games-Solitaire-Verify/Exception-Class--replacement/lib/Exception/Class/Base.pm b/cpan/Games-Solita
index 01ba90d..5f6cc56 100644
--- a/cpan/Games-Solitaire-Verify/Exception-Class--replacement/lib/Exception/Class/Base.pm
+++ b/cpan/Games-Solitaire-Verify/Exception-Class--replacement/lib/Exception/Class/Base.pm
@@ -8,6 +8,9 @@ use Class::Data::Inheritable 0.02;
 our @ISA = ( qw(Class::Data::Inheritable) );

 BEGIN {
+    use Class::Data::Inheritable 0.02;
+    our @ISA = ( qw(Class::Data::Inheritable) );
+
     __PACKAGE__->mk_classdata('Trace');
     __PACKAGE__->mk_classdata('NoRefs');
     __PACKAGE__->NoRefs(1);

@fglock
Copy link
Owner

fglock commented Nov 10, 2014

I've created a perl script to investigate in more detail how BEGIN side-effects work - https://github.com/fglock/Perlito/blob/master/misc/typeglob/dumper.pl

These features will be integrated back into Perlito5. In the meanwhile, the "dumper" could potentially be used to preprocess BEGIN blocks out, before the perl5-to-js step.

@shlomif
Copy link
Collaborator Author

shlomif commented Nov 11, 2014

@fglock : thanks - I'll see if it'll help me.

@shlomif
Copy link
Collaborator Author

shlomif commented Dec 8, 2014

@fglock : is there any progress with this? Can I help you some how?

@fglock
Copy link
Owner

fglock commented Dec 9, 2014

There was some progress with BEGIN blocks, but not enough to fix the problem.
The "dumper" script should be able to preprocess the BEGIN blocks using 'perl' - https://github.com/fglock/Perlito/blob/master/misc/typeglob/dumper.pl
but that is not a final solution.
What I'm aiming for is a way to scan the memory after the first step of compilation, and serialize the state (global variables, including all closures) in AST format. Then code generation would proceed as normal.
Unfortunately, this is not as easy as it looks.

@fglock
Copy link
Owner

fglock commented Apr 11, 2017

update: BEGIN blocks are now working

@fglock
Copy link
Owner

fglock commented Dec 11, 2017

Some of the problems are now fixed - in particular, BEGIN blocks now work in JavaScript and Java, and some of the core modules now work.

Some problems can't be easily fixed - for example, only some functions of POSIX.pm can be ported.

Possible follow up tasks: rewrite some of the problems we found here into unit tests.

@fglock fglock closed this as completed Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants