eval: add support for C.read/3, C.malloc/1, `$if openbsd {`
parent
be04ec0620
commit
f72297c331
|
@ -10,11 +10,11 @@ fn C.memmove(dest voidptr, const_src voidptr, n usize) voidptr
|
|||
fn C.memset(str voidptr, c int, n usize) voidptr
|
||||
|
||||
[trusted]
|
||||
fn C.calloc(int, int) &byte
|
||||
fn C.calloc(int, int) &u8
|
||||
|
||||
fn C.malloc(int) &byte
|
||||
fn C.malloc(int) &u8
|
||||
|
||||
fn C.realloc(a &byte, b int) &byte
|
||||
fn C.realloc(a &u8, b int) &u8
|
||||
|
||||
fn C.free(ptr voidptr)
|
||||
|
||||
|
|
|
@ -24,13 +24,21 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
|
|||
e.error('c does not have methods')
|
||||
}
|
||||
match expr.name.all_after('C.') {
|
||||
'read' {
|
||||
return Int{C.read(args[0].int_val(), args[1] as voidptr, args[2].int_val()), 64}
|
||||
}
|
||||
'write' {
|
||||
return Int{C.write(args[0].int_val(), args[1] as voidptr,
|
||||
args[2].int_val()), 32}
|
||||
args[2].int_val()), 64}
|
||||
}
|
||||
'malloc' {
|
||||
return Ptr{
|
||||
val: unsafe { C.malloc(args[0].int_val()) }
|
||||
}
|
||||
}
|
||||
'calloc' {
|
||||
return Ptr{
|
||||
val: vcalloc(int(args[0].int_val() * args[1].int_val()))
|
||||
val: unsafe { C.calloc(args[0].int_val(), args[1].int_val()) }
|
||||
}
|
||||
}
|
||||
'getcwd' {
|
||||
|
@ -142,6 +150,9 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
|
|||
'freebsd' {
|
||||
do_if = e.pref.os == .freebsd
|
||||
}
|
||||
'openbsd' {
|
||||
do_if = e.pref.os == .openbsd
|
||||
}
|
||||
'prealloc' {
|
||||
do_if = e.pref.prealloc
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue