Compilation exception

57 views
Skip to first unread message

Stefan Hertenberger

unread,
Sep 18, 2023, 9:58:38 AM9/18/23
to ParaSail Programming Language
Hello,

i started playing around with ParaSail, while compiling a short test i got the following excpetion. Any ideas ?

kind regards Stefan

Installing Debugging Console!
psc-interpreter-builtins.adb:612: Error: overflow check failed

/home/stefan/Devel/parasail/parasail/lib/aaa.psi:8140:32: Runtime error: Exception CONSTRAINT_ERROR propagated.
Executing "indexing" at PC 1
/home/stefan/Devel/parasail/parasail/lib/aaa.psi:8140:16: Info: executing in interpreter
  Locals at 16#563D_7950_45D8#
>> ParaSail Debugger
Stack frame #2:
  func PSL::Containers::Array::"indexing" (
    Arr : Array
    Index : Countable
  ) -> Elem_Type : Assignable
  Enclosing_Type : PSL::Containers::Array<PSL::Core::Integer<".."(0, 0xFF)>, PSL::Core::Integer<".."(-2 ** 63 + 1, +2 ** 63 - 1)>>
  Src_Pos : /home/stefan/Devel/parasail/parasail/lib/aaa.psi:8140:32 (Pc : 1)
  Illegal value in operation:
   8140>        return Arr.Data[ Index - Arr.Bounds.First + 1 ]
(tcb:1.603.20) (psldb) quit
Exiting.
dvb.psl:44:16: Info: Propagating exception
Executing Init at PC 1
dvb.psl:44:16: Info: executing in interpreter
  Locals at 16#563D_7950_45A8#
dvb.psl:63:36: Info: Propagating exception
Executing $lambda_4566_63_21 at PC 1
dvb.psl:63:21: Info: executing in interpreter
  Locals at 16#563D_7950_4568#

raised PSC.INTERPRETER.PROPAGATING_EXCEPTION : psc-interpreter.adb:18007


`
interface DvbCsaBlock<> is
    type DVB_CSA_KEYS is Array<Integer<Range => 0..0xFF>, Indexed_By => Integer>

    func dvbcsa_block_decrypt(key: DVB_CSA_KEYS)

    func Init(idx: Integer) -> Integer<Range => 0..0xFF>;
    func Print();
end interface DvbCsaBlock;

class DvbCsaBlock is
    const DVBCSA_DATA_SIZE := 8
    const DVBCSA_KEYSBUFF_SIZE := 56

    type DVB_CSA_BLOCK is Array<Integer<Range => 0..0xFF>, Indexed_By => Integer>
   
    type SBOX is Array<Integer<Range => 0..0xFF>, Indexed_By => Integer>

    const dvbcsa_block_sbox : SBOX := [
        0x3a, 0xea, 0x68, 0xfe, 0x33, 0xe9, 0x88, 0x1a, 0x83, 0xcf, 0xe1, 0x7f, 0xba, 0xe2, 0x38, 0x12,
        0xe8, 0x27, 0x61, 0x95, 0x0c, 0x36, 0xe5, 0x70, 0xa2, 0x06, 0x82, 0x7c, 0x17, 0xa3, 0x26, 0x49,
        0xbe, 0x7a, 0x6d, 0x47, 0xc1, 0x51, 0x8f, 0xf3, 0xcc, 0x5b, 0x67, 0xbd, 0xcd, 0x18, 0x08, 0xc9,
        0xff, 0x69, 0xef, 0x03, 0x4e, 0x48, 0x4a, 0x84, 0x3f, 0xb4, 0x10, 0x04, 0xdc, 0xf5, 0x5c, 0xc6,
        0x16, 0xab, 0xac, 0x4c, 0xf1, 0x6a, 0x2f, 0x3c, 0x3b, 0xd4, 0xd5, 0x94, 0xd0, 0xc4, 0x63, 0x62,
        0x71, 0xa1, 0xf9, 0x4f, 0x2e, 0xaa, 0xc5, 0x56, 0xe3, 0x39, 0x93, 0xce, 0x65, 0x64, 0xe4, 0x58,
        0x6c, 0x19, 0x42, 0x79, 0xdd, 0xee, 0x96, 0xf6, 0x8a, 0xec, 0x1e, 0x85, 0x53, 0x45, 0xde, 0xbb,
        0x7e, 0x0a, 0x9a, 0x13, 0x2a, 0x9d, 0xc2, 0x5e, 0x5a, 0x1f, 0x32, 0x35, 0x9c, 0xa8, 0x73, 0x30,
        0x29, 0x3d, 0xe7, 0x92, 0x87, 0x1b, 0x2b, 0x4b, 0xa5, 0x57, 0x97, 0x40, 0x15, 0xe6, 0xbc, 0x0e,
        0xeb, 0xc3, 0x34, 0x2d, 0xb8, 0x44, 0x25, 0xa4, 0x1c, 0xc7, 0x23, 0xed, 0x90, 0x6e, 0x50, 0x00,
        0x99, 0x9e, 0x4d, 0xd9, 0xda, 0x8d, 0x6f, 0x5f, 0x3e, 0xd7, 0x21, 0x74, 0x86, 0xdf, 0x6b, 0x05,
        0x8e, 0x5d, 0x37, 0x11, 0xd2, 0x28, 0x75, 0xd6, 0xa7, 0x77, 0x24, 0xbf, 0xf0, 0xb0, 0x02, 0xb7,
        0xf8, 0xfc, 0x81, 0x09, 0xb1, 0x01, 0x76, 0x91, 0x7d, 0x0f, 0xc8, 0xa0, 0xf2, 0xcb, 0x78, 0x60,
        0xd1, 0xf7, 0xe0, 0xb5, 0x98, 0x22, 0xb3, 0x20, 0x1d, 0xa6, 0xdb, 0x7b, 0x59, 0x9f, 0xae, 0x31,
        0xfb, 0xd3, 0xb6, 0xca, 0x43, 0x72, 0x07, 0xf4, 0xd8, 0x41, 0x14, 0x55, 0x0d, 0x54, 0x8b, 0xb9,
        0xad, 0x46, 0x0b, 0xaf, 0x80, 0x52, 0x2c, 0xfa, 0x8c, 0x89, 0x66, 0xfd, 0xb2, 0xa9, 0x9b, 0xc0];

exports
    func dvbcsa_block_decrypt(key: DVB_CSA_KEYS) is
        var i : Integer := DVBCSA_KEYSBUFF_SIZE;
        var w : DVB_CSA_BLOCK;

    end func dvbcsa_block_decrypt;

    func Init(idx: Integer) -> Integer<Range => 0..0xFF> is
        return dvbcsa_block_sbox[idx];
    end func Init;

    func Print ( ) is
        for I in 1..dvbcsa_block_sbox.Length() loop
            var a := dvbcsa_block_sbox[I];
            Println(I | " a := " | a);
        end loop
    end func Print;

end class DvbCsaBlock;

func main () is
    var key : DvbCsaBlock::DVB_CSA_KEYS := [0,0,0,0,0,0,0,0]

    DvbCsaBlock::Print()
    DvbCsaBlock::dvbcsa_block_decrypt(key)
    var a : Integer := 1;
    Println("b := " | DvbCsaBlock::Init(a))
    Println("c := " | DvbCsaBlock::Init(1)) // This causes the compile exception
end func main;
`

vernonb...@gmail.com

unread,
Sep 23, 2023, 2:25:21 PM9/23/23
to ParaSail Programming Language
The issue is that Integer doesn't make a good index type, since it starts at -2 ** 62 instead of at 1.  Thus index position 1 is 2**62 positions past the 1st element in the array, and way out of range.
The easiest way to fix this is to use Basic_Array instead of Array, since Basic_Array defaults to using an Integer index that starts at 1.
Ex: type DVB_CSA_KEYS is Basic_Array<Integer<Range => 0..0xFF>>

I made this change and your code now loads and runs without error.

Reply all
Reply to author
Forward
0 new messages