rustpp_main: Fix exitcode semantics

This commit is contained in:
2025-07-11 16:59:44 -04:00
parent 3f0d6703ad
commit 1f9806a658
3 changed files with 23 additions and 13 deletions
+17 -10
View File
@@ -11,20 +11,22 @@
type Cstr = char *;
/** The main function: does main things */
fn rustpp__main () -> i32;
mod termination {
class Termination {
struct ExitCode {
int code;
fn return_value () -> int {
return 0;
return code;
}
};
}
/** The main function: does main things */
fn rustpp__main () -> termination::ExitCode;
mod option {
template <typename T>
class Option: termination::Termination {
class Option {
union {
u8 None = 0;
T Some;
@@ -37,6 +39,10 @@ mod option {
public:
makeSelf (Option<T>);
operator termination::ExitCode () {
return { (int) variant };
}
static fn Some (T value) -> Self {
Self op;
op.value.Some = value;
@@ -51,10 +57,6 @@ mod option {
return op;
}
fn return_value () -> int {
return self.is_some ();
}
fn is_some () -> bool {
return variant == variant::Some;
}
@@ -117,6 +119,10 @@ mod result {
public:
makeSelf (Result<T, E>);
operator termination::ExitCode () {
return { (int) variant };
}
// TODO: destructor for Result
static fn Ok (T value) -> Self {
@@ -372,7 +378,8 @@ mod env {
mod prelude {
use slice::Slice;
use option::Option, option::Some, option::None;
use result::Result;
use result::Result, result::Err, result::Ok;
use termination::ExitCode;
}