| author | |
| committer | |
| log | 54675b060ae6139f60e111521b9a2688f66977a0 |
| tree | d0e91290608737fbdeca7e9504bd640bc34a2a7a |
| parent | 9ca798bc75bddac4d3db05463f1a42cfd7906bd3 |
closes #4159 files changed, 110 insertions(+), 80 deletions(-)
src/all_types.hpp+1| ... | ... | @@ -1226,6 +1226,7 @@ enum BuiltinFnId { |
| 1226 | 1226 | BuiltinFnIdPtrCast, |
| 1227 | 1227 | BuiltinFnIdBitCast, |
| 1228 | 1228 | BuiltinFnIdIntToPtr, |
| 1229 | BuiltinFnIdPtrToInt, | |
| 1229 | 1230 | BuiltinFnIdEnumTagName, |
| 1230 | 1231 | BuiltinFnIdFieldParentPtr, |
| 1231 | 1232 | BuiltinFnIdOffsetOf, |
src/codegen.cpp+1| ... | ... | @@ -4545,6 +4545,7 @@ static void define_builtin_fns(CodeGen *g) { |
| 4545 | 4545 | create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2); |
| 4546 | 4546 | create_builtin_fn(g, BuiltinFnIdBitCast, "bitCast", 2); |
| 4547 | 4547 | create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2); |
| 4548 | create_builtin_fn(g, BuiltinFnIdPtrToInt, "ptrToInt", 1); | |
| 4548 | 4549 | create_builtin_fn(g, BuiltinFnIdEnumTagName, "enumTagName", 1); |
| 4549 | 4550 | create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3); |
| 4550 | 4551 | create_builtin_fn(g, BuiltinFnIdOffsetOf, "offsetOf", 2); |
src/ir.cpp+52-31| ... | ... | @@ -4372,6 +4372,15 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4372 | 4372 | |
| 4373 | 4373 | return ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value); |
| 4374 | 4374 | } |
| 4375 | case BuiltinFnIdPtrToInt: | |
| 4376 | { | |
| 4377 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | |
| 4378 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); | |
| 4379 | if (arg0_value == irb->codegen->invalid_instruction) | |
| 4380 | return arg0_value; | |
| 4381 | ||
| 4382 | return ir_build_ptr_to_int(irb, scope, node, arg0_value); | |
| 4383 | } | |
| 4375 | 4384 | case BuiltinFnIdEnumTagName: |
| 4376 | 4385 | { |
| 4377 | 4386 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| ... | ... | @@ -7336,30 +7345,6 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 7336 | 7345 | return result; |
| 7337 | 7346 | } |
| 7338 | 7347 | |
| 7339 | static IrInstruction *ir_analyze_ptr_to_int(IrAnalyze *ira, IrInstruction *source_instr, | |
| 7340 | IrInstruction *target, TypeTableEntry *wanted_type) | |
| 7341 | { | |
| 7342 | assert(wanted_type->id == TypeTableEntryIdInt); | |
| 7343 | ||
| 7344 | if (instr_is_comptime(target)) { | |
| 7345 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | |
| 7346 | if (!val) | |
| 7347 | return ira->codegen->invalid_instruction; | |
| 7348 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { | |
| 7349 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, | |
| 7350 | source_instr->source_node, wanted_type); | |
| 7351 | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); | |
| 7352 | return result; | |
| 7353 | } | |
| 7354 | } | |
| 7355 | ||
| 7356 | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, source_instr->scope, | |
| 7357 | source_instr->source_node, target); | |
| 7358 | result->value.type = wanted_type; | |
| 7359 | return result; | |
| 7360 | } | |
| 7361 | ||
| 7362 | ||
| 7363 | 7348 | static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, |
| 7364 | 7349 | IrInstruction *target, TypeTableEntry *wanted_type) |
| 7365 | 7350 | { |
| ... | ... | @@ -7500,7 +7485,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7500 | 7485 | TypeTableEntry *wanted_type, IrInstruction *value) |
| 7501 | 7486 | { |
| 7502 | 7487 | TypeTableEntry *actual_type = value->value.type; |
| 7503 | TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize; | |
| 7504 | 7488 | |
| 7505 | 7489 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| 7506 | 7490 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -7521,11 +7505,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 7521 | 7505 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBoolToInt, false); |
| 7522 | 7506 | } |
| 7523 | 7507 | |
| 7524 | // explicit cast from pointer to usize | |
| 7525 | if (wanted_type == usize_type && type_is_codegen_pointer(actual_type)) { | |
| 7526 | return ir_analyze_ptr_to_int(ira, source_instr, value, wanted_type); | |
| 7527 | } | |
| 7528 | ||
| 7529 | 7508 | // explicit widening or shortening cast |
| 7530 | 7509 | if ((wanted_type->id == TypeTableEntryIdInt && |
| 7531 | 7510 | actual_type->id == TypeTableEntryIdInt) || |
| ... | ... | @@ -13937,6 +13916,47 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 13937 | 13916 | zig_unreachable(); |
| 13938 | 13917 | } |
| 13939 | 13918 | |
| 13919 | static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { | |
| 13920 | IrInstruction *target = instruction->target->other; | |
| 13921 | if (type_is_invalid(target->value.type)) | |
| 13922 | return ira->codegen->builtin_types.entry_invalid; | |
| 13923 | ||
| 13924 | TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; | |
| 13925 | ||
| 13926 | if (!(target->value.type->id == TypeTableEntryIdPointer || | |
| 13927 | target->value.type->id == TypeTableEntryIdFn || | |
| 13928 | (target->value.type->id == TypeTableEntryIdMaybe && | |
| 13929 | (target->value.type->data.maybe.child_type->id == TypeTableEntryIdPointer || | |
| 13930 | target->value.type->data.maybe.child_type->id == TypeTableEntryIdFn)))) | |
| 13931 | { | |
| 13932 | ir_add_error(ira, target, | |
| 13933 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name))); | |
| 13934 | return ira->codegen->builtin_types.entry_invalid; | |
| 13935 | } | |
| 13936 | ||
| 13937 | if (instr_is_comptime(target)) { | |
| 13938 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); | |
| 13939 | if (!val) | |
| 13940 | return ira->codegen->builtin_types.entry_invalid; | |
| 13941 | if (target->value.type->id == TypeTableEntryIdMaybe) { | |
| 13942 | val = val->data.x_maybe; | |
| 13943 | } | |
| 13944 | if (val->type->id == TypeTableEntryIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { | |
| 13945 | IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope, | |
| 13946 | instruction->base.source_node, usize); | |
| 13947 | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); | |
| 13948 | ir_link_new_instruction(result, &instruction->base); | |
| 13949 | return usize; | |
| 13950 | } | |
| 13951 | } | |
| 13952 | ||
| 13953 | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, | |
| 13954 | instruction->base.source_node, target); | |
| 13955 | result->value.type = usize; | |
| 13956 | ir_link_new_instruction(result, &instruction->base); | |
| 13957 | return usize; | |
| 13958 | } | |
| 13959 | ||
| 13940 | 13960 | static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 13941 | 13961 | switch (instruction->id) { |
| 13942 | 13962 | case IrInstructionIdInvalid: |
| ... | ... | @@ -13948,7 +13968,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 13948 | 13968 | case IrInstructionIdStructFieldPtr: |
| 13949 | 13969 | case IrInstructionIdEnumFieldPtr: |
| 13950 | 13970 | case IrInstructionIdInitEnum: |
| 13951 | case IrInstructionIdPtrToInt: | |
| 13952 | 13971 | zig_unreachable(); |
| 13953 | 13972 | case IrInstructionIdReturn: |
| 13954 | 13973 | return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction); |
| ... | ... | @@ -14106,6 +14125,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 14106 | 14125 | return ir_analyze_instruction_bit_cast(ira, (IrInstructionBitCast *)instruction); |
| 14107 | 14126 | case IrInstructionIdIntToPtr: |
| 14108 | 14127 | return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction); |
| 14128 | case IrInstructionIdPtrToInt: | |
| 14129 | return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction); | |
| 14109 | 14130 | case IrInstructionIdEnumTagName: |
| 14110 | 14131 | return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionEnumTagName *)instruction); |
| 14111 | 14132 | case IrInstructionIdFieldParentPtr: |
std/debug.zig+1-1| ... | ... | @@ -83,7 +83,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 83 | 83 | |
| 84 | 84 | var ignored_count: usize = 0; |
| 85 | 85 | |
| 86 | var fp = usize(@frameAddress()); | |
| 86 | var fp = @ptrToInt(@frameAddress()); | |
| 87 | 87 | while (fp != 0) : (fp = *@intToPtr(&const usize, fp)) { |
| 88 | 88 | if (ignored_count < ignore_frame_count) { |
| 89 | 89 | ignored_count += 1; |
std/os/linux.zig+39-39| ... | ... | @@ -337,11 +337,11 @@ pub fn dup2(old: i32, new: i32) -> usize { |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | pub fn chdir(path: &const u8) -> usize { |
| 340 | arch.syscall1(arch.SYS_chdir, usize(path)) | |
| 340 | arch.syscall1(arch.SYS_chdir, @ptrToInt(path)) | |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize { |
| 344 | arch.syscall3(arch.SYS_execve, usize(path), usize(argv), usize(envp)) | |
| 344 | arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)) | |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | pub fn fork() -> usize { |
| ... | ... | @@ -349,50 +349,50 @@ pub fn fork() -> usize { |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | pub fn getcwd(buf: &u8, size: usize) -> usize { |
| 352 | arch.syscall2(arch.SYS_getcwd, usize(buf), size) | |
| 352 | arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size) | |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize { |
| 356 | arch.syscall3(arch.SYS_getdents, usize(fd), usize(dirp), usize(count)) | |
| 356 | arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), usize(count)) | |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | pub fn isatty(fd: i32) -> bool { |
| 360 | 360 | var wsz: winsize = undefined; |
| 361 | return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, usize(&wsz)) == 0; | |
| 361 | return arch.syscall3(arch.SYS_ioctl, usize(fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize { |
| 365 | arch.syscall3(arch.SYS_readlink, usize(path), usize(buf_ptr), buf_len) | |
| 365 | arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len) | |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | pub fn mkdir(path: &const u8, mode: usize) -> usize { |
| 369 | arch.syscall2(arch.SYS_mkdir, usize(path), mode) | |
| 369 | arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode) | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize) |
| 373 | 373 | -> usize |
| 374 | 374 | { |
| 375 | arch.syscall6(arch.SYS_mmap, usize(address), length, prot, flags, usize(fd), offset) | |
| 375 | arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), offset) | |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | pub fn munmap(address: &u8, length: usize) -> usize { |
| 379 | arch.syscall2(arch.SYS_munmap, usize(address), length) | |
| 379 | arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length) | |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { |
| 383 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) | |
| 383 | arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count) | |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | pub fn rmdir(path: &const u8) -> usize { |
| 387 | arch.syscall1(arch.SYS_rmdir, usize(path)) | |
| 387 | arch.syscall1(arch.SYS_rmdir, @ptrToInt(path)) | |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | pub fn symlink(existing: &const u8, new: &const u8) -> usize { |
| 391 | arch.syscall2(arch.SYS_symlink, usize(existing), usize(new)) | |
| 391 | arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new)) | |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize { |
| 395 | arch.syscall4(arch.SYS_pread, usize(fd), usize(buf), count, offset) | |
| 395 | arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset) | |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | pub fn pipe(fd: &[2]i32) -> usize { |
| ... | ... | @@ -400,31 +400,31 @@ pub fn pipe(fd: &[2]i32) -> usize { |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | pub fn pipe2(fd: &[2]i32, flags: usize) -> usize { |
| 403 | arch.syscall2(arch.SYS_pipe2, usize(fd), flags) | |
| 403 | arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags) | |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { |
| 407 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) | |
| 407 | arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count) | |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize { |
| 411 | arch.syscall4(arch.SYS_pwrite, usize(fd), usize(buf), count, offset) | |
| 411 | arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset) | |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | pub fn rename(old: &const u8, new: &const u8) -> usize { |
| 415 | arch.syscall2(arch.SYS_rename, usize(old), usize(new)) | |
| 415 | arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new)) | |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | pub fn open(path: &const u8, flags: usize, perm: usize) -> usize { |
| 419 | arch.syscall3(arch.SYS_open, usize(path), flags, perm) | |
| 419 | arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm) | |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | pub fn create(path: &const u8, perm: usize) -> usize { |
| 423 | arch.syscall2(arch.SYS_creat, usize(path), perm) | |
| 423 | arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm) | |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize { |
| 427 | arch.syscall4(arch.SYS_openat, usize(dirfd), usize(path), flags, mode) | |
| 427 | arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode) | |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | pub fn close(fd: i32) -> usize { |
| ... | ... | @@ -441,7 +441,7 @@ pub fn exit(status: i32) -> noreturn { |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { |
| 444 | arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags)) | |
| 444 | arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags)) | |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | pub fn kill(pid: i32, sig: i32) -> usize { |
| ... | ... | @@ -449,11 +449,11 @@ pub fn kill(pid: i32, sig: i32) -> usize { |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | pub fn unlink(path: &const u8) -> usize { |
| 452 | arch.syscall1(arch.SYS_unlink, usize(path)) | |
| 452 | arch.syscall1(arch.SYS_unlink, @ptrToInt(path)) | |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize { |
| 456 | arch.syscall4(arch.SYS_wait4, usize(pid), usize(status), usize(options), 0) | |
| 456 | arch.syscall4(arch.SYS_wait4, usize(pid), @ptrToInt(status), usize(options), 0) | |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | const NSIG = 65; |
| ... | ... | @@ -471,15 +471,15 @@ pub fn raise(sig: i32) -> i32 { |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | fn blockAllSignals(set: &sigset_t) { |
| 474 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8); | |
| 474 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8); | |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | fn blockAppSignals(set: &sigset_t) { |
| 478 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8); | |
| 478 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8); | |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | fn restoreSignals(set: &sigset_t) { |
| 482 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8); | |
| 482 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8); | |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | |
| ... | ... | @@ -537,11 +537,11 @@ pub const iovec = extern struct { |
| 537 | 537 | // |
| 538 | 538 | |
| 539 | 539 | pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { |
| 540 | arch.syscall3(arch.SYS_getsockname, usize(fd), usize(addr), usize(len)) | |
| 540 | arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len)) | |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { |
| 544 | arch.syscall3(arch.SYS_getpeername, usize(fd), usize(addr), usize(len)) | |
| 544 | arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len)) | |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { |
| ... | ... | @@ -549,29 +549,29 @@ pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize { |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize { |
| 552 | arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen)) | |
| 552 | arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen)) | |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize { |
| 556 | arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen)) | |
| 556 | arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen)) | |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { |
| 560 | arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags) | |
| 560 | arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags) | |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { |
| 564 | arch.syscall3(arch.SYS_connect, usize(fd), usize(addr), usize(len)) | |
| 564 | arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len)) | |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { |
| 568 | arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags) | |
| 568 | arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags) | |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, |
| 572 | 572 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize |
| 573 | 573 | { |
| 574 | arch.syscall6(arch.SYS_recvfrom, usize(fd), usize(buf), len, flags, usize(addr), usize(alen)) | |
| 574 | arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)) | |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | pub fn shutdown(fd: i32, how: i32) -> usize { |
| ... | ... | @@ -579,7 +579,7 @@ pub fn shutdown(fd: i32, how: i32) -> usize { |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize { |
| 582 | arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len)) | |
| 582 | arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len)) | |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | pub fn listen(fd: i32, backlog: i32) -> usize { |
| ... | ... | @@ -587,11 +587,11 @@ pub fn listen(fd: i32, backlog: i32) -> usize { |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize { |
| 590 | arch.syscall6(arch.SYS_sendto, usize(fd), usize(buf), len, flags, usize(addr), usize(alen)) | |
| 590 | arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen)) | |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize { |
| 594 | arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), usize(&fd[0])) | |
| 594 | arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0])) | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { |
| ... | ... | @@ -599,7 +599,7 @@ pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usiz |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize { |
| 602 | arch.syscall4(arch.SYS_accept4, usize(fd), usize(addr), usize(len), flags) | |
| 602 | arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags) | |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | // error NameTooLong; |
| ... | ... | @@ -634,5 +634,5 @@ pub const stat = arch.stat; |
| 634 | 634 | pub const timespec = arch.timespec; |
| 635 | 635 | |
| 636 | 636 | pub fn fstat(fd: i32, stat_buf: &stat) -> usize { |
| 637 | arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf)) | |
| 637 | arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf)) | |
| 638 | 638 | } |
test/cases/cast.zig+2-2| ... | ... | @@ -4,13 +4,13 @@ const mem = @import("std").mem; |
| 4 | 4 | test "int to ptr cast" { |
| 5 | 5 | const x = usize(13); |
| 6 | 6 | const y = @intToPtr(&u8, x); |
| 7 | const z = usize(y); | |
| 7 | const z = @ptrToInt(y); | |
| 8 | 8 | assert(z == 13); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | test "integer literal to pointer cast" { |
| 12 | 12 | const vga_mem = @intToPtr(&u16, 0xB8000); |
| 13 | assert(usize(vga_mem) == 0xB8000); | |
| 13 | assert(@ptrToInt(vga_mem) == 0xB8000); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | test "pointer reinterpret const float to int" { |
test/cases/sizeof_and_typeof.zig+4-4| ... | ... | @@ -28,7 +28,7 @@ test "offsetOf" { |
| 28 | 28 | |
| 29 | 29 | // Non-packed struct fields can be moved/padded |
| 30 | 30 | const a: A = undefined; |
| 31 | assert(usize(&a.a) - usize(&a) == @offsetOf(A, "a")); | |
| 32 | assert(usize(&a.b) - usize(&a) == @offsetOf(@typeOf(a), "b")); | |
| 33 | assert(usize(&a.c) - usize(&a) == @offsetOf(@typeOf(a), "c")); | |
| 34 | } | |
| \ No newline at end of file | ||
| 31 | assert(@ptrToInt(&a.a) - @ptrToInt(&a) == @offsetOf(A, "a")); | |
| 32 | assert(@ptrToInt(&a.b) - @ptrToInt(&a) == @offsetOf(@typeOf(a), "b")); | |
| 33 | assert(@ptrToInt(&a.c) - @ptrToInt(&a) == @offsetOf(@typeOf(a), "c")); | |
| 34 | } |
test/cases/slice.zig+2-2| ... | ... | @@ -3,9 +3,9 @@ const assert = @import("std").debug.assert; |
| 3 | 3 | const x = @intToPtr(&i32, 0x1000)[0..0x500]; |
| 4 | 4 | const y = x[0x100..]; |
| 5 | 5 | test "compile time slice of pointer to hard coded address" { |
| 6 | assert(usize(x.ptr) == 0x1000); | |
| 6 | assert(@ptrToInt(x.ptr) == 0x1000); | |
| 7 | 7 | assert(x.len == 0x500); |
| 8 | 8 | |
| 9 | assert(usize(y.ptr) == 0x1100); | |
| 9 | assert(@ptrToInt(y.ptr) == 0x1100); | |
| 10 | 10 | assert(y.len == 0x400); |
| 11 | 11 | } |
test/compile_errors.zig+8-1| ... | ... | @@ -1769,7 +1769,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1769 | 1769 | |
| 1770 | 1770 | cases.add("save reference to inline function", |
| 1771 | 1771 | \\export fn foo() { |
| 1772 | \\ quux(usize(bar)); | |
| 1772 | \\ quux(@ptrToInt(bar)); | |
| 1773 | 1773 | \\} |
| 1774 | 1774 | \\inline fn bar() { } |
| 1775 | 1775 | \\extern fn quux(usize); |
| ... | ... | @@ -1952,4 +1952,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1952 | 1952 | \\} |
| 1953 | 1953 | , |
| 1954 | 1954 | ".tmp_source.zig:2:9: error: fractional component prevents float value 12.340000 from being casted to type 'i32'"); |
| 1955 | ||
| 1956 | cases.add("non pointer given to @ptrToInt", | |
| 1957 | \\export fn entry(x: i32) -> usize { | |
| 1958 | \\ @ptrToInt(x) | |
| 1959 | \\} | |
| 1960 | , | |
| 1961 | ".tmp_source.zig:2:15: error: expected pointer, found 'i32'"); | |
| 1955 | 1962 | } |