From d7bf75a1cfe83a68bc222fe9643361cbbbf93058 Mon Sep 17 00:00:00 2001 From: x Date: Sun, 2 Jul 2023 18:03:40 +0700 Subject: [PATCH] Make [failProc] to be not overloaded; Add [getUnchecked]s; Add another one [@] to Quaternion.mpl; Update [failProc] usage --- Function.mpl | 17 ++++++++++++-- HashTable.mpl | 16 +++++-------- Json.mpl | 7 ++---- Quaternion.mpl | 30 ++++++++++++++++++------- Span.mpl | 29 ++++++++++++------------ SpanStatic.mpl | 3 ++- algorithm.mpl | 36 +++++++++++++++++++++++++----- control.mpl | 8 ++++++- sha1.mpl | 37 ++++++++++++++++--------------- tests/universal/algorithmTest.mpl | 5 +++-- 10 files changed, 122 insertions(+), 66 deletions(-) diff --git a/Function.mpl b/Function.mpl index c093302..f5c3172 100644 --- a/Function.mpl +++ b/Function.mpl @@ -6,11 +6,24 @@ # By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner. "algorithm.case" use +"control.AsRef" use +"control.Int32" use +"control.Nat64" use +"control.Nat8" use +"control.Natx" use +"control.Ref" use +"control.assert" use +"control.assignable?" use +"control.drop" use +"control.dup" use +"control.failProc" use +"control.initializable?" use +"control.sized?" use +"control.times" use +"control.when" use "objectTools.insertField" use "objectTools.unwrapField" use -"control" use # failProc does not work with separate [use]s - FUNCTION_ASSIGN_KEY: [0]; FUNCTION_CALL_KEY: [1]; FUNCTION_DIE_KEY: [2]; diff --git a/HashTable.mpl b/HashTable.mpl index accc6a9..7921a2e 100644 --- a/HashTable.mpl +++ b/HashTable.mpl @@ -94,17 +94,13 @@ HashTable: [ i: 0 dynamic; [ - i curBucket.size < [ - node: i @curBucket.at; - node.key key = [ - i @curBucket.erase - FALSE - ] [ - i 1 + @i set TRUE - ] if - ] [ - "Erasing unexisting element!" failProc + [i curBucket.size <] "Key doesn't present" assert + node: i @curBucket.at; + node.key key = [ + i @curBucket.erase FALSE + ] [ + i 1 + @i set TRUE ] if ] loop diff --git a/Json.mpl b/Json.mpl index 5dd5158..d6de8e4 100644 --- a/Json.mpl +++ b/Json.mpl @@ -698,11 +698,8 @@ catJSONNodeWithPaddingImpl: [ json.getTag JSONArray = [ catArrayJSON ] [ - json.getTag JSONObject = [ - catObjectJSON - ] [ - "Unknown JSON tag!" failProc - ] if + [json.getTag JSONObject =] "Unknown JSON tag!" assert + catObjectJSON ] if ] if ] if diff --git a/Quaternion.mpl b/Quaternion.mpl index f67236e..cc7e0ab 100644 --- a/Quaternion.mpl +++ b/Quaternion.mpl @@ -19,7 +19,11 @@ "algebra.trans" use "algebra.unit" use "algorithm.each" use +"control.&&" use "control.Ref" use +"control.compilable?" use +"control.drop" use +"control.getUnchecked" use "control.pfunc" use "control.real?" use "control.sqr" use @@ -96,21 +100,21 @@ quaternion: [ ] [ next: (1 2 0); i: 1 1 m @ @ 0 0 m @ @ > [1] [0] if; - 2 2 m @ @ i i m @ @ > [ + 2 2 m @ @ i i m getUnchecked getUnchecked > [ 2 !i ] when - j: i next @; - k: j next @; + j: i next getUnchecked; + k: j next getUnchecked; q: trace Quaternion; - qi: i i m @ @ j j m @ @ - k k m @ @ - 1 trace cast + sqrt 0.5 trace cast *; + qi: i i m getUnchecked getUnchecked j j m getUnchecked getUnchecked - k k m getUnchecked getUnchecked - 1 trace cast + sqrt 0.5 trace cast *; fr: 0.25 qi cast qi /; - qi i @q @ set - i j m @ @ j i m @ @ + fr * j @q @ set - i k m @ @ k i m @ @ + fr * k @q @ set - j k m @ @ k j m @ @ - fr * 3 @q @ set + qi i @q getUnchecked set + i j m getUnchecked getUnchecked j i m getUnchecked getUnchecked + fr * j @q getUnchecked set + i k m getUnchecked getUnchecked k i m getUnchecked getUnchecked + fr * k @q getUnchecked set + j k m getUnchecked getUnchecked k j m getUnchecked getUnchecked - fr * 3 @q @ set q ] if ] pfunc; @@ -147,6 +151,16 @@ vector: ["QUATERNION" has] [ @: ["QUATERNION" has] [.@entries @] pfunc; +@: ["QUATERNION" has [new isDynamic] &&] [ + [0 dynamic (0) @] compilable? ~ ["Component key doesn't known at compile-time. Depending on the input either provide [failProc], use [getUnchecked] from Quaternion.mpl, or disable bounds check" raiseStaticError] when + .@entries @ +] pfunc; + +getUnchecked: ["QUATERNION" has] [ + failProc: [drop]; + @ +] pfunc; + fieldCount: ["QUATERNION" has] [.entries fieldCount] pfunc; # Basic operations diff --git a/Span.mpl b/Span.mpl index 09085e6..258b4db 100644 --- a/Span.mpl +++ b/Span.mpl @@ -5,19 +5,20 @@ # It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner. # By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner. -"control.&&" use -"control.Cref" use -"control.Int32" use -"control.Nat8" use -"control.Natx" use -"control.Ref" use -"control.Text" use -"control.assert" use -"control.between" use -"control.dup" use -"control.pfunc" use -"control.when" use -"control.within" use +"control.&&" use +"control.Cref" use +"control.Int32" use +"control.Nat8" use +"control.Natx" use +"control.Ref" use +"control.Text" use +"control.assert" use +"control.between" use +"control.dup" use +"control.getUnchecked" use +"control.pfunc" use +"control.when" use +"control.within" use Span: [ data:; @@ -31,7 +32,7 @@ toSpan: [Text same] [ toSpan: [object:; @object isCombined [@object 0 fieldIsRef ~] &&] [ struct:; - 0 dynamic @struct @ struct fieldCount toSpan2 # [dynamic] is used to check for non-homogeneous tuples + 0 dynamic @struct getUnchecked struct fieldCount toSpan2 # [dynamic] is used to check for non-homogeneous tuples ] pfunc; toSpan: ["span" has] [.span] pfunc; diff --git a/SpanStatic.mpl b/SpanStatic.mpl index 8053f68..c83c165 100644 --- a/SpanStatic.mpl +++ b/SpanStatic.mpl @@ -15,6 +15,7 @@ "control.assert" use "control.between" use "control.dup" use +"control.getUnchecked" use "control.pfunc" use "control.when" use "control.within" use @@ -32,7 +33,7 @@ toSpanStatic: [Text same] [ toSpanStatic: [object:; @object isCombined [@object 0 fieldIsRef ~] &&] [ struct:; - 0 dynamic @struct @ struct fieldCount toSpanStatic2 # [dynamic] is used to check for non-homogeneous tuples + 0 dynamic @struct getUnchecked struct fieldCount toSpanStatic2 # [dynamic] is used to check for non-homogeneous tuples ] pfunc; toSpanStatic: ["spanStatic" has] [.spanStatic] pfunc; diff --git a/algorithm.mpl b/algorithm.mpl index 258fd0c..2583157 100644 --- a/algorithm.mpl +++ b/algorithm.mpl @@ -47,7 +47,33 @@ # Trying to create a new View that goes beyond the current one is undefined behavior. # A View itself does not provide access to items, but other interfaces such as Index or Iterable can provide it. -"control" use +"control.&&" use +"control.<" use +"control.=" use +"control.>" use +"control.AsRef" use +"control.Cref" use +"control.Int32" use +"control.Nat8" use +"control.Natx" use +"control.Text" use +"control.assert" use +"control.between" use +"control.copyable?" use +"control.drop" use +"control.dup" use +"control.getUnchecked" use +"control.isBuiltinTuple" use +"control.min" use +"control.movable?" use +"control.over" use +"control.pfunc" use +"control.swap" use +"control.times" use +"control.unwrap" use +"control.when" use +"control.within" use +"control.||" use isDirtyOrDynamic: [ object:; @@ -188,7 +214,7 @@ makeTupleIndex: [ tuple: offset: size:;;; [offset 0 @tuple fieldCount between] "offset is out of bounds" assert [size 0 @tuple fieldCount offset - between] "size is out of bounds" assert - offset isDynamic [@tuple storageAddress 0 dynamic @tuple @ storageSize offset Natx cast * + 0 @tuple @ addressToReference size makeArrayIndex] [ + offset isDynamic [@tuple storageAddress 0 dynamic @tuple getUnchecked storageSize offset Natx cast * + 0 @tuple @ addressToReference size makeArrayIndex] [ { SCHEMA_NAME: virtual "TupleIndex"; tuple: @tuple; @@ -210,7 +236,7 @@ makeTupleIter: [ tuple: offset: size:;;; [offset 0 @tuple fieldCount between] "offset is out of bounds" assert [size 0 @tuple fieldCount offset - between] "size is out of bounds" assert - offset isDynamic [@tuple storageAddress 0 dynamic @tuple @ storageSize offset Natx cast * + 0 @tuple @ addressToReference size makeArrayIter] [ + offset isDynamic [@tuple storageAddress 0 dynamic @tuple getUnchecked storageSize offset Natx cast * + 0 @tuple @ addressToReference size makeArrayIter] [ { SCHEMA_NAME: virtual "TupleIter"; tuple: @tuple; @@ -223,7 +249,7 @@ makeTupleIter: [ @tuple 0 fieldIsRef [ REF_SIZE Natx cast offset0 Natx cast * + 0 @tuple @ AsRef addressToReference .@data ] [ - 0 dynamic @tuple @ storageSize offset0 Natx cast * + 0 @tuple @ addressToReference + 0 dynamic @tuple getUnchecked storageSize offset0 Natx cast * + 0 @tuple @ addressToReference ] if ] [ offset0 @tuple fieldCount < [offset0 @tuple @] [()] if @@ -242,7 +268,7 @@ makeTupleView: [ tuple: offset: size:;;; [offset 0 @tuple fieldCount between] "offset is out of bounds" assert [size 0 @tuple fieldCount offset - between] "size is out of bounds" assert - offset isDynamic [@tuple storageAddress 0 dynamic @tuple @ storageSize offset Natx cast * + 0 @tuple @ addressToReference size makeArrayView] [ + offset isDynamic [@tuple storageAddress 0 dynamic @tuple getUnchecked storageSize offset Natx cast * + 0 @tuple @ addressToReference size makeArrayView] [ { SCHEMA_NAME: virtual "TupleView"; tuple: @tuple; diff --git a/control.mpl b/control.mpl index a2ef3cd..d3827fa 100644 --- a/control.mpl +++ b/control.mpl @@ -186,7 +186,7 @@ virtualizable?: [ # -overload failProc: [ +failProc: [ print trace: getCallTrace; @@ -438,6 +438,12 @@ enum: [ @: ["at" has] [.at] pfunc; +getUnchecked: ["at" has ~] [ + key: object:;; + failProc: [drop]; + key @object @ +] pfunc; + isBuiltinTuple: [ object:; @object isCombined [@object () same [@object 0 fieldName "" =] ||] && diff --git a/sha1.mpl b/sha1.mpl index 82f66b1..6ecbc70 100644 --- a/sha1.mpl +++ b/sha1.mpl @@ -5,23 +5,24 @@ # It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner. # By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner. -"Span.toSpan" use -"algorithm.unhead" use -"control.!" use -"control.&&" use -"control.@" use -"control.Int32" use -"control.Nat32" use -"control.Nat64" use -"control.Nat8" use -"control.Natx" use -"control.drop" use -"control.min" use -"control.times" use -"control.when" use -"control.while" use -"memory.memcpy" use -"memory.memset" use +"Span.toSpan" use +"algorithm.unhead" use +"control.!" use +"control.&&" use +"control.@" use +"control.Int32" use +"control.Nat32" use +"control.Nat64" use +"control.Nat8" use +"control.Natx" use +"control.drop" use +"control.getUnchecked" use +"control.min" use +"control.times" use +"control.when" use +"control.while" use +"memory.memcpy" use +"memory.memset" use Sha1Internal: { rol: [ @@ -256,7 +257,7 @@ sha1: [ source.data storageAddress buf storageAddress memcpy drop - 0x80n8 count @buf @ set + 0x80n8 count @buf getUnchecked set count 1 + !count count 56 > [ 64 count - Natx cast diff --git a/tests/universal/algorithmTest.mpl b/tests/universal/algorithmTest.mpl index 8202672..e9727cc 100644 --- a/tests/universal/algorithmTest.mpl +++ b/tests/universal/algorithmTest.mpl @@ -15,6 +15,7 @@ "control.drop" use "control.dup" use "control.ensure" use +"control.getUnchecked" use "control.isBuiltinTuple" use "control.pfunc" use "control.times" use @@ -762,7 +763,7 @@ testView: [ next: [ offset tuple fieldCount = [Int32 Ref FALSE] [ - offset @tuple @ + offset @tuple getUnchecked offset 1 + !offset TRUE ] if @@ -915,7 +916,7 @@ testView: [ next: [ offset tuple fieldCount = [Int32 Ref FALSE] [ - offset @tuple @ + offset @tuple getUnchecked offset 1 + !offset TRUE ] if