change the way to read a token beginning with a colon.
added more primitive functions to the core module
This commit is contained in:
@ -13,6 +13,7 @@ check_SCRIPTS = \
|
||||
fun-01.hak \
|
||||
insta-01.hak \
|
||||
insta-02.hak \
|
||||
prim-01.hak \
|
||||
proc-01.hak \
|
||||
ret-01.hak \
|
||||
retvar-01.hak \
|
||||
|
@ -542,6 +542,7 @@ check_SCRIPTS = \
|
||||
fun-01.hak \
|
||||
insta-01.hak \
|
||||
insta-02.hak \
|
||||
prim-01.hak \
|
||||
proc-01.hak \
|
||||
ret-01.hak \
|
||||
retvar-01.hak \
|
||||
|
@ -346,3 +346,12 @@ class[#b] X (a) {
|
||||
|
||||
class Y: X { ##ERROR: exception not handled - "incompatible byte superclass X with oop class"
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
## you can't send a binary message to an object the receiver:message syntax.
|
||||
## you must omit the colon for the binary message
|
||||
## it must be '20 == 40'
|
||||
|
||||
fun Number:==(b) { return (core.+ self b) }
|
||||
20 :== 40 ##ERROR: syntax error - prohibited binary selector '=='
|
||||
|
39
t/prim-01.hak
Normal file
39
t/prim-01.hak
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
## START
|
||||
| x |
|
||||
|
||||
x := (sprintf "%b %b" 123 (core.bit-not 123))
|
||||
expected := "1111011 -1111100"
|
||||
if (core.eql? x "1111011 -1111100") { ## bit-inversion of 123 is -124.
|
||||
printf "OK: %s\n" expected
|
||||
} else {
|
||||
printf "BAD: x is not %s - %s\n" expected x
|
||||
}
|
||||
|
||||
|
||||
##fun Number:"+"(b) { return (core.+ self b) }
|
||||
fun Number:+(b) { return (core.+ self b) }
|
||||
fun Number:-(b) { return (core.- self b) }
|
||||
fun Number:*(b) { return (core.* self b) }
|
||||
fun Number:/(b) { return (core./ self b) }
|
||||
fun Apex:==(b) { return (core.eql? self b) }
|
||||
fun Apex:~=(b) { return (core.nql? self b) }
|
||||
## big numbers and fixed pointer decimals don't share the same object for the same values.
|
||||
## we must use eql or nql, can't use eqv or nqv.
|
||||
|
||||
expected := 2
|
||||
if ((x := (1 + 2 * 3 / 4)) == expected) { ## note: there is no operator precedence since it doesn't no what operation each binop represents
|
||||
printf "OK: %d\n" expected
|
||||
} else {
|
||||
printf "BAD: x is not %d - %d\n" expected x
|
||||
}
|
||||
|
||||
expected := 2.2
|
||||
if ((x := (1.0 + 2 * 3 / 4)) ~= expected) {
|
||||
printf "BAD: x is not %O - %O\n" expected x
|
||||
} else {
|
||||
printf "OK: %O\n" expected
|
||||
}
|
||||
|
||||
## END
|
||||
}
|
Reference in New Issue
Block a user