annotate semiconginev2/core/utils.nim @ 1219:c61658d2d227 compiletime-tests

del: old test file
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 21:03:30 +0700
parents 56781cc0fc7c
children 841e12f33c47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
890
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
1 type
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
2 HorizontalAlignment* = enum
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
3 Left
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
4 Center
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
5 Right
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
6 VerticalAlignment* = enum
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
7 Top
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
8 Center
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
9 Bottom
48e946f9b192 did: small fix with materials & cleanup
Sam <sam@basx.dev>
parents: 840
diff changeset
10
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
11 func CleanString*(str: openArray[char]): string =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
12 for i in 0 ..< len(str):
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
13 if str[i] == char(0):
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
14 result = join(str[0 ..< i])
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
15 break
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
16
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
17 func ToCPointer*[T](list: openArray[T]): ptr T =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
18 if list.len > 0: addr(list[0]) else: nil
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
19
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
20 proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
21 let (output, exitcode) = gorgeEx(
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
22 command = command,
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
23 input = input)
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
24 if exitcode != 0:
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
25 raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output)
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
26 return output
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
27
984
4e487f06378b add: inital version of storage api (untested)
sam <sam@basx.dev>
parents: 943
diff changeset
28 proc AppName*(): string =
4e487f06378b add: inital version of storage api (untested)
sam <sam@basx.dev>
parents: 943
diff changeset
29 return string(Path(getAppFilename()).splitFile.name)
4e487f06378b add: inital version of storage api (untested)
sam <sam@basx.dev>
parents: 943
diff changeset
30
1137
a4aa9f374d44 did: more renaming
sam <sam@basx.dev>
parents: 984
diff changeset
31 func Size*[T: seq](list: T): uint64 =
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
32 uint64(list.len * sizeof(get(genericParams(typeof(list)), 0)))
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
33
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
34 template TimeAndLog*(body: untyped): untyped =
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
35 let t0 = getMonoTime()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
36 body
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
37 echo (getMonoTime() - t0).inNanoseconds.float / 1_000_000
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
38
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
39 template TimeAndLog*(name: string, body: untyped): untyped =
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
40 let t0 = getMonoTime()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
41 body
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1190
diff changeset
42 echo name, ": ", (getMonoTime() - t0).inNanoseconds.float / 1_000_000