diff --git a/cmd/fsplc/main.go b/cmd/fsplc/main.go index 700e83a..e91ddfb 100644 --- a/cmd/fsplc/main.go +++ b/cmd/fsplc/main.go @@ -47,6 +47,13 @@ func main () { 'O', "optimization", "Optimization level (0-3)", "0", cli.NewValSet("0", "1", "2", "3")) + includePath := cli.NewInputFlag ( + 'u', "unit-directory", + "Extra directory(s) to search for units in", "", + cli.ValString) + includePath.Found = func (application *cli.Cli, value string) { + comp.Resolver.AddPathFront(value) + } application := cli.New ( "Compile FSPL source files", @@ -55,7 +62,8 @@ func main () { quiet, filetype, output, - optimization) + optimization, + includePath) application.Syntax = "[OPTION]... ADDRESS" application.ParseOrExit(os.Args) diff --git a/compiler/resolver.go b/compiler/resolver.go index 39f313a..4dfb0c0 100644 --- a/compiler/resolver.go +++ b/compiler/resolver.go @@ -48,7 +48,7 @@ func (resolver *Resolver) AddPathFront (path ...string) { // - If the address starts with '/', it is treated as an absolute path from // the fs root // - Else, the address is searched for in the resolver's paths -func (resolver Resolver) Resolve (context string, address entity.Address) (string, error) { +func (resolver *Resolver) Resolve (context string, address entity.Address) (string, error) { strAddr := string(address) switch { case strings.HasPrefix(strAddr, "."): @@ -71,7 +71,7 @@ func (resolver Resolver) Resolve (context string, address entity.Address) (strin } } -func (resolver Resolver) search (needle string) (string, error) { +func (resolver *Resolver) search (needle string) (string, error) { for _, dirPath := range resolver.Path { // attempt to open the file as dir. // if we can't open the dir, just skip it, because it is @@ -98,7 +98,7 @@ func (resolver Resolver) search (needle string) (string, error) { // ResolveCwd resolves the address within the context of the current working // directory. -func (resolver Resolver) ResolveCwd (address entity.Address) (string, error) { +func (resolver *Resolver) ResolveCwd (address entity.Address) (string, error) { wd, err := os.Getwd() if err != nil { return "", err } return resolver.Resolve(wd, address)