Added S as a prefix to signed integers to make more consistent. E.g.: sint8 instead of int8.
This commit is contained in:
parent
3f5fabae92
commit
0ceebfbdad
3 changed files with 136 additions and 7 deletions
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
// Signed integer type examples with two's complement wrapping
|
||||
|
||||
int8 s8 = -1 // should be -1 within int8 range
|
||||
int16 s16 = -32768 // min int16
|
||||
int32 s32 = -2147483648
|
||||
int64 s64 = -9223372036854775808
|
||||
sint8 s8 = -1 // should be -1 within sint8 range
|
||||
sint16 s16 = -32768 // min sint16
|
||||
sint32 s32 = -2147483648
|
||||
sint64 s64 = -9223372036854775808
|
||||
|
||||
print("s8 = " + to_string(s8) + " :: " + typeof(s8))
|
||||
print("s16 = " + to_string(s16) + " :: " + typeof(s16))
|
||||
|
|
|
|||
63
examples/typeof_features.fun
Normal file
63
examples/typeof_features.fun
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
// Demonstration of enhanced typeof behavior:
|
||||
//
|
||||
// - typeof(<identifier>) for declared integer types returns the subtype:
|
||||
// Sint8, Sint16, Sint32, Sint64, Uint8, Uint16, Uint32, Uint64
|
||||
// - typeof(<expression>) or non-integer identifiers returns runtime categories:
|
||||
// Number, String, Array, Map, Function, Nil
|
||||
|
||||
// Integer subtypes (declared)
|
||||
sint8 si8 = -1
|
||||
sint16 si16 = -32768
|
||||
sint32 si32 = -2147483648
|
||||
sint64 si64 = -9223372036854775808
|
||||
|
||||
uint8 ui8 = 255
|
||||
uint16 ui16 = 65535
|
||||
uint32 ui32 = 4294967295
|
||||
uint64 ui64 = 18446744073709551615
|
||||
|
||||
// 'number' maps to Uint64 behavior by design
|
||||
number n = 42
|
||||
|
||||
// Other runtime types
|
||||
string s = "hello"
|
||||
arr = [1, 2, 3]
|
||||
m = { "k": 1 }
|
||||
|
||||
fun f()
|
||||
return 0
|
||||
|
||||
nil x = nil
|
||||
|
||||
// typeof on identifiers (for integers => declared subtype)
|
||||
print("typeof(si8) = " + typeof(si8)) // Int8
|
||||
print("typeof(si16) = " + typeof(si16)) // Int16
|
||||
print("typeof(si32) = " + typeof(si32)) // Int32
|
||||
print("typeof(si64) = " + typeof(si64)) // Int64
|
||||
|
||||
print("typeof(ui8) = " + typeof(ui8)) // Uint8
|
||||
print("typeof(ui16) = " + typeof(ui16)) // Uint16
|
||||
print("typeof(ui32) = " + typeof(ui32)) // Uint32
|
||||
print("typeof(ui64) = " + typeof(ui64)) // Uint64
|
||||
|
||||
print("typeof(n) = " + typeof(n)) // Uint64
|
||||
|
||||
// typeof on identifiers for non-integers -> runtime categories
|
||||
print("typeof(s) = " + typeof(s)) // String
|
||||
print("typeof(arr) = " + typeof(arr)) // Array
|
||||
print("typeof(m) = " + typeof(m)) // Map
|
||||
print("typeof(f) = " + typeof(f)) // Function
|
||||
print("typeof(x) = " + typeof(x)) // Nil
|
||||
|
||||
// typeof on expressions -> runtime category (Number), not the declared subtype
|
||||
print("typeof(ui8 + 1) = " + typeof(ui8 + 1)) // Number
|
||||
print("typeof(si16 - 2) = " + typeof(si16 - 2))// Number
|
||||
|
||||
// Demonstrate that subtype remains on identifier after operations (assignment clamps)
|
||||
ui8 = ui8 + 10
|
||||
print("ui8 value = " + to_string(ui8) + ", typeof(ui8) = " + typeof(ui8)) // Uint8
|
||||
|
||||
si8 = si8 - 5
|
||||
print("si8 value = " + to_string(si8) + ", typeof(si8) = " + typeof(si8)) // Int8
|
||||
Loading…
Add table
Add a link
Reference in a new issue