diff --git a/src/include/rust.hh b/src/include/rust.hh index baa2fbc..5a745cb 100644 --- a/src/include/rust.hh +++ b/src/include/rust.hh @@ -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 @@ -39,10 +30,6 @@ mod option { public: makeSelf (Option); - 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); - 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 { 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); @@ -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; } diff --git a/src/main.cc b/src/main.cc index aedb934..77c2a2d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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::new (); v.push (10); diff --git a/src/runtime.cc b/src/runtime.cc index a6cfcb7..4a256ba 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -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;