rewrote compile_fun() to support attribute list for a function
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -18,11 +18,11 @@ class B + ##ERROR: syntax error - prohibited binary selector '+'
|
||||
J := 11
|
||||
class B {
|
||||
if (== J 10) {
|
||||
fun :*newA() {
|
||||
fun(#ci) newA() {
|
||||
return self
|
||||
}
|
||||
} else {
|
||||
fun :*newB() {
|
||||
fun(#ci) newB() {
|
||||
return self
|
||||
}
|
||||
}
|
||||
@ -45,7 +45,7 @@ class B [ x y ] {
|
||||
};
|
||||
|
||||
class X :: B [ a b ] {
|
||||
fun :* new(t) {
|
||||
fun(#ci) new(t) {
|
||||
| a |
|
||||
set self.a t;
|
||||
set a 100;
|
||||
@ -67,24 +67,25 @@ class X :: B [ a b ] {
|
||||
---
|
||||
|
||||
class X {
|
||||
fun :* xxx() {
|
||||
fun(#ci) xxx() {
|
||||
return X;
|
||||
}
|
||||
fun :* qqq() {
|
||||
|
||||
fun(#ci) qqq() {
|
||||
return "hello"
|
||||
}
|
||||
|
||||
fun String:length() { ##ERROR: syntax error - function name not valid
|
||||
return (str.length self)
|
||||
fun String:length() { ##ERROR: syntax error - class name 'String' before :'length' prohibited in class initialization context
|
||||
return (core.basicSize self)
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
class X {
|
||||
fun :* xxx() {
|
||||
fun(#ci) xxx() {
|
||||
return X;
|
||||
}
|
||||
fun :* qqq() {
|
||||
fun(#ci) qqq() {
|
||||
return "hello"
|
||||
}
|
||||
}
|
||||
@ -109,7 +110,7 @@ fun X:xxx() { ##ERROR: exception not handled - "not class"
|
||||
## and the clase instantiation method can't specify the size
|
||||
## you can't place an item in the arrya at all.
|
||||
|
||||
fun Array:*boom() {
|
||||
fun(#ci) Array:boom() {
|
||||
core.basicAtPut self 0 10 ##ERROR: exception not handled - "position(0) out of range - negative or greater than or equal to 0"
|
||||
printf "%O" self
|
||||
return self
|
||||
@ -119,7 +120,7 @@ Array:boom
|
||||
---
|
||||
|
||||
class X [ a b c ] {
|
||||
fun :* new () {
|
||||
fun(#ci) new () {
|
||||
self.a := 20
|
||||
return self
|
||||
}
|
||||
@ -186,3 +187,10 @@ F := (class F { ##ERROR: exception not handle - "prohibited redefintion of F"
|
||||
##F := 30
|
||||
##class F { ##ERROR: exception not handled - "prohibited redefintion of F"
|
||||
##}
|
||||
|
||||
|
||||
---
|
||||
class a {
|
||||
fun() { ##ERROR: syntax error - unnamed function defined with 'fun' prohibited in class initialziation context
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,11 @@ fun :* fun1() { ##ERROR: syntax error - invalid function name ':*' for 'fun'
|
||||
|
||||
---
|
||||
|
||||
fun(#ci) fun1() { ##ERROR: syntax error - unsupported attribute list for plain function 'fun1'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(10 + 20 30) ##ERROR: syntax error - redundant operand '30'
|
||||
|
||||
---
|
||||
|
19
t/fun-01.hcl
19
t/fun-01.hcl
@ -97,7 +97,7 @@ if (== y 29) {
|
||||
## --------------------------------------
|
||||
|
||||
defclass A [ a b c ] {
|
||||
fun :* newInstance(x y z) {
|
||||
fun(#ci) newInstance(x y z) {
|
||||
set a x
|
||||
set b y
|
||||
set c z
|
||||
@ -113,8 +113,15 @@ k := (A:newInstance 11 22 33);
|
||||
##set k (A:newInstance 11 22 33);
|
||||
|
||||
set v (k:get-a);
|
||||
if (== v 11) {
|
||||
printf "OK - %d\n" v;
|
||||
} else {
|
||||
printf "ERROR - %d\n" v;
|
||||
};
|
||||
if (== v 11) { printf "OK - %d\n" v; } else { printf "ERROR - %d, ot 11\n" v; };
|
||||
|
||||
## --------------------------------------
|
||||
|
||||
k := (fun (x) { + x 20 }) ## (+ x 20) would be syntax error, must be { + x 20 }
|
||||
v := (k 10)
|
||||
if (== v 30) { printf "OK - %d\n" v } else { printf "ERROR - %d, not 30\n" v };
|
||||
|
||||
## --------------------------------------
|
||||
fun k(x) (+ x 30) ## (+ x 30) is valid function body
|
||||
v := (k 10)
|
||||
if (== v 40) { printf "OK - %d\n" v } else { printf "ERROR - %d, not 40\n" v };
|
||||
|
@ -14,7 +14,7 @@ fun Number: ~= (oprnd) { return (~= self oprnd) }
|
||||
|
||||
class A [ a b c ] {
|
||||
|
||||
fun :*newInstance(x y z) {
|
||||
fun(#ci) newInstance(x y z) {
|
||||
set a x;
|
||||
set b y;
|
||||
set c z;
|
||||
@ -28,7 +28,7 @@ class A [ a b c ] {
|
||||
|
||||
class B :: A [ d e f ] {
|
||||
|
||||
fun :*newInstance(x y z) {
|
||||
fun(#ci) newInstance(x y z) {
|
||||
super:newInstance (* x 2) (* y 2) (* z 2);
|
||||
set d x;
|
||||
set e y;
|
||||
@ -36,9 +36,9 @@ class B :: A [ d e f ] {
|
||||
return self;
|
||||
};
|
||||
|
||||
fun :: getSuper() { return super; };
|
||||
###fun :: getSuperclass() { return (self:superclass); };
|
||||
fun :: getSelf() { return self; };
|
||||
fun(#c) getSuper() { return super; };
|
||||
###fun(#c) getSuperclass() { return (self:superclass); };
|
||||
fun(#c) getSelf() { return self; };
|
||||
|
||||
fun sum() {
|
||||
return (+ (super:get-a) (super:get-b) (super:get-c) self.d self.e self.f);
|
||||
|
@ -12,7 +12,7 @@ fun Number: ~= (oprnd) { return (~= self oprnd) }
|
||||
## --------------------------------------------------------------
|
||||
set t (
|
||||
class [ x ] {
|
||||
fun :* make() { x := 1234; return self; };
|
||||
fun(#ci) make() { x := 1234; return self; };
|
||||
fun get-x() { return x };
|
||||
}
|
||||
);
|
||||
@ -40,7 +40,7 @@ else { printf "OK: value is %d\n" v };
|
||||
## --------------------------------------------------------------
|
||||
|
||||
class X0 [ a b c d ] {
|
||||
fun :*new() {
|
||||
fun(#ci) new() {
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ else { printf "OK: value is %d\n" v }
|
||||
## --------------------------------------------------------------
|
||||
|
||||
class X1 [ a b c ] {
|
||||
fun :* new () {
|
||||
fun(#classinst) new () {
|
||||
self.a := 20
|
||||
return self
|
||||
}
|
||||
@ -108,11 +108,11 @@ class F [ j t ] {
|
||||
}
|
||||
|
||||
class X2 [ a b c ] {
|
||||
fun :* new () {
|
||||
fun(#classinst) new () {
|
||||
| j |
|
||||
self.a := 20
|
||||
j := (self.a * 2)
|
||||
fun F::get_x() { return (j * j) }
|
||||
fun(#class) F:get_x() { return (j * j) }
|
||||
return self
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ else { printf "OK: value is %d\n" v }
|
||||
|
||||
## --------------------------------------------------------------
|
||||
class X3 {
|
||||
fun :* new (a b) {
|
||||
fun(#ci) new (a b) {
|
||||
fun X3:sum() { return (fun(j) { return (j + (a + b)) }) }
|
||||
return self;
|
||||
}
|
||||
@ -136,15 +136,15 @@ else { printf "OK: value is %d\n" v }
|
||||
|
||||
## --------------------------------------------------------------
|
||||
class X4 {
|
||||
fun :: t() {
|
||||
fun(#class) t() {
|
||||
| X5 |
|
||||
class X5 { ## this X5 isn't the local variable X4
|
||||
fun :: t() {
|
||||
fun(#class) t() {
|
||||
X6 := (class {
|
||||
fun :: t() {
|
||||
fun(#class) t() {
|
||||
| X7 |
|
||||
X7 := (class { ## this X4 is the local variable X4
|
||||
fun :: t() { return 60 }
|
||||
fun(#class) t() { return 60 }
|
||||
})
|
||||
return 40
|
||||
}
|
||||
|
@ -36,12 +36,12 @@
|
||||
set X1 999;
|
||||
set X2 888;
|
||||
|
||||
fun :: get ( :: x y) {
|
||||
fun(#class) get ( :: x y) {
|
||||
set x X1;
|
||||
set y X2;
|
||||
};
|
||||
|
||||
fun :: get2 (inc :: x y) {
|
||||
fun(#class) get2 (inc :: x y) {
|
||||
set x (+ X1 inc);
|
||||
set y (+ X2 inc);
|
||||
};
|
||||
@ -60,9 +60,9 @@
|
||||
else { printf "OK: d=%d\n" d }
|
||||
|
||||
class X [ x, y ] {
|
||||
fun ::f(a :: b c) { b := (+ a 10); c := (+ a 20) }
|
||||
fun(#class) f(a :: b c) { b := (+ a 10); c := (+ a 20) }
|
||||
|
||||
fun :*new(z) {
|
||||
fun(#classinst) new(z) {
|
||||
## multi-variable assignment with return variables to member variables
|
||||
[self.x, self.y] := (X:f z)
|
||||
return self;
|
||||
@ -83,7 +83,7 @@
|
||||
|
||||
|
||||
## create a new binary operator message returning two output values
|
||||
fun Number: // (x :: quo rem) {
|
||||
fun Number:// (x :: quo rem) {
|
||||
quo := (/ self x)
|
||||
rem := (- self (* quo x))
|
||||
}
|
||||
|
5
t/run.sh
5
t/run.sh
@ -3,4 +3,9 @@
|
||||
## program crashes or exits without an error message.
|
||||
echo RUN "[$@]"
|
||||
($@ 2>&1 || echo "ERROR: exited with $?") | grep -E '^ERROR:' && exit 1
|
||||
##[ "x$MEMCHECK" = "xyes" ] && {
|
||||
## [ -x /usr/bin/valgrind ] && {
|
||||
## valgrind --leak-check=full --show-reachable=yes --track-fds=yes --log-file=/tmp/x "$@" 2>&1
|
||||
## }
|
||||
##}
|
||||
exit 0
|
||||
|
@ -58,7 +58,7 @@ x
|
||||
|
||||
class T [ j ] {
|
||||
|
||||
fun :* new() {
|
||||
fun(#classinst) new() {
|
||||
set j 99
|
||||
return self
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
defclass A [ a ] {
|
||||
fun :* init1() {
|
||||
fun(#ci) init1() {
|
||||
| b |
|
||||
set b (+ 1 2);
|
||||
set a b;
|
||||
@ -15,7 +15,7 @@ defclass A [ a ] {
|
||||
printf ">>> %d\n" j;
|
||||
}
|
||||
|
||||
fun :* init2() {
|
||||
fun(#ci) init2() {
|
||||
| b |
|
||||
set b (+ 10 20);
|
||||
set a b;
|
||||
@ -26,7 +26,7 @@ defclass A [ a ] {
|
||||
|
||||
---
|
||||
|
||||
fun String length() { ##ERROR: syntax error - no argument list
|
||||
fun String length() { ##ERROR: syntax error - 'String' not followed by ( but followed by 'length'
|
||||
}
|
||||
|
||||
---
|
||||
|
@ -1,2 +1,66 @@
|
||||
fun self.x() { ##ERROR: syntax error - invalid function name 'self.x' for 'fun'
|
||||
};
|
||||
|
||||
---
|
||||
|
||||
fun if() { ##ERROR: syntax error - invalid function name 'if' for 'fun'
|
||||
};
|
||||
|
||||
---
|
||||
|
||||
fun a if() { ##ERROR: syntax error - 'a' not followed by ( but followed by 'if'
|
||||
};
|
||||
|
||||
---
|
||||
|
||||
fun a:b if() { ##ERROR: syntax error - 'b' not followed by ( but followed by 'if'
|
||||
};
|
||||
|
||||
---
|
||||
|
||||
fun x (x :: 20) { ##ERROR: syntax error - invalid return variable '20' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
fun x (x :: if) { ##ERROR: syntax error - invalid return variable 'if' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (x :: self.y) { ##ERROR: syntax error - invalid return variable 'self.y' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (x :: z z) { ##ERROR: syntax error - duplicate return variable 'z' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (x 20) { ##ERROR: syntax error - invalid argument name '20' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (+) { ##ERROR: syntax error - invalid argument name '+' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (a while) { ##ERROR: syntax error - invalid argument name 'while' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (a b a) { ##ERROR: syntax error - duplicate argument name 'a' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (... a) { ##ERROR: syntax error - unexpected token 'a' after '...' for 'fun'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
fun x (... : a) { ##ERROR: syntax error - : disallowed
|
||||
}
|
||||
|
Reference in New Issue
Block a user