Changed number from Uint64 to Sint64.
This commit is contained in:
parent
0ceebfbdad
commit
57719279c7
3 changed files with 36 additions and 18 deletions
37
examples/typeof_features.fun
Normal file → Executable file
37
examples/typeof_features.fun
Normal file → Executable file
|
|
@ -1,5 +1,14 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://hanez.org/project/fun/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the ISC license.
|
||||
* https://opensource.org/license/isc-license-txt
|
||||
*/
|
||||
|
||||
// Demonstration of enhanced typeof behavior:
|
||||
//
|
||||
// - typeof(<identifier>) for declared integer types returns the subtype:
|
||||
|
|
@ -8,17 +17,17 @@
|
|||
// Number, String, Array, Map, Function, Nil
|
||||
|
||||
// Integer subtypes (declared)
|
||||
sint8 si8 = -1
|
||||
sint16 si16 = -32768
|
||||
sint32 si32 = -2147483648
|
||||
sint64 si64 = -9223372036854775808
|
||||
sint8 si8 = -1
|
||||
sint16 si16 = -32768
|
||||
sint32 si32 = -2147483648
|
||||
sint64 si64 = -9223372036854775808
|
||||
|
||||
uint8 ui8 = 255
|
||||
uint8 ui8 = 255
|
||||
uint16 ui16 = 65535
|
||||
uint32 ui32 = 4294967295
|
||||
uint64 ui64 = 18446744073709551615
|
||||
|
||||
// 'number' maps to Uint64 behavior by design
|
||||
// 'number' maps to Sint64 behavior by design
|
||||
number n = 42
|
||||
|
||||
// Other runtime types
|
||||
|
|
@ -27,22 +36,22 @@ arr = [1, 2, 3]
|
|||
m = { "k": 1 }
|
||||
|
||||
fun f()
|
||||
return 0
|
||||
return nil
|
||||
|
||||
nil x = nil
|
||||
nil x = f()
|
||||
|
||||
// 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(si8) = " + typeof(si8)) // Sint8
|
||||
print("typeof(si16) = " + typeof(si16)) // Sint16
|
||||
print("typeof(si32) = " + typeof(si32)) // Sint32
|
||||
print("typeof(si64) = " + typeof(si64)) // Sint64
|
||||
|
||||
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
|
||||
print("typeof(n) = " + typeof(n)) // Sint64
|
||||
|
||||
// typeof on identifiers for non-integers -> runtime categories
|
||||
print("typeof(s) = " + typeof(s)) // String
|
||||
|
|
@ -60,4 +69,4 @@ 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
|
||||
print("si8 value = " + to_string(si8) + ", typeof(si8) = " + typeof(si8)) // Sint8
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue