2024-09-03 03:18:08 +00:00
|
|
|
fun Number: + (oprnd) { return (+ self oprnd) }
|
|
|
|
fun Number: - (oprnd) { return (- self oprnd) }
|
|
|
|
fun Number: * (oprnd) { return (* self oprnd) }
|
|
|
|
fun Number: / (oprnd) { return (/ self oprnd) }
|
|
|
|
fun Number: > (oprnd) { return (> self oprnd) }
|
|
|
|
fun Number: < (oprnd) { return (< self oprnd) }
|
|
|
|
fun Number: >= (oprnd) { return (>= self oprnd) }
|
|
|
|
fun Number: <= (oprnd) { return (<= self oprnd) }
|
|
|
|
fun Number: == (oprnd) { return (== self oprnd) }
|
|
|
|
fun Number: ~= (oprnd) { return (~= self oprnd) }
|
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
2024-01-02 04:59:03 +00:00
|
|
|
set t (
|
2024-10-18 17:31:54 +00:00
|
|
|
class {
|
|
|
|
var x
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#ci) make() { x := 1234; return self; };
|
2024-09-28 02:57:56 +00:00
|
|
|
fun get-x() { return x };
|
2024-01-02 04:59:03 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
set X t;
|
|
|
|
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? t X) { printf "ERROR: t must point to X\n" } \
|
2024-01-02 04:59:03 +00:00
|
|
|
else { printf "OK: t points to X\n" };
|
|
|
|
|
|
|
|
set t ((t:make):get-x);
|
|
|
|
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? t 1234) { printf "ERROR: t must be 1234\n" } \
|
2024-01-02 04:59:03 +00:00
|
|
|
else { printf "OK: t is %d\n" t };
|
|
|
|
|
|
|
|
|
2024-02-04 17:43:50 +00:00
|
|
|
j := #{ ((X:make):get-x): 9999, 4512: ((X: make): get-x) };
|
|
|
|
v := (dic.get j 1234);
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? v 9999) { printf "ERROR: v is not 9999\n" } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v };
|
2024-01-02 04:59:03 +00:00
|
|
|
|
2024-02-04 17:43:50 +00:00
|
|
|
v := (dic.get j 4512);
|
2024-01-18 14:55:50 +00:00
|
|
|
if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v };
|
|
|
|
|
2024-04-18 14:06:28 +00:00
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
|
|
|
|
2024-10-18 17:31:54 +00:00
|
|
|
class X0 {
|
|
|
|
var a b c d
|
|
|
|
fun(#ci) new() {
|
|
|
|
return self;
|
|
|
|
}
|
2024-04-18 14:06:28 +00:00
|
|
|
|
2024-10-18 17:31:54 +00:00
|
|
|
fun x() {
|
2024-04-18 14:06:28 +00:00
|
|
|
a := 20 ; self.b:=(a + 10); c := (b + 20)
|
|
|
|
printf "%d %d %d\n" self.a self.b self.c
|
|
|
|
return (+ self.a self.b self.c)
|
2024-10-18 17:31:54 +00:00
|
|
|
}
|
|
|
|
|
2024-04-18 14:06:28 +00:00
|
|
|
fun y() {
|
|
|
|
self.d := (fun(k) {
|
|
|
|
return (k + 1)
|
|
|
|
})
|
|
|
|
return self.d
|
|
|
|
}
|
|
|
|
|
2024-07-23 14:50:29 +00:00
|
|
|
}; a := (X0:new); v := (a:x)
|
2024-04-18 14:06:28 +00:00
|
|
|
if (nqv? v 100) { printf "ERROR: v is not 100\n" } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-04-18 14:06:28 +00:00
|
|
|
|
|
|
|
v := ((a:y) 20);
|
|
|
|
if (nqv? v 21) { printf "ERROR: v is not 21\n" } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-05-31 06:16:31 +00:00
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
|
|
|
|
2024-10-18 17:31:54 +00:00
|
|
|
class X1 {
|
|
|
|
var a b c
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#classinst) new () {
|
2024-05-31 06:16:31 +00:00
|
|
|
self.a := 20
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getA() { return self.a }
|
|
|
|
|
|
|
|
fun make(t a b) {
|
|
|
|
| v |
|
|
|
|
v := 50
|
|
|
|
if (t > 5) {
|
2024-07-22 08:24:26 +00:00
|
|
|
fun X1:get_j() { return (((1 + t) + a) + (b + v)) }
|
2024-05-31 06:16:31 +00:00
|
|
|
} else {
|
2024-07-22 08:24:26 +00:00
|
|
|
fun X1:get_j() { return ((2 * (t + a)) + (b + v)) }
|
2024-05-31 06:16:31 +00:00
|
|
|
}
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
fun X1:get_a() {
|
2024-05-31 06:16:31 +00:00
|
|
|
return (self:getA)
|
|
|
|
}
|
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
v := ((X1:new):get_a)
|
2024-05-31 06:16:31 +00:00
|
|
|
if (nqv? v 20) { printf "ERROR: v is not 20 - %d\n" v } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-05-31 06:16:31 +00:00
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
v := (((X1:new):make 5 6 7):get_j)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 79) { printf "ERROR: v is not 79 - %d\n" v } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-05-31 06:16:31 +00:00
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
v := (((X1:new):make 6 6 7):get_j)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 70) { printf "ERROR: v is not 70 - %d\n" v } \
|
2024-10-03 13:54:03 +00:00
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-05-31 15:11:51 +00:00
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
|
|
|
|
2024-10-18 17:31:54 +00:00
|
|
|
class F {
|
|
|
|
var j t
|
2024-05-31 15:11:51 +00:00
|
|
|
}
|
|
|
|
|
2024-10-18 17:31:54 +00:00
|
|
|
class X2 {
|
|
|
|
var a b c
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#classinst) new () {
|
2024-05-31 15:11:51 +00:00
|
|
|
| j |
|
|
|
|
self.a := 20
|
|
|
|
j := (self.a * 2)
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#class) F:get_x() { return (j * j) }
|
2024-05-31 15:11:51 +00:00
|
|
|
return self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
X2:new
|
2024-05-31 15:11:51 +00:00
|
|
|
v := (F:get_x)
|
|
|
|
if (nqv? v 1600) { printf "ERROR: v is not 1600 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
2024-07-22 08:24:26 +00:00
|
|
|
class X3 {
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#ci) new (a b) {
|
2024-07-22 08:24:26 +00:00
|
|
|
fun X3:sum() { return (fun(j) { return (j + (a + b)) }) }
|
2024-05-31 15:11:51 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
v := (((X3:new 10 2):sum) 23)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 35) { printf "ERROR: v is not 35 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
2024-07-22 08:24:26 +00:00
|
|
|
class X4 {
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#class) t() {
|
2024-07-22 14:46:38 +00:00
|
|
|
| X5 |
|
|
|
|
class X5 { ## this X5 isn't the local variable X4
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#class) t() {
|
2024-07-22 14:46:38 +00:00
|
|
|
X6 := (class {
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#class) t() {
|
2024-07-22 14:46:38 +00:00
|
|
|
| X7 |
|
|
|
|
X7 := (class { ## this X4 is the local variable X4
|
2024-10-01 15:33:34 +00:00
|
|
|
fun(#class) t() { return 60 }
|
2024-05-31 15:11:51 +00:00
|
|
|
})
|
|
|
|
return 40
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 30
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 08:24:26 +00:00
|
|
|
v := (X4:t)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 30) { printf "ERROR: v is not 30 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
|
|
|
|
2024-07-22 14:46:38 +00:00
|
|
|
v := (X5:t)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 20) { printf "ERROR: v is not 20 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
|
|
|
|
2024-07-22 14:46:38 +00:00
|
|
|
v := (X6:t)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 40) { printf "ERROR: v is not 40 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
|
|
|
|
2024-07-22 14:46:38 +00:00
|
|
|
v := (X6:t)
|
2024-05-31 15:11:51 +00:00
|
|
|
if (nqv? v 40) { printf "ERROR: v is not 40 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-09-03 03:18:08 +00:00
|
|
|
|
|
|
|
v := { X5:t; (X6:t) + 10 }
|
|
|
|
if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \
|
|
|
|
else { printf "OK: value is %d\n" v }
|
2024-10-03 13:54:03 +00:00
|
|
|
|
|
|
|
## --------------------------------------------------------------
|
2024-10-18 17:31:54 +00:00
|
|
|
class X10 {
|
|
|
|
var x
|
2024-10-03 13:54:03 +00:00
|
|
|
fun(#ci) make() { x := 1234; return self; };
|
|
|
|
fun get-x() { return x };
|
|
|
|
}
|
|
|
|
|
|
|
|
X11 := (class:X10 {
|
|
|
|
})
|
|
|
|
|
|
|
|
v := (X11:make)
|
|
|
|
v := (v:get-x)
|
|
|
|
if (== v 1234) { printf "OK: v is %d\n" v } \
|
|
|
|
else {printf "ERROR: v is %d, not 1234\n" v }
|