-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib.srm
75 lines (63 loc) · 1.42 KB
/
stdlib.srm
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
type Putchar=(Char):Int
extern let putchar:Putchar=(x:Char):Int;
type Getchar=():Int
extern let getchar:Getchar=():Int;
type Sin=(Float):Float
extern let sin:Sin=(x:Float):Float;
let add=(x:Int, y:Int):Int=>{x+y}
let sayHello=()=>{
putchar(64+8 as Char)
putchar(64+5 as Char)
putchar(64+12 as Char)
putchar(64+12 as Char)
putchar(64+15 as Char)
putchar(10 as Char)
putchar(13 as Char)
}
extern let newLine=()=>{
putchar(10 as Char)
putchar(13 as Char)
};
type Puts=(Ptr):Int
extern let puts:Puts=(str:Ptr):Int;
type Ptrcat=(Ptr,Ptr):Int
extern const strcat:Ptrcat=(a:Ptr,b:Ptr):Int;
extern const memcpy:Ptrcat=(a:Ptr,b:Ptr):Int;
type Point<T> ={x:T; y:T};
extern const midPoint=(a:Point<Float>, b:Point<Float>):Point<Float> =>({
x:(a.x+b.x)/2.0,
y:(a.y+b.y)/2.0
});
extern const modulo=(x:Int, base:Int):Int=>{
while x > 0{
x=x-base;
}
if x==0{}else{x=x+base}
x
}
extern const pow=(x:Int, y:Int):Int=>{
let res=x;
if y==0{ res=1; }else{ res=x;}
while y>1{
res=res*x
y=y-1
}
res
}
extern const printInt=(val:Int)=>{
let digits:Int=1;
let temp=val;
while temp > 9{
temp=temp/10;
digits=digits+1;
}
while digits > 0{
putchar(val/pow(10, digits-1) +48 as Char);
val=modulo(val, pow(10, digits-1));
digits=digits-1;
}
};
type NewArray = <L:Int>(L):[Int;L];
extern const newArray: NewArray = <L:Int>(len:L): [Int; L] =>{
malloc(len*4) as IntPtr
}