Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(do not merge) Make [failProc] to be not overloaded #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Function.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
16 changes: 6 additions & 10 deletions HashTable.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions Json.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions Quaternion.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions Span.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion SpanStatic.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
36 changes: 31 additions & 5 deletions algorithm.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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:;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion control.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ virtualizable?: [

#

overload failProc: [
failProc: [
print

trace: getCallTrace;
Expand Down Expand Up @@ -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 "" =] ||] &&
Expand Down
37 changes: 19 additions & 18 deletions sha1.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/universal/algorithmTest.mpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -762,7 +763,7 @@ testView: [

next: [
offset tuple fieldCount = [Int32 Ref FALSE] [
offset @tuple @
offset @tuple getUnchecked
offset 1 + !offset
TRUE
] if
Expand Down Expand Up @@ -915,7 +916,7 @@ testView: [

next: [
offset tuple fieldCount = [Int32 Ref FALSE] [
offset @tuple @
offset @tuple getUnchecked
offset 1 + !offset
TRUE
] if
Expand Down