updating the compiler/reader to handle binops more specially

This commit is contained in:
2025-09-21 17:13:47 +09:00
parent 013dbb9e5c
commit 5819be7fa5
15 changed files with 350 additions and 128 deletions

View File

@ -105,3 +105,33 @@ core.basicAtPut "xbcdefghiklmnl" 4 k ##ERROR: exception not handled - "receiver
k := (core.basicAt #abcdefg 1)
core.basicAtPut #xbcdefghiklmnl 4 k ##ERROR: exception not handled - "receiver immutable - xbcdefghiklmnl"
---
## the compiler/runtime needs to improve on this although this is an error for now.
fun + (a b) {}
printf "%O\n" #{+: 20} ##ERROR: no builtin hash implemented for #<BLOCK>
---
class X {
fun + () {} ##ERROR: syntax error - only one argument expected for '+'
}
---
## the binop method defined for a class must have one argument
class X {
fun + (t) {}
fun f1 (t1 t2) {}
}
fun X:- (a b) {} ##ERROR: syntax error - only one argument expected for 'X:-'
---
class X {
fun[#ci] +(a b c) { printf "jjj\n" } ## the one argument rule applies to binary instance methods only.
fun +(c d) { printf "jjj\n" } ##ERROR: syntax error - only one argument expected for '+'
}

View File

@ -132,6 +132,7 @@ if (== i k) { printf "OK: i is %d\n" i k } \
else { printf "ERROR: i is not equal to %d\n" k }
## dictionary
a := #{
(if (> 10 20) true else false ): 10,
(if (< 10 20) true else false ): 20

View File

@ -166,6 +166,7 @@ abc.? := 20 ##ERROR: syntax error - '?' prohibited as first character of identif
---
- := 20 ##ERROR: syntax error - bad lvalue - invalid element - -
---

View File

@ -126,3 +126,22 @@ 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 };
## ----------------------------------------
fun plus(x y) {
##printf "plus %d %d\n" x y
fun minus(x y) {
##printf "minus %d %d\n" x y
- x y
}
+ x y
}
fun dummy(q) {
printf "%s\n" q
}
plus 10 20 ## minus is now available after plus is executed
v := (minus 10 1)
if (== v 9) { printf "OK - %d\n" v } else { printf "ERROR - %d, not 9\n" v }