-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.c
executable file
·59 lines (44 loc) · 881 Bytes
/
library.c
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
/*
This is the standard library of functions for bminor, implemented in C.
The print statement in bminor expects there to exist a function
for each type that can be printed. So, the following bminor code:
x: int = 10;
b: boolean = true;
x: string = "hello";
print x, b, s;
Is effectively translated to the following C code:
print_integer(x);
print_boolean(b);
print_string(s);
And the following bminor code:
x = a ^ b;
Is effectively this C code:
x = integer_power(a,b);
*/
#include <stdio.h>
#include <stdint.h>
void print_integer( long x )
{
printf("%ld",x);
}
void print_string( const char *s )
{
printf("%s",s);
}
void print_boolean( int b )
{
printf("%s",b?"true":"false");
}
void print_character( char c )
{
printf("%c",c);
}
long integer_power( long x, long y )
{
long result = 1;
while(y>0) {
result = result * x;
y = y -1;
}
return result;
}