forked from min-lang/min
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc.m
123 lines (86 loc) · 2.24 KB
/
c.m
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# char, character, unicode code point
https://en.wikipedia.org/wiki/Character_(computing)
https://en.wikipedia.org/wiki/Unicode
add x:C y:N : C = Asm
mov a sp 16
mov c sp 8
add a c
mov sp 24 a
ret
sub x:C y:N : C = Asm
mov a sp 16
mov c sp 8
sub a c
mov sp 24 a
ret
Fact (\. == 46)
Fact (\a == 97)
eq x:C y:C : B = N.eq x y
ne x:C y:C : B = N.ne x y
bin x:C : N = x - \0
Fact (bin \0 == 0)
Fact (bin \1 == 1)
hex x:C : N = between \a x \f & x - \a + 10 | x - \0
Fact (hex \a == 0a)
hex2 x:C y:C : N = (16 * hex x) + hex y
Fact (hex2 \4 \2 == 042)
meta : C? C = (\.? 0a; \!? 0d; \'? \"; \"? \'; \\? \\) # printf format
Fact (meta \. == 0a)
Fact (meta \! == 0d)
Fact (meta \' == \")
Fact (meta \" == \')
code2 : C? S = (09? '\,'; 0a? '\.'; 0d? '\!'; x? str x)
Fact (code2 0a == '\.')
Fact (code2 09 == '\,')
Fact (code2 0d == '\!')
out x:C = x.str.Out
put x:C = x.str.Put
err x:C = x.str.Err
log x:C = x.str.Log
str x:C : S = (s = S.new 1; S.set s x; s)
Fact (str \a == 'a')
str2 x:C y:C : S = (s = S.new 2; S.set s x; S.set s+1 y; s)
Fact (str2 \2 \a == '2a')
code x:C : S = (r = S.new 2; S.set r \\; S.set r+1 x; r)
Fact (code \a == "\\a")
between a:C x:C b:C : B = N.between a x b
is_bin x:C : B = x == \0 | x == \1
Fact (is_bin \0)
Fact (is_bin \1)
Fact !(is_bin \2)
is_lo_bin x:C : B = x == \0 | x == \1 | x == \_
Fact (is_lo_bin \_)
Fact (is_lo_bin \0)
Fact (is_lo_bin \1)
Fact !(is_lo_bin \2)
is_digit x:C : B = between \0 x \9
Fact (is_digit \7)
Fact !(is_digit \a)
is_dec x:C : B = x == \_ | is_digit x
Fact (is_dec \7)
Fact (is_dec \_)
is_hex x:C : B = is_dec x | between \a x \f
Fact (is_hex \a)
Fact (is_hex \_)
upper x:C : C = add x (\A - \a)
Fact (upper \a == \A)
is_upper x:C : B = between \A x \Z
Fact (is_upper \A)
Fact !(is_upper \a)
is_lower x:C : B = between \a x \z
Fact (is_lower \a)
Fact !(is_lower \A)
is_lo_upper x:C : B = x == \_ | is_upper x
is_lo_lower x:C : B = x == \_ | is_lower x
is_letter x:C : B = is_upper x | is_lower x
is_alpha x:C : B = is_dec x | is_letter x
Fact (is_alpha \a)
Fact (is_alpha \_)
is_name x:C : B = x == \. | is_alpha x
Fact (is_name \A)
Fact (is_name \.)
is_nil x:C : B = x == 0
is_any x:C : B = 1
nat x:C : N = Cast.char_nat x
max = 010_fffd
opt x:C : !C = Cast.any (x + 1)