Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/om/quantity/quantity.om # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / om / quantity / quantity.om` 142 lines ยท 2504 bytes Raw Blame History 1 note SC1-Q API and status contract frozen in README.md. Raw structs are trusted not sealed. 2 struct qty val ulong cap ulong end 3 struct qobj ident ulong ver ulong extent ulong end 4 struct qslic ident ulong ver ulong off ulong count ulong end 5 6 fn qword out edit qty raw ulong cap ulong to int 7 if gt raw cap 8 ret int 3 9 end 10 put out val raw 11 put out cap cap 12 ret int 0 13 end 14 15 fn qsigned out edit qty raw long cap ulong to int 16 if lt raw long 0 17 ret int 2 18 end 19 ret qword out ulong raw cap 20 end 21 22 fn qvalid a view qty to int 23 if gt get a val get a cap 24 ret int 1 25 end 26 ret int 0 27 end 28 29 fn qpair a view qty b view qty to int 30 if ne qvalid a int 0 31 ret int 1 32 end 33 if ne qvalid b int 0 34 ret int 1 35 end 36 if ne get a cap get b cap 37 ret int 2 38 end 39 ret int 0 40 end 41 42 fn qadd out edit qty a view qty b view qty to int 43 rc = qpair a b 44 if ne rc int 0 45 ret rc 46 end 47 note Q1_ADD_GUARD mutation removes this check only. 48 if gt get b val sub get a cap get a val 49 ret int 3 50 end 51 put out val add get a val get b val 52 put out cap get a cap 53 ret int 0 54 end 55 56 fn qsub out edit qty a view qty b view qty to int 57 rc = qpair a b 58 if ne rc int 0 59 ret rc 60 end 61 if gt get b val get a val 62 ret int 3 63 end 64 put out val sub get a val get b val 65 put out cap get a cap 66 ret int 0 67 end 68 69 fn qmul out edit qty a view qty b view qty to int 70 rc = qpair a b 71 if ne rc int 0 72 ret rc 73 end 74 note Q4_MUL_GUARD mutation removes this check only. 75 if ne get a val ulong 0 76 if gt get b val div get a cap get a val 77 ret int 3 78 end 79 end 80 put out val mul get a val get b val 81 put out cap get a cap 82 ret int 0 83 end 84 85 fn qnarrow out edit qty a view qty cap ulong to int 86 rc = qvalid a 87 if ne rc int 0 88 ret rc 89 end 90 if gt cap get a cap 91 ret int 2 92 end 93 if gt get a val cap 94 ret int 3 95 end 96 put out val get a val 97 put out cap cap 98 ret int 0 99 end 100 101 fn qnext out edit qty a view qty to int 102 rc = qvalid a 103 if ne rc int 0 104 ret rc 105 end 106 if eq get a val get a cap 107 ret int 3 108 end 109 put out val add get a val ulong 1 110 put out cap get a cap 111 ret int 0 112 end 113 114 fn qtyslice out edit qslic off view qty count view qty expect view qobj current view qobj to int 115 if ne get expect ident get current ident 116 ret int 4 117 end 118 if ne get expect ver get current ver 119 ret int 4 120 end 121 if ne get expect extent get current extent 122 ret int 4 123 end 124 rc = qpair off count 125 if ne rc int 0 126 ret rc 127 end 128 if ne get off cap get current extent 129 ret int 2 130 end 131 if gt get off val get current extent 132 ret int 3 133 end 134 if gt get count val sub get current extent get off val 135 ret int 3 136 end 137 put out ident get current ident 138 put out ver get current ver 139 put out off get off val 140 put out count get count val 141 ret int 0 142 end