Created
February 22, 2013 19:40
-
-
Save perlpilot/5016011 to your computer and use it in GitHub Desktop.
HLL::Compiler lineof sans Q:PIR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/local/bin/parrot -L. -X. --library=src/stage1 src/stage1/nqp.pbc \ | |
--target=pir --output=src/stage2/gen/nqp-mo.pir \ | |
--setting=NULL src/stage2/gen/nqp-mo.pm | |
Error while compiling block : Error while compiling block : Cannot bind attributes in a type object | |
current instr.: '' pc 61631 (src/stage1/QAST.pir:23750) (src/stage1/QAST.nqp:2537) | |
called from Sub '' pc 60511 (src/stage1/QAST.pir:23363) (src/stage1/QAST.nqp:2521) | |
called from Sub 'as_post' pc 59877 (src/stage1/QAST.pir:23108) (src/stage1/QAST.nqp:2512) | |
called from Sub 'as_post' pc 57072 (src/stage1/QAST.pir:22061) (src/stage1/QAST.nqp:2375) | |
called from Sub 'as_post' pc 57354 (src/stage1/QAST.pir:22182) (src/stage1/QAST.nqp:2394) | |
called from Sub 'as_post' pc 57072 (src/stage1/QAST.pir:22061) (src/stage1/QAST.nqp:2375) | |
called from Sub 'post' pc 56556 (src/stage1/QAST.pir:21831) (src/stage1/QAST.nqp:2333) | |
called from Sub 'post' pc 32699 (src/stage1/gen/NQPHLL.pir:12831) (src/stage1/gen/NQPHLL.pm:1256) | |
called from Sub '' pc 31905 (src/stage1/gen/NQPHLL.pir:12498) (src/stage1/gen/NQPHLL.pm:1206) | |
called from Sub 'compile' pc 31814 (src/stage1/gen/NQPHLL.pir:12458) (src/stage1/gen/NQPHLL.pm:1204) | |
called from Sub 'eval' pc 28174 (src/stage1/gen/NQPHLL.pir:10891) (src/stage1/gen/NQPHLL.pm:988) | |
called from Sub 'evalfiles' pc 31179 (src/stage1/gen/NQPHLL.pir:12195) (src/stage1/gen/NQPHLL.pm:1188) | |
called from Sub 'command_eval' pc 30023 (src/stage1/gen/NQPHLL.pir:11723) (src/stage1/gen/NQPHLL.pm:1123) | |
called from Sub 'command_line' pc 29093 (src/stage1/gen/NQPHLL.pir:11335) (src/stage1/gen/NQPHLL.pm:1073) | |
called from Sub 'MAIN' pc 744 (src/stage1/gen/NQP.pir:267) (src/stage1/gen/NQP.pm:3391) | |
called from Sub '' pc 721 (src/stage1/gen/NQP.pir:254) (src/stage1/gen/NQP.pm:3387) | |
called from Sub '' pc 166012 (src/stage1/gen/NQP.pir:60421) (src/stage1/gen/NQP.pm:3368) | |
make: *** [src/stage2/nqpmo.pbc] Error 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method lineof($target, $pos, :$cache) { | |
my @linepos; | |
@linepos := nqp::getattr(self, HLL::Compiler, '@!linepos') unless ?$cache; | |
unless +@linepos { | |
@linepos := nqp::list(); | |
my $eos := nqp::chars($target); | |
my $jpos; | |
# Search for all of the newline markers in C<$target>. When we | |
# find one, mark the ending offset of the line in C<@linepos>. | |
while 1 { | |
$jpos := nqp::findcclass(nqp::const::CCLASS_NEWLINE, $target, $jpos, $eos); | |
last unless $jpos < $eos; | |
$jpos++; | |
nqp::push(@linepos, $jpos); | |
# Treat \r\n as a single logical newline | |
$jpos++ if nqp::ord(nqp::substr($target, $jpos-1, 1)) == 13 && $jpos < $eos && | |
nqp::ord(nqp::substr($target, $jpos,1)) == 10; | |
} | |
nqp::bindattr(self, HLL::Compiler, '@!linepos', @linepos) if ?$cache; | |
} | |
# We have C<@linepos>, so now we (binary) search the array | |
# for the largest element that is not greater than C<$pos>. | |
my $lo := 0; | |
my $hi := +@linepos; | |
my $line := 0; | |
while $lo < $hi { | |
$line := ($lo + $hi) / 2; | |
if @linepos[$line] > $pos { $hi := $line } | |
else { $lo := $line + 1 } | |
} | |
# C<$line> gives us the EOL index which are 0-based, | |
# so actual line number is +1 | |
return $line + 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment