forked from pmichaud/pmtcl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NQP overrides to TclList; getIndex(), similar to TclString's
- Loading branch information
Showing
4 changed files
with
42 additions
and
26 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This class is currently created via PIR in src/class/tcllist.pir | ||
|
||
INIT { | ||
my $interp := pir::getinterp__p(); | ||
my $tcl := pir::get_class__ps('TclList'), | ||
|
||
my $core := pir::get_class__ps('ResizablePMCArray'), | ||
$interp.hll_map($core, $tcl); | ||
|
||
$core := pir::get_class__ps('Array'), | ||
$interp.hll_map($core, $tcl); | ||
|
||
$core := pir::get_class__ps('ResizableStringArray'), | ||
$interp.hll_map($core, $tcl); | ||
} | ||
|
||
module TclList { | ||
method getIndex($index) { | ||
my $parse := Partcl::Grammar.parse( | ||
$index, :rule('index'), | ||
:actions(Partcl::Actions) | ||
); | ||
|
||
if ?$parse && $parse.chars() == pir::length__is($index) { | ||
my @pos := $parse.ast(); | ||
my $len := +self; | ||
my $loc := @pos[1]; | ||
if @pos[0] == 2 { # position relative from end. | ||
$loc := $len - 1 + $loc; | ||
} | ||
return $loc; | ||
} else { | ||
error("bad index \"$index\": must be integer?[+-]integer? or end?[+-]integer?"); | ||
} | ||
} | ||
} | ||
|
||
# vim: filetype=perl6: |
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