Skip to content

Commit

Permalink
Reflow and adjust links
Browse files Browse the repository at this point in the history
Refs #2568
  • Loading branch information
JJ committed Jan 23, 2019
1 parent a7c21ad commit de32476
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
13 changes: 7 additions & 6 deletions doc/Language/nativecall.pod6
Expand Up @@ -125,13 +125,14 @@ my $result = clock_gettime( 0, $this-time);
say "$result, $this-time"; # OUTPUT: «0, timespec<65385480>␤»
=end code
The L<original function we are calling,
The original function we are calling,
L<clock_gettime|https://linux.die.net/man/3/clock_gettime>, uses a pointer to
the C<timespec> struct as second argument. We declare it as a L<class|/syntax/class> here, but
specify its representation as C<is repr('CStruct')>, to indicate it corresponds
to a C data structure. When we create an object of that class, we are creating
exactly the kind of pointer C<clock_gettime> expects. This way, data can be
transferred seamlessly to and from the native interface.
the C<timespec> struct as second argument. We declare it as a
L<class|/syntax/class> here, but specify its representation as C<is
repr('CStruct')>, to indicate it corresponds to a C data structure. When we
create an object of that class, we are creating exactly the kind of pointer
C<clock_gettime> expects. This way, data can be transferred seamlessly to and
from the native interface.
=head1 Basic use of pointers
Expand Down
4 changes: 2 additions & 2 deletions doc/Language/nativetypes.pod6
Expand Up @@ -31,7 +31,7 @@ used instead of the types C<int> or C<num> listed above.
In general, these variables will behave in the same way as regular
scalar variables, in a behavior that is called
L<I<auto-boxing>|/language/numerics#Auto-Boxing>; however, there are
L<I<auto-boxing>|/language/numerics#Auto-boxing>; however, there are
some differences, since what you are actually declaring is how they will
be represented, not their actual type. The first one is that their type
will be actually their equivalent type, not their native type.
Expand Down Expand Up @@ -201,4 +201,4 @@ Which would print the five elements of the array, as it should be expected.
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
42 changes: 22 additions & 20 deletions doc/Language/numerics.pod6
Expand Up @@ -567,7 +567,7 @@ say Buf.new(1000, 2000, 3000).List; # OUTPUT: «(232 208 184)␤»
say my uint8 @a = 1000, 2000, 3000; # OUTPUT: «232 208 184␤»
=end code
=head2 Auto-Boxing
=head2 Auto-boxing
While they can be referred to as "native I<types>", native numerics are not
actually classes that have any sort of methods available. However, you I<can>
Expand Down Expand Up @@ -595,9 +595,9 @@ my int $a-native = -42;
{ for ^1000_000 { $a-native.abs }; say now - ENTER now } # OUTPUT: «0.938720␤»
=end code
As you can see above, the native variant is more than twice slower. The reason is the method
call requires the native type to be boxed, while no such thing is needed in the non-native
variant, hence the performance loss.
As you can see above, the native variant is more than twice slower. The reason
is the method call requires the native type to be boxed, while no such thing is
needed in the non-native variant, hence the performance loss.
In this particular case, we can simply switch to a subroutine form of L<abs|/routine/abs>, which can work
with native types without boxing them. In other cases, you may need to seek out other solutions
Expand All @@ -621,13 +621,13 @@ pragma).
=head2 Native dispatch
It is possible to have native candidates alongside non-native candidates to, for example,
offer faster algorithms with native candidates when sizes are predictable, but to fallback
to slower non-native alternatives otherwise. The following are the rules concerning multi-dispatch
involving native candidates.
It is possible to have native candidates alongside non-native candidates to, for
example, offer faster algorithms with native candidates when sizes are
predictable, but to fallback to slower non-native alternatives otherwise. The
following are the rules concerning multi-dispatch involving native candidates.
First, the size of the native type does not play a role in dispatch and an C<int8> is considered
to be the same as C<int16> or C<int>:
First, the size of the native type does not play a role in dispatch and an
C<int8> is considered to be the same as C<int16> or C<int>:
=begin code
multi foo(int $x) { say "int" }
Expand All @@ -640,10 +640,10 @@ foo my int $x = 42;
=end code
Second, if a routine is an C<only>—i.e. it is not a
L«C<multi>|/language/functions#Multi-dispatch»—that
takes a non-native type but a native one was given during the call, or vice-versa, then the argument
will be auto-boxed or auto-unboxed to make the call possible. If the given
argument is too large to fit into the native parameter, an exception will be thrown:
L«C<multi>|/language/functions#Multi-dispatch»—that takes a non-native type but
a native one was given during the call, or vice-versa, then the argument will be
auto-boxed or auto-unboxed to make the call possible. If the given argument is
too large to fit into the native parameter, an exception will be thrown:
=begin code
-> int {}( 42 ); # OK; auto-unboxing
Expand All @@ -652,18 +652,20 @@ argument is too large to fit into the native parameter, an exception will be thr
-> Int {}( my int $ = 42 ); # OK; auto-boxing
=end code
When it comes to L«C<multi>|/language/functions#Multi-dispatch» routines, native arguments
will always be auto-boxed if no native candidates are available to take them:
When it comes to L«C<multi>|/language/functions#Multi-dispatch» routines, native
arguments will always be auto-boxed if no native candidates are available to
take them:
=begin code
multi foo (Int $x) { $x }
say foo my int $ = 42; # OUTPUT: «42␤»
=end code
The same luxury is not afforded when going the other way. If only a native candidate is
available, a non-native argument will I<not> be auto-unboxed and instead an exception indicating
no candidates matched will be thrown (the reason for this asymmetry is a native type can always
be boxed, but a non-native may be too large to fit into a native):
The same luxury is not afforded when going the other way. If only a native
candidate is available, a non-native argument will I<not> be auto-unboxed and
instead an exception indicating no candidates matched will be thrown (the reason
for this asymmetry is a native type can always be boxed, but a non-native may be
too large to fit into a native):
=begin code
multi f(int $x) { $x }
Expand Down
5 changes: 2 additions & 3 deletions doc/Type/Variable.pod6
Expand Up @@ -15,8 +15,7 @@ introspect and manipulate variables.
=head1 Traits
X<|is default (Variable)>
=head2 X<Trait is default>
=head2 X<Trait is default|is default (Variable)>
Sets the default value with which a variable is initialized, and to which it is
reset when L<Nil|/type/Nil> is assigned to it. Trait arguments are evaluated at
Expand Down Expand Up @@ -98,4 +97,4 @@ Returns the name of the variable, including the sigil.
=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 comments on commit de32476

Please sign in to comment.