Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CPointer becomes OpaquePointer for better naming win; start to stub i…

…n some support for array style return values.
  • Loading branch information...
commit 8e36c743149eb55e424eda4c29a06805bf19d9dc 1 parent ee1bc1c
@jnthn authored
Showing with 36 additions and 13 deletions.
  1. +36 −13 lib/NativeCall.pm
View
49 lib/NativeCall.pm
@@ -1,12 +1,21 @@
-class CPointer { }
+class OpaquePointer { }
+
+class NativeArray {
+ has $!unmanaged;
+
+ method postcircumfix:<[ ]>($key) {
+ die "Native Array NYI";
+ }
+}
our sub map-type-to-sig-char(Mu $type) {
given $type {
- when Int { 'i' }
- when Str { 't' }
- when Num { 'd' }
- when Rat { 'd' }
- when CPointer { 'p' }
+ when Int { 'i' }
+ when Str { 't' }
+ when Num { 'd' }
+ when Rat { 'd' }
+ when OpaquePointer { 'p' }
+ when Positional { 'p' }
default { die "Can not handle type " ~ $_.perl ~ " in an 'is native' signature." }
}
}
@@ -20,14 +29,28 @@ our sub perl6-sig-to-backend-sig(Routine $r) {
return $sig-string;
}
+our sub make-mapper(Mu $type) {
+ given $type {
+ when Positional {
+ -> \$umanaged-struct {
+ NativeArray.new(unmanaged => $umanaged-struct)
+ }
+ }
+ default { -> \$x { $x } }
+ }
+}
+
our multi trait_mod:<is>(Routine $r, $libname, :$native!) {
- my $entry-point = $r.name();
- my $call-sig = perl6-sig-to-backend-sig($r);
+ my $entry-point = $r.name();
+ my $call-sig = perl6-sig-to-backend-sig($r);
+ my $return-mapper = make-mapper($r.returns);
pir::setattribute__vPsP($r, '$!do', pir::clone__PP(-> |$c {
- (pir::dlfunc__PPss(
- pir::loadlib__Ps($libname),
- $entry-point,
- $call-sig
- )).(|$c)
+ $return-mapper(
+ (pir::dlfunc__PPss(
+ pir::loadlib__Ps($libname),
+ $entry-point,
+ $call-sig
+ )).(|$c)
+ )
}));
}
Please sign in to comment.
Something went wrong with that request. Please try again.