-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
76 lines (65 loc) · 1.34 KB
/
Copy pathmain.c
File metadata and controls
76 lines (65 loc) · 1.34 KB
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
// microl language
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
#define MICROL_STR_OBJ_LIM 1024
#define bool char
#define true 1
#define false 0
#define dmain_printf(...) //printf(__VA_ARGS__)
#define dmain_puts(...) //puts(__VA_ARGS__)
#include "intr.h"
void help(const char *name)
{
printf(
"Usage:\n"
" %s run <filename>\n"
" %s help\n"
" %s about\n",
name, name, name
);
}
void about()
{
printf("microl language\nversion %d.%d\n", VERSION_MAJOR, VERSION_MINOR);
}
int cli(int argc, char **argv)
{
const char *program_name = argv[0];
if(argc < 2) return help(program_name), 1;
char *command = argv[1];
char **args = argv + 2;
int args_count = argc - 2;
if(strcmp(command, "run") == 0)
{
if(args_count != 1) return help(program_name), 1;
free_context(run_file(args[0], true));
}
else if(strcmp(command, "help") == 0)
{
help(program_name);
}
else if(strcmp(command, "about") == 0)
{
if(args_count != 0) return help(program_name), 1;
about();
}
else
{
return help(program_name), 1;
}
return 0;
}
#include <time.h>
// benckmark
int main(int argc, char **argv)
{
clock_t begin = clock();
int o = cli(argc, argv);
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("[finished in %fs]!\n", time_spent);
return o;
}