diff --git a/LICENSE b/LICENSE index 261eeb9..782d1bf 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2018 Status Research & Development GmbH Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/ranges.nim b/ranges.nim new file mode 100644 index 0000000..51b74ba --- /dev/null +++ b/ranges.nim @@ -0,0 +1,6 @@ +import + ranges/memranges + +export + memranges + diff --git a/ranges.nimble b/ranges.nimble new file mode 100644 index 0000000..aa7f3d2 --- /dev/null +++ b/ranges.nimble @@ -0,0 +1,21 @@ +mode = ScriptMode.Verbose + +packageName = "ranges" +version = "0.0.1" +author = "Status Research & Development GmbH" +description = "Exploration of various implementations of memory range types" +license = "Apache2" +skipDirs = @["tests"] + +requires "nim >= 0.17.0" + +proc configForTests() = + --hints: off + --debuginfo + --path: "." + --run + +task test, "run CPU tests": + configForTests() + setCommand "c", "tests/all.nim" + diff --git a/ranges/memranges.nim b/ranges/memranges.nim new file mode 100644 index 0000000..8df5e20 --- /dev/null +++ b/ranges/memranges.nim @@ -0,0 +1,25 @@ +import + ptr_arith + +type + MemRange* = object + start: pointer + size: csize + +template len*(mr: MemRange): int = mr.size +template `[]`*(mr: MemRange, idx: int): byte = (cast[ptr byte](shift(mr.start, idx)))[] +proc baseAddr*(mr: MemRange): pointer = mr.start + +when false: + # XXX: Alternative definition that crashes the compiler. Investigate + type + MemRange* = distinct (pointer, csize) + + template len*(mr: MemRange): int = mr[1] + template `[]`*(mr: MemRange, idx: int): byte = (cast[ptr byte](shift(mr[0], idx)))[] + proc baseAddr*(mr: MemRange): pointer = mr[0] + +proc makeMemRange*(start: pointer, size: csize): MemRange = + result.start = start + result.size = size + diff --git a/tests/all.nim b/tests/all.nim new file mode 100644 index 0000000..e69de29