wbraswell / rperl

RPerl Compiler
Other
277 stars 34 forks source link

Implement Operator, Bitwise And CPPOPS_CPPTYPES #96

Open wbraswell opened 5 years ago

wbraswell commented 5 years ago

Implement the ast_to_cppgenerateCPPOPS_CPPTYPES() C++ code generation subroutine for the "bitwise and" operator:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/Bitwise/And.pm

Ensure all tests continue to pass in both the existing PERLOPS_PERLTYPES mode as well as the new CPPOPS_CPPTYPES mode:

https://github.com/wbraswell/rperl/tree/master/lib/RPerl/Test/Operator13BitwiseAnd

Upgrade the "good" test to include output, which may be dependent on compiler settings and/or integer bit length:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Test/Operator13BitwiseAnd/program_00_good.pl

Use the "bitwise negation" test as reference for EXECUTE_SUCCESS_INTEGER_32 and EXECUTE_SUCCESS_INTEGER_64 test output:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Test/Operator05BitwiseNegation/program_01_good.pl

Use the "logical and" operator as reference:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/Logical/And.pm

Use the "getting started" documentation for step-by-step instructions:

https://github.com/wbraswell/rperl/blob/master/docs/devs_getting_started.txt

wbraswell commented 5 years ago

@shpsi Hello Mr. Singh,

This is your issue for GSoC Pull Request Challenge, Round 1! :-)

Please use this comment thread for all discussions related to this Pull Request Challenge.

shpsi commented 5 years ago

Thank you! will soon get back to you

shpsi commented 5 years ago

how can i get it done for macOS
https://github.com/wbraswell/rperl/blob/master/INSTALL ? by just running bash script it runs apt-get which is for linux . is there option to select for mac?

wbraswell commented 5 years ago

MacOS is not yet fully supported:

"Everywhere that calls the apt-get command, you will have to substitute your equivalent."

https://github.com/wbraswell/rperl/blob/master/INSTALL#L18

Please use Linux instead, preferably Xubuntu:

https://xubuntu.org/

shpsi commented 5 years ago

I am running xubuntu in virtual Box . do you guys use any specific ide?

wbraswell commented 5 years ago

I use Eclipse with Perl Epic plugin for complex jobs like the entire RPerl compiler.

For a simple job like just one RPerl operator, you can use normal vim or gvim if you want to keep it simple.

If vim is too simple, then go with Eclipse & Perl Epic plugin.

shpsi commented 5 years ago

Hey will , I have some doubts:- I was studying this https://metacpan.org/pod/rperl and can rperl compiler compiles more than one file rperl [ARGUMENTS] input_program_0.pl [input_program_1.pl input_program_2.pl ...] and how to see outputs? or how to run the tests on builtin operators

In this code, https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/Logical/And.pm what operator_122 and 128 means??

wbraswell commented 5 years ago

Hello Mr. Singh, There is currently no part of this Pull Request Challenge which requires you to compile more than one file at a time, so please don't bother with that for now.

Operator_122 and Operator_128 are RPerl AST nodes which map to corresponding RPerl classes, both of which map to RPerl::Operation::Expression::Operator::Logical::And in this case:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Grammar.eyp#L355

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Grammar.eyp#L361

Before you can try to run operator tests, you must ensure that RPerl itself is installed correctly:

foouser@foomachine:~/repos_github/rperl-latest$ export RPERL_DEBUG=1
foouser@foomachine:~/repos_github/rperl-latest$ export RPERL_VERBOSE=1
foouser@foomachine:~/repos_github/rperl-latest$ rperl -v
WARNING WEXRP00: Found multiple `rperl` executables, using first located, `/home/foouser/github_repos/rperl-latest/script/rperl`; other locations include `script/rperl`
[[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
validate Stage
Starting Build Preprocess Stage
get_maps Stage
Finished Build Preprocess Stage

Starting Build Parse Stage
Finished Build Parse Stage

Starting Build Glue 1 Stage
Finished Build Glue 1 Stage

Starting Build Glue 2 Stage
Finished Build Glue 2 Stage

Starting Build Glue 3 Stage
Finished Build Glue 3 Stage

Starting Build Compile Stage
  Starting "perl Makefile.PL" Stage
Generating a Unix-style Makefile
Writing Makefile for eval_79_7886
Writing MYMETA.yml and MYMETA.json
  Finished "perl Makefile.PL" Stage

  Starting "make" Stage
Running Mkbootstrap for eval_79_7886 ()
chmod 644 "eval_79_7886.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- eval_79_7886.bs blib/arch/auto/eval_79_7886/eval_79_7886.bs 644
"/usr/bin/perl" "/home/foouser/perl5/lib/perl5/ExtUtils/xsubpp"  -typemap "/usr/share/perl/5.22/ExtUtils/typemap" -typemap "/home/foouser/github_repos/rperl-latest/lib/typemap.rperl"   eval_79_7886.xs > eval_79_7886.xsc
mv eval_79_7886.xsc eval_79_7886.c
g++ -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -xc++ -c  -I"/home/foouser/repos_github/rperl-latest/script" -I/home/foouser/github_repos/rperl-latest/lib -Ilib -I/home/foouser/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/auto/share/dist/Alien-PCRE2/include -I/home/foouser/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/auto/share/dist/Alien-JPCRE2/include -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unused-variable -DNO_XSLOCKS -Wno-deprecated -std=c++11 -Wno-literal-suffix -Wall -Wextra -Wno-delete-non-virtual-dtor -Wl,-E -L"/home/foouser/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/auto/share/dist/Alien-PCRE2/lib" -D__CPP__TYPES -D__TYPE__INTEGER__LONG -D__TYPE__NUMBER__DOUBLE -O3 -fomit-frame-pointer -march=native -g   -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fPIC "-I/usr/lib/x86_64-linux-gnu/perl/5.22/CORE"   eval_79_7886.c
rm -f blib/arch/auto/eval_79_7886/eval_79_7886.so
LD_RUN_PATH="/usr/lib/x86_64-linux-gnu" x86_64-linux-gnu-gcc  -shared -L/usr/local/lib -fstack-protector-strong  eval_79_7886.o  -o blib/arch/auto/eval_79_7886/eval_79_7886.so  \
   -lstdc++   \

chmod 755 blib/arch/auto/eval_79_7886/eval_79_7886.so
  Finished "make" Stage

  Starting "make install" Stage
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- eval_79_7886.bs blib/arch/auto/eval_79_7886/eval_79_7886.bs 644
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /home/foouser/repos_github/rperl-latest/_Inline/lib/auto/eval_79_7886/eval_79_7886.so
  Finished "make install" Stage

  Starting Cleaning Up Stage
  Finished Cleaning Up Stage

Finished Build Compile Stage

[[[ END   'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
This is RPerl version 4.002_000, Long Date 20181115, Star Date 2018.319, Codename Enterprise
v4.002_000 using RPerl's underscore-is-comma numbering scheme
v4.002000  using  CPAN's underscore-is-beta  numbering scheme

Copyright © 2013, 2014, 2015, 2016, 2017, 2018, William N. Braswell, Jr..  All Rights Reserved.
RPerl is part of the RPerl Family of software and documentation.
This work is Free & Open Source; you can redistribute it and/or modify it
under the same terms as Perl 5.28.0.

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
For licensing details, please see http://dev.perl.org/licenses/

Complete documentation for RPerl, including FAQ lists, should be found on
this system using `man rperl` or `perldoc rperl` or `perldoc RPerl::Learning`.
If you have access to the Internet, point your browser at the RPerl Home Page.
http://www.rperl.org/

If you are able to successfully run the rperl -v command as shown in the output above, then RPerl is (presumably) installed correctly and you can proceed to running tests. I will provide instructions for running tests shortly.

shpsi commented 5 years ago

Hey will, https://ibb.co/DrRRx8C . see this . i guess while running bash script and i chose different options like enviroment [locallib / cpan / system ] so i may be getting different . am i saying correct?

i got this after setting verbose=1 https://ibb.co/c3XSdtL

wbraswell commented 5 years ago

Yes your output looks good so RPerl should be installed, although you should always turn on both export RPERL_DEBUG=1 and export RPERL_VERBOSE=1 to see the full output as shown in my copy-paste.

shpsi commented 5 years ago

I updated above comment with new image see .

how to run simple hello world code using rperl?? is it must to give arguements like modes, code, ops ,types etc?

rperl -V fileName.pl was throwing error.is it expected?

wbraswell commented 5 years ago

If you delete the "_Inline/" directory, and then rerun the rperl -v command, then you will see all of the C++ boostrapping commands.

You may run Hello World in PERLOPS_PERLTYPES mode: $ rperl -t lib/RPerl/Learning/Chapter1/exercise_1-hello_world.p

And in CPPOPS_CPPTYPES mode: $ rperl lib/RPerl/Learning/Chapter1/exercise_1-hello_world.p

shpsi commented 5 years ago

Thank you so much! I was trying on my own for some hours and it already midnight here. thanks! for rescuing

wbraswell commented 5 years ago

If you have used CPAN to install RPerl, then you will need to uninstall it because you need to be working on the latest GitHub code only, not the stable CPAN code. I am making updates to the Logical::And operator on GitHub today, and will tell you when it is ready.

Meanwhile, you can work on uninstalling your CPAN version of RPerl and running the same rperl -v command from your own GitHub fork of this RPerl repository. If you correctly chose to use local::lib in order to install all CPAN modules in your "/home/username/perl5/" directory, then you can easily uninstall RPerl by searching "/home/username/perl5/" for all file and directory names containing "rperl" or "RPerl" and deleting them yourself. Then there will be no more rperl -v command or use RPerl; Perl code until you enable you clone a local copy of your GitHub fork repo.

shpsi commented 5 years ago

how can i check if i installed through cpan?? did you mean command similar to "apt-get cpan install rperl" ? or while executing installer.sh option of choosing cpan?? i dont remember i need to check.

wbraswell commented 5 years ago

There is no such command as apt-get install rperl, it is cpan rperl or cpanm rperl.

And if you did not specifically use your own GitHub fork already, then yes you presumably did install from CPAN and thus need to uninstall as described in my previous message.

wbraswell commented 5 years ago

(At some time in the future we will release Debian & Ubuntu packages so that apt-get install rperl will work, but that task is not yet complete.)

shpsi commented 5 years ago

okay so you are saying me to have "git clone shpsi/rperl" right? i earlier did that :(

wbraswell commented 5 years ago

Yes git clone ... is the correct command to use the latest GitHub code instead of the stable CPAN code.

However, if you have executed BOTH the git clone command AND the cpan rperl command, then you have incorrectly installed 2 different copies of RPerl.

shpsi commented 5 years ago

so git clone is sufficient?

shpsi commented 5 years ago

i have not run cpan command . i just ran installer

wbraswell commented 5 years ago

The RPerl installer can install from either CPAN or GitHub, depending on which option you choose in step 24:

https://github.com/wbraswell/rperl/blob/master/script/rperl_installer.sh#L1403-L1447

Which option did you choose?

shpsi commented 5 years ago

I dont remember now but as fas as remember i just clicked 'enter' not sure! to verify i found your latest commit on github repo this was one of them:- https://github.com/shpsi/rperl/blob/bd0a7efd9e9b47f2ed6d8b7203689fe50b0103c9/docs/compiler_oracle_FOOBARperl5221_solaris211_sunos511_sunC513.txt so in my rperl/ folder i found this file with same content. so can i assume i installed from github code not cpan?

I have one folder named rperl5.old

wbraswell commented 5 years ago

Please do not EVER just "click enter" without paying attention to what you are doing!

There is no "docs/compiler_oracle_FOOBARperl5221_solaris211_sunos511_sunC513.txt" file in the CPAN stable version, only on GitHub:

https://fastapi.metacpan.org/source/WBRASWELL/RPerl-4.002000/docs/

https://github.com/wbraswell/rperl/tree/master/docs

You can also look inside the rperl directory to see if there is a ".git/" folder, which is only present for git repositories not CPAN installs.

If you have a folder named "/home/username/perl5.old" then that means you already had installed some CPAN software via local::lib before your current installation, this could have been because you ran the installer more than once or because you tried it yourself before running the installer, etc. You can simply delete that "perl5.old" folder.

https://github.com/wbraswell/rperl/blob/master/script/rperl_installer.sh#L462-L464

shpsi commented 5 years ago

Sorry for carelessly running enter command. i have deleted rperl5.old and also i found ./git in rperl/ so i guess i am in correct path as i can see git branch output,.

wbraswell commented 5 years ago

Yes I believe you are correctly using the GitHub clone.

To be totally sure, please run a system-wide search to ensure no other installations of RPerl are found: sudo find / -iname *RPerl* 2> /dev/null

shpsi commented 5 years ago

sorry to disturb you again but i am reading your book. whats difference between following @{ [ 10, 20, 30, 40, 50 ] } @{ my integer_arrayref $TYPED_i_array = [ 10, 20, 30, 40, 50 ] } @{ [ my integer $TYPED_i0 = 10, 20, 30, 40, 50 ] }

file name contains 'good' or 'bad' , what these mean? how to identify test files? are these kind contains use RPerl::Test::Foo; ?

shpsi commented 5 years ago

BDW, instead by installing 'cpan RPerl' if i install using git clone then rperl -v gives error of "rperl command not found as /user/bin/rperl is not present" hot to fix this? i guess to move the script/rperl folder to /usr/local/bin/.

Do you know why this error comes "No typemap for typemap return : skipping return sv_newmortal()"?

wbraswell commented 5 years ago

@{ [ 10, 20, 30, 40, 50 ] } is an un-typed array @{ my integer_arrayref $TYPED_i_array = [ 10, 20, 30, 40, 50 ] } is a typed array @{ [ my integer $TYPED_i0 = 10, 20, 30, 40, 50 ] } is an array with one typed element

shpsi commented 5 years ago

Is there support of comparator function while sorting?

wbraswell commented 5 years ago

I am very confused by your problems with running rperl -v, I thought you said it was working via git clone install, but now you are saying it does not work. Did you try to re-install it for some reason???

wbraswell commented 5 years ago

I do not understand your question about comparator functions, and I do not see how it is related to the Bitwise And operator?

shpsi commented 5 years ago

Yes i tried to reinstall it . leave it . I have done one clean and successful installation.

i know comparator func is not related to bitwise AND operator . i was just suggesting new feature.

I have completed reading your book one more time and this time with detail. now i am confident enough to take this challenge.

wbraswell commented 5 years ago

Okay so I will not worry about your installation problems, as you have solved that now.

As for comparator functions, please do not suggest new features because we already have hundreds of tasks on the to-do list:

https://github.com/wbraswell/rperl/blob/master/docs/todo.txt

(After GSoC is totally finished, then we can discuss new features.)

I am glad you have been reading the Learning RPerl book, I will be updating and completing the content of that book soon, and for now it is a very good resource for you, in addition to the devs_getting_started document.

shpsi commented 5 years ago

Hey mentors, Install, Base Dependencies Install, CPAN Dependencies Install, Test Suite Initialize, Bootstrap Subcompile Initialize, Configuration Compile, Arguments & Files Compile, Dependencies Compile, Parse Phase 0 (Check Perl Syntax) Compile, Parse Phase 1 (Criticize Perl Syntax) Compile, Parse Phase 2 (Parse RPerl Syntax) Compile, Generate (C++ Syntax) Compile, Save Phase 0 (Final File Modifications) Compile, Save Phase 1 (Format & Write Files To Disk) Compile, Subcompile (Generate Binary) Execute Do i need to do these in order to complete this challenge? Are these required?

JJ commented 5 years ago

@shpsi this is a challenge. We don't need anything at all. You need to complete the challenge and submit it to us. The challenge is well specified in the issue. Do you understand clearly what is required for you to pass the challenge?

shpsi commented 5 years ago

@JJ Thank you Sir ! Yes i understand . From previous discussions, I got to know that multiple rperl compilation is not needed and many other things too. "Learning RPerl" book has these in contents so i got little confused that do i need to have all these installations/compilations before the executing my code. @wbraswell and also what arguements should be provided for compiling my code :: rperl -t -D -V ?

wbraswell commented 5 years ago

@shpsi The long list you have copied and pasted is an explanation of all the phases necessary for RPerl to be installed and executed.

If you can successfully run the rperl -v command, then you have already completed the "Install" phases.

When you run a rperl somefile.pl command, then RPerl is going through all the other Initialize/Compile/Execute phases.

Executing the rperl command with the -V -D flags is the same thing as explicitly executing export RPERL_VERBOSE=1 and export RPERL_DEBUG=1 in your terminal, followed by a normal rperl command. In other words, the -V flag is for VERBOSE output, and the -D flag is for DEBUG output. You need to have them both turned on for every execution of RPerl, so as to ensure that you are seeing all pertinent output.

I will make another post tonight with more information about how to invoke the operator tests.

shpsi commented 5 years ago

Hey @wbraswell , How to get the meaning of each errorcode ECOGEASRP00 , ECOGEASCP00?

wbraswell commented 5 years ago

When generated by RPerl, each error code is followed by a plain-English explanation of the error.

If you are looking at RPerl code output, just read the error message immediately following the generated error code.

If you are looking inside the RPerl source code, again just read the text following the associated error code:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/Logical/And.pm#L96-L99

die RPerl::Parser::rperl_rule__replace( 'ERROR ECOGEASCP000, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule ' . $self_class . ' found where Operator_122 or Operator_128 expected, dying' ) . "\n";

The above source code clearly shows you that error code ECOGEASCP000 corresponds to CODE GENERATOR, ABSTRACT SYNTAX TO C++ error number 000. To break it down: E: "Error" CO: "Code" GE: "Generator" AS: "Abstract Syntax" CP: "C++" 000: "Serial number 000"

And the actual meaning of this code is that the RPerl grammar and/or parser have somehow internally generated the incorrect AST nodes, because only Operator_122 and Operator_128 are valid in this case. This is a highly technical internal RPerl error, which should never be experienced by an end-user of stable versions of RPerl. It should only occur when modifying or otherwise working on the RPerl grammar and parser directly, which you are not doing in this Pull Request Challenge.

wbraswell commented 5 years ago

Updates to the Logical And operator

I have recently made an important upgrade to the Logical And operator (explained below), which will require you to update your forked RPerl repository.

Unfortunately, the only good way for you to update your forked repository is actually to DELETE your forked repository, and create a new fork from my current repository. Otherwise, if you try to keep your current fork and somehow update it directly, then we will end up with a confusing mess of git merge loops which I do not want to deal with whatsoever.

So, please BACKUP ANY FILES which you may have already started modifying, by copying them somewhere OUTSIDE of the git directory itself on your local machine. Then, go to your forked repo web interface in GitHub, click the gear icon for "Settings", then scroll all the way to the bottom red area "Danger Zone", and click "Delete this repository", and follow the directions.

Finally, execute rm -Rf PATH_TO_GIT_DIR/ to delete ONLY your current GitHub directory in your local VM, then re-fork my RPerl repo in GitHub's web interface, and re-clone your new fork onto your local machine. (If you had any modified files backed up, you can now manually re-copy them back into the new fork.)

After all this, you should NOT have to re-install anything via CPAN because I did not create any new CPAN dependencies. To ensure your new fork is installed and working correctly, you can simply try to run the rperl -v command and see if it generates the same version information as before.

More information about the Logical And operator

Since you are using the Logical And operator as your example code, this message will pertain to only the Logical And operator. It is important to understand that the RPerl grammar will parse the Logical And operator in 2 different scenarios, called Operator15 and Operator23. Technically, both Operator15 and Operator23 are considered to be RPerl abstract syntax tree (AST) nodes, implemented as Perl hash data structures.

The difference between these two RPerl AST nodes is that Operator15 is generated when parsing &&, while Operator23 has a lower precedence and is generated when parsing and. Other than that, the semantic behavior is identical between Operator15 and Operator23, they both represent the same Logical And operator, and they are the only 2 RPerl ASTs which represent Logical And.

You can easily see the difference between 0 && 1 versus (0 and 1) by looking inside the test files:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Test/Operator23LogicalAnd/program_00_good.pl

More info about updates to the Logical And operator

As mentioned above, I have made changes to the Logical And operator, specifically adding the ANDl macro because Perl's Logical And behaves differently than the C/C++ operator, so we can not simply generate the C/C++ operator directly. You can see how the Logical/And.pm file utilizes the ANDl macro here:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/Logical/And.pm#L19

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Operation/Expression/Operator/Logical/And.pm#L80-L81

The difference between the behavior of Perl and C++ is that Perl returns the value of the right-most operand if the operator is found to have an overall value of "true", instead of always returning a boolean value as in C++. You can see this behavior implemented with a nested ternary-in-ternary operator, in the ANDl macro definition:

https://github.com/wbraswell/rperl/blob/master/lib/rperloperations.h#L24-L25

Finally, the ANDl macro must make use of the so-called "double negation" trick in order to safely convert a string into a boolean, as required by Perl's enhanced behavior. The negation operation itself is overloaded for C++ string types here:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/DataType/String.cpp#L16-L24

How to invoke the Logical And operator tests, automated

From inside the RPerl source code directory, execute the following commands to run automated RPerl tests on the Logical And operator, in the Operator15 parse scenario:

$ perl t/09_interpret_execute.t lib/RPerl/Test/Operator15LogicalAnd/

# [[[ Beginning Interpret-Execute Pre-Test Loading, RPerl Execution System ]]]
1..1
# [[[ Beginning Interpret-Execute Tests, RPerl Execution System, PERL Operations & PERL Data Types ]]]
# Test File #1 of 1: lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl
ok 1 - Program interprets and executes without errors & with expected output:          lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl
$ perl t/12_parse.t lib/RPerl/Test/Operator15LogicalAnd/

# [[[ Beginning Parser Pre-Test Loading, RPerl Compilation System ]]]
1..5
# [[[ Beginning Parser Tests, RPerl Compilation System ]]]
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...       
ok 1 - Program or module parses with expected error(s):  lib/RPerl/Test/Operator15LogicalAnd/program_00_bad_00.pl
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...       
ok 2 - Program or module parses with expected error(s):  lib/RPerl/Test/Operator15LogicalAnd/program_00_bad_01.pl
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...       
ok 3 - Program or module parses with expected error(s):  lib/RPerl/Test/Operator15LogicalAnd/program_00_bad_02.pl
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...       
ok 4 - Program or module parses with expected error(s):  lib/RPerl/Test/Operator15LogicalAnd/program_00_bad_03.pl
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...        done.
ok 5 - Program or module parses without errors:          lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl
$ perl t/13_generate.t lib/RPerl/Test/Operator15LogicalAnd/

# [[[ Beginning Generator Pre-Test Loading, RPerl Compilation System ]]]
1..4
# [[[ Beginning Generator Tests, RPerl Compilation System, CPP Operations & CPP Data Types ]]]
ok 1 - mode 'CPP Operations & CPP Data Types' enabled
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...        done.
GENERATE:           Generate   C++ syntax...        done.
ok 2 - Program or module generates without errors, yes diff check:  lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl
# [[[ Beginning Generator Tests, RPerl Compilation System, PERL Operations & PERL Data Types ]]]
ok 3 - mode 'PERL Operations & PERL Data Types' enabled
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...        done.
GENERATE:           Generate RPerl syntax...        done.
ok 4 - Program or module generates without errors, yes diff check:  lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl

The three commands above will test the files in the following directory:

https://github.com/wbraswell/rperl/tree/master/lib/RPerl/Test/Operator15LogicalAnd

Specifically, the 09_interpret_execute.t command will execute the 1 "good" file in the test directory using the normal Perl interpreter (not compiled), and will ensure that the good file produces the correct output.

The 12_parse.t command will use RPerl to parse the 1 "good" and 4 "bad" input files, this time ensuring the good file parses without errors and the bad files produce the correct errors.

The 13_generate.t command will use RPerl to generate both the PERLOPS_PERLTYPES and CPPOPS_CPPTYPES output code for the 1 "good" input file. In PERLOPS_PERLTYPES mode, the generated Perl code is compared to the original input .pl file code, which should match. (In other words, it simply parses & regenerates the same Perl output code as the Perl input code.) In CPPOPS_CPPTYPES mode, the generated C++ code for input file "program_00_good.pl" is compared to the already-compiled file "program_00_good.cpp.CPPOPS_CPPTYPES" to ensure the source code matches:

https://github.com/wbraswell/rperl/blob/master/lib/RPerl/Test/Operator15LogicalAnd/program_00_good.cpp.CPPOPS_CPPTYPES

Likewise, you may run the following 3 commands to test Logical And in the Operator23 parse scenario.

perl t/09_interpret_execute.t lib/RPerl/Test/Operator23LogicalAnd/

perl t/12_parse.t lib/RPerl/Test/Operator23LogicalAnd/

perl t/13_generate.t lib/RPerl/Test/Operator23LogicalAnd/

How to invoke the Logical And operator tests, manual

You can run the Operator15 "good" test file using the normal Perl interpreter (PERLOPS_PERLTYPES) by executing the following command from within the RPerl source code directory:

$ lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl

[[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
[[[ END   'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
have $foo_integer = 9_123
have $foo_number  = 9_123.456_789
have $foo_string  = howdy

have $aaa_boolean = 0
have $bbb_boolean = 0
have $ccc_boolean = 0
have $ddd_boolean = 1
have $aaa_integer = 9_123
have $bbb_integer = 22
have $aaa_number  = 9_123.456_789
have $bbb_number  = -22.3
have $aaa_string  = howdy
have $bbb_string  = doody

You can run the same test file through the RPerl compiler in -t test mode (also PERLOPS_PERLTYPES):

$ rperl -t -V -D lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl

[[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
[[[ END   'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
Verbose Flag......... 1
Debug Flag........... 1

in rperl, have $RPerl::DEBUG   = 1, $ENV{RPERL_DEBUG}   = 1
in rperl, have $RPerl::VERBOSE = 1, $ENV{RPERL_VERBOSE} = 1
Input File:         lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl
Output File(s):     lib/RPerl/Test/Operator15LogicalAnd/program_00_good  
Modes:              magic => LOW, code => CPP, ops => PERL, types => PERL, check => TRACE, uncompile => OFF, compile => GENERATE, subcompile => OFF, parallel => OFF, execute => ON, label => ON

DEPENDENCIES:       Follow & find all deps...    0 found.
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...        done.
GENERATE:           Generate RPerl syntax...        done.
EXECUTE:            Run code...

[[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
[[[ END   'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
have $foo_integer = 9_123
have $foo_number  = 9_123.456_789
have $foo_string  = howdy

have $aaa_boolean = 0
have $bbb_boolean = 0
have $ccc_boolean = 0
have $ddd_boolean = 1
have $aaa_integer = 9_123
have $bbb_integer = 22
have $aaa_number  = 9_123.456_789
have $bbb_number  = -22.3
have $aaa_string  = howdy
have $bbb_string  = doody

You can compile and run the file (CPPOPS_CPPTYPES):

$ rperl -V -D lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl

[[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
[[[ END   'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]]
Verbose Flag......... 0
Debug Flag........... 0

in rperl, have $RPerl::DEBUG   = 0, $ENV{RPERL_DEBUG}   = 1
in rperl, have $RPerl::VERBOSE = 0, $ENV{RPERL_VERBOSE} = 1
Input File:         lib/RPerl/Test/Operator15LogicalAnd/program_00_good.pl
Output File(s):     lib/RPerl/Test/Operator15LogicalAnd/program_00_good.cpp
                    lib/RPerl/Test/Operator15LogicalAnd/program_00_good
Modes:              magic => LOW, code => CPP, ops => CPP, types => CPP, check => TRACE, uncompile => OFF, compile => SUBCOMPILE, subcompile => DYNAMIC, parallel => OFF, execute => ON, label => ON

DEPENDENCIES:       Follow & find all deps...    0 found.
PARSE PHASE 0:      Check     Perl syntax...        done.
PARSE PHASE 1:      Criticize Perl syntax...        done.
PARSE PHASE 2:      Parse    RPerl syntax...        done.
GENERATE:           Generate   C++ syntax...        done.
SAVE  PHASE 0:      Final file modifications...     done.
SAVE  PHASE 1:      Format & write files to disk... done.
SUBCOMPILE:         Generate binary...     

g++ -pthread -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xc++ -I"/home/wbraswell/github_repos/rperl-latest" -I"/home/wbraswell/github_repos/rperl-latest/lib" -I. -Ilib -I"/home/wbraswell/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/auto/share/dist/Alien-PCRE2/include" -I"/home/wbraswell/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/auto/share/dist/Alien-JPCRE2/include" -Wno-unused-variable -DNO_XSLOCKS -Wno-deprecated -std=c++11 -Wno-literal-suffix -Wall -Wextra -Wno-delete-non-virtual-dtor -Wl,-E -L"/home/wbraswell/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/auto/share/dist/Alien-PCRE2/lib" -D__CPP__TYPES -D__TYPE__INTEGER__LONG -D__TYPE__NUMBER__DOUBLE -O3 -fomit-frame-pointer -march=native -g -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fPIC "-I/usr/lib/x86_64-linux-gnu/perl/5.22/CORE" lib/RPerl/Test/Operator15LogicalAnd/program_00_good.cpp -o  lib/RPerl/Test/Operator15LogicalAnd/program_00_good -lperl -lpcre2-8 -lpcre2-16 -lpcre2-32

SUBCOMPILE:         Generate binary...              done.
EXECUTE:            Run code...

have $foo_integer = 9_123
have $foo_number  = 9_123.456_789
have $foo_string  = howdy

have $aaa_boolean = 0
have $bbb_boolean = 0
have $ccc_boolean = 0
have $ddd_boolean = 1
have $aaa_integer = 9_123
have $bbb_integer = 22
have $aaa_number  = 9_123.456_789
have $bbb_number  = -22.3
have $aaa_string  = howdy
have $bbb_string  = doody

Finally, you can run the compiled binary executable file again without any Perl involved at all:

$ lib/RPerl/Test/Operator15LogicalAnd/program_00_good

have $foo_integer = 9_123
have $foo_number  = 9_123.456_789
have $foo_string  = howdy

have $aaa_boolean = 0
have $bbb_boolean = 0
have $ccc_boolean = 0
have $ddd_boolean = 1
have $aaa_integer = 9_123
have $bbb_integer = 22
have $aaa_number  = 9_123.456_789
have $bbb_number  = -22.3
have $aaa_string  = howdy
have $bbb_string  = doody

The primary task in this Pull Request Challenge is to generate, inspect, and compile the C++ code file(s) which are generated, only 1 file in this case:

$ cat lib/RPerl/Test/Operator15LogicalAnd/program_00_good.cpp

//!/usr/bin/env rperl

#include <rperlstandalone.h>
#ifndef __CPP__INCLUDED__RPerl__Test__Operator15LogicalAnd__program_00_good_cpp
#define __CPP__INCLUDED__RPerl__Test__Operator15LogicalAnd__program_00_good_cpp 0.001_000
# ifdef __CPP__TYPES

int main() {
    // [[[ OPERATIONS HEADER ]]]

// [[[ OPERATIONS ]]]
    integer foo_integer = 9123;
    number foo_number = 9123.456789;
    string foo_string = (const string) "howdy";
    print "have $foo_integer = " << integer_to_string(foo_integer) << endl;
    print "have $foo_number  = " << number_to_string(foo_number) << endl;
    print "have $foo_string  = " << foo_string << endl;
    print endl;
    boolean aaa_boolean = ANDl(0, 0);
    boolean bbb_boolean = ANDl(0, 1);
    boolean ccc_boolean = ANDl(1, 0);
    boolean ddd_boolean = ANDl(1, 1);
    integer aaa_integer = ANDl(22, foo_integer);
    integer bbb_integer = ANDl(foo_integer, 22);
    number aaa_number = ANDl(-22.3, foo_number);
    number bbb_number = ANDl(foo_number, -22.3);
    string aaa_string = ANDl((const string) "doody", foo_string);
    string bbb_string = ANDl(foo_string, (const string) "doody");
    print "have $aaa_boolean = " << aaa_boolean << endl;
    print "have $bbb_boolean = " << bbb_boolean << endl;
    print "have $ccc_boolean = " << ccc_boolean << endl;
    print "have $ddd_boolean = " << ddd_boolean << endl;
    print "have $aaa_integer = " << integer_to_string(aaa_integer) << endl;
    print "have $bbb_integer = " << integer_to_string(bbb_integer) << endl;
    print "have $aaa_number  = " << number_to_string(aaa_number) << endl;
    print "have $bbb_number  = " << number_to_string(bbb_number) << endl;
    print "have $aaa_string  = " << aaa_string << endl;
    print "have $bbb_string  = " << bbb_string << endl;

    // [[[ OPERATIONS FOOTER ]]]
    return 0;
}

// [[[ FOOTER ]]]
# elif defined __PERL__TYPES
Purposefully_die_from_a_compile-time_error,_due_to____PERL__TYPES_being_defined.__We_need_to_define_only___CPP__TYPES_in_this_file!
# endif
#endif

Your general work flow is as follows:

  1. Run all the commands above and make sure it all works correctly.

  2. Copy all necessary functionality from Logical And operator into Bitwise And operator.

  3. Run all the commands above again, except using Bitwise And instead of Logical And.

  4. For each Perl error, fix the Perl code in Bitwise/And.pm and any associated .pm or .pl Perl file(s)

  5. For each C++ compiler error or incorrect C++ runtime behavior:

    5a. Manually modify the generated .cpp C++ file(s), then copy-and-paste the long complicated g++ compiler command automatically generated by RPerl, and keep trying to re-compile the C++ code manually until you fix the .cpp file by hand. Rename the "myfile.cpp" into "myfile.cpp.MANUAL" to keep it from being overwritten in step 5b below.

    5b. Modify the Bitwise/And.pm subroutine ast_to_cppgenerateCPPOPS_CPPTYPES() to generate the correct C++ output code which matches your manually-corrected .cpp file. Re-run the RPerl command(s) which failed before and ensure they now pass. If a new C++ error occurs, go back to the beginning of step 5 and repeat.

  6. Return to the beginning of step 3 and repeat until Bitwise And has all desired CPPOPS_CPPTYPES functionality and tests, just like Logical And.

shpsi commented 5 years ago

I was thinking to do this :- Change directory to my local repository. Switch to master branch git remote add upstream git fetch upstream your-repo-url git rebase upstream/master At this stage i will check that commits what will be merged by typing git status git push origin master anyway it would be better to delete and clone a new one.

wbraswell commented 5 years ago

I am pretty sure your proposed git rebase process will (at the very least) create duplicate entries in the git history, which I do not want. Please delete the repo and fork a new one.

wbraswell commented 5 years ago

I have been through this process myself while trying to create clean pull requests across multiple different repositories, and the only 100% correct solution I have found is a full delete and re-fork.

wbraswell commented 5 years ago

@shpsi When you were most recently running the RPerl installer, did you experience any errors during installation of the RPerl dependencies from CPAN?

(Specifically, I am wondering if Inline::C or Inline::CPP had any installation errors on CPAN, because we are seeing some issues which may affect installation. These are not issues with RPerl itself, but one or more of RPerl's dependencies on CPAN.)

shpsi commented 5 years ago

I might have but didn't notice as installation was complete but is this the reason of me getting following error:- I ran following command to run the whole test files $ perl Makefile.PL; make realclean; perl Makefile.PL; make test specifically , inside t/07_type_gmp.t I got lot of errors like these No typemap for typemap return : skipping return sv_newmortal() annd No typemap for unsigned _integer Skipping number unsigned_integer to number (unsigned_integer) such errors were thrown for lot of type-conversion or string_substiute_global etc methods.

wbraswell commented 5 years ago

@shpsi You are still not providing enough information regarding this error.

  1. What is the name and version of your operating system, version of Perl, version of RPerl, and version of GCC?

  2. Exactly what command(s) did you run to create the output?

  3. Full copy-and-paste of all output both before and after error message, not just 1 or 2 selected lines

shpsi commented 5 years ago

1) Xubuntu 18.04 , Perl 5.26.1 , RPerl 4.002_000 , gcc 7.3.0

2) rperl -t lib/RPerl/Learning/Chapter1/exercise_1-hello_world.pl

3) WARNING WEXRP00: Found multiplerperlexecutables, using first located,/usr/local/bin/rperl; other locations includescript/rperl` [[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]] validate Stage Starting Build Preprocess Stage get_maps Stage Finished Build Preprocess Stage

Starting Build Parse Stage Finished Build Parse Stage

Starting Build Glue 1 Stage No typemap for type return. Skipping return sv_newmortal() Finished Build Glue 1 Stage

Starting Build Glue 2 Stage Finished Build Glue 2 Stage

Starting Build Glue 3 Stage Finished Build Glue 3 Stage

Starting Build Compile Stage Starting "perl Makefile.PL" Stage Generating a Unix-style Makefile Writing Makefile for eval_74_7886 Writing MYMETA.yml and MYMETA.json Finished "perl Makefile.PL" Stage

Starting "make" Stage Running Mkbootstrap for eval_74_7886 () chmod 644 "eval_74_7886.bs" "/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- eval_74_7886.bs blib/arch/auto/eval_74_7886/eval_74_7886.bs 644 "/usr/bin/perl" "/usr/local/share/perl/5.26.1/ExtUtils/xsubpp" -typemap "/usr/share/perl/5.26/ExtUtils/typemap" -typemap "/usr/local/share/perl/5.26.1/typemap.rperl" eval_74_7886.xs > eval_74_7886.xsc mv eval_74_7886.xsc eval_74_7886.c g++ -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xc++ -c -I"/usr/local/bin" -I/usr/local/share/perl/5.26.1 -I. -Ilib -I/usr/local/lib/i386-linux-gnu/perl/5.26.1/auto/share/dist/Alien-PCRE2/include -I/usr/local/lib/i386-linux-gnu/perl/5.26.1/auto/share/dist/Alien-JPCRE2/include -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wno-unused-variable -DNO_XSLOCKS -Wno-deprecated -std=c++11 -Wno-literal-suffix -Wall -Wextra -Wno-delete-non-virtual-dtor -Wl,-E -L"/usr/local/lib/i386-linux-gnu/perl/5.26.1/auto/share/dist/Alien-PCRE2/lib" -DCPPTYPES -DTYPEINTEGERLONG -DTYPENUMBERDOUBLE -O3 -fomit-frame-pointer -march=native -g -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fPIC "-I/usr/lib/i386-linux-gnu/perl/5.26/CORE" eval_74_7886.c rm -f blib/arch/auto/eval_74_7886/eval_74_7886.so LD_RUN_PATH="/usr/lib/i386-linux-gnu" i686-linux-gnu-gcc -shared -L/usr/local/lib -fstack-protector-strong eval_74_7886.o -o blib/arch/auto/eval_74_7886/eval_74_7886.so \ -lstdc++ \

chmod 755 blib/arch/auto/eval_74_7886/eval_74_7886.so Finished "make" Stage

Starting "make install" Stage "/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- eval_74_7886.bs blib/arch/auto/eval_74_7886/eval_74_7886.bs 644 Files found in blib/arch: installing files in blib/lib into architecture dependent library tree Installing /home/shivsi/rperl/_Inline/lib/auto/eval_74_7886/eval_74_7886.so Finished "make install" Stage

Starting Cleaning Up Stage Finished Cleaning Up Stage

Finished Build Compile Stage

[[[ END 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]] Verbose Flag......... 0 Debug Flag........... 0

in rperl, have $RPerl::DEBUG = 0, $ENV{RPERL_DEBUG} = 1 in rperl, have $RPerl::VERBOSE = 0, $ENV{RPERL_VERBOSE} = 1 Input File: lib/RPerl/Learning/Chapter1/exercise_1-hello_world.pl Output File(s): lib/RPerl/Learning/Chapter1/exercise_1-hello_world
Modes: magic => LOW, code => CPP, ops => PERL, types => PERL, check => TRACE, uncompile => OFF, compile => GENERATE, subcompile => OFF, parallel => OFF, execute => ON, label => ON

DEPENDENCIES: Follow & find all deps... 0 found. PARSE PHASE 0: Check Perl syntax... done. PARSE PHASE 1: Criticize Perl syntax... done. PARSE PHASE 2: Parse RPerl syntax... done. GENERATE: Generate RPerl syntax... done. EXECUTE: Run code...

WARNING WEXRP00: Found multiple rperl executables, using first located, /usr/local/bin/rperl; other locations include script/rperl [[[ BEGIN 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]] [[[ END 'use Inline' STAGE for 'RPerl/HelperFunctions.cpp' ]]] Hello, World!`

wbraswell commented 5 years ago

@shpsi There is no error typemap return anywhere in the output you have pasted!

wbraswell commented 5 years ago

Also, you have an important warning which indicates that you have incorrectly installed RPerl into multiple locations, which is very bad for new developers:

Found multiple rperlexecutables, using first located,/usr/local/bin/rperl; other locations include script/rperl

You should only have 1 rperl executable file, and it should be located only in your locally cloned GitHub directory. Now that you have incorrectly installed RPerl system-wide as /usr/local/bin/rperl, you will need to once again start over from scratch with a clean VM and then chat with me on IRC so that I can walk you through proper use of the RPerl installer. Please do NOT try to re-install everything yourself, because it will really just be a waste of everyone's time.