-
-
Save modularbot/0613c95485ee838e00dc7289b81efa2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias dtype = DType.float64 | |
struct MyStruct: | |
var ptr : DTypePointer[dtype] | |
var len:Int | |
fn __init__(inout self, len:Int): | |
self.len = len | |
self.ptr = DTypePointer[dtype].alloc(len) | |
fn __copyinit__(inout self, borrowed existing:Self): | |
print("> __copyinit__()") | |
self.len = existing.len | |
self.ptr = DTypePointer[dtype].alloc(self.len) | |
for i in range(self.len): | |
self.ptr[i] = existing.ptr[i] | |
fn __moveinit__(inout self, owned existing:Self): | |
print("> __moveinit__()") | |
self.len = existing.len | |
self.ptr = existing.ptr | |
fn __del__(owned self): | |
print("> __del__()") | |
self.ptr.free() | |
fn do_something_meaningful(owned val:Float64): | |
print("amount donated to Modular:", val,"$") | |
fn main(): | |
print("$ var a = MyStruct(10)") | |
var a = MyStruct(10) | |
print("$ a.ptr[0] = 37") | |
a.ptr[0] = 37 | |
print("$ do_something_meaningful(a.ptr[0])") | |
do_something_meaningful(a.ptr[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment