eval: add support for C.read/3, C.malloc/1, `$if openbsd {`

Delyan Angelov 2022-04-28 11:30:36 +03:00 committed by Jef Roosens
parent 444d8c7a81
commit 31bee98607
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 16 additions and 5 deletions

View File

@ -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)

View File

@ -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
}