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

Pirop to nqpop #40

Merged
merged 23 commits into from
May 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4a4fca
pir::split to nqp::split
kboga May 30, 2012
279e3d0
pir::substr to nqp::substr
kboga May 30, 2012
ecf8f3b
pir::push to nqp::push and nqp::push_s
kboga May 30, 2012
2f737c0
pir::join to nqp::join
kboga May 30, 2012
4821925
pir::die to nqp::die
kboga May 30, 2012
872c132
pir::exists & pir::delete to nqp::exists(key|pos) nqp::delete(key|pos)
kboga May 30, 2012
fb47559
pir::can to nqp::can
kboga May 30, 2012
00c0fd7
pir::new('Hash'|'ResizablePMCArray') to nqp::hash()|list() and pir::r…
kboga May 30, 2012
e17ff70
pir::type_check__IPP to nqp::istype
kboga May 30, 2012
8fdf0dc
pir::setattribute__vPPsP to nqp::bindattr
kboga May 30, 2012
a1dfffb
pir::null__P to nqp::null and pir::isnull to nqp::isnull
kboga May 30, 2012
30327b6
pir::index to nqp::index
kboga May 30, 2012
fa2d42b
pir::nqp_bigint_to_str__SP to nqp::tostr_I and pir::nqp_bigint_from_s…
kboga May 30, 2012
f8fd2fb
another pir::repr_instance_of__pp to nqp::create
kboga May 30, 2012
df22e84
pir::length to nqp::chars
kboga May 30, 2012
926887d
fix typo
kboga May 30, 2012
5f0abdf
pir::clone__PP to nqp::clone
kboga May 30, 2012
881c8d1
pir::time__N to nqp::time_n
kboga May 30, 2012
47cdc2b
pir::downcase to nqp::lc
kboga May 30, 2012
1697865
more pir::clone to nqp::clone
kboga May 30, 2012
4702e8a
pir::chr to nqp::chr and pir::print to nqp::print and pir::say to nqp…
kboga May 30, 2012
a59bb74
add nqp::die|sleep|exit|throw|rethrow and use them instead of their p…
kboga May 30, 2012
daec48f
nqp::throw needs to return the thrown Exception
kboga May 30, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/6model/overview.markdown
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ to add_method in order to specify what happens when the method is called.
Finally, we can make an instance and call the method. Finally, we can make an instance and call the method.


# Make an instance. # Make an instance.
my $obj := pir::repr_instance_of__PP($type); my $obj := nqp::create($type);


# Call the method. # Call the method.
$obj.drink(); $obj.drink();
Expand Down
9 changes: 5 additions & 4 deletions docs/nqp-opcode.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ General notes:
nqp::unless(test, iffalse, iftrue) nqp::unless(test, iffalse, iftrue)
nqp::while(test, body) nqp::while(test, body)
nqp::loop(init, test, next, body) nqp::loop(init, test, next, body)
nqp::throw pir::throw__P nqp::throw pir::throw__0P
nqp::die pir::die nqp::rethrow pir::rethrow__0P
nqp::die pir::die__vP
nqp::exit pir::exit__vi nqp::exit pir::exit__vi
nqp::sleep pir::sleep__vn nqp::sleep pir::sleep__vn
(need ops to fetch caller, outer, context, etc?) (need ops to fetch caller, outer, context, etc?)
Expand Down Expand Up @@ -75,7 +76,7 @@ General notes:


object: object:
nqp::bindattribute pir::setattribute__0PPsP nqp::bindattribute pir::setattribute__0PPsP
nqp::getattribute pir::getattribute__PPsP nqp::getattribute pir::getattribute__PPPs
nqp::findmethod pir::find_method__PPs (?) nqp::findmethod pir::find_method__PPs (?)
nqp::null pir::null__P nqp::null pir::null__P
nqp::isnull pir::isnull__IP nqp::isnull pir::isnull__IP
Expand All @@ -84,7 +85,7 @@ General notes:
nqp::clone pir::clone__PP nqp::clone pir::clone__PP
nqp::typecheck or ::isa pir::type_check__IPP nqp::typecheck or ::isa pir::type_check__IPP
or ::istype or ::istype
nqp::?? pir::repr_instance_of__PP (?) nqp::create pir::repr_instance_of__PP (?)
nqp::unbox_i pir::repr_unbox_int__IP nqp::unbox_i pir::repr_unbox_int__IP
nqp::unbox_n pir::repr_unbox_num__NP nqp::unbox_n pir::repr_unbox_num__NP
nqp::unbox_s pir::repr_unbox_str__SP nqp::unbox_s pir::repr_unbox_str__SP
Expand Down
8 changes: 4 additions & 4 deletions examples/fib.nqp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ sub fib($n) {


my $N := 29; my $N := 29;


my $t0 := pir::time__N(); my $t0 := nqp::time_n();
my $z := fib($N); my $z := fib($N);
my $t1 := pir::time__N(); my $t1 := nqp::time_n();


pir::say("fib($N) = " ~ fib($N)); nqp::say("fib($N) = " ~ fib($N));
pir::say("time = " ~ ($t1-$t0)); nqp::say("time = " ~ ($t1-$t0));
10 changes: 5 additions & 5 deletions src/HLL/Actions.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class HLL::Actions {
if pir::does($ints, 'array') { if pir::does($ints, 'array') {
my $result := ''; my $result := '';
for $ints { for $ints {
$result := $result ~ pir::chr($_.ast); $result := $result ~ nqp::chr($_.ast);
} }
$result; $result;
} else { } else {
pir::chr($ints.ast); nqp::chr($ints.ast);
} }
} }


Expand Down Expand Up @@ -55,7 +55,7 @@ class HLL::Actions {
elsif $<OPER><O><pirop> { $past.pirop( ~$<OPER><O><pirop> ); } elsif $<OPER><O><pirop> { $past.pirop( ~$<OPER><O><pirop> ); }
unless $past.name { unless $past.name {
if $key eq 'LIST' { $key := 'infix'; } if $key eq 'LIST' { $key := 'infix'; }
my $name := pir::downcase($key) ~ ':<' ~ $<OPER><sym> ~ '>'; my $name := nqp::lc($key) ~ ':<' ~ $<OPER><sym> ~ '>';
$past.name('&' ~ $name); $past.name('&' ~ $name);
} }
} }
Expand Down Expand Up @@ -170,7 +170,7 @@ class HLL::Actions {
pir::trans_encoding__Ssi(~$/, pir::trans_encoding__Ssi(~$/,
pir::find_encoding__Is('utf8')) ); pir::find_encoding__Is('utf8')) );
$/.CURSOR.panic("Unrecognized character name $/") if $codepoint < 0; $/.CURSOR.panic("Unrecognized character name $/") if $codepoint < 0;
make pir::chr($codepoint); make nqp::chr($codepoint);
} }


method charnames($/) { method charnames($/) {
Expand All @@ -180,6 +180,6 @@ class HLL::Actions {
} }


method charspec($/) { method charspec($/) {
make $<charnames> ?? $<charnames>.ast !! pir::chr(string_to_int( $/, 10 )); make $<charnames> ?? $<charnames>.ast !! nqp::chr(string_to_int( $/, 10 ));
} }
} }
48 changes: 24 additions & 24 deletions src/HLL/CommandLine.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ class HLL::CommandLine::Result {


method init() { method init() {
@!arguments := []; @!arguments := [];
%!options := pir::new('Hash'); %!options := nqp::hash();
} }


method arguments() { @!arguments } method arguments() { @!arguments }
method options() { %!options } method options() { %!options }


method add-argument($x) { method add-argument($x) {
pir::push__vPP(@!arguments, $x); nqp::push(@!arguments, $x);
} }


method add-option($name, $value) { method add-option($name, $value) {
# how I miss p6's Hash.push # how I miss p6's Hash.push


if pir::exists(%!options, $name) { if nqp::existskey(%!options, $name) {
if pir::does(%!options{$name}, 'array') { if pir::does(%!options{$name}, 'array') {
pir::push(%!options{$name}, $value); nqp::push(%!options{$name}, $value);
} else { } else {
%!options{$name} := [ %!options{$name}, $value ]; %!options{$name} := [ %!options{$name}, $value ];
} }
Expand Down Expand Up @@ -148,20 +148,20 @@ class HLL::CommandLine::Parser {
} }


method split-option-aliases($s) { method split-option-aliases($s) {
pir::split('|', $s); nqp::split('|', $s);


} }


method add-spec($s) { method add-spec($s) {
my $i := pir::index($s, '='); my $i := nqp::index($s, '=');
my $type; my $type;
my @options; my @options;
if $i < 0 { if $i < 0 {
$type := 'b'; $type := 'b';
@options := self.split-option-aliases($s); @options := self.split-option-aliases($s);
} else { } else {
$type := pir::substr($s, $i + 1); $type := nqp::substr($s, $i + 1);
@options := self.split-option-aliases(pir::substr($s, 0, $i)); @options := self.split-option-aliases(nqp::substr($s, 0, $i));
} }
for @options { for @options {
%!options{$_} := $type; %!options{$_} := $type;
Expand All @@ -171,13 +171,13 @@ class HLL::CommandLine::Parser {


method is-option($x) { method is-option($x) {
return 0 if $x eq '-' || $x eq '--'; return 0 if $x eq '-' || $x eq '--';
return 1 if pir::substr($x, 0, 1) eq '-'; return 1 if nqp::substr($x, 0, 1) eq '-';
0; 0;
} }


method wants-value($x) { method wants-value($x) {
my $spec := %!options{$x}; my $spec := %!options{$x};
pir::substr($spec, 0, 1) eq 's'; nqp::substr($spec, 0, 1) eq 's';
} }


method optional-value($x) { method optional-value($x) {
Expand All @@ -195,11 +195,11 @@ class HLL::CommandLine::Parser {
# called when an option expects a value after it # called when an option expects a value after it
sub get-value($opt) { sub get-value($opt) {
if $i == $arg-count - 1 { if $i == $arg-count - 1 {
pir::die("Option $opt needs a value"); nqp::die("Option $opt needs a value");
} elsif self.is-option(@args[$i + 1]) { } elsif self.is-option(@args[$i + 1]) {
pir::die("Option $opt needs a value, but is followed by an option"); nqp::die("Option $opt needs a value, but is followed by an option");
} elsif %!stopper{@args[$i + 1]} { } elsif %!stopper{@args[$i + 1]} {
pir::die("Option $opt needs a value, but is followed by a stopper"); nqp::die("Option $opt needs a value, but is followed by a stopper");
} else { } else {
$i++; $i++;
@args[$i]; @args[$i];
Expand All @@ -219,34 +219,34 @@ class HLL::CommandLine::Parser {
while $i < $arg-count { while $i < $arg-count {
my $cur := @args[$i]; my $cur := @args[$i];
if self.is-option($cur) { if self.is-option($cur) {
if pir::substr($cur, 0, 2) eq '--' { if nqp::substr($cur, 0, 2) eq '--' {
# long option # long option
my $opt := pir::substr(@args[$i], 2); my $opt := nqp::substr(@args[$i], 2);
my $idx := pir::index($opt, '='); my $idx := nqp::index($opt, '=');
my $value := 1; my $value := 1;
my $has-value := 0; my $has-value := 0;


if $idx >= 0 { if $idx >= 0 {
$value := pir::substr($opt, $idx + 1); $value := nqp::substr($opt, $idx + 1);
$opt := pir::substr($opt, 0, $idx); $opt := nqp::substr($opt, 0, $idx);
$has-value := 1; $has-value := 1;
} elsif self.optional-value($opt) { } elsif self.optional-value($opt) {
$value := ''; $value := '';
$has-value := 1; $has-value := 1;
} }
pir::die("Illegal option --$opt") unless pir::exists(%!options, $opt); nqp::die("Illegal option --$opt") unless nqp::existskey(%!options, $opt);
pir::die("Option --$opt does not allow a value") if !self.wants-value($opt) && $has-value; nqp::die("Option --$opt does not allow a value") if !self.wants-value($opt) && $has-value;
if !$has-value && self.wants-value($opt) { if !$has-value && self.wants-value($opt) {
$value := get-value("--$opt"); $value := get-value("--$opt");
} }
$result.add-option($opt, $value); $result.add-option($opt, $value);
slurp-rest if %!stopper{"--$opt"}; slurp-rest if %!stopper{"--$opt"};
} else { } else {
my $opt := pir::substr($cur, 1); my $opt := nqp::substr($cur, 1);
my $len := pir::length($opt); my $len := nqp::chars($opt);
if $len == 1 { if $len == 1 {
# not grouped, so it might have a value # not grouped, so it might have a value
pir::die("No such option -$opt") unless %!options{$opt}; nqp::die("No such option -$opt") unless %!options{$opt};
if self.wants-value($opt) { if self.wants-value($opt) {
$result.add-option($opt, $result.add-option($opt,
get-value("-$opt")); get-value("-$opt"));
Expand All @@ -271,7 +271,7 @@ class HLL::CommandLine::Parser {
} }
} }
else { else {
pir::die("Grouped options '-$opt' contain '$o', which is not a valid option") nqp::die("Grouped options '-$opt' contain '$o', which is not a valid option")
} }
$i++; $i++;
} }
Expand Down
Loading