fixed a test case regarding self and super as a return value
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
hyung-hwan 2024-02-08 01:39:21 +09:00
parent ded917711e
commit 00438200f9
2 changed files with 36 additions and 6 deletions

View File

@ -4430,6 +4430,8 @@ redo:
case HCL_CNODE_SELF: case HCL_CNODE_SELF:
case HCL_CNODE_SUPER: case HCL_CNODE_SUPER:
/* if super is not sent a message, super represents the receiver
* just like self does */
if (emit_byte_instruction(hcl, HCL_CODE_PUSH_RECEIVER, HCL_CNODE_GET_LOC(oprnd)) <= -1) return -1; if (emit_byte_instruction(hcl, HCL_CODE_PUSH_RECEIVER, HCL_CNODE_GET_LOC(oprnd)) <= -1) return -1;
goto done; goto done;

View File

@ -24,28 +24,56 @@ defclass B :: A | d e f | {
return self; return self;
}; };
defun :: getSuper() { return super; };
###defun :: getSuperclass() { return (self:superclass); };
defun :: getSelf() { return self; };
defun sum() { defun sum() {
return (+ (super:get-a) (super:get-b) (super:get-c) self.d self.e self.f); return (+ (super:get-a) (super:get-b) (super:get-c) self.d self.e self.f);
}; };
}; };
set a ((B:newInstance 1 2 3):sum); a := ((B:newInstance 1 2 3):sum);
if (/= a 18) { printf "ERROR: a must be 18\n"; } \ if (/= a 18) { printf "ERROR: a must be 18\n"; } \
else { printf "OK %d\n" a; }; else { printf "OK %d\n" a; };
set b (B:newInstance 2 3 4); b := (B:newInstance 2 3 4);
set a (b:get-a); a := (b:get-a);
if (/= a 4) {printf "ERROR: a must be 4\n" } \ if (/= a 4) {printf "ERROR: a must be 4\n" } \
else { printf "OK %d\n" a }; else { printf "OK %d\n" a };
set a (b:get-b); a := (b:get-b);
if (/= a 6) { printf "ERROR: a must be 6\n" } \ if (/= a 6) { printf "ERROR: a must be 6\n" } \
else { printf "OK %d\n" a }; else { printf "OK %d\n" a };
set a (b:get-c); a := (b:get-c);
if (/= a 8) { printf "ERROR: a must be 8\n" } \ if (/= a 8) { printf "ERROR: a must be 8\n" } \
else {printf "OK %d\n" a }; else {printf "OK %d\n" a };
set a (b:sum); a := (b:sum);
if (/= a 27) { printf "ERROR: a must be 27\n" } \ if (/= a 27) { printf "ERROR: a must be 27\n" } \
else { printf "OK %d\n" a }; else { printf "OK %d\n" a };
## super is equivalent to self unless a message is sent to it.
## if super itself is returned without a message, it just return
## the receiver just like self. To get the superclass, it must use
## the superclass method inherited from the Class class.
b := (B:getSelf)
a := (B:getSuper)
##c := (B:getSuperlcass)
if (nqv? a b) { printf "ERROR: a is not equivalent to b\n" } \
else { printf "OK a is equivalent to b\n" };
##if (eqv? a c) { printf "ERROR: a is equivalent to b\n" } \
##else { printf "OK a is not equivalent to b\n" };
if (nqv? a B) { printf "ERROR: a is not equivalent to B\n" } \
else { printf "OK a is equivalent to A\n" };
if (nqv? b B) { printf "ERROR: b is not equivalent to B\n" } \
else { printf "OK b is equivalent to B\n" };
##if (nqv? c A) { printf "ERROR: c is not equivalent to A\n" } \
##else { printf "OK c is equivalent to A\n" };