@@ -113,7 +113,6 @@ typedef struct {
113113 char param [32 ];
114114 node * body ;
115115 cj_label entry ;
116- size_t offset ;
117116 int (* fn )(int );
118117} function ;
119118static node * parse_expr (lexer * lx , node_arena * arena , const char * param ) {
@@ -301,22 +300,13 @@ int main(void) {
301300 fprintf (stderr , "no main function\n" );
302301 return 1 ;
303302 }
304- if (main_idx != 0 ) {
305- function tmp = functions [0 ];
306- functions [0 ] = functions [main_idx ];
307- functions [main_idx ] = tmp ;
308- main_idx = 0 ;
309- }
310-
311303 resolve_calls (& arena , functions , function_count );
312304
313305 cj_ctx * cj = create_cj_ctx ();
314306 for (int i = 0 ; i < function_count ; i ++ ) functions [i ].entry = cj_create_label (cj );
315307
316308 codegen cg = {.cj = cj , .functions = functions };
317- emit_function (& cg , & functions [main_idx ]);
318- for (int i = 0 ; i < function_count ; i ++ )
319- if (i != main_idx ) emit_function (& cg , & functions [i ]);
309+ for (int i = 0 ; i < function_count ; i ++ ) emit_function (& cg , & functions [i ]);
320310
321311 cj_fn module = create_cj_fn (cj );
322312 if (!module ) {
@@ -331,8 +321,9 @@ int main(void) {
331321 }
332322
333323 printf ("minilang demo:\n" );
324+ function * main_fn = & functions [main_idx ];
334325 for (int i = 0 ; i <= 5 ; i ++ ) {
335- int result = functions [ main_idx ]. fn (i );
326+ int result = main_fn -> fn (i );
336327 printf (" main(%d) = %d\n" , i , result );
337328 }
338329
0 commit comments