Unfix exitcode semantics.

This commit is contained in:
2025-07-12 05:00:08 -04:00
parent 1f9806a658
commit d0cef92631
3 changed files with 16 additions and 23 deletions
+14 -21
View File
@@ -12,17 +12,8 @@
type Cstr = char *; type Cstr = char *;
mod termination {
struct ExitCode {
int code;
fn return_value () -> int {
return code;
}
};
}
/** The main function: does main things */ /** The main function: does main things */
fn rustpp__main () -> termination::ExitCode; fn rustpp__main () -> i32;
mod option { mod option {
template <typename T> template <typename T>
@@ -39,10 +30,6 @@ mod option {
public: public:
makeSelf (Option<T>); makeSelf (Option<T>);
operator termination::ExitCode () {
return { (int) variant };
}
static fn Some (T value) -> Self { static fn Some (T value) -> Self {
Self op; Self op;
op.value.Some = value; op.value.Some = value;
@@ -69,6 +56,10 @@ mod option {
return this->is_some (); return this->is_some ();
} }
operator i32 () {
return (i32) variant;
}
fn unwrap_unchecked () -> T { fn unwrap_unchecked () -> T {
return value.Some; return value.Some;
} }
@@ -119,10 +110,6 @@ mod result {
public: public:
makeSelf (Result<T, E>); makeSelf (Result<T, E>);
operator termination::ExitCode () {
return { (int) variant };
}
// TODO: destructor for Result // TODO: destructor for Result
static fn Ok (T value) -> Self { static fn Ok (T value) -> Self {
@@ -147,6 +134,10 @@ mod result {
return variant == variant::Err; return variant == variant::Err;
} }
operator i32 () {
return (i32) variant;
}
fn ok () -> option::Option<T> { fn ok () -> option::Option<T> {
match (variant) { match (variant) {
arm (variant::Ok, return option::Some (value.Ok)); arm (variant::Ok, return option::Some (value.Ok));
@@ -239,7 +230,8 @@ mod slice {
T *head; T *head;
T *tail; T *tail;
Iter (T *head, T *tail) : head (head), tail (tail) {} Iter (T *head, T *tail) : head (head),
tail (tail) {}
public: public:
makeSelf (Iter<T>); makeSelf (Iter<T>);
@@ -281,7 +273,9 @@ mod vec {
T *tail; T *tail;
public: public:
Drain () : allocation (nullptr), head (nullptr), tail (nullptr) {} Drain () : allocation (nullptr),
head (nullptr),
tail (nullptr) {}
Drain (T *allocation, usize len) : allocation (allocation), Drain (T *allocation, usize len) : allocation (allocation),
head (allocation), head (allocation),
tail (allocation + len) {} tail (allocation + len) {}
@@ -379,7 +373,6 @@ mod prelude {
use slice::Slice; use slice::Slice;
use option::Option, option::Some, option::None; use option::Option, option::Some, option::None;
use result::Result, result::Err, result::Ok; use result::Result, result::Err, result::Ok;
use termination::ExitCode;
} }
+1 -1
View File
@@ -3,7 +3,7 @@
// rust.hh changes language semantics, so must be included last! // rust.hh changes language semantics, so must be included last!
#include "rust.hh" #include "rust.hh"
fn main () -> ExitCode { fn main () -> i32 {
let v = vec::Vec<i32>::new (); let v = vec::Vec<i32>::new ();
v.push (10); v.push (10);
+1 -1
View File
@@ -14,7 +14,7 @@ fn main (int argc, char **argv) -> int {
int exitcode = 0; int exitcode = 0;
program_args = { (Cstr *) argv, (usize) argc }; program_args = { (Cstr *) argv, (usize) argc };
try { try {
exitcode = rustpp__main ().return_value (); exitcode = rustpp__main ();
} catch (panic::Panic p) { } catch (panic::Panic p) {
std::println ("Thread exited with explicit panic: {}", p.what ()); std::println ("Thread exited with explicit panic: {}", p.what ());
exitcode = -1; exitcode = -1;