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 *;
mod termination {
struct ExitCode {
int code;
fn return_value () -> int {
return code;
}
};
}
/** The main function: does main things */
fn rustpp__main () -> termination::ExitCode;
fn rustpp__main () -> i32;
mod option {
template <typename T>
@@ -39,10 +30,6 @@ mod option {
public:
makeSelf (Option<T>);
operator termination::ExitCode () {
return { (int) variant };
}
static fn Some (T value) -> Self {
Self op;
op.value.Some = value;
@@ -69,6 +56,10 @@ mod option {
return this->is_some ();
}
operator i32 () {
return (i32) variant;
}
fn unwrap_unchecked () -> T {
return value.Some;
}
@@ -119,10 +110,6 @@ mod result {
public:
makeSelf (Result<T, E>);
operator termination::ExitCode () {
return { (int) variant };
}
// TODO: destructor for Result
static fn Ok (T value) -> Self {
@@ -147,6 +134,10 @@ mod result {
return variant == variant::Err;
}
operator i32 () {
return (i32) variant;
}
fn ok () -> option::Option<T> {
match (variant) {
arm (variant::Ok, return option::Some (value.Ok));
@@ -239,7 +230,8 @@ mod slice {
T *head;
T *tail;
Iter (T *head, T *tail) : head (head), tail (tail) {}
Iter (T *head, T *tail) : head (head),
tail (tail) {}
public:
makeSelf (Iter<T>);
@@ -281,7 +273,9 @@ mod vec {
T *tail;
public:
Drain () : allocation (nullptr), head (nullptr), tail (nullptr) {}
Drain () : allocation (nullptr),
head (nullptr),
tail (nullptr) {}
Drain (T *allocation, usize len) : allocation (allocation),
head (allocation),
tail (allocation + len) {}
@@ -379,7 +373,6 @@ mod prelude {
use slice::Slice;
use option::Option, option::Some, option::None;
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!
#include "rust.hh"
fn main () -> ExitCode {
fn main () -> i32 {
let v = vec::Vec<i32>::new ();
v.push (10);
+1 -1
View File
@@ -14,7 +14,7 @@ fn main (int argc, char **argv) -> int {
int exitcode = 0;
program_args = { (Cstr *) argv, (usize) argc };
try {
exitcode = rustpp__main ().return_value ();
exitcode = rustpp__main ();
} catch (panic::Panic p) {
std::println ("Thread exited with explicit panic: {}", p.what ());
exitcode = -1;