From 6230645a3b064dae8008fe926eeec592f723e357 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Thu, 17 Feb 2022 17:30:40 +0100 Subject: [PATCH] Streamline Buf role generation a bit - fall back to globally fail method, don't use local sub - replace int candidates of AT/ASSIGN-POS with uint ones --- src/core.c/Buf.pm6 | 46 +++++++++++----------------------- tools/build/makeBUF_ROLES.raku | 21 +++++----------- 2 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/core.c/Buf.pm6 b/src/core.c/Buf.pm6 index d39eb5295d4..e0fa0182230 100644 --- a/src/core.c/Buf.pm6 +++ b/src/core.c/Buf.pm6 @@ -918,34 +918,25 @@ my class utf32 does Blob[uint32] is repr('VMArray') { my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) { #- start of generated part of Buf Signed role -------------------------------- -#- Generated on 2022-02-15T10:19:32+01:00 by ./tools/build/makeBUF_ROLES.raku +#- Generated on 2022-02-17T17:11:17+01:00 by ./tools/build/makeBUF_ROLES.raku #- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE my role SignedBuf[::T] is repr('VMArray') is array_type(T) is implementation-detail { - sub OOR(int $got) is hidden-from-backtrace { - Failure.new(X::OutOfRange.new( - :what($*INDEX // 'Index'), :$got, :range<0..^Inf> - )) - } - multi method AT-POS(::?ROLE:D: int $pos) is raw is default { - nqp::islt_i($pos,0) - ?? OOR($pos) - !! nqp::atposref_i(self,$pos) + multi method AT-POS(::?ROLE:D: uint $pos) is raw is default { + nqp::atposref_i(self,$pos) } multi method AT-POS(::?ROLE:D: Int:D $pos) is raw is default { nqp::islt_i($pos,0) - ?? OOR($pos) + ?? self!fail-range($pos) !! nqp::atposref_i(self,$pos) } - multi method ASSIGN-POS(::?ROLE:D: int $pos, Mu \assignee) { - nqp::islt_i($pos,0) - ?? OOR($pos) - !! nqp::bindpos_i(self,$pos,assignee) + multi method ASSIGN-POS(::?ROLE:D: uint $pos, Mu \assignee) { + nqp::bindpos_i(self,$pos,assignee) } multi method ASSIGN-POS(::?ROLE:D: Int:D $pos, Mu \assignee) { nqp::islt_i($pos,0) - ?? OOR($pos) + ?? self!fail-range($pos) !! nqp::bindpos_i(self,$pos,assignee) } @@ -1035,34 +1026,25 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) { #- end of generated part of Buf Signed role ---------------------------------- #- start of generated part of Buf Unsigned role -------------------------------- -#- Generated on 2022-02-15T10:19:32+01:00 by ./tools/build/makeBUF_ROLES.raku +#- Generated on 2022-02-17T17:11:17+01:00 by ./tools/build/makeBUF_ROLES.raku #- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE my role UnsignedBuf[::T] is repr('VMArray') is array_type(T) is implementation-detail { - sub OOR(int $got) is hidden-from-backtrace { - Failure.new(X::OutOfRange.new( - :what($*INDEX // 'Index'), :$got, :range<0..^Inf> - )) - } - multi method AT-POS(::?ROLE:D: int $pos) is raw is default { - nqp::islt_i($pos,0) - ?? OOR($pos) - !! nqp::atposref_u(self,$pos) + multi method AT-POS(::?ROLE:D: uint $pos) is raw is default { + nqp::atposref_u(self,$pos) } multi method AT-POS(::?ROLE:D: Int:D $pos) is raw is default { nqp::islt_i($pos,0) - ?? OOR($pos) + ?? self!fail-range($pos) !! nqp::atposref_u(self,$pos) } - multi method ASSIGN-POS(::?ROLE:D: int $pos, Mu \assignee) { - nqp::islt_i($pos,0) - ?? OOR($pos) - !! nqp::bindpos_u(self,$pos,assignee) + multi method ASSIGN-POS(::?ROLE:D: uint $pos, Mu \assignee) { + nqp::bindpos_u(self,$pos,assignee) } multi method ASSIGN-POS(::?ROLE:D: Int:D $pos, Mu \assignee) { nqp::islt_i($pos,0) - ?? OOR($pos) + ?? self!fail-range($pos) !! nqp::bindpos_u(self,$pos,assignee) } diff --git a/tools/build/makeBUF_ROLES.raku b/tools/build/makeBUF_ROLES.raku index f201975698c..29dfdbf321b 100755 --- a/tools/build/makeBUF_ROLES.raku +++ b/tools/build/makeBUF_ROLES.raku @@ -56,30 +56,21 @@ while @lines { say Q:to/SOURCE/.subst(/ '#' (\w+) '#' /, -> $/ { %mapper{$0} }, :g).chomp; my role #name#[::T] is repr('VMArray') is array_type(T) is implementation-detail { - sub OOR(int $got) is hidden-from-backtrace { - Failure.new(X::OutOfRange.new( - :what($*INDEX // 'Index'), :$got, :range<0..^Inf> - )) - } - multi method AT-POS(::?ROLE:D: int $pos) is raw is default { - nqp::islt_i($pos,0) - ?? OOR($pos) - !! nqp::atposref_#postfix#(self,$pos) + multi method AT-POS(::?ROLE:D: uint $pos) is raw is default { + nqp::atposref_#postfix#(self,$pos) } multi method AT-POS(::?ROLE:D: Int:D $pos) is raw is default { nqp::islt_i($pos,0) - ?? OOR($pos) + ?? self!fail-range($pos) !! nqp::atposref_#postfix#(self,$pos) } - multi method ASSIGN-POS(::?ROLE:D: int $pos, Mu \assignee) { - nqp::islt_i($pos,0) - ?? OOR($pos) - !! nqp::bindpos_#postfix#(self,$pos,assignee) + multi method ASSIGN-POS(::?ROLE:D: uint $pos, Mu \assignee) { + nqp::bindpos_#postfix#(self,$pos,assignee) } multi method ASSIGN-POS(::?ROLE:D: Int:D $pos, Mu \assignee) { nqp::islt_i($pos,0) - ?? OOR($pos) + ?? self!fail-range($pos) !! nqp::bindpos_#postfix#(self,$pos,assignee) }