diff --git a/compile.phi b/compile.phi index 2289043..6eb2f4d 100644 --- a/compile.phi +++ b/compile.phi @@ -1,27 +1,27 @@ (fn Emitter (ast filename) (do - (let output ()) + (let output (list)) (let (enter_scope leave_scope define_sym get_sym print_syms) (call Syms)) (let (let_node_reg_count let_node_reg_increment) (call Counter)) (let (sym_id_count sym_id_increment) (call Counter)) - (let builtin_syms ( - ("format" "builtinFormat") - ("print" "builtinPrint") - ("println" "builtinPrintln") - ("panic" "builtinPanic") - ("read_text_file" "builtinReadTextFile") - ("write_text_file" "builtinWriteTextFile") - ("push" "builtinPush") - ("at" "builtinAt") - ("set" "builtinSet") - ("len" "builtinLen") - ("string_to_int" "builtinStringToInt") - ("char_code" "builtinCharCode") - ("strings_join" "builtinStringsJoin") - ("get_args" "builtinGetArgs") + (let builtin_syms (list + (list "format" "builtinFormat") + (list "print" "builtinPrint") + (list "println" "builtinPrintln") + (list "panic" "builtinPanic") + (list "read_text_file" "builtinReadTextFile") + (list "write_text_file" "builtinWriteTextFile") + (list "push" "builtinPush") + (list "at" "builtinAt") + (list "set" "builtinSet") + (list "len" "builtinLen") + (list "string_to_int" "builtinStringToInt") + (list "char_code" "builtinCharCode") + (list "strings_join" "builtinStringsJoin") + (list "get_args" "builtinGetArgs") )) (fn generate () (do @@ -389,7 +389,7 @@ (let sym_id (call sym_id_count)) (call sym_id_increment) - (call define_sym ident (sym_id "builtin" builtin_id)) + (call define_sym ident (list sym_id "builtin" builtin_id)) (return sym_id) )) @@ -397,7 +397,7 @@ (let sym_id (call sym_id_count)) (call sym_id_increment) - (call define_sym ident (sym_id "fn" ident line)) + (call define_sym ident (list sym_id "fn" ident line)) (return sym_id) )) @@ -405,7 +405,7 @@ (let sym_id (call sym_id_count)) (call sym_id_increment) - (call define_sym ident (sym_id "param" ident line)) + (call define_sym ident (list sym_id "param" ident line)) (return sym_id) )) @@ -413,11 +413,11 @@ (let sym_id (call sym_id_count)) (call sym_id_increment) - (call define_sym ident (sym_id "let" ident line)) + (call define_sym ident (list sym_id "let" ident line)) (return sym_id) )) - (return (generate)) + (return (list generate)) )) (fn Counter () (do @@ -431,14 +431,14 @@ (+= counter 1) )) - (return (count increment)) + (return (list count increment)) )) (fn Syms () (do - (let syms (null ())) + (let syms (list null (list))) (fn enter_scope () (do - (= syms (syms ())) + (= syms (list syms (list))) )) (fn leave_scope () (do @@ -453,12 +453,12 @@ (if (>= i (call len map)) (break)) (let (s_ident _) (call at map i)) (if (== ident s_ident) (do - (call set map i (ident sym)) + (call set map i (list ident sym)) (return) )) (+= i 1) )) - (call push map (ident sym)) + (call push map (list ident sym)) )) (fn find_sym (syms ident) (do @@ -496,7 +496,7 @@ (call print_syms_node syms 0) )) - (return ( + (return (list enter_scope leave_scope define @@ -538,7 +538,7 @@ (let tok (call at tokens i)) (fn parse () (do - (let exprs ()) + (let exprs (list)) (loop (do (if (call done) (break)) (call push exprs (call parse_expr)) @@ -549,7 +549,7 @@ (fn parse_expr () (do (let (ty line value) tok) (if (call eat "(") (do - (let values ()) + (let values (list)) (loop (do (if (call test ")") (break)) (call push values (call parse_expr)) @@ -557,13 +557,13 @@ (if (not (call eat ")")) (do (call panic "expected ')' on line %" (call at tok 1)) )) - (return ("list" line values)) + (return (list "list" line values)) ) (if (call eat "string") (do - (return ("string" line value)) + (return (list "string" line value)) ) (if (call eat "int") (do - (return ("int" line (call string_to_int value))) + (return (list "int" line (call string_to_int value))) ) (if (call eat "ident") (do - (return ("ident" line value)) + (return (list "ident" line value)) ) (do (call panic "expected expression, got '%' on line %" ty line) ))))) @@ -593,13 +593,13 @@ (return (>= i (call len tokens))) )) - (return (parse)) + (return (list parse)) )) (fn tokenize (text) (do (let text_len (call len text)) - (let tokens ()) + (let tokens (list)) (let i 0) (let line 1) @@ -624,7 +624,7 @@ (+= i 1) )) ) (if (call contains "()" ch) (do - (call push tokens (ch line)) + (call push tokens (list ch line)) (+= i 1) ) (if (== ch "\"") (do (let value "") @@ -661,7 +661,7 @@ (call panic "expected '\"' on line %" line) )) (+= i 1) - (call push tokens ("string" line value)) + (call push tokens (list "string" line value)) ) (if (call contains "0123456789" ch) (do (let value "") (loop (do @@ -672,7 +672,7 @@ (+= value ch) (+= i 1) )) - (call push tokens ("int" line value)) + (call push tokens (list "int" line value)) ) (if (call contains ident_chars ch) (do (let value "") (loop (do @@ -683,7 +683,7 @@ (+= value ch) (+= i 1) )) - (call push tokens ("ident" line value)) + (call push tokens (list "ident" line value)) ) (do (call println "illegal char '%'" ch) (+= i 1) @@ -747,7 +747,7 @@ (fn slice (list idx) (do (let list_len (call len list)) - (let elems ()) + (let elems (list)) (let i idx) (loop (do (if (>= i list_len) (break))