-
Notifications
You must be signed in to change notification settings - Fork 14
/
Span.mpl
116 lines (97 loc) · 2.83 KB
/
Span.mpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (C) Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# 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
Span: [
data:;
@data Ref 0 toSpan2
];
toSpan: [Text same] [
text:;
text storageAddress Nat8 Cref addressToReference text textSize Int32 cast toSpan2
] pfunc;
toSpan: [object:; @object isCombined [@object 0 fieldIsRef ~] &&] [
struct:;
0 dynamic @struct @ struct fieldCount toSpan2 # [dynamic] is used to check for non-homogeneous tuples
] pfunc;
toSpan: ["span" has] [.span] pfunc;
toSpan2: [
spanData: spanSize:;;
{
SCHEMA_NAME: "Span<" @spanData schemaName & ">" & virtual;
assign: [
other:;
@other.data !spanData
other.size !spanSize
];
at: [
key:;
[key 0 spanSize within] "Key is out of bounds" assert
@spanData storageAddress @spanData storageSize key Natx cast * + @spanData addressToReference
];
data: [
@spanData
];
iter: [
span
];
iterReverse: [
{
SCHEMA_NAME: "SpanIterReverse" virtual;
data: @spanData storageAddress @spanData storageSize spanSize Natx cast * + @spanData storageSize - @spanData addressToReference;
size: spanSize new;
next: [
@data
size 0 = ~ dup [
@data storageAddress @data storageSize - @data addressToReference !data
size 1 - !size
] when
];
}
];
next: [
@spanData
spanSize 0 = ~ dup [
@spanData storageAddress @spanData storageSize + @spanData addressToReference !spanData
spanSize 1 - !spanSize
] when
];
size: [
spanSize new
];
slice: [
offset: size:;;
[offset 0 spanSize between] "Offset is out of bounds" assert
[size 0 spanSize offset - between] "Size is out of bounds" assert
@spanData storageAddress @spanData storageSize offset Natx cast * + @spanData addressToReference size toSpan2
];
span: [
@spanData spanSize toSpan2
];
spanStatic: [
"SpanStatic.toSpanStatic2" use
@spanData spanSize toSpanStatic2
];
stringView: [
"String.toStringView" use
(spanData spanSize new) toStringView
];
private spanData: @spanData;
private spanSize: spanSize new;
}
];