interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / quantity / quantity.om

142 lines · 2504 bytes Raw Blame History
1note SC1-Q API and status contract frozen in README.md. Raw structs are trusted not sealed.
2struct qty val ulong cap ulong end
3struct qobj ident ulong ver ulong extent ulong end
4struct qslic ident ulong ver ulong off ulong count ulong end
5
6fn qword out edit qty raw ulong cap ulong to int
7if gt raw cap
8ret int 3
9end
10put out val raw
11put out cap cap
12ret int 0
13end
14
15fn qsigned out edit qty raw long cap ulong to int
16if lt raw long 0
17ret int 2
18end
19ret qword out ulong raw cap
20end
21
22fn qvalid a view qty to int
23if gt get a val get a cap
24ret int 1
25end
26ret int 0
27end
28
29fn qpair a view qty b view qty to int
30if ne qvalid a int 0
31ret int 1
32end
33if ne qvalid b int 0
34ret int 1
35end
36if ne get a cap get b cap
37ret int 2
38end
39ret int 0
40end
41
42fn qadd out edit qty a view qty b view qty to int
43rc = qpair a b
44if ne rc int 0
45ret rc
46end
47note Q1_ADD_GUARD mutation removes this check only.
48if gt get b val sub get a cap get a val
49ret int 3
50end
51put out val add get a val get b val
52put out cap get a cap
53ret int 0
54end
55
56fn qsub out edit qty a view qty b view qty to int
57rc = qpair a b
58if ne rc int 0
59ret rc
60end
61if gt get b val get a val
62ret int 3
63end
64put out val sub get a val get b val
65put out cap get a cap
66ret int 0
67end
68
69fn qmul out edit qty a view qty b view qty to int
70rc = qpair a b
71if ne rc int 0
72ret rc
73end
74note Q4_MUL_GUARD mutation removes this check only.
75if ne get a val ulong 0
76if gt get b val div get a cap get a val
77ret int 3
78end
79end
80put out val mul get a val get b val
81put out cap get a cap
82ret int 0
83end
84
85fn qnarrow out edit qty a view qty cap ulong to int
86rc = qvalid a
87if ne rc int 0
88ret rc
89end
90if gt cap get a cap
91ret int 2
92end
93if gt get a val cap
94ret int 3
95end
96put out val get a val
97put out cap cap
98ret int 0
99end
100
101fn qnext out edit qty a view qty to int
102rc = qvalid a
103if ne rc int 0
104ret rc
105end
106if eq get a val get a cap
107ret int 3
108end
109put out val add get a val ulong 1
110put out cap get a cap
111ret int 0
112end
113
114fn qtyslice out edit qslic off view qty count view qty expect view qobj current view qobj to int
115if ne get expect ident get current ident
116ret int 4
117end
118if ne get expect ver get current ver
119ret int 4
120end
121if ne get expect extent get current extent
122ret int 4
123end
124rc = qpair off count
125if ne rc int 0
126ret rc
127end
128if ne get off cap get current extent
129ret int 2
130end
131if gt get off val get current extent
132ret int 3
133end
134if gt get count val sub get current extent get off val
135ret int 3
136end
137put out ident get current ident
138put out ver get current ver
139put out off get off val
140put out count get count val
141ret int 0
142end