use relative imports

This commit is contained in:
sfja 2025-09-25 15:59:06 +02:00
parent 7e42abb239
commit f17f098d20
5 changed files with 773 additions and 762 deletions

View File

@ -1,6 +1,6 @@
(import "stdlib.phi" (slice contains indent)) (import "./stdlib.phi" (slice contains indent))
(import "compiler/parse.phi" (Parser tokenize)) (import "./compiler/parse.phi" (Parser tokenize))
(import "compiler/emit_js.phi" (JsEmitter)) (import "./compiler/emit_js.phi" (JsEmitter))
(fn print_expr (expr depth) (do (fn print_expr (expr depth) (do
(let (ty line value) expr) (let (ty line value) expr)
@ -15,7 +15,10 @@
)) ))
)) ))
(let (input_filename output_filename) (get_args)) (let (input_filename_rel output_filename_rel) (get_args))
(let input_filename (fs_resolve (fs_cwd) input_filename_rel))
(let output_filename (fs_resolve (fs_cwd) output_filename_rel))
(println "compiling '%'..." input_filename) (println "compiling '%'..." input_filename)
(let text (read_text_file input_filename)) (let text (read_text_file input_filename))

View File

@ -1,10 +1,10 @@
(import "stdlib.phi" ( (import "../stdlib.phi" (
slice contains slice contains
list_push list_pop list_contains list_push list_pop list_contains
map map_has map_get map_set map map_has map_get map_set
)) ))
(import "compiler/parse.phi" (Parser tokenize)) (import "./parse.phi" (Parser tokenize))
(import "compiler/syms.phi" (Syms)) (import "./syms.phi" (Syms))
(fn JsEmitter (ast initial_filename) (do (fn JsEmitter (ast initial_filename) (do
(let output (list)) (let output (list))
@ -139,7 +139,9 @@
(panic "illegal function on line %" line) (panic "illegal function on line %" line)
)) ))
(if (== id "import") (do (if (== id "import") (do
(let (_ (_ _ inner_filename) (_ _ idents)) s) (let (_ (_ _ inner_filename_rel) (_ _ idents)) s)
(let inner_filename (fs_resolve (fs_dirname filename) inner_filename_rel))
(if (list_contains import_stack inner_filename) (do (if (list_contains import_stack inner_filename) (do
(panic "circular dependendy: '%' imports '%'" filename inner_filename) (panic "circular dependendy: '%' imports '%'" filename inner_filename)

View File

@ -1,4 +1,4 @@
(import "stdlib.phi" (slice slice_eq contains)) (import "../stdlib.phi" (slice slice_eq contains))
(fn Parser (tokens) (do (fn Parser (tokens) (do
(let i 0) (let i 0)

View File

@ -1,4 +1,4 @@
(import "stdlib.phi" (indent map map_has map_get map_set)) (import "../stdlib.phi" (indent map map_has map_get map_set))
(fn Syms () (do (fn Syms () (do
(let syms (list null (map))) (let syms (list null (map)))

1510
stage2.js

File diff suppressed because it is too large Load Diff