eval: add support for C.read/3, C.malloc/1, `$if openbsd {`
							parent
							
								
									444d8c7a81
								
							
						
					
					
						commit
						31bee98607
					
				| 
						 | 
					@ -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
 | 
					fn C.memset(str voidptr, c int, n usize) voidptr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[trusted]
 | 
					[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)
 | 
					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')
 | 
											e.error('c does not have methods')
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					match expr.name.all_after('C.') {
 | 
										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' {
 | 
											'write' {
 | 
				
			||||||
							return Int{C.write(args[0].int_val(), args[1] as voidptr,
 | 
												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' {
 | 
											'calloc' {
 | 
				
			||||||
							return Ptr{
 | 
												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' {
 | 
											'getcwd' {
 | 
				
			||||||
| 
						 | 
					@ -142,6 +150,9 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
 | 
				
			||||||
								'freebsd' {
 | 
													'freebsd' {
 | 
				
			||||||
									do_if = e.pref.os == .freebsd
 | 
														do_if = e.pref.os == .freebsd
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
 | 
													'openbsd' {
 | 
				
			||||||
 | 
														do_if = e.pref.os == .openbsd
 | 
				
			||||||
 | 
													}
 | 
				
			||||||
								'prealloc' {
 | 
													'prealloc' {
 | 
				
			||||||
									do_if = e.pref.prealloc
 | 
														do_if = e.pref.prealloc
 | 
				
			||||||
								}
 | 
													}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue