@@ -277,15 +277,12 @@ static void emit_function(codegen *cg, function *fn) {
277277 cj_builder_scratch_release (& cg -> scratch );
278278}
279279
280- static const char * program_source = "(def main (x) (sub (call inc x) 3))\n"
281- "(def inc (x) (add x 1))\n" ;
282-
283- int main (void ) {
280+ int main (int argc , char * * argv ) {
284281 node_arena arena = {0 };
285282 function functions [MAX_FUN ];
286283 int function_count = 0 ;
287284 lexer lx ;
288- init_lexer (& lx , program_source );
285+ init_lexer (& lx , argv [ 1 ] );
289286
290287 while (lx .tok .kind != TOK_END ) {
291288 if (function_count >= MAX_FUN ) {
@@ -320,12 +317,10 @@ int main(void) {
320317 functions [i ].fn = (int (* )(int ))addr ;
321318 }
322319
323- printf ("minilang demo:\n" );
324320 function * main_fn = & functions [main_idx ];
325- for (int i = 0 ; i <= 5 ; i ++ ) {
326- int result = main_fn -> fn (i );
327- printf (" main(%d) = %d\n" , i , result );
328- }
321+ int input = strtol (argv [2 ], NULL , 10 );
322+ int result = main_fn -> fn (input );
323+ printf ("main(%d) = %d\n" , input , result );
329324
330325 destroy_cj_fn (cj , module );
331326 destroy_cj_ctx (cj );
0 commit comments