enhanced the reader and compiler to treat the binop expression like a message-send expression
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-03 12:18:08 +09:00
parent 4c1a50df83
commit a62b89cea9
18 changed files with 197 additions and 106 deletions

View File

@ -14,16 +14,20 @@
};
set-r v1 v2 v3 (ff 10 20);
if (/= v1 130) { printf "ERROR: v1 must be 130\n" };
if (/= v2 260) { printf "ERROR: v2 must be 260\n" };
if (/= v3 1099) { printf "ERROR: v3 must be 1099\n" };
printf "OK v1=%d v2=%d v3=%d\n" v1 v2 v3;
if (~= v1 130) { printf "ERROR: v1 must be 130\n" } \
else { printf "OK: v1=%d\n" v1 }
if (~= v2 260) { printf "ERROR: v2 must be 260\n" } \
else { printf "OK: v2=%d\n" v2 }
if (~= v3 1099) { printf "ERROR: v3 must be 1099\n" } \
else { printf "OK: v3=%d\n" v3 }
set-r v1 v2 (ff 1 2); ## using 2 return variables only. not assigning to v3
if (/= v1 1003) { printf "ERROR: v1 must be 1003\n" };
if (/= v2 2006) { printf "ERROR: v2 must be 2006\n" };
if (/= v3 1099) { printf "ERROR: v3 must be 1099\n" };
printf "OK v1=%d v2=%d v3=%d\n" v1 v2 v3;
if (~= v1 1003) { printf "ERROR: v1 must be 1003\n" } \
else { printf "OK: v1=%d\n" v1 }
if (~= v2 2006) { printf "ERROR: v2 must be 2006\n" } \
else { printf "OK: v2=%d\n" v2 }
if (~= v3 1099) { printf "ERROR: v3 must be 1099\n" } \
else { printf "OK: v3=%d\n" v3 }
## test return variables in message sends
@ -46,15 +50,17 @@
set-r a b (B:get);
set-r c d (B:get2 -100);
if (/= a 999) { printf "ERROR: a must be 999\n" };
if (/= b 888) { printf "ERROR: b must be 888\n" };
if (/= c 899) { printf "ERROR: c must be 899\n" };
if (/= d 788) { printf "ERROR: d must be 788\n" };
printf "OK a=%d b=%d c=%d d=%d\n" a b c d;
if (~= a 999) { printf "ERROR: a must be 999\n" } \
else { printf "OK: a=%d\n" a }
if (~= b 888) { printf "ERROR: b must be 888\n" } \
else { printf "OK: b=%d\n" b }
if (~= c 899) { printf "ERROR: c must be 899\n" } \
else { printf "OK: c=%d\n" c }
if (~= d 788) { printf "ERROR: d must be 788\n" } \
else { printf "OK: d=%d\n" d }
class X [ x, y ] {
fun ::f(a :: b c) { b := (a + 10); c := (a + 20) }
fun ::f(a :: b c) { b := (+ a 10); c := (+ a 20) }
fun :*new(z) {
## multi-variable assignment with return variables to member variables
@ -67,7 +73,23 @@
}
z := (X:new 9)
if ((x := (z:getX)) /= 19) { printf "ERROR: z:getX msut return 19\n" }
if ((y := (z:getY)) /= 29) { printf "ERROR: z:getX msut return 29\n" }
printf "OK z:getX=%d z:getY=%d\n" x y
if (~= (x := (z:getX)) 19) { printf "ERROR: z:getX must return 19\n" } \
else { printf "OK: z:getX=%d\n" x }
if (~= (y := (z:getY)) 29) { printf "ERROR: z:getX must return 29\n" } \
else { printf "OK: z:getY=%d\n" y }
});
## create a new binary operator message returning two output values
fun Number: // (x :: quo rem) {
quo := (/ self x)
rem := (- self (* quo x))
}
[q,r] := (123 // 4)
if (~= q 30) { printf "ERROR: q is not 30" } \
else { printf "OK: q is %d\n" q }
if (~= r 3) { printf "ERROR: r is not 3" } \
else { printf "OK: r is %d\n" r }