enhancing the compiler to handle 'var' in the class scope. unneeded code to be removed asap
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-19 02:31:54 +09:00
parent 3c88ada3bf
commit f2479c55cd
12 changed files with 225 additions and 55 deletions

View File

@ -15,13 +15,15 @@ class B + ##ERROR: syntax error - prohibited binary selector '+'
---
class A [ a ] {
| j | ##ERROR: syntax error - variable declaration disallowed in class init scope
class A {
var a
| j | ##ERROR: syntax error - variable declaration disallowed
}
---
class 10 [ a ] { ##ERROR: syntax error - invalid class name '10' for 'class'
class 10 { ##ERROR: syntax error - invalid class name '10' for 'class'
var a
}
---
@ -31,7 +33,8 @@ class class { ##ERROR: syntax error - invalid class name 'class' for 'class'
---
class super.a [ a ] { ##ERROR: syntax error - invalid class name 'super.a' for 'class'
class super.a { ##ERROR: syntax error - invalid class name 'super.a' for 'class'
var a
}
---
@ -70,18 +73,20 @@ t1 := (B:newA) ##ERROR: exception not handled - "unable to send newA to B - 'new
---
class B [ x ] {
class B {
var x
if (x > 0) { ##ERROR: syntax error - prohibited access to instance variable - x
}
}
---
class B [ x y ] {
class B {
var x y
};
class X: B [ a b ] {
class X: B {
var a b
fun(#ci) new(t) {
| a |
set self.a t;
@ -156,7 +161,8 @@ Array:boom
---
class X [ a b c ] {
class X {
var a b c
fun(#ci) new () {
self.a := 20
return self
@ -176,10 +182,12 @@ printf "%d\n" ((X:new):get_a)
---
class F [ a b c ] {
class F {
var a b c
}
class X [ a b c ] {
class X {
var a b c
fun oh() {
fun F:get_a() {
return super.a ##ERROR: syntax error - not allowed to prefix with super
@ -233,7 +241,8 @@ class a {
---
class X10 [ x ] {
class X10 {
var x
fun(#ci) make() { x := 1234; return self; };
fun get-x() { return x };
}

View File

@ -96,7 +96,8 @@ if (== y 29) {
## --------------------------------------
class A [ a b c ] {
class A {
var a b c
fun(#ci) newInstance(x y z) {
set a x
set b y

View File

@ -12,7 +12,8 @@ fun Number: <= (oprnd) { return (<= self oprnd) }
fun Number: == (oprnd) { return (== self oprnd) }
fun Number: ~= (oprnd) { return (~= self oprnd) }
class A [ a b c ] {
class A {
var a b c
fun(#ci) newInstance(x y z) {
set a x;
@ -26,7 +27,8 @@ class A [ a b c ] {
fun get-c() { return self.c; };
};
class B: A [ d e f ] {
class B: A {
var d e f
fun(#ci) newInstance(x y z) {
super:newInstance (* x 2) (* y 2) (* z 2);

View File

@ -11,7 +11,8 @@ fun Number: ~= (oprnd) { return (~= self oprnd) }
## --------------------------------------------------------------
set t (
class [ x ] {
class {
var x
fun(#ci) make() { x := 1234; return self; };
fun get-x() { return x };
}
@ -40,16 +41,18 @@ else { printf "OK: value is %d\n" v };
## --------------------------------------------------------------
class X0 [ a b c d ] {
fun(#ci) new() {
return self;
}
class X0 {
var a b c d
fun(#ci) new() {
return self;
}
fun x() {
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)
@ -67,7 +70,8 @@ else { printf "OK: value is %d\n" v }
## --------------------------------------------------------------
class X1 [ a b c ] {
class X1 {
var a b c
fun(#classinst) new () {
self.a := 20
return self
@ -105,10 +109,12 @@ else { printf "OK: value is %d\n" v }
## --------------------------------------------------------------
class F [ j t ] {
class F {
var j t
}
class X2 [ a b c ] {
class X2 {
var a b c
fun(#classinst) new () {
| j |
self.a := 20
@ -178,7 +184,8 @@ if (nqv? v 50) { printf "ERROR: v is not 50 - %d\n" v } \
else { printf "OK: value is %d\n" v }
## --------------------------------------------------------------
class X10 [ x ] {
class X10 {
var x
fun(#ci) make() { x := 1234; return self; };
fun get-x() { return x };
}

View File

@ -31,7 +31,8 @@
## test return variables in message sends
class B [ [X1 X2] ] {
class B {
var(#class) X1 X2
set X1 999;
set X2 888;
@ -59,7 +60,9 @@
if (~= d 788) { printf "ERROR: d must be 788\n" } \
else { printf "OK: d=%d\n" d }
class X [ x, y ] {
class X {
var x y
fun(#class) f(a :: b c) { b := (+ a 10); c := (+ a 20) }
fun(#classinst) new(z) {

View File

@ -56,7 +56,8 @@ fun x () {
x
class T [ j ] {
class T {
var j
fun(#classinst) new() {
set j 99