Skip to content

Commit

Permalink
Switch NativeCall types to use ^parameterize.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 12, 2015
1 parent a93f156 commit 9f637e7
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/NativeCall.pm
Expand Up @@ -114,7 +114,7 @@ augment class Pointer {
# method ^name($obj) { 'Pointer[' ~ TValue.^name ~ ']' }
method deref(::?CLASS:D \ptr:) { nativecast(TValue, ptr) }
}
multi method PARAMETERIZE_TYPE(Mu:U \t) {
method ^parameterize($, Mu:U \t) {
die "A typed pointer can only hold integers, numbers, strings, CStructs, CPointers or CArrays (not {t.^name})"
unless t ~~ Int || t ~~ Num || t === Str || t === void || t.REPR eq 'CStruct' | 'CUnion' | 'CPPStruct' | 'CPointer' | 'CArray';
my \typed := TypedPointer[t];
Expand Down Expand Up @@ -269,10 +269,6 @@ augment class CArray {
nqp::bindpos_i(nqp::decont(arr), $pos, nqp::unbox_i($assignee));
}
}
multi method PARAMETERIZE_TYPE(Int:U $t) {
my \typed := IntTypedCArray[$t.WHAT];
typed.HOW.make_pun(typed);
}

my role NumTypedCArray[::TValue] does Positional[TValue] is CArray is repr('CArray') is array_type(TValue) {
multi method AT-POS(::?CLASS:D \arr: $pos) is rw {
Expand Down Expand Up @@ -308,10 +304,6 @@ augment class CArray {
nqp::bindpos_n(nqp::decont(arr), $pos, nqp::unbox_n($assignee));
}
}
multi method PARAMETERIZE_TYPE(Num:U $t) {
my \typed := NumTypedCArray[$t.WHAT];
typed.HOW.make_pun(typed);
}

my role TypedCArray[::TValue] does Positional[TValue] is CArray is repr('CArray') is array_type(TValue) {
multi method AT-POS(::?CLASS:D \arr: $pos) is rw {
Expand Down Expand Up @@ -341,11 +333,20 @@ augment class CArray {
nqp::bindpos(nqp::decont(arr), nqp::unbox_i($pos), nqp::decont(assignee));
}
}
multi method PARAMETERIZE_TYPE(Mu:U \t) {
die "A C array can only hold integers, numbers, strings, CStructs, CPointers or CArrays (not {t.^name})"
unless t === Str || t.REPR eq 'CStruct' | 'CPointer' | 'CArray';
my \typed := TypedCArray[t];
typed.HOW.make_pun(typed);
method ^parameterize($, Mu:U \t) {
my $typed;
if t ~~ Int {
$typed := IntTypedCArray[t.WHAT];
}
elsif t ~~ Num {
$typed := NumTypedCArray[t.WHAT];
}
else {
die "A C array can only hold integers, numbers, strings, CStructs, CPointers or CArrays (not {t.^name})"
unless t === Str || t.REPR eq 'CStruct' | 'CPointer' | 'CArray';
$typed := TypedCArray[t];
}
$typed.^make_pun();
}
}

Expand Down

0 comments on commit 9f637e7

Please sign in to comment.