summaryrefslogtreecommitdiff
path: root/tests/examplefiles/example.clay
blob: 784752c64aae3b84c430227cb11e28d84a1f4d62 (plain)
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

/// @section  StringLiteralRef 

record StringLiteralRef (
    sizep : Pointer[SizeT],
);


/// @section  predicates 

overload ContiguousSequence?(#StringLiteralRef) : Bool = true;
[s when StringLiteral?(s)]
overload ContiguousSequence?(#Static[s]) : Bool = true;



/// @section  size, begin, end, index 

forceinline overload size(a:StringLiteralRef) = a.sizep^;

forceinline overload begin(a:StringLiteralRef) : Pointer[Char] = Pointer[Char](a.sizep + 1);
forceinline overload end(a:StringLiteralRef) = begin(a) + size(a);

[I when Integer?(I)]
forceinline overload index(a:StringLiteralRef, i:I) : ByRef[Char] {
    assert["boundsChecks"](i >= 0 and i < size(a), "StringLiteralRef index out of bounds");
    return ref (begin(a) + i)^;
}

foo() = """
long\tlong
story
"""