4
4
#include "prelude.h"
5
5
#include <limits.h>
6
6
#include <assert.h>
7
+ #include <time.h>
7
8
#include <string.h>
8
9
#include <unistd.h>
9
10
#include <ctype.h>
14
15
#include <sys/wait.h>
15
16
#include <execinfo.h>
16
17
17
- #define STRING_ (x ) #x
18
- #define STRING (x ) STRING_(x)
19
-
20
18
ast_list_t * full_ast = NULL ;
21
19
module_t * pmod = NULL ;
22
20
char * heap = NULL ;
23
21
module_t prelude1 = { .prefix = "prelude" }; // written in C
24
22
module_t prelude2 = { .prefix = "prelude" }; // written in Cognate
25
23
module_list_t preludes = { .mod = & prelude2 , .next = & (module_list_t ){.mod = & prelude1 , .next = NULL } };
26
24
25
+ int usleep (__useconds_t );
26
+ char * strdup (const char * );
27
+
27
28
static bool is_prelude (module_t * mod )
28
29
{
29
30
return mod == & prelude1 || mod == & prelude2 ;
30
31
}
31
32
32
- static void print_banner ()
33
+ static void print_banner (void )
33
34
{
34
35
char * banner =
35
36
"\t ______ ______\n"
@@ -38,11 +39,11 @@ static void print_banner()
38
39
"\t/ /___/ /_/ / /_/ / / / / /_/ / /___\n"
39
40
"\t\\____/\\____/\\__, /_/ /_/\\__,_/\\____/\n"
40
41
"\t /____/\n"
41
- "\t Cognate Compiler" ;
42
+ "\t Cognate Compiler\n " ;
42
43
puts (banner );
43
44
}
44
45
45
- _Noreturn static void unreachable ()
46
+ _Noreturn static void unreachable (void )
46
47
{
47
48
char msg [] = "\n\n\033[31;1m"
48
49
"\t ___ _\n"
@@ -73,7 +74,7 @@ static void* alloc(size_t n)
73
74
return (heap += n ) - n ;
74
75
}
75
76
76
- where_t * parse_pos ()
77
+ where_t * parse_pos (void )
77
78
{
78
79
where_t * p = alloc (sizeof * p );
79
80
p -> mod = pmod ;
@@ -92,8 +93,6 @@ _Noreturn void type_error(val_type_t expected, val_type_t got, where_t* pos)
92
93
93
94
_Noreturn void throw_error (char * message , where_t * where )
94
95
{
95
- // TODO this segfaults if the error is in prelude
96
-
97
96
/*
98
97
puts(message);
99
98
puts(where->mod->prefix);
@@ -116,9 +115,10 @@ _Noreturn void throw_error(char* message, where_t* where)
116
115
char c ;
117
116
do { c = fgetc (where -> mod -> file ); } while (c != '\n' ); // read one line. TODO this is bad
118
117
}
119
- size_t n = SIZE_MAX ;
120
- char * line = NULL ;
121
- getline (& line , & n , where -> mod -> file );
118
+
119
+ char line_start [MAX_ERROR_LINE_LENGTH ];
120
+ char * line = line_start ;
121
+ fgets (line , MAX_ERROR_LINE_LENGTH , where -> mod -> file );
122
122
123
123
// Now we strip leading whitespace
124
124
while (isspace (* line )) line ++ , offset -- ;
@@ -231,7 +231,7 @@ func_list_t* push_func(func_t* f, func_list_t* next)
231
231
return n ;
232
232
}
233
233
234
- char * make_func_name ()
234
+ char * make_func_name (void )
235
235
{
236
236
static size_t fid = 0 ;
237
237
char * str = alloc (20 );
@@ -371,7 +371,7 @@ reg_t* pop_register_rear(reg_dequeue_t* registers)
371
371
return reg ;
372
372
}
373
373
374
- reg_dequeue_t * make_register_dequeue ()
374
+ reg_dequeue_t * make_register_dequeue (void )
375
375
{
376
376
reg_dequeue_t * r = alloc (sizeof * r );
377
377
r -> front = r -> rear = NULL ;
@@ -775,10 +775,20 @@ void to_exe(module_t* mod)
775
775
};
776
776
pid_t p = fork ();
777
777
if (!p ) execvp (args [0 ], args );
778
- printf ("\n%s " , mod -> path );
779
778
int status ;
780
- while (!waitpid (p , & status , WNOHANG )) usleep (10000 ), fputc ('>' , stdout ), fflush (stdout );
781
- printf (" %s\n" , exe_path );
779
+ int i = 0 ;
780
+ while (!waitpid (p , & status , WNOHANG ))
781
+ {
782
+ usleep (50000 );
783
+ fputc ('\r' , stdout );
784
+ printf ("%s " , mod -> path );
785
+ char * bar [3 ] = { "> >> >> >> >> >> >> >> >> >> " , ">> >> >> >> >> >> >> >> >> >>" , " >> >> >> >> >> >> >> >> >> >" };
786
+ fputs (bar [i ], stdout );
787
+ if (++ i == 3 ) i = 0 ;
788
+ printf (" %s" , exe_path );
789
+ fflush (stdout );
790
+ }
791
+ fputc ('\n' , stdout );
782
792
if (status != EXIT_SUCCESS ) exit (status );
783
793
}
784
794
@@ -2767,7 +2777,7 @@ void static_calls(module_t* m)
2767
2777
}
2768
2778
}
2769
2779
2770
- ast_list_t * make_astlist ()
2780
+ ast_list_t * make_astlist (void )
2771
2781
{
2772
2782
ast_list_t * a = alloc (sizeof * a );
2773
2783
ast_list_t * b = alloc (sizeof * b );
@@ -2856,8 +2866,8 @@ void static_branches(module_t* m)
2856
2866
if (f -> stack ) clear_registers (regs );
2857
2867
if (f -> returns )
2858
2868
push_register_front (make_register (f -> rettype , a ), regs );
2859
- break ;
2860
2869
}
2870
+ break ;
2861
2871
case bind :
2862
2872
{
2863
2873
reg_t * r = pop_register_front (regs );
@@ -3217,7 +3227,7 @@ lit_t* mk_lit(val_type_t t, const char* str)
3217
3227
return l ;
3218
3228
}
3219
3229
3220
- word_list_t * builtins ()
3230
+ word_list_t * builtins (void )
3221
3231
{
3222
3232
static builtin_t b [] =
3223
3233
{
0 commit comments