31 lines
830 B
Plaintext
31 lines
830 B
Plaintext
from stdint import *
|
|
import stdio
|
|
|
|
|
|
def bump(v: char) -> char:
|
|
return char(v + 1)
|
|
|
|
|
|
export def main() -> int:
|
|
# 1) char annotation: char = t.CChar = i8 (scalar builtin, not a pointer)
|
|
ch: char = 65
|
|
stdio.printf("1 char annot: %d (expect 65)\n", ch)
|
|
|
|
# 2) char() cast int to char: 300 truncates to i8, giving 44
|
|
big: char = char(300)
|
|
stdio.printf("2 char cast trunc: %d (expect 44)\n", big)
|
|
|
|
# 3) Function returns char (stored as i8)
|
|
nx: char = bump(ch)
|
|
stdio.printf("3 char return: %d (expect 66)\n", nx)
|
|
|
|
# 4) Single-char literal 'Z' assigned to char (90)
|
|
lit: char = 'Z'
|
|
stdio.printf("4 char literal: %d (expect 90)\n", lit)
|
|
|
|
# 5) char in arithmetic (i8 promoted when mixed with int)
|
|
s: int = ch + 1
|
|
stdio.printf("5 char arith: %d (expect 66)\n", s)
|
|
|
|
return 0
|