initial definition of a MemRange type
This commit is contained in:
parent
27aa9d9bc2
commit
9815d9708f
2
LICENSE
2
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.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import
|
||||
ranges/memranges
|
||||
|
||||
export
|
||||
memranges
|
||||
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue