Frank Saez
Frank Saez
MModular
Created by tcorpse on 7/4/2024 in #questions
UnsafePointer & Structs
I've tried this
@value
struct Test(Stringable):

var prev: UnsafePointer[Test]
var label: String

fn __init__(inout self, label: String):
self.label = label
self.prev = UnsafePointer[Test]()

fn __init__(inout self, label: String, prev: Self):
self.label = label
self.prev = UnsafePointer[Test](prev)


fn __str__(self) -> String:
return "Test: " + self.label

fn next(self, label: String) -> Self:
return Test(label, self)

fn main():

var x = Test("x")
var y = x.next("y")
var z = y.prev[]
print(x)
print(y)
print(z)
@value
struct Test(Stringable):

var prev: UnsafePointer[Test]
var label: String

fn __init__(inout self, label: String):
self.label = label
self.prev = UnsafePointer[Test]()

fn __init__(inout self, label: String, prev: Self):
self.label = label
self.prev = UnsafePointer[Test](prev)


fn __str__(self) -> String:
return "Test: " + self.label

fn next(self, label: String) -> Self:
return Test(label, self)

fn main():

var x = Test("x")
var y = x.next("y")
var z = y.prev[]
print(x)
print(y)
print(z)
and it gives me :
Test: x
Test: y
Test: x
Test: x
Test: y
Test: x
I guess the difference is in :
self.prev = UnsafePointer[Test](prev)
self.prev = UnsafePointer[Test](prev)
6 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
thanks. BOLT doesn't work, at least on my setup, that's why I've asked. I've got this error :
BOLT-ERROR: function reordering only works when relocations are enabled
BOLT-ERROR: function reordering only works when relocations are enabled
It's usually solved with something like "-Wl,--emit-relocs" in the LDFLAGS. but it's no big deal, really.
16 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
another question but I guess I know the answer. Any plan for LTO/PGO/BOLT ? BOLT could be the easier to enable as it usually rely on a LDFLAGS.
16 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
thanks. I'm "plumbing" Mojo with the libjpeg and I'll dive into MLIR after that
16 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
thanks. I've already found this and it's why I've asked for a "clean and official" way 😋
16 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
yeah, I've start to feel the pain with this. I've found nothing to convert to/from Int and even a basic & doesn't seems to exist 😋 Guess, it will be Int for now
16 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
thanks. It should be UInt since size_t is supposed to be unsigned
16 replies
MModular
Created by Frank Saez on 6/5/2024 in #questions
Question about iterating a list of strings
@FSaez good to know, thanks.
14 replies
MModular
Created by Frank Saez on 6/5/2024 in #questions
Question about iterating a list of strings
thanks !
14 replies