ic-mops 0.8.5 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/.mops/base@0.7.4/LICENSE +0 -208
- package/.mops/base@0.7.4/README.md +0 -64
- package/.mops/base@0.7.4/mops.toml +0 -5
- package/.mops/base@0.7.4/src/Array.mo +0 -686
- package/.mops/base@0.7.4/src/AssocList.mo +0 -203
- package/.mops/base@0.7.4/src/Blob.mo +0 -55
- package/.mops/base@0.7.4/src/Bool.mo +0 -44
- package/.mops/base@0.7.4/src/Buffer.mo +0 -1937
- package/.mops/base@0.7.4/src/CertifiedData.mo +0 -29
- package/.mops/base@0.7.4/src/Char.mo +0 -67
- package/.mops/base@0.7.4/src/Debug.mo +0 -15
- package/.mops/base@0.7.4/src/Deque.mo +0 -75
- package/.mops/base@0.7.4/src/Error.mo +0 -41
- package/.mops/base@0.7.4/src/ExperimentalCycles.mo +0 -51
- package/.mops/base@0.7.4/src/ExperimentalInternetComputer.mo +0 -36
- package/.mops/base@0.7.4/src/ExperimentalStableMemory.mo +0 -121
- package/.mops/base@0.7.4/src/Float.mo +0 -150
- package/.mops/base@0.7.4/src/Func.mo +0 -38
- package/.mops/base@0.7.4/src/Hash.mo +0 -83
- package/.mops/base@0.7.4/src/HashMap.mo +0 -229
- package/.mops/base@0.7.4/src/Heap.mo +0 -113
- package/.mops/base@0.7.4/src/Int.mo +0 -150
- package/.mops/base@0.7.4/src/Int16.mo +0 -159
- package/.mops/base@0.7.4/src/Int32.mo +0 -160
- package/.mops/base@0.7.4/src/Int64.mo +0 -161
- package/.mops/base@0.7.4/src/Int8.mo +0 -160
- package/.mops/base@0.7.4/src/Iter.mo +0 -220
- package/.mops/base@0.7.4/src/IterType.mo +0 -7
- package/.mops/base@0.7.4/src/List.mo +0 -433
- package/.mops/base@0.7.4/src/Nat.mo +0 -75
- package/.mops/base@0.7.4/src/Nat16.mo +0 -146
- package/.mops/base@0.7.4/src/Nat32.mo +0 -146
- package/.mops/base@0.7.4/src/Nat64.mo +0 -146
- package/.mops/base@0.7.4/src/Nat8.mo +0 -146
- package/.mops/base@0.7.4/src/None.mo +0 -19
- package/.mops/base@0.7.4/src/Option.mo +0 -160
- package/.mops/base@0.7.4/src/Order.mo +0 -46
- package/.mops/base@0.7.4/src/Prelude.mo +0 -33
- package/.mops/base@0.7.4/src/Principal.mo +0 -58
- package/.mops/base@0.7.4/src/RBTree.mo +0 -218
- package/.mops/base@0.7.4/src/Random.mo +0 -188
- package/.mops/base@0.7.4/src/Result.mo +0 -210
- package/.mops/base@0.7.4/src/Stack.mo +0 -40
- package/.mops/base@0.7.4/src/Text.mo +0 -615
- package/.mops/base@0.7.4/src/Time.mo +0 -37
- package/.mops/base@0.7.4/src/Trie.mo +0 -1200
- package/.mops/base@0.7.4/src/TrieMap.mo +0 -180
- package/.mops/base@0.7.4/src/TrieSet.mo +0 -97
- package/.mops/base@0.8.3/LICENSE +0 -208
- package/.mops/base@0.8.3/README.md +0 -64
- package/.mops/base@0.8.3/mops.toml +0 -6
- package/.mops/base@0.8.3/src/Array.mo +0 -717
- package/.mops/base@0.8.3/src/AssocList.mo +0 -404
- package/.mops/base@0.8.3/src/Blob.mo +0 -212
- package/.mops/base@0.8.3/src/Bool.mo +0 -44
- package/.mops/base@0.8.3/src/Buffer.mo +0 -2660
- package/.mops/base@0.8.3/src/CertifiedData.mo +0 -53
- package/.mops/base@0.8.3/src/Char.mo +0 -65
- package/.mops/base@0.8.3/src/Debug.mo +0 -56
- package/.mops/base@0.8.3/src/Deque.mo +0 -243
- package/.mops/base@0.8.3/src/Error.mo +0 -68
- package/.mops/base@0.8.3/src/ExperimentalCycles.mo +0 -151
- package/.mops/base@0.8.3/src/ExperimentalInternetComputer.mo +0 -60
- package/.mops/base@0.8.3/src/ExperimentalStableMemory.mo +0 -348
- package/.mops/base@0.8.3/src/Float.mo +0 -843
- package/.mops/base@0.8.3/src/Func.mo +0 -46
- package/.mops/base@0.8.3/src/Hash.mo +0 -82
- package/.mops/base@0.8.3/src/HashMap.mo +0 -457
- package/.mops/base@0.8.3/src/Heap.mo +0 -233
- package/.mops/base@0.8.3/src/Int.mo +0 -365
- package/.mops/base@0.8.3/src/Int16.mo +0 -521
- package/.mops/base@0.8.3/src/Int32.mo +0 -522
- package/.mops/base@0.8.3/src/Int64.mo +0 -522
- package/.mops/base@0.8.3/src/Int8.mo +0 -522
- package/.mops/base@0.8.3/src/Iter.mo +0 -227
- package/.mops/base@0.8.3/src/IterType.mo +0 -7
- package/.mops/base@0.8.3/src/List.mo +0 -930
- package/.mops/base@0.8.3/src/Nat.mo +0 -305
- package/.mops/base@0.8.3/src/Nat16.mo +0 -144
- package/.mops/base@0.8.3/src/Nat32.mo +0 -144
- package/.mops/base@0.8.3/src/Nat64.mo +0 -144
- package/.mops/base@0.8.3/src/Nat8.mo +0 -144
- package/.mops/base@0.8.3/src/None.mo +0 -19
- package/.mops/base@0.8.3/src/Option.mo +0 -154
- package/.mops/base@0.8.3/src/Order.mo +0 -46
- package/.mops/base@0.8.3/src/Prelude.mo +0 -33
- package/.mops/base@0.8.3/src/Principal.mo +0 -249
- package/.mops/base@0.8.3/src/RBTree.mo +0 -681
- package/.mops/base@0.8.3/src/Random.mo +0 -270
- package/.mops/base@0.8.3/src/Result.mo +0 -209
- package/.mops/base@0.8.3/src/Stack.mo +0 -93
- package/.mops/base@0.8.3/src/Text.mo +0 -761
- package/.mops/base@0.8.3/src/Time.mo +0 -36
- package/.mops/base@0.8.3/src/Timer.mo +0 -62
- package/.mops/base@0.8.3/src/Trie.mo +0 -1603
- package/.mops/base@0.8.3/src/TrieMap.mo +0 -392
- package/.mops/base@0.8.3/src/TrieSet.mo +0 -148
- package/network.txt +0 -1
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// Certified data.
|
|
2
|
-
///
|
|
3
|
-
/// The Internet Computer allows canister smart contracts to store a small amount of data during
|
|
4
|
-
/// update method processing so that during query call processing, the canister can obtain
|
|
5
|
-
/// a certificate about that data.
|
|
6
|
-
///
|
|
7
|
-
/// This module provides a _low-level_ interface to this API, aimed at advanced
|
|
8
|
-
/// users and library implementors. See the Internet Computer Functional
|
|
9
|
-
/// Specification and corresponding documentation for how to use this to make query
|
|
10
|
-
/// calls to your canister tamperproof.
|
|
11
|
-
|
|
12
|
-
import Prim "mo:⛔";
|
|
13
|
-
|
|
14
|
-
module {
|
|
15
|
-
|
|
16
|
-
/// Set the certified data.
|
|
17
|
-
///
|
|
18
|
-
/// Must be called from an update method, else traps.
|
|
19
|
-
/// Must be passed a blob of at most 32 bytes, else traps.
|
|
20
|
-
public let set : (data : Blob) -> () = Prim.setCertifiedData;
|
|
21
|
-
|
|
22
|
-
/// Gets a certificate
|
|
23
|
-
///
|
|
24
|
-
/// Returns `null` if no certificate is available, e.g. when processing an
|
|
25
|
-
/// update call or inter-canister call. This returns a non-`null` value only
|
|
26
|
-
/// when processing a query call.
|
|
27
|
-
public let getCertificate : () -> ?Blob = Prim.getCertificate;
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/// Characters
|
|
2
|
-
import Prim "mo:⛔";
|
|
3
|
-
module {
|
|
4
|
-
|
|
5
|
-
/// Characters represented as Unicode code points.
|
|
6
|
-
public type Char = Prim.Types.Char;
|
|
7
|
-
|
|
8
|
-
/// Convert character `c` to a word containing its Unicode scalar value.
|
|
9
|
-
public let toNat32 : (c : Char) -> Nat32 = Prim.charToNat32;
|
|
10
|
-
|
|
11
|
-
/// Convert `w` to a character.
|
|
12
|
-
/// Traps if `w` is not a valid Unicode scalar value.
|
|
13
|
-
/// Value `w` is valid if, and only if, `w < 0xD800 or (0xE000 <= w and w <= 0x10FFFF)`.
|
|
14
|
-
public let fromNat32 : (w : Nat32) -> Char = Prim.nat32ToChar;
|
|
15
|
-
|
|
16
|
-
/// Convert character `c` to single character text.
|
|
17
|
-
public let toText : (c : Char) -> Text = Prim.charToText;
|
|
18
|
-
|
|
19
|
-
// Not exposed pending multi-char implementation.
|
|
20
|
-
private let toUpper : (c : Char) -> Char = Prim.charToUpper;
|
|
21
|
-
|
|
22
|
-
// Not exposed pending multi-char implementation.
|
|
23
|
-
private let toLower : (c : Char) -> Char = Prim.charToLower;
|
|
24
|
-
|
|
25
|
-
/// Returns `true` when `c` is a decimal digit between `0` and `9`, otherwise `false`.
|
|
26
|
-
public func isDigit(c : Char) : Bool {
|
|
27
|
-
Prim.charToNat32(c) -% Prim.charToNat32('0') <= (9 : Nat32)
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/// Returns the Unicode _White_Space_ property of `c`.
|
|
31
|
-
public let isWhitespace : (c : Char) -> Bool = Prim.charIsWhitespace;
|
|
32
|
-
|
|
33
|
-
/// Returns the Unicode _Lowercase_ property of `c`.
|
|
34
|
-
public let isLowercase : (c : Char) -> Bool = Prim.charIsLowercase;
|
|
35
|
-
|
|
36
|
-
/// Returns the Unicode _Uppercase_ property of `c`.
|
|
37
|
-
public let isUppercase : (c : Char) -> Bool = Prim.charIsUppercase;
|
|
38
|
-
|
|
39
|
-
/// Returns the Unicode _Alphabetic_ property of `c`.
|
|
40
|
-
public let isAlphabetic : (c : Char) -> Bool = Prim.charIsAlphabetic;
|
|
41
|
-
|
|
42
|
-
/// Returns `x == y`.
|
|
43
|
-
public func equal(x : Char, y : Char) : Bool { x == y };
|
|
44
|
-
|
|
45
|
-
/// Returns `x != y`.
|
|
46
|
-
public func notEqual(x : Char, y : Char) : Bool { x != y };
|
|
47
|
-
|
|
48
|
-
/// Returns `x < y`.
|
|
49
|
-
public func less(x : Char, y : Char) : Bool { x < y };
|
|
50
|
-
|
|
51
|
-
/// Returns `x <= y`.
|
|
52
|
-
public func lessOrEqual(x : Char, y : Char) : Bool { x <= y };
|
|
53
|
-
|
|
54
|
-
/// Returns `x > y`.
|
|
55
|
-
public func greater(x : Char, y : Char) : Bool { x > y };
|
|
56
|
-
|
|
57
|
-
/// Returns `x >= y`.
|
|
58
|
-
public func greaterOrEqual(x : Char, y : Char) : Bool { x >= y };
|
|
59
|
-
|
|
60
|
-
/// Returns the order of `x` and `y`.
|
|
61
|
-
public func compare(x : Char, y : Char) : { #less; #equal; #greater } {
|
|
62
|
-
if (x < y) { #less }
|
|
63
|
-
else if (x == y) { #equal }
|
|
64
|
-
else { #greater }
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// Debugging aids
|
|
2
|
-
|
|
3
|
-
import Prim "mo:⛔";
|
|
4
|
-
module {
|
|
5
|
-
|
|
6
|
-
/// `print(t)` emits text `t` to the debug output stream.
|
|
7
|
-
/// How this stream is stored or displayed depends on the
|
|
8
|
-
/// execution environment.
|
|
9
|
-
public let print : Text -> () = Prim.debugPrint;
|
|
10
|
-
|
|
11
|
-
/// `trap(t)` traps execution with a user-provided message.
|
|
12
|
-
public let trap : Text -> None = Prim.trap;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/// Functions for persistent, double-ended queues.
|
|
2
|
-
|
|
3
|
-
import List "List";
|
|
4
|
-
import P "Prelude";
|
|
5
|
-
|
|
6
|
-
module {
|
|
7
|
-
type List<T> = List.List<T>;
|
|
8
|
-
|
|
9
|
-
/// Double-ended queue
|
|
10
|
-
public type Deque<T> = (List<T>, List<T>);
|
|
11
|
-
|
|
12
|
-
/// Empty queue
|
|
13
|
-
public func empty<T> () : Deque<T> { (List.nil(), List.nil()); };
|
|
14
|
-
|
|
15
|
-
/// True when the queue is empty
|
|
16
|
-
public func isEmpty<T>(q : Deque<T>) : Bool {
|
|
17
|
-
switch q {
|
|
18
|
-
case (f, r) { List.isNil(f) and List.isNil(r) };
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
func check<T>(q : Deque<T>) : Deque<T> {
|
|
23
|
-
switch q {
|
|
24
|
-
case (null, r) { let (a,b) = List.split(List.size(r) / 2, r); (List.reverse(b), a) };
|
|
25
|
-
case (f, null) { let (a,b) = List.split(List.size(f) / 2, f); (a, List.reverse(b)) };
|
|
26
|
-
case q { q };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/// Insert a new element on the front end of the queue
|
|
31
|
-
public func pushFront<T>(q : Deque<T>, x : T) : Deque<T> {
|
|
32
|
-
check (List.push(x, q.0), q.1);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/// Inspect the (optional) first element on the front end of the queue
|
|
36
|
-
public func peekFront<T>(q : Deque<T>) : ?T {
|
|
37
|
-
switch q {
|
|
38
|
-
case (?(x, f), r) { ?x };
|
|
39
|
-
case (null, ?(x, r)) { ?x };
|
|
40
|
-
case _ { null };
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/// Remove the first element on the front end of the queue; Returns null when empty.
|
|
45
|
-
public func popFront<T>(q : Deque<T>) : ?(T, Deque<T>) {
|
|
46
|
-
switch q {
|
|
47
|
-
case (?(x, f), r) { ?(x, check(f, r)) };
|
|
48
|
-
case (null, ?(x, r)) { ?(x, check(null, r)) };
|
|
49
|
-
case _ { null };
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/// Insert a new element on the back end of the queue
|
|
54
|
-
public func pushBack<T>(q : Deque<T>, x : T) : Deque<T> {
|
|
55
|
-
check (q.0, List.push(x, q.1));
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/// Inspect the (optional) first element on the back end of the queue
|
|
59
|
-
public func peekBack<T>(q : Deque<T>) : ?T {
|
|
60
|
-
switch q {
|
|
61
|
-
case (f, ?(x, r)) { ?x };
|
|
62
|
-
case (?(x, r), null) { ?x };
|
|
63
|
-
case _ { null };
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/// Remove the first element on the back end of the queue; Returns null when empty.
|
|
68
|
-
public func popBack<T>(q : Deque<T>) : ?(Deque<T>, T) {
|
|
69
|
-
switch q {
|
|
70
|
-
case (f, ?(x, r)) { ?(check(f, r), x) };
|
|
71
|
-
case (?(x, f), null) { ?(check(f, null), x) };
|
|
72
|
-
case _ { null };
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/// Error values and inspection.
|
|
2
|
-
///
|
|
3
|
-
/// The `Error` type is the argument to `throw`, parameter of `catch`.
|
|
4
|
-
/// The `Error` type is opaque.
|
|
5
|
-
|
|
6
|
-
import Prim "mo:⛔";
|
|
7
|
-
|
|
8
|
-
module {
|
|
9
|
-
|
|
10
|
-
/// Error values resulting from `async` computations
|
|
11
|
-
public type Error = Prim.Types.Error;
|
|
12
|
-
|
|
13
|
-
/// Error codes (user and system), where module `Prim` defines:
|
|
14
|
-
/// ```motoko
|
|
15
|
-
/// type ErrorCode = {
|
|
16
|
-
/// // Fatal error.
|
|
17
|
-
/// #system_fatal;
|
|
18
|
-
/// // Transient error.
|
|
19
|
-
/// #system_transient;
|
|
20
|
-
/// // Destination invalid.
|
|
21
|
-
/// #destination_invalid;
|
|
22
|
-
/// // Explicit reject by canister code.
|
|
23
|
-
/// #canister_reject;
|
|
24
|
-
/// // Canister trapped.
|
|
25
|
-
/// #canister_error;
|
|
26
|
-
/// // Future error code (with unrecognized numeric code)
|
|
27
|
-
/// #future : Nat32;
|
|
28
|
-
/// };
|
|
29
|
-
/// ```
|
|
30
|
-
public type ErrorCode = Prim.ErrorCode;
|
|
31
|
-
|
|
32
|
-
/// Create an error from message `m` with code #canister_reject.
|
|
33
|
-
public let reject : (m : Text) -> Error = Prim.error;
|
|
34
|
-
|
|
35
|
-
/// Returns the code of an error `e`.
|
|
36
|
-
public let code : (e : Error) -> ErrorCode = Prim.errorCode;
|
|
37
|
-
|
|
38
|
-
/// Returns the message of an error `e`.
|
|
39
|
-
public let message : (e : Error) -> Text = Prim.errorMessage;
|
|
40
|
-
|
|
41
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/// Managing cycles
|
|
2
|
-
///
|
|
3
|
-
/// Usage of the Internet Computer is measured, and paid for, in _cycles_.
|
|
4
|
-
/// This library provides imperative operations for observing cycles, transferring cycles and
|
|
5
|
-
/// observing refunds of cycles.
|
|
6
|
-
///
|
|
7
|
-
/// **WARNING:** This low-level API is **experimental** and likely to change or even disappear.
|
|
8
|
-
/// Dedicated syntactic support for manipulating cycles may be added to the language in future, obsoleting this library.
|
|
9
|
-
///
|
|
10
|
-
/// **NOTE:** Since cycles measure computational resources, the value of
|
|
11
|
-
/// `balance()` can change from one call to the next.
|
|
12
|
-
|
|
13
|
-
import Prim "mo:⛔";
|
|
14
|
-
module {
|
|
15
|
-
|
|
16
|
-
/// Returns the actor's current balance of cycles as `amount`.
|
|
17
|
-
public let balance : () -> (amount : Nat) = Prim.cyclesBalance;
|
|
18
|
-
|
|
19
|
-
/// Returns the currently available `amount` of cycles.
|
|
20
|
-
/// The amount available is the amount received in the current call,
|
|
21
|
-
/// minus the cumulative amount `accept`ed by this call.
|
|
22
|
-
/// On exit from the current shared function or async expression via `return` or `throw`
|
|
23
|
-
/// any remaining available amount is automatically
|
|
24
|
-
/// refunded to the caller/context.
|
|
25
|
-
public let available : () -> (amount : Nat) = Prim.cyclesAvailable;
|
|
26
|
-
|
|
27
|
-
/// Transfers up to `amount` from `available()` to `balance()`.
|
|
28
|
-
/// Returns the amount actually transferred, which may be less than
|
|
29
|
-
/// requested, for example, if less is available, or if canister balance limits are reached.
|
|
30
|
-
public let accept : (amount : Nat) -> (accepted : Nat) = Prim.cyclesAccept;
|
|
31
|
-
|
|
32
|
-
/// Indicates additional `amount` of cycles to be transferred in
|
|
33
|
-
/// the next call, that is, evaluation of a shared function call or
|
|
34
|
-
/// async expression.
|
|
35
|
-
/// Traps if the current total would exceed 2^128 cycles.
|
|
36
|
-
/// Upon the call, but not before, the total amount of cycles ``add``ed since
|
|
37
|
-
/// the last call is deducted from `balance()`.
|
|
38
|
-
/// If this total exceeds `balance()`, the caller traps, aborting the call.
|
|
39
|
-
///
|
|
40
|
-
/// **Note**: the implicit register of added amounts is reset to zero on entry to
|
|
41
|
-
/// a shared function and after each shared function call or resume from an await.
|
|
42
|
-
public let add : (amount : Nat) -> () = Prim.cyclesAdd;
|
|
43
|
-
|
|
44
|
-
/// Reports `amount` of cycles refunded in the last `await` of the current
|
|
45
|
-
/// context, or zero if no await has occurred yet.
|
|
46
|
-
/// Calling `refunded()` is solely informational and does not affect `balance()`.
|
|
47
|
-
/// Instead, refunds are automatically added to the current balance,
|
|
48
|
-
/// whether or not `refunded` is used to observe them.
|
|
49
|
-
public let refunded : () -> (amount : Nat) = Prim.cyclesRefunded;
|
|
50
|
-
|
|
51
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/// Low-level interface to the Internet Computer.
|
|
2
|
-
///
|
|
3
|
-
/// **WARNING:** This low-level API is **experimental** and likely to change or even disappear.
|
|
4
|
-
|
|
5
|
-
import Prim "mo:⛔";
|
|
6
|
-
|
|
7
|
-
module {
|
|
8
|
-
|
|
9
|
-
/// Calls ``canister``'s update or query function, `name`, with the binary contents of `data` as IC argument.
|
|
10
|
-
/// Returns the response to the call, an IC _reply_ or _reject_, as a Motoko future:
|
|
11
|
-
///
|
|
12
|
-
/// * The message data of an IC reply determines the binary contents of `reply`.
|
|
13
|
-
/// * The error code and textual message data of an IC reject determines the future's `Error` value.
|
|
14
|
-
///
|
|
15
|
-
/// Note: `call` is an asynchronous function and can only be applied in an asynchronous context.
|
|
16
|
-
public let call : (canister : Principal, name : Text, data : Blob) ->
|
|
17
|
-
async (reply : Blob) = Prim.call_raw;
|
|
18
|
-
|
|
19
|
-
/// Given computation, `comp`, counts the number of actual and (for IC system calls) notional WebAssembly
|
|
20
|
-
/// instructions performed during the execution of `comp()`.
|
|
21
|
-
///
|
|
22
|
-
/// More precisely, returns the difference between the state of the IC instruction counter (_performance counter_ `0`) before and after executing `comp()`
|
|
23
|
-
/// (see [Performance Counter](https://internetcomputer.org/docs/current/references/ic-interface-spec#system-api-performance-counter)).
|
|
24
|
-
///
|
|
25
|
-
/// NB: `countInstructions(comp)` will _not_ account for any deferred garbage collection costs incurred by `comp()`.
|
|
26
|
-
public func countInstructions(comp : () -> ()) : Nat64 {
|
|
27
|
-
let init = Prim.performanceCounter(0);
|
|
28
|
-
let pre = Prim.performanceCounter(0);
|
|
29
|
-
comp();
|
|
30
|
-
let post = Prim.performanceCounter(0);
|
|
31
|
-
// performance_counter costs around 200 extra instructions, we perform an empty measurement to decide the overhead
|
|
32
|
-
let overhead = pre - init;
|
|
33
|
-
post - pre - overhead
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/// Byte-level access to (virtual) _stable memory_.
|
|
2
|
-
///
|
|
3
|
-
/// **WARNING**: As its name suggests, this library is **experimental**, subject to change
|
|
4
|
-
/// and may be replaced by safer alternatives in later versions of Motoko.
|
|
5
|
-
/// Use at your own risk and discretion.
|
|
6
|
-
///
|
|
7
|
-
/// This is a lightweight abstraction over IC _stable memory_ and supports persisting
|
|
8
|
-
/// raw binary data across Motoko upgrades.
|
|
9
|
-
/// Use of this module is fully compatible with Motoko's use of
|
|
10
|
-
/// _stable variables_, whose persistence mechanism also uses (real) IC stable memory internally, but does not interfere with this API.
|
|
11
|
-
///
|
|
12
|
-
/// Memory is allocated, using `grow(pages)`, sequentially and on demand, in units of 64KiB pages, starting with 0 allocated pages.
|
|
13
|
-
/// New pages are zero initialized.
|
|
14
|
-
/// Growth is capped by a soft limit on page count controlled by compile-time flag
|
|
15
|
-
/// `--max-stable-pages <n>` (the default is 65536, or 4GiB).
|
|
16
|
-
///
|
|
17
|
-
/// Each `load` operation loads from byte address `offset` in little-endian
|
|
18
|
-
/// format using the natural bit-width of the type in question.
|
|
19
|
-
/// The operation traps if attempting to read beyond the current stable memory size.
|
|
20
|
-
///
|
|
21
|
-
/// Each `store` operation stores to byte address `offset` in little-endian format using the natural bit-width of the type in question.
|
|
22
|
-
/// The operation traps if attempting to write beyond the current stable memory size.
|
|
23
|
-
///
|
|
24
|
-
/// Text values can be handled by using `Text.decodeUtf8` and `Text.encodeUtf8`, in conjunction with `loadBlob` and `storeBlob`.
|
|
25
|
-
///
|
|
26
|
-
/// The current page allocation and page contents is preserved across upgrades.
|
|
27
|
-
///
|
|
28
|
-
/// NB: The IC's actual stable memory size (`ic0.stable_size`) may exceed the
|
|
29
|
-
/// page size reported by Motoko function `size()`.
|
|
30
|
-
/// This (and the cap on growth) are to accommodate Motoko's stable variables.
|
|
31
|
-
/// Applications that plan to use Motoko stable variables sparingly or not at all can
|
|
32
|
-
/// increase `--max-stable-pages` as desired, approaching the IC maximum (currently 8GiB).
|
|
33
|
-
/// All applications should reserve at least one page for stable variable data, even when no stable variables are used.
|
|
34
|
-
|
|
35
|
-
import Prim "mo:⛔";
|
|
36
|
-
|
|
37
|
-
module {
|
|
38
|
-
|
|
39
|
-
/// Current size of the stable memory, in pages.
|
|
40
|
-
/// Each page is 64KiB (65536 bytes).
|
|
41
|
-
/// Initially `0`.
|
|
42
|
-
/// Preserved across upgrades, together with contents of allocated
|
|
43
|
-
/// stable memory.
|
|
44
|
-
public let size : () -> (pages : Nat64) =
|
|
45
|
-
Prim.stableMemorySize;
|
|
46
|
-
|
|
47
|
-
/// Grow current `size` of stable memory by `pagecount` pages.
|
|
48
|
-
/// Each page is 64KiB (65536 bytes).
|
|
49
|
-
/// Returns previous `size` when able to grow.
|
|
50
|
-
/// Returns `0xFFFF_FFFF_FFFF_FFFF` if remaining pages insufficient.
|
|
51
|
-
/// Every new page is zero-initialized, containing byte 0 at every offset.
|
|
52
|
-
/// Function `grow` is capped by a soft limit on `size` controlled by compile-time flag
|
|
53
|
-
/// `--max-stable-pages <n>` (the default is 65536, or 4GiB).
|
|
54
|
-
public let grow : (new_pages : Nat64) -> (oldpages : Nat64) =
|
|
55
|
-
Prim.stableMemoryGrow;
|
|
56
|
-
|
|
57
|
-
/// Returns a query that, when called, returns the number of bytes of (real) IC stable memory that would be
|
|
58
|
-
/// occupied by persisting its current stable variables before an upgrade.
|
|
59
|
-
/// This function may be used to monitor or limit real stable memory usage.
|
|
60
|
-
/// The query computes the estimate by running the first half of an upgrade, including any `preupgrade` system method.
|
|
61
|
-
/// Like any other query, its state changes are discarded so no actual upgrade (or other state change) takes place.
|
|
62
|
-
/// The query can only be called by the enclosing actor and will trap for other callers.
|
|
63
|
-
public let stableVarQuery : () -> (shared query () -> async {size : Nat64}) =
|
|
64
|
-
Prim.stableVarQuery;
|
|
65
|
-
|
|
66
|
-
public let loadNat32 : (offset : Nat64) -> Nat32 =
|
|
67
|
-
Prim.stableMemoryLoadNat32;
|
|
68
|
-
public let storeNat32 : (offset : Nat64, value: Nat32) -> () =
|
|
69
|
-
Prim.stableMemoryStoreNat32;
|
|
70
|
-
|
|
71
|
-
public let loadNat8 : (offset : Nat64) -> Nat8 =
|
|
72
|
-
Prim.stableMemoryLoadNat8;
|
|
73
|
-
public let storeNat8 : (offset : Nat64, value : Nat8) -> () =
|
|
74
|
-
Prim.stableMemoryStoreNat8;
|
|
75
|
-
|
|
76
|
-
public let loadNat16 : (offset : Nat64) -> Nat16 =
|
|
77
|
-
Prim.stableMemoryLoadNat16;
|
|
78
|
-
public let storeNat16 : (offset : Nat64, value : Nat16) -> () =
|
|
79
|
-
Prim.stableMemoryStoreNat16;
|
|
80
|
-
|
|
81
|
-
public let loadNat64 : (offset : Nat64) -> Nat64 =
|
|
82
|
-
Prim.stableMemoryLoadNat64;
|
|
83
|
-
public let storeNat64 : (offset : Nat64, value : Nat64) -> () =
|
|
84
|
-
Prim.stableMemoryStoreNat64;
|
|
85
|
-
|
|
86
|
-
public let loadInt32 : (offset : Nat64) -> Int32 =
|
|
87
|
-
Prim.stableMemoryLoadInt32;
|
|
88
|
-
public let storeInt32 : (offset : Nat64, value : Int32) -> () =
|
|
89
|
-
Prim.stableMemoryStoreInt32;
|
|
90
|
-
|
|
91
|
-
public let loadInt8 : (offset : Nat64) -> Int8 =
|
|
92
|
-
Prim.stableMemoryLoadInt8;
|
|
93
|
-
public let storeInt8 : (offset : Nat64, value : Int8) -> () =
|
|
94
|
-
Prim.stableMemoryStoreInt8;
|
|
95
|
-
|
|
96
|
-
public let loadInt16 : (offset : Nat64) -> Int16 =
|
|
97
|
-
Prim.stableMemoryLoadInt16;
|
|
98
|
-
public let storeInt16 : (offset : Nat64, value : Int16) -> () =
|
|
99
|
-
Prim.stableMemoryStoreInt16;
|
|
100
|
-
|
|
101
|
-
public let loadInt64 : (offset : Nat64) -> Int64 =
|
|
102
|
-
Prim.stableMemoryLoadInt64;
|
|
103
|
-
public let storeInt64 : (offset : Nat64, value : Int64) -> () =
|
|
104
|
-
Prim.stableMemoryStoreInt64;
|
|
105
|
-
|
|
106
|
-
public let loadFloat : (offset : Nat64) -> Float =
|
|
107
|
-
Prim.stableMemoryLoadFloat;
|
|
108
|
-
public let storeFloat : (offset : Nat64, value : Float) -> () =
|
|
109
|
-
Prim.stableMemoryStoreFloat;
|
|
110
|
-
|
|
111
|
-
/// Load `size` bytes starting from `offset` as a `Blob`.
|
|
112
|
-
/// Traps on out-of-bounds access.
|
|
113
|
-
public let loadBlob : (offset : Nat64, size : Nat) -> Blob =
|
|
114
|
-
Prim.stableMemoryLoadBlob;
|
|
115
|
-
|
|
116
|
-
/// Write bytes of `blob` beginning at `offset`.
|
|
117
|
-
/// Traps on out-of-bounds access.
|
|
118
|
-
public let storeBlob : (offset : Nat64, value : Blob) -> () =
|
|
119
|
-
Prim.stableMemoryStoreBlob;
|
|
120
|
-
|
|
121
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/// 64-bit Floating-point numbers
|
|
2
|
-
|
|
3
|
-
import Prim "mo:⛔";
|
|
4
|
-
import Int "Int";
|
|
5
|
-
|
|
6
|
-
module {
|
|
7
|
-
|
|
8
|
-
/// 64-bit floating point numbers.
|
|
9
|
-
public type Float = Prim.Types.Float;
|
|
10
|
-
|
|
11
|
-
/// Ratio of the circumference of a circle to its diameter.
|
|
12
|
-
public let pi : Float = 3.14159265358979323846; // taken from musl math.h
|
|
13
|
-
|
|
14
|
-
/// Base of the natural logarithm.
|
|
15
|
-
public let e : Float = 2.7182818284590452354; // taken from musl math.h
|
|
16
|
-
|
|
17
|
-
/// Returns the absolute value of `x`.
|
|
18
|
-
public let abs : (x : Float) -> Float = Prim.floatAbs;
|
|
19
|
-
|
|
20
|
-
/// Returns the square root of `x`.
|
|
21
|
-
public let sqrt : (x : Float) -> Float = Prim.floatSqrt;
|
|
22
|
-
|
|
23
|
-
/// Returns the smallest integral float greater than or equal to `x`.
|
|
24
|
-
public let ceil : (x : Float) -> Float = Prim.floatCeil;
|
|
25
|
-
|
|
26
|
-
/// Returns the largest integral float less than or equal to `x`.
|
|
27
|
-
public let floor : (x : Float) -> Float = Prim.floatFloor;
|
|
28
|
-
|
|
29
|
-
/// Returns the nearest integral float not greater in magnitude than `x`.
|
|
30
|
-
public let trunc : (x : Float) -> Float = Prim.floatTrunc;
|
|
31
|
-
|
|
32
|
-
/// Returns the nearest integral float to `x`.
|
|
33
|
-
public let nearest : (x : Float) -> Float = Prim.floatNearest;
|
|
34
|
-
|
|
35
|
-
/// Returns `x` if `x` and `y` have same sign, otherwise `x` with negated sign.
|
|
36
|
-
public let copySign : (x : Float, y : Float) -> Float = Prim.floatCopySign;
|
|
37
|
-
|
|
38
|
-
/// Returns the smaller value of `x` and `y`.
|
|
39
|
-
public let min : (x : Float, y : Float) -> Float = Prim.floatMin;
|
|
40
|
-
|
|
41
|
-
/// Returns the larger value of `x` and `y`.
|
|
42
|
-
public let max : (x : Float, y : Float) -> Float = Prim.floatMax;
|
|
43
|
-
|
|
44
|
-
/// Returns the sine of the radian angle `x`.
|
|
45
|
-
public let sin : (x : Float) -> Float = Prim.sin;
|
|
46
|
-
|
|
47
|
-
/// Returns the cosine of the radian angle `x`.
|
|
48
|
-
public let cos : (x : Float) -> Float = Prim.cos;
|
|
49
|
-
|
|
50
|
-
/// Returns the tangent of the radian angle `x`.
|
|
51
|
-
public let tan : (x : Float) -> Float = Prim.tan;
|
|
52
|
-
|
|
53
|
-
/// Returns the arc sine of `x` in radians.
|
|
54
|
-
public let arcsin: (x : Float) -> Float = Prim.arcsin;
|
|
55
|
-
|
|
56
|
-
/// Returns the arc cosine of `x` in radians.
|
|
57
|
-
public let arccos : (x : Float) -> Float = Prim.arccos;
|
|
58
|
-
|
|
59
|
-
/// Returns the arc tangent of `x` in radians.
|
|
60
|
-
public let arctan : (x : Float) -> Float = Prim.arctan;
|
|
61
|
-
|
|
62
|
-
/// Given `(y,x)`, returns the arc tangent in radians of `y/x` based on the signs of both values to determine the correct quadrant.
|
|
63
|
-
public let arctan2 : (y : Float, x : Float) -> Float = Prim.arctan2;
|
|
64
|
-
|
|
65
|
-
/// Returns the value of `e` raised to the `x`-th power.
|
|
66
|
-
public let exp : (x : Float) -> Float = Prim.exp;
|
|
67
|
-
|
|
68
|
-
/// Returns the natural logarithm (base-`e`) of `x`.
|
|
69
|
-
public let log : (x : Float) -> Float = Prim.log;
|
|
70
|
-
|
|
71
|
-
/// Formatting. `format(fmt, x)` formats `x` to `Text` according to the
|
|
72
|
-
/// formatting directive `fmt`, which can take one of the following forms:
|
|
73
|
-
///
|
|
74
|
-
/// * `#fix prec` as fixed-point format with `prec` digits
|
|
75
|
-
/// * `#exp prec` as exponential format with `prec` digits
|
|
76
|
-
/// * `#gen prec` as generic format with `prec` digits
|
|
77
|
-
/// * `#hex prec` as hexadecimal format with `prec` digits
|
|
78
|
-
/// * `#exact` as exact format that can be decoded without loss.
|
|
79
|
-
public func format
|
|
80
|
-
(fmt : { #fix : Nat8; #exp : Nat8; #gen : Nat8; #hex : Nat8; #exact }, x : Float) : Text =
|
|
81
|
-
switch fmt {
|
|
82
|
-
case (#fix(prec)) { Prim.floatToFormattedText(x, prec, 0) };
|
|
83
|
-
case (#exp(prec)) { Prim.floatToFormattedText(x, prec, 1) };
|
|
84
|
-
case (#gen(prec)) { Prim.floatToFormattedText(x, prec, 2) };
|
|
85
|
-
case (#hex(prec)) { Prim.floatToFormattedText(x, prec, 3) };
|
|
86
|
-
case (#exact) { Prim.floatToFormattedText(x, 17, 2) };
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/// Conversion to Text. Use `format(fmt, x)` for more detailed control.
|
|
90
|
-
public let toText : Float -> Text = Prim.floatToText;
|
|
91
|
-
|
|
92
|
-
/// Conversion to Int64 by truncating Float, equivalent to `toInt64(trunc(f))`
|
|
93
|
-
public let toInt64 : Float -> Int64 = Prim.floatToInt64;
|
|
94
|
-
|
|
95
|
-
/// Conversion from Int64.
|
|
96
|
-
public let fromInt64 : Int64 -> Float = Prim.int64ToFloat;
|
|
97
|
-
|
|
98
|
-
/// Conversion to Int.
|
|
99
|
-
public let toInt : Float -> Int = Prim.floatToInt;
|
|
100
|
-
|
|
101
|
-
/// Conversion from Int. May result in `Inf`.
|
|
102
|
-
public let fromInt : Int -> Float = Prim.intToFloat;
|
|
103
|
-
|
|
104
|
-
/// Returns `x == y`.
|
|
105
|
-
public func equal(x : Float, y : Float) : Bool { x == y };
|
|
106
|
-
|
|
107
|
-
/// Returns `x != y`.
|
|
108
|
-
public func notEqual(x : Float, y : Float) : Bool { x != y };
|
|
109
|
-
|
|
110
|
-
/// Returns `x < y`.
|
|
111
|
-
public func less(x : Float, y : Float) : Bool { x < y };
|
|
112
|
-
|
|
113
|
-
/// Returns `x <= y`.
|
|
114
|
-
public func lessOrEqual(x : Float, y : Float) : Bool { x <= y };
|
|
115
|
-
|
|
116
|
-
/// Returns `x > y`.
|
|
117
|
-
public func greater(x : Float, y : Float) : Bool { x > y };
|
|
118
|
-
|
|
119
|
-
/// Returns `x >= y`.
|
|
120
|
-
public func greaterOrEqual(x : Float, y : Float) : Bool { x >= y };
|
|
121
|
-
|
|
122
|
-
/// Returns the order of `x` and `y`.
|
|
123
|
-
public func compare(x : Float, y : Float) : { #less; #equal; #greater} {
|
|
124
|
-
if (x < y) { #less }
|
|
125
|
-
else if (x == y) { #equal }
|
|
126
|
-
else { #greater }
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/// Returns the negation of `x`, `-x` .
|
|
130
|
-
public func neq(x : Float) : Float { -x; };
|
|
131
|
-
|
|
132
|
-
/// Returns the sum of `x` and `y`, `x + y`.
|
|
133
|
-
public func add(x : Float, y : Float) : Float { x + y };
|
|
134
|
-
|
|
135
|
-
/// Returns the difference of `x` and `y`, `x - y`.
|
|
136
|
-
public func sub(x : Float, y : Float) : Float { x - y };
|
|
137
|
-
|
|
138
|
-
/// Returns the product of `x` and `y`, `x * y`.
|
|
139
|
-
public func mul(x : Float, y : Float) : Float { x * y };
|
|
140
|
-
|
|
141
|
-
/// Returns the division of `x` by `y`, `x / y`.
|
|
142
|
-
public func div(x : Float, y : Float) : Float { x / y };
|
|
143
|
-
|
|
144
|
-
/// Returns the remainder of `x` divided by `y`, `x % y`.
|
|
145
|
-
public func rem(x : Float, y : Float) : Float { x % y };
|
|
146
|
-
|
|
147
|
-
/// Returns `x` to the power of `y`, `x ** y`.
|
|
148
|
-
public func pow(x : Float, y : Float) : Float { x ** y };
|
|
149
|
-
|
|
150
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/// Functions on functions
|
|
2
|
-
///
|
|
3
|
-
/// (Most commonly used when programming in functional style using higher-order
|
|
4
|
-
/// functions.)
|
|
5
|
-
|
|
6
|
-
module {
|
|
7
|
-
|
|
8
|
-
/// The composition of two functions `f` and `g` is a function that applies `g` and then `f`.
|
|
9
|
-
///
|
|
10
|
-
/// ```
|
|
11
|
-
/// compose(f, g)(x) = f(g(x))
|
|
12
|
-
/// ```
|
|
13
|
-
public func compose<A, B, C>(f : B -> C, g : A -> B) : A -> C {
|
|
14
|
-
func (x : A) : C {
|
|
15
|
-
f(g(x));
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/// The `identity` function returns its argument.
|
|
20
|
-
/// ```motoko
|
|
21
|
-
/// import Func "mo:base/Func";
|
|
22
|
-
/// assert(Func.identity(10) == 10);
|
|
23
|
-
/// assert(Func.identity(true) == true);
|
|
24
|
-
/// ```
|
|
25
|
-
public func identity<A>(x : A) : A = x;
|
|
26
|
-
|
|
27
|
-
/// The const function is a _curried_ function that accepts an argument `x`,
|
|
28
|
-
/// and then returns a function that discards its argument and always returns
|
|
29
|
-
/// the `x`.
|
|
30
|
-
///
|
|
31
|
-
/// ```motoko
|
|
32
|
-
/// import Func "mo:base/Func";
|
|
33
|
-
/// assert(Func.const<Nat, Text>(10)("hello") == 10);
|
|
34
|
-
/// assert(Func.const<Bool, Nat>(true)(20) == true);
|
|
35
|
-
/// ```
|
|
36
|
-
public func const<A, B>(x : A) : B -> A =
|
|
37
|
-
func (_) = x;
|
|
38
|
-
}
|