This commit is contained in:
Folkert 2023-01-18 23:18:09 +01:00
parent bb44063419
commit 01b6d234ff
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 150 additions and 190 deletions

View file

@ -1858,7 +1858,7 @@ fn add_function(
writeln!(buf, "{INDENT}{INDENT}extern \"C\" {{").unwrap(); writeln!(buf, "{INDENT}{INDENT}extern \"C\" {{").unwrap();
writeln!( writeln!(
buf, buf,
"{INDENT}{INDENT}{INDENT} fn {extern_name}(output: *mut {return_type_str}, {argument_types});" "{INDENT}{INDENT}{INDENT} fn {extern_name}(output: *mut {return_type_str}, {argument_types}, closure_data: *mut u8);"
) )
.unwrap(); .unwrap();
writeln!(buf, "{INDENT}{INDENT}}}").unwrap(); writeln!(buf, "{INDENT}{INDENT}}}").unwrap();
@ -1873,7 +1873,7 @@ fn add_function(
writeln!( writeln!(
buf, buf,
"{INDENT}{INDENT}unsafe {{ {extern_name}(output.as_mut_ptr(), {argument_names}) }};" "{INDENT}{INDENT}unsafe {{ {extern_name}(output.as_mut_ptr(), {argument_names}, self.closure_data) }};"
) )
.unwrap(); .unwrap();

View file

@ -997,8 +997,8 @@ fn add_type_help<'a>(
_ => unreachable!(), _ => unreachable!(),
}; };
// String::from("roc__mainForHost_1__Fx2_caller"); let extern_name = String::from("roc__mainForHost_1__Fx2_caller");
let extern_name = env.extern_names.get(&lambda_set).cloned().unwrap(); // let extern_name = env.extern_names.get(&lambda_set).cloned().unwrap();
dbg!(&extern_name, &name); dbg!(&extern_name, &name);

View file

@ -59,17 +59,18 @@ pub struct Op {
pointer: *mut union_Op, pointer: *mut union_Op,
} }
#[cfg(any( #[cfg(any(
target_arch = "arm", target_arch = "arm",
target_arch = "aarch64",
target_arch = "wasm32", target_arch = "wasm32",
target_arch = "x86" target_arch = "x86",
target_arch = "x86_64"
))] ))]
#[repr(C)] #[repr(C)]
union union_Op { union union_Op {
StderrWrite: core::mem::ManuallyDrop<Op_StderrWrite>, StderrWrite: core::mem::ManuallyDrop<Op_StderrWrite>,
StdoutWrite: core::mem::ManuallyDrop<Op_StdoutWrite>, StdoutWrite: core::mem::ManuallyDrop<Op_StdoutWrite>,
_sizer: [u8; 4], _sizer: [u8; 8],
} }
#[cfg(any( #[cfg(any(
@ -85,7 +86,6 @@ union union_Op {
target_arch = "x86_64" target_arch = "x86_64"
))] ))]
//TODO HAS CLOSURE 2 //TODO HAS CLOSURE 2
#[cfg(any( #[cfg(any(
target_arch = "arm", target_arch = "arm",
target_arch = "aarch64", target_arch = "aarch64",
@ -93,20 +93,20 @@ union union_Op {
target_arch = "x86", target_arch = "x86",
target_arch = "x86_64" target_arch = "x86_64"
))] ))]
#[repr(C)] #[repr(C)]
pub struct RocFunction_65 { pub struct RocFunction_65<'a> {
pub closure_data: (), closure_data: *const u8,
_marker: std::marker::PhantomData<&'a ()>,
} }
impl RocFunction_65 { impl<'a> RocFunction_65<'a> {
pub fn force_thunk(self, ) -> Op { pub fn force_thunk(self) -> Op {
extern "C" { extern "C" {
fn roc__getter__5(output: *mut Op, ); fn roc__mainForHost_1__Fx2_caller(output: *mut Op, input: *const u8);
} }
let mut output = std::mem::MaybeUninit::uninit(); let mut output = std::mem::MaybeUninit::uninit();
unsafe { roc__getter__5(output.as_mut_ptr(), ) }; unsafe { roc__mainForHost_1__Fx2_caller(output.as_mut_ptr(), self.closure_data) };
unsafe { output.assume_init() } unsafe { output.assume_init() }
} }
} }
@ -118,35 +118,23 @@ impl RocFunction_65 {
target_arch = "x86", target_arch = "x86",
target_arch = "x86_64" target_arch = "x86_64"
))] ))]
#[repr(C)] #[repr(C)]
pub struct RocFunction_67 { pub struct RocFunction_67 {
pub closure_data: (), pub closure_data: (),
} }
impl RocFunction_67 { impl RocFunction_67 {
pub fn force_thunk(self, ) -> Op { pub fn force_thunk(self) -> Op {
extern "C" { extern "C" {
fn roc__getter__5(output: *mut Op, ); fn roc__mainForHost_1__Fx2_caller(output: *mut Op);
} }
let mut output = std::mem::MaybeUninit::uninit(); let mut output = std::mem::MaybeUninit::uninit();
unsafe { roc__getter__5(output.as_mut_ptr(), ) }; unsafe { roc__mainForHost_1__Fx2_caller(output.as_mut_ptr()) };
unsafe { output.assume_init() } unsafe { output.assume_init() }
} }
} }
#[cfg(any(
target_arch = "aarch64",
target_arch = "x86_64"
))]
#[repr(C)]
union union_Op {
StderrWrite: core::mem::ManuallyDrop<Op_StderrWrite>,
StdoutWrite: core::mem::ManuallyDrop<Op_StdoutWrite>,
_sizer: [u8; 8],
}
impl Op { impl Op {
#[cfg(any( #[cfg(any(
target_arch = "arm", target_arch = "arm",
@ -170,28 +158,18 @@ impl Op {
if untagged.is_null() { if untagged.is_null() {
None None
} else { } else {
unsafe { unsafe { Some(&*untagged.sub(1)) }
Some(&*untagged.sub(1))
}
} }
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Returns which variant this tag union holds. Note that this never includes a payload! /// Returns which variant this tag union holds. Note that this never includes a payload!
pub fn discriminant(&self) -> discriminant_Op { pub fn discriminant(&self) -> discriminant_Op {
// The discriminant is stored in the unused bytes at the end of the recursive pointer // The discriminant is stored in the unused bytes at the end of the recursive pointer
unsafe { core::mem::transmute::<u8, discriminant_Op>((self.pointer as u8) & 0b11) } unsafe { core::mem::transmute::<u8, discriminant_Op>((self.pointer as u8) & 0b11) }
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Internal helper /// Internal helper
fn tag_discriminant(pointer: *mut union_Op, discriminant: discriminant_Op) -> *mut union_Op { fn tag_discriminant(pointer: *mut union_Op, discriminant: discriminant_Op) -> *mut union_Op {
// The discriminant is stored in the unused bytes at the end of the union pointer // The discriminant is stored in the unused bytes at the end of the union pointer
@ -201,11 +179,7 @@ impl Op {
tagged as *mut union_Op tagged as *mut union_Op
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Internal helper /// Internal helper
fn union_pointer(&self) -> *mut union_Op { fn union_pointer(&self) -> *mut union_Op {
// The discriminant is stored in the unused bytes at the end of the union pointer // The discriminant is stored in the unused bytes at the end of the union pointer
@ -283,32 +257,28 @@ impl Op {
))] ))]
/// Construct a tag named `StderrWrite`, with the appropriate payload /// Construct a tag named `StderrWrite`, with the appropriate payload
pub fn StderrWrite(arg: Op_StderrWrite) -> Self { pub fn StderrWrite(arg: Op_StderrWrite) -> Self {
let size = core::mem::size_of::<union_Op>(); let size = core::mem::size_of::<union_Op>();
let align = core::mem::align_of::<union_Op>() as u32; let align = core::mem::align_of::<union_Op>() as u32;
unsafe { unsafe {
let ptr = roc_std::roc_alloc_refcounted::<union_Op>(); let ptr = roc_std::roc_alloc_refcounted::<union_Op>();
*ptr = union_Op { *ptr = union_Op {
StderrWrite: core::mem::ManuallyDrop::new(arg) StderrWrite: core::mem::ManuallyDrop::new(arg),
}; };
Self { Self {
pointer: Self::tag_discriminant(ptr, discriminant_Op::StderrWrite), pointer: Self::tag_discriminant(ptr, discriminant_Op::StderrWrite),
}
} }
}
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and convert it to `StderrWrite`'s payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and convert it to `StderrWrite`'s payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`.
pub unsafe fn into_StderrWrite(mut self) -> Op_StderrWrite { pub unsafe fn into_StderrWrite(mut self) -> Op_StderrWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b11) as *mut union_Op; let ptr = (self.pointer as usize & !0b11) as *mut union_Op;
let mut uninitialized = core::mem::MaybeUninit::uninit(); let mut uninitialized = core::mem::MaybeUninit::uninit();
@ -327,16 +297,12 @@ impl Op {
payload payload
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and return its payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and return its payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`.
pub unsafe fn as_StderrWrite(&self) -> &Op_StderrWrite { pub unsafe fn as_StderrWrite(&self) -> &Op_StderrWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b11) as *mut union_Op; let ptr = (self.pointer as usize & !0b11) as *mut union_Op;
@ -386,14 +352,16 @@ impl Op {
extern "C" { extern "C" {
#[link_name = "roc__getter__3"] #[link_name = "roc__getter__3"]
fn getter(_: *mut RocFunction_65, _: *const Op); fn getter(_: *const Op) -> *const u8;
// fn getter(_: *mut RocFunction_65, _: *const Op);
} }
let mut ret = core::mem::MaybeUninit::uninit(); let ptr = getter(self);
getter(ret.as_mut_ptr(), self); RocFunction_65 {
closure_data: ptr,
ret.assume_init() _marker: Default::default(),
}
} }
#[cfg(any( #[cfg(any(
@ -405,32 +373,28 @@ impl Op {
))] ))]
/// Construct a tag named `StdoutWrite`, with the appropriate payload /// Construct a tag named `StdoutWrite`, with the appropriate payload
pub fn StdoutWrite(arg: Op_StdoutWrite) -> Self { pub fn StdoutWrite(arg: Op_StdoutWrite) -> Self {
let size = core::mem::size_of::<union_Op>(); let size = core::mem::size_of::<union_Op>();
let align = core::mem::align_of::<union_Op>() as u32; let align = core::mem::align_of::<union_Op>() as u32;
unsafe { unsafe {
let ptr = roc_std::roc_alloc_refcounted::<union_Op>(); let ptr = roc_std::roc_alloc_refcounted::<union_Op>();
*ptr = union_Op { *ptr = union_Op {
StdoutWrite: core::mem::ManuallyDrop::new(arg) StdoutWrite: core::mem::ManuallyDrop::new(arg),
}; };
Self { Self {
pointer: Self::tag_discriminant(ptr, discriminant_Op::StdoutWrite), pointer: Self::tag_discriminant(ptr, discriminant_Op::StdoutWrite),
}
} }
}
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and convert it to `StdoutWrite`'s payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and convert it to `StdoutWrite`'s payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`.
pub unsafe fn into_StdoutWrite(mut self) -> Op_StdoutWrite { pub unsafe fn into_StdoutWrite(mut self) -> Op_StdoutWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b11) as *mut union_Op; let ptr = (self.pointer as usize & !0b11) as *mut union_Op;
let mut uninitialized = core::mem::MaybeUninit::uninit(); let mut uninitialized = core::mem::MaybeUninit::uninit();
@ -449,16 +413,12 @@ impl Op {
payload payload
} }
#[cfg(any( #[cfg(any(target_arch = "arm", target_arch = "wasm32", target_arch = "x86"))]
target_arch = "arm",
target_arch = "wasm32",
target_arch = "x86"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and return its payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and return its payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`.
pub unsafe fn as_StdoutWrite(&self) -> &Op_StdoutWrite { pub unsafe fn as_StdoutWrite(&self) -> &Op_StdoutWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b11) as *mut union_Op; let ptr = (self.pointer as usize & !0b11) as *mut union_Op;
@ -468,20 +428,14 @@ impl Op {
&payload &payload
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Returns which variant this tag union holds. Note that this never includes a payload! /// Returns which variant this tag union holds. Note that this never includes a payload!
pub fn discriminant(&self) -> discriminant_Op { pub fn discriminant(&self) -> discriminant_Op {
// The discriminant is stored in the unused bytes at the end of the recursive pointer // The discriminant is stored in the unused bytes at the end of the recursive pointer
unsafe { core::mem::transmute::<u8, discriminant_Op>((self.pointer as u8) & 0b111) } unsafe { core::mem::transmute::<u8, discriminant_Op>((self.pointer as u8) & 0b111) }
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Internal helper /// Internal helper
fn tag_discriminant(pointer: *mut union_Op, discriminant: discriminant_Op) -> *mut union_Op { fn tag_discriminant(pointer: *mut union_Op, discriminant: discriminant_Op) -> *mut union_Op {
// The discriminant is stored in the unused bytes at the end of the union pointer // The discriminant is stored in the unused bytes at the end of the union pointer
@ -491,25 +445,19 @@ impl Op {
tagged as *mut union_Op tagged as *mut union_Op
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Internal helper /// Internal helper
fn union_pointer(&self) -> *mut union_Op { fn union_pointer(&self) -> *mut union_Op {
// The discriminant is stored in the unused bytes at the end of the union pointer // The discriminant is stored in the unused bytes at the end of the union pointer
((self.pointer as usize) & (!0b111 as usize)) as *mut union_Op ((self.pointer as usize) & (!0b111 as usize)) as *mut union_Op
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and convert it to `StderrWrite`'s payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and convert it to `StderrWrite`'s payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`.
pub unsafe fn into_StderrWrite(mut self) -> Op_StderrWrite { pub unsafe fn into_StderrWrite(mut self) -> Op_StderrWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b111) as *mut union_Op; let ptr = (self.pointer as usize & !0b111) as *mut union_Op;
let mut uninitialized = core::mem::MaybeUninit::uninit(); let mut uninitialized = core::mem::MaybeUninit::uninit();
@ -528,15 +476,12 @@ impl Op {
payload payload
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and return its payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StderrWrite` and return its payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StderrWrite`.
pub unsafe fn as_StderrWrite(&self) -> &Op_StderrWrite { pub unsafe fn as_StderrWrite(&self) -> &Op_StderrWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StderrWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b111) as *mut union_Op; let ptr = (self.pointer as usize & !0b111) as *mut union_Op;
@ -546,15 +491,12 @@ impl Op {
&payload &payload
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and convert it to `StdoutWrite`'s payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and convert it to `StdoutWrite`'s payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`.
pub unsafe fn into_StdoutWrite(mut self) -> Op_StdoutWrite { pub unsafe fn into_StdoutWrite(mut self) -> Op_StdoutWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b111) as *mut union_Op; let ptr = (self.pointer as usize & !0b111) as *mut union_Op;
let mut uninitialized = core::mem::MaybeUninit::uninit(); let mut uninitialized = core::mem::MaybeUninit::uninit();
@ -573,15 +515,12 @@ impl Op {
payload payload
} }
#[cfg(any( #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
target_arch = "aarch64",
target_arch = "x86_64"
))]
/// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and return its payload. /// Unsafely assume this `Op` has a `.discriminant()` of `StdoutWrite` and return its payload.
/// (Always examine `.discriminant()` first to make sure this is the correct variant!) /// (Always examine `.discriminant()` first to make sure this is the correct variant!)
/// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`. /// Panics in debug builds if the `.discriminant()` doesn't return `StdoutWrite`.
pub unsafe fn as_StdoutWrite(&self) -> &Op_StdoutWrite { pub unsafe fn as_StdoutWrite(&self) -> &Op_StdoutWrite {
debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite); debug_assert_eq!(self.discriminant(), discriminant_Op::StdoutWrite);
let payload = { let payload = {
let ptr = (self.pointer as usize & !0b111) as *mut union_Op; let ptr = (self.pointer as usize & !0b111) as *mut union_Op;
@ -610,17 +549,23 @@ impl Drop for Op {
if needs_dealloc { if needs_dealloc {
// Drop the payload first. // Drop the payload first.
match self.discriminant() { match self.discriminant() {
discriminant_Op::Done => {} discriminant_Op::Done => {}
discriminant_Op::StderrWrite => unsafe { core::mem::ManuallyDrop::drop(&mut (&mut *self.union_pointer()).StderrWrite) }, discriminant_Op::StderrWrite => unsafe {
discriminant_Op::StdoutWrite => unsafe { core::mem::ManuallyDrop::drop(&mut (&mut *self.union_pointer()).StdoutWrite) }, core::mem::ManuallyDrop::drop(&mut (&mut *self.union_pointer()).StderrWrite)
} },
discriminant_Op::StdoutWrite => unsafe {
core::mem::ManuallyDrop::drop(&mut (&mut *self.union_pointer()).StdoutWrite)
},
}
// Dealloc the pointer // Dealloc the pointer
let alignment = core::mem::align_of::<Self>().max(core::mem::align_of::<roc_std::Storage>()); let alignment =
core::mem::align_of::<Self>().max(core::mem::align_of::<roc_std::Storage>());
unsafe { crate::roc_dealloc(storage.as_ptr().cast(), alignment as u32); } unsafe {
crate::roc_dealloc(storage.as_ptr().cast(), alignment as u32);
}
} else { } else {
// Write the storage back. // Write the storage back.
storage.set(new_storage); storage.set(new_storage);
@ -640,15 +585,19 @@ impl PartialEq for Op {
target_arch = "x86_64" target_arch = "x86_64"
))] ))]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
if self.discriminant() != other.discriminant() { if self.discriminant() != other.discriminant() {
return false; return false;
} }
unsafe { unsafe {
match self.discriminant() { match self.discriminant() {
discriminant_Op::Done => true, discriminant_Op::Done => true,
discriminant_Op::StderrWrite => (&*self.union_pointer()).StderrWrite == (&*other.union_pointer()).StderrWrite, discriminant_Op::StderrWrite => {
discriminant_Op::StdoutWrite => (&*self.union_pointer()).StdoutWrite == (&*other.union_pointer()).StdoutWrite, (&*self.union_pointer()).StderrWrite == (&*other.union_pointer()).StderrWrite
}
discriminant_Op::StdoutWrite => {
(&*self.union_pointer()).StdoutWrite == (&*other.union_pointer()).StdoutWrite
}
} }
} }
} }
@ -671,8 +620,12 @@ impl PartialOrd for Op {
unsafe { unsafe {
match self.discriminant() { match self.discriminant() {
discriminant_Op::Done => Some(core::cmp::Ordering::Equal), discriminant_Op::Done => Some(core::cmp::Ordering::Equal),
discriminant_Op::StderrWrite => (&*self.union_pointer()).StderrWrite.partial_cmp(&(&*other.union_pointer()).StderrWrite), discriminant_Op::StderrWrite => (&*self.union_pointer())
discriminant_Op::StdoutWrite => (&*self.union_pointer()).StdoutWrite.partial_cmp(&(&*other.union_pointer()).StdoutWrite), .StderrWrite
.partial_cmp(&(&*other.union_pointer()).StderrWrite),
discriminant_Op::StdoutWrite => (&*self.union_pointer())
.StdoutWrite
.partial_cmp(&(&*other.union_pointer()).StdoutWrite),
} }
} }
} }
@ -687,16 +640,20 @@ impl Ord for Op {
target_arch = "x86_64" target_arch = "x86_64"
))] ))]
fn cmp(&self, other: &Self) -> core::cmp::Ordering { fn cmp(&self, other: &Self) -> core::cmp::Ordering {
match self.discriminant().cmp(&other.discriminant()) { match self.discriminant().cmp(&other.discriminant()) {
core::cmp::Ordering::Equal => {} core::cmp::Ordering::Equal => {}
not_eq => return not_eq, not_eq => return not_eq,
} }
unsafe { unsafe {
match self.discriminant() { match self.discriminant() {
discriminant_Op::Done => core::cmp::Ordering::Equal, discriminant_Op::Done => core::cmp::Ordering::Equal,
discriminant_Op::StderrWrite => (&*self.union_pointer()).StderrWrite.cmp(&(&*other.union_pointer()).StderrWrite), discriminant_Op::StderrWrite => (&*self.union_pointer())
discriminant_Op::StdoutWrite => (&*self.union_pointer()).StdoutWrite.cmp(&(&*other.union_pointer()).StdoutWrite), .StderrWrite
.cmp(&(&*other.union_pointer()).StderrWrite),
discriminant_Op::StdoutWrite => (&*self.union_pointer())
.StdoutWrite
.cmp(&(&*other.union_pointer()).StdoutWrite),
} }
} }
} }
@ -720,7 +677,7 @@ impl Clone for Op {
} }
Self { Self {
pointer: self.pointer pointer: self.pointer,
} }
} }
} }
@ -733,16 +690,17 @@ impl core::hash::Hash for Op {
target_arch = "x86", target_arch = "x86",
target_arch = "x86_64" target_arch = "x86_64"
))] ))]
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { match self.discriminant() { fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
match self.discriminant() {
discriminant_Op::Done => discriminant_Op::Done.hash(state), discriminant_Op::Done => discriminant_Op::Done.hash(state),
discriminant_Op::StderrWrite => unsafe { discriminant_Op::StderrWrite => unsafe {
discriminant_Op::StderrWrite.hash(state); discriminant_Op::StderrWrite.hash(state);
(&*self.union_pointer()).StderrWrite.hash(state); (&*self.union_pointer()).StderrWrite.hash(state);
}, },
discriminant_Op::StdoutWrite => unsafe { discriminant_Op::StdoutWrite => unsafe {
discriminant_Op::StdoutWrite.hash(state); discriminant_Op::StdoutWrite.hash(state);
(&*self.union_pointer()).StdoutWrite.hash(state); (&*self.union_pointer()).StdoutWrite.hash(state);
}, },
} }
} }
} }
@ -761,12 +719,14 @@ impl core::fmt::Debug for Op {
unsafe { unsafe {
match self.discriminant() { match self.discriminant() {
discriminant_Op::Done => f.write_str("Done"), discriminant_Op::Done => f.write_str("Done"),
discriminant_Op::StderrWrite => f.debug_tuple("StderrWrite") discriminant_Op::StderrWrite => f
// TODO HAS CLOSURE .debug_tuple("StderrWrite")
.finish(), // TODO HAS CLOSURE
discriminant_Op::StdoutWrite => f.debug_tuple("StdoutWrite") .finish(),
// TODO HAS CLOSURE discriminant_Op::StdoutWrite => f
.finish(), .debug_tuple("StdoutWrite")
// TODO HAS CLOSURE
.finish(),
} }
} }
} }