slovo/tests/numeric-struct-fields.surface.lower
2026-05-22 08:38:43 +02:00

135 lines
3.3 KiB
Plaintext

program main
struct NumericRecord
field wide: i64
field ratio: f64
fn make_record(wide: i64, ratio: f64) -> NumericRecord
construct NumericRecord
field wide
var wide
field ratio
var ratio
fn literal_record() -> NumericRecord
construct NumericRecord
field wide
i64 2147483648
field ratio
float 3.5
fn echo_record(record: NumericRecord) -> NumericRecord
var record
fn local_record(wide: i64, ratio: f64) -> NumericRecord
local let record: NumericRecord
call make_record
var wide
var ratio
call echo_record
var record
fn record_wide(record: NumericRecord) -> i64
field-access wide
var record
fn record_ratio(record: NumericRecord) -> f64
field-access ratio
var record
fn wide_total(record: NumericRecord) -> i64
binary +
field-access wide
var record
i64 10
fn ratio_total(record: NumericRecord) -> f64
binary +
field-access ratio
var record
float 1.5
fn wide_in_range(record: NumericRecord) -> bool
if
binary >
field-access wide
var record
i64 2147483640
binary <
field-access wide
var record
i64 2147483660
bool false
fn ratio_in_range(record: NumericRecord) -> bool
if
binary >
field-access ratio
var record
float 3
binary <
field-access ratio
var record
float 4
bool false
fn wide_text(record: NumericRecord) -> string
call std.num.i64_to_string
field-access wide
var record
fn ratio_text(record: NumericRecord) -> string
call std.num.f64_to_string
field-access ratio
var record
fn main() -> i32
call std.io.print_i64
call record_wide
call literal_record
call std.io.print_f64
call record_ratio
call literal_record
if
call wide_in_range
call local_record
i64 2147483648
float 3.5
if
call ratio_in_range
call local_record
i64 2147483648
float 3.5
int 0
int 1
int 1
test "numeric struct i64 field access"
binary =
call record_wide
call literal_record
i64 2147483648
test "numeric struct f64 field access"
binary =
call record_ratio
call literal_record
float 3.5
test "numeric struct i64 arithmetic after access"
binary =
call wide_total
call literal_record
i64 2147483658
test "numeric struct f64 arithmetic after access"
binary =
call ratio_total
call literal_record
float 5
test "numeric struct i64 comparison after access"
call wide_in_range
call literal_record
test "numeric struct f64 comparison after access"
call ratio_in_range
call literal_record
test "numeric struct local param return call flow"
binary =
call wide_total
call local_record
i64 2147483648
float 3.5
i64 2147483658
test "numeric struct i64 format after access"
binary =
call wide_text
call literal_record
string "2147483648"
test "numeric struct f64 format after access"
binary =
call ratio_text
call literal_record
string "3.5"