compiler improvement to support out-of-class class method or calss instance method definitions. pending more tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-05-26 23:18:26 +09:00
parent c219d073ca
commit b4d435a593
14 changed files with 201 additions and 66 deletions

View File

@ -1,9 +1,9 @@
defclass B | x y | {
class B | x y | {
};
defclass X :: B | a b | {
defun :* new(t) {
class X :: B | a b | {
fun :* new(t) {
| a |
set self.a t;
set a 100;
@ -15,7 +15,7 @@ defclass X :: B | a b | {
return self;
};
defun print() {
fun print() {
self.c (+ self.a self.b);
printf "a=%d b=%d\n" self.a self.b;
}
@ -24,30 +24,41 @@ defclass X :: B | a b | {
---
defclass X {
defun :* xxx() {
class X {
fun :* xxx() {
return X;
}
defun :* qqq() {
fun :* qqq() {
return "hello"
}
defun String:length() { ##ERROR: syntax error - function name not valid
fun String:length() { ##ERROR: syntax error - function name not valid
return (str.length self)
}
}
---
defclass X {
defun :* xxx() {
class X {
fun :* xxx() {
return X;
}
defun :* qqq() {
fun :* qqq() {
return "hello"
}
}
## this will trigger a runtime error as J isn't a class name
defun J:ccc() { ##ERROR: exception not handled
fun J:ccc() { ##ERROR: exception not handled
return 999
}
---
## this must not be very useful as Array is an index item
## and the clase instantiation method can't specify the size
## you can't place an item in the arrya at all.
fun Array:*boom() {
arr.put self 0 10 ##ERROR: exception not handled
printf "%O" self
}
Array:boom

View File

@ -1,6 +1,6 @@
## test class instantiation methods
defclass A | a b c | {
class A | a b c | {
defun :*newInstance(x y z) {
set a x;
@ -14,7 +14,7 @@ defclass A | a b c | {
defun get-c() { return self.c; };
};
defclass B :: A | d e f | {
class B :: A | d e f | {
defun :*newInstance(x y z) {
super:newInstance (* x 2) (* y 2) (* z 2);

View File

@ -23,3 +23,8 @@ defclass A | a | {
return self;
};
};
---
defun String length() { ##ERROR: syntax error - no argument list
}