MM
MM
MModular
Created by richard.kiss on 9/15/2024 in #questions
debug
11 replies
MModular
Created by richard.kiss on 9/15/2024 in #questions
debug
I get the same message too, maybe we should file a bug?
11 replies
MModular
Created by Martin Dudek on 5/14/2024 in #questions
Regular Expression Engine for Mojo, any plans?
A simd accelerated multiple substring matching algorithm called "Teddy". This is used in Rust's ripgrep. https://github.com/rust-lang/regex/blob/3de8c44f5357d5b582a80b7282480e38e8b7d50d/src/simd_accel/teddy128.rs
87 replies
MModular
Created by Martin Dudek on 5/14/2024 in #questions
Regular Expression Engine for Mojo, any plans?
While glimpsing through the re2 source code I found this link in a comment https://swtch.com/~rsc/regexp/. It has some bare bones examples in C that may provide a less intimidating starting point than the re2 library for someone toying with the idea of implementing regexes for Mojo.
87 replies
MModular
Created by Martin Dudek on 5/14/2024 in #questions
Regular Expression Engine for Mojo, any plans?
The only one I know of is a very simple (60 loc) regex match implementaion in Mojo by sstadic (https://github.com/sstadick/ExtraMojo/blob/main/ExtraMojo/regex/simple_re.mojo). However I'm also very interested to know of any plans. To my understanding Rust has a fast regex library.
87 replies
MModular
Created by MM on 4/19/2024 in #questions
Accessing C struct members from external_call
For the record, here's how I tested the localeconv function of the C standard library. I only manage to print the decimal_point member all the other members are blank.
from sys.ffi import external_call

alias c_char = UInt8
alias LC_MONETARY = 4
var locale = "it_IT".data()._as_scalar_pointer()

# Return type struct lconv

@register_passable("trivial")
struct lconv:
var decimal_point: Pointer[c_char]
var thousands_sep: Pointer[c_char]
var grouping: Pointer[c_char]
var int_curr_symbol: Pointer[c_char]
var currency_symbol: Pointer[c_char]
var mon_decimal_point: Pointer[c_char]
var mon_thousands_sep: Pointer[c_char]
var mon_grouping: Pointer[c_char]
var positive_sign: Pointer[c_char]
var negative_sign: Pointer[c_char]
var int_frac_digits: c_char
var frac_digits: c_char
var p_cs_precedes: c_char
var p_sep_by_space: c_char
var n_cs_precedes: c_char
var n_sep_by_space: c_char
var p_sign_posn: c_char
var n_sign_posn: c_char

var lc = external_call["localeconv", Pointer[lconv]]()
print(chr(lc[].decimal_point[0].to_int()))
from sys.ffi import external_call

alias c_char = UInt8
alias LC_MONETARY = 4
var locale = "it_IT".data()._as_scalar_pointer()

# Return type struct lconv

@register_passable("trivial")
struct lconv:
var decimal_point: Pointer[c_char]
var thousands_sep: Pointer[c_char]
var grouping: Pointer[c_char]
var int_curr_symbol: Pointer[c_char]
var currency_symbol: Pointer[c_char]
var mon_decimal_point: Pointer[c_char]
var mon_thousands_sep: Pointer[c_char]
var mon_grouping: Pointer[c_char]
var positive_sign: Pointer[c_char]
var negative_sign: Pointer[c_char]
var int_frac_digits: c_char
var frac_digits: c_char
var p_cs_precedes: c_char
var p_sep_by_space: c_char
var n_cs_precedes: c_char
var n_sep_by_space: c_char
var p_sign_posn: c_char
var n_sign_posn: c_char

var lc = external_call["localeconv", Pointer[lconv]]()
print(chr(lc[].decimal_point[0].to_int()))
8 replies
MModular
Created by MM on 4/19/2024 in #questions
Accessing C struct members from external_call
Thanks a lot! I have tried both DLHandle and external_call, but cannot get either one work. A good idea to check the source code of the ffi now that the std library is OS. I tried to read it through, but my grasp of mlir and C and low-level stuff is non-existant, so I'm afraid I was not able to find the answer to the question yet. I'm sure it must be possible though – it's hard to believe that the CPython integration could work with limited interoperability.
8 replies