osdev - Can i use rust instead of c++ in OS Development -
i want know if rust complied code have os dependent code in or not.(not talking print stuff)
for illustration
let x = (4i,2i,3i) allow y = (3i,4i,4i)
now if compare x == y
using of library , if yes platform dependent.
edited: in c++ should not utilize new, seek catch, or standard lib. things should avoid while writing in rust.
you can see code rust compiler generate snippet yourself, without having install rust locally.
just visit web-based playpen, , type snippet in there. can run programme (and observe via print statements), or, more usefully in case, can compile programme downwards generated assembly , inspect see if has calls underlying scheme routines.
if go link: http://is.gd/be6yvj have set such programme playpen. (see bottom of post actual programme text.)
if nail asm button, can see assembly each routine. (i have added inline(never)
attributes relevant functions ensure not optimized away compiler.)
here generated assembly bar
below, function calls out higher-order function pair of 3-tuples, , compares them equality:
.section .text._zn3bar20h2bb2fd5b9c9e987beaae,"ax",@progbits .align 16, 0x90 .type _zn3bar20h2bb2fd5b9c9e987beaae,@function _zn3bar20h2bb2fd5b9c9e987beaae: .cfi_startproc cmpq %fs:112, %rsp ja .lbb0_2 movabsq $56, %r10 movabsq $0, %r11 callq __morestack retq .lbb0_2: subq $56, %rsp .ltmp0: .cfi_def_cfa_offset 64 movq %rdi, %rax leaq 8(%rsp), %rdi callq *%rax movq 8(%rsp), %rcx xorl %eax, %eax cmpq 32(%rsp), %rcx jne .lbb0_5 movq 40(%rsp), %rcx cmpq %rcx, 16(%rsp) jne .lbb0_5 movq 48(%rsp), %rax cmpq %rax, 24(%rsp) sete %al .lbb0_5: addq $56, %rsp retq .ltmp1: .size _zn3bar20h2bb2fd5b9c9e987beaae, .ltmp1-_zn3bar20h2bb2fd5b9c9e987beaae .cfi_endproc
so can see thing calling out helper routine, __morestack
, checks stack-overflow (or allocate more stack, in systems segmented stack support). (so illustration this, core functionality need provide yourself; note have halt kernel.)
here programme set playpen:
#[inline(never)] fn bar(f: fn() -> ((int, int, int), (int, int, int))) -> bool { allow (x, y) = f(); x == y } #[inline(never)] fn foo_1() -> ((int,int,int), (int,int,int)) { allow x = (4i,2i,3i); allow y = (3i,4i,4i); (x, y) } #[inline(never)] fn foo_2() -> ((int,int,int), (int,int,int)) { allow x = (4i,2i,3i); (x, x) } fn main() { println!("bar(foo_1): {}", bar(foo_1)); println!("bar(foo_2): {}", bar(foo_2)); }
rust osdev
No comments:
Post a Comment