-
Notifications
You must be signed in to change notification settings - Fork 5
/
Char.fm
84 lines (74 loc) · 2.33 KB
/
Char.fm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// An unicode codepoint.
Char: Type
U16
// Creates a character from 16 bits.
Char.new
(b0: Bit) (b1: Bit) (b2: Bit) (b3: Bit)
(b4: Bit) (b5: Bit) (b6: Bit) (b7: Bit)
(b8: Bit) (b9: Bit) (bA: Bit) (bB: Bit)
(bC: Bit) (bD: Bit) (bE: Bit) (bF: Bit)
: U16
let kF = b0<>(Word.0<>, Word.1<>)
let kE = b1<>(Word.0<>, Word.1<>)
let kD = b2<>(Word.0<>, Word.1<>)
let kC = b3<>(Word.0<>, Word.1<>)
let kB = b4<>(Word.0<>, Word.1<>)
let kA = b5<>(Word.0<>, Word.1<>)
let k9 = b6<>(Word.0<>, Word.1<>)
let k8 = b7<>(Word.0<>, Word.1<>)
let k7 = b8<>(Word.0<>, Word.1<>)
let k6 = b9<>(Word.0<>, Word.1<>)
let k5 = bA<>(Word.0<>, Word.1<>)
let k4 = bB<>(Word.0<>, Word.1<>)
let k3 = bC<>(Word.0<>, Word.1<>)
let k2 = bD<>(Word.0<>, Word.1<>)
let k1 = bE<>(Word.0<>, Word.1<>)
let k0 = bF<>(Word.0<>, Word.1<>)
let kx = Word.nil
U16.new(k0(k1(k2(k3(k4(k5(k6(k7(k8(k9(kA(kB(kC(kD(kE(kF(kx)))))))))))))))))
Char.newline: Char
Char.new(
Bit.0, Bit.0, Bit.0, Bit.0,
Bit.0, Bit.0, Bit.0, Bit.0,
Bit.0, Bit.0, Bit.0, Bit.0,
Bit.1, Bit.0, Bit.1, Bit.0)
// Receives a hex char (0-9, a-f, A-F) and returns its value.
Char.hex_value16(chr: Char): U16
def U16.add10((x0)
def x1 = U16.inc(U16.inc(U16.inc(U16.inc(U16.inc(x0)))))
def x2 = U16.inc(U16.inc(U16.inc(U16.inc(U16.inc(x1)))))
x2) :: U16 -> U16
if Bool.and(U16.gte(chr,'0'),U16.lte(chr,'9')) then
U16.sub(chr,'0')
else if Bool.and(U16.gte(chr,'a'),U16.lte(chr,'f')) then
U16.add10(U16.sub(chr,'a'))
else if Bool.and(U16.gte(chr,'A'),U16.lte(chr,'F')) then
U16.add10(U16.sub(chr,'A'))
else
U16.0
Char.hex_value32(chr: Char): U32
U16.to_u32(Char.hex_value16(chr))
Char.hex_value(chr: Char): Nat
U32.to_nat(Char.hex_value32(chr))
Char.parse.type(str: String): Type
case str:
| Unit;
| Char;
// Parses a character. Example: `Char.parse("x")`
Char.parse(str: String): Char.parse.type(str)
case str:
| Unit.new;
| str.head;
: Char.parse.type(str.self);
//Char.quote : Char
//Char.new
//| Bit.0; | Bit.0; | Bit.0; | Bit.0;
//| Bit.0; | Bit.0; | Bit.0; | Bit.0;
//| Bit.0; | Bit.0; | Bit.1; | Bit.0;
//| Bit.0; | Bit.0; | Bit.1; | Bit.0;
//Char.tab: Char
//Char.new
//| Bit.0; | Bit.0; | Bit.0; | Bit.0;
//| Bit.0; | Bit.0; | Bit.0; | Bit.0;
//| Bit.0; | Bit.0; | Bit.0; | Bit.0;
//| Bit.1; | Bit.0; | Bit.0; | Bit.1;