200 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			200 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
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) }
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
set t (
 | 
						|
	class {
 | 
						|
		var x
 | 
						|
		fun[#ci] make() { x := 1234; return self; };
 | 
						|
		fun get-x() { return x };
 | 
						|
	}
 | 
						|
);
 | 
						|
 | 
						|
set X t;
 | 
						|
 | 
						|
if (nqv? t X) { printf "ERROR: t must point to X\n" } \
 | 
						|
else { printf "OK: t points to X\n" };
 | 
						|
 | 
						|
set t ((t:make):get-x);
 | 
						|
 | 
						|
if (nqv? t 1234) { printf "ERROR: t must be 1234\n" } \
 | 
						|
else { printf "OK: t is %d\n" t };
 | 
						|
 | 
						|
 | 
						|
j := #{ ((X:make):get-x): 9999, 4512: ((X: make): get-x) };
 | 
						|
v := (dic.get j 1234);
 | 
						|
if (nqv? v 9999) { printf "ERROR: v is not 9999\n" } \
 | 
						|
else {  printf "OK: value is %d\n" v };
 | 
						|
 | 
						|
v := (dic.get j 4512);
 | 
						|
if (nqv? v 1234) { printf "ERROR: v is not 1234\n" } \
 | 
						|
else { printf "OK: value is %d\n" v };
 | 
						|
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
 | 
						|
class X0 {
 | 
						|
	var a b c d
 | 
						|
	fun[#ci] new() {
 | 
						|
		return self;
 | 
						|
	}
 | 
						|
 | 
						|
	fun x() {
 | 
						|
		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)
 | 
						|
	}
 | 
						|
 | 
						|
	fun y() {
 | 
						|
		self.d := (fun(k) {
 | 
						|
			return (k + 1)
 | 
						|
		})
 | 
						|
		return self.d
 | 
						|
	}
 | 
						|
 | 
						|
}; a := (X0:new); v := (a:x)
 | 
						|
if (nqv? v 100) { printf "ERROR: v is not 100\n" } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
v := ((a:y) 20);
 | 
						|
if (nqv? v 21) { printf "ERROR: v is not 21\n" } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
 | 
						|
class X1 {
 | 
						|
	var a b c
 | 
						|
	fun[#classinst] new () {
 | 
						|
		self.a := 20
 | 
						|
		return self
 | 
						|
	}
 | 
						|
 | 
						|
	fun getA() { return self.a }
 | 
						|
 | 
						|
	fun make(t a b) {
 | 
						|
		| v |
 | 
						|
		v := 50
 | 
						|
		if (t > 5) {
 | 
						|
			fun X1:get_j() { return (((1 + t) + a) + (b + v)) }
 | 
						|
		} else {
 | 
						|
			fun X1:get_j() { return ((2 * (t + a)) + (b + v)) }
 | 
						|
		}
 | 
						|
		return self
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
fun X1:get_a() {
 | 
						|
	return (self:getA)
 | 
						|
}
 | 
						|
 | 
						|
v := ((X1:new):get_a)
 | 
						|
if (nqv? v 20) { printf "ERROR: v is not 20 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
v := (((X1:new):make 5 6 7):get_j)
 | 
						|
if (nqv? v 79) { printf "ERROR: v is not 79 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
v := (((X1:new):make 6 6 7):get_j)
 | 
						|
if (nqv? v 70) { printf "ERROR: v is not 70 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
 | 
						|
class F {
 | 
						|
	var j t
 | 
						|
}
 | 
						|
 | 
						|
class X2 {
 | 
						|
	var a b c
 | 
						|
	fun[#classinst] new () {
 | 
						|
		| j |
 | 
						|
		self.a := 20
 | 
						|
		j := (self.a  * 2)
 | 
						|
		fun[#class] F:get_x() { return (j * j) }
 | 
						|
		return self
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
X2:new
 | 
						|
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 }
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
class X3 {
 | 
						|
	fun[#ci] new (a b) {
 | 
						|
		fun X3:sum() { return (fun(j) { return (j + (a + b)) }) }
 | 
						|
		return self;
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
v := (((X3:new 10 2):sum) 23)
 | 
						|
if (nqv? v 35) { printf "ERROR: v is not 35 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
class X4 {
 | 
						|
	fun[#class] t() {
 | 
						|
		| X5 |
 | 
						|
		class X5 { ## this X5 isn't the local variable X4
 | 
						|
			fun[#class]  t() {
 | 
						|
				X6 := (class {
 | 
						|
					fun[#class] t() {
 | 
						|
						| X7 |
 | 
						|
						X7 := (class { ## this X4 is the local variable X4
 | 
						|
							fun[#class] t() { return 60 }
 | 
						|
						})
 | 
						|
						return 40
 | 
						|
					}
 | 
						|
				})
 | 
						|
				return 20;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		return 30
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
v := (X4:t)
 | 
						|
if (nqv? v 30) { printf "ERROR: v is not 30 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
v := (X5:t)
 | 
						|
if (nqv? v 20) { printf "ERROR: v is not 20 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
v := (X6:t)
 | 
						|
if (nqv? v 40) { printf "ERROR: v is not 40 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
v := (X6:t)
 | 
						|
if (nqv? v 40) { printf "ERROR: v is not 40 - %d\n" v } \
 | 
						|
else { printf "OK: value is %d\n" v }
 | 
						|
 | 
						|
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 }
 | 
						|
 | 
						|
## --------------------------------------------------------------
 | 
						|
class X10 {
 | 
						|
	var x
 | 
						|
	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 }
 |