From 406172425f91d7e334fc75538256f7ed65d1dfb9 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 6 Jul 2026 11:58:24 +0200 Subject: [PATCH] Implemented functions command --- src/cli/Exec.go | 3 +++ src/cli/Exec_test.go | 1 + src/cli/files.go | 2 +- src/cli/functions.go | 25 +++++++++++++++++++++++++ src/cli/help.txt | 6 +++++- src/verbose/Functions.go | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/cli/functions.go create mode 100644 src/verbose/Functions.go diff --git a/src/cli/Exec.go b/src/cli/Exec.go index ef5d605..4bc442f 100644 --- a/src/cli/Exec.go +++ b/src/cli/Exec.go @@ -19,6 +19,9 @@ func Exec(args []string) int { case "format": return format(args[1:]) + case "functions": + return functions(args[1:]) + case "help": return help() diff --git a/src/cli/Exec_test.go b/src/cli/Exec_test.go index 3094b06..26bb966 100644 --- a/src/cli/Exec_test.go +++ b/src/cli/Exec_test.go @@ -20,6 +20,7 @@ func TestExec(t *testing.T) { assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-no-lint"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-no-optimize"}), 0) assert.Equal(t, cli.Exec([]string{"files", "../../examples/hello"}), 0) + assert.Equal(t, cli.Exec([]string{"functions", "../../examples/hello"}), 0) assert.Equal(t, cli.Exec([]string{"format", "../../examples/hello/hello.q"}), 0) assert.Equal(t, cli.Exec([]string{"help"}), 0) assert.Equal(t, cli.Exec([]string{"keywords"}), 0) diff --git a/src/cli/files.go b/src/cli/files.go index 36402a9..dcdb81c 100644 --- a/src/cli/files.go +++ b/src/cli/files.go @@ -5,7 +5,7 @@ import ( "git.urbach.dev/cli/q/src/verbose" ) -// files shows the entire list of files that are used in a build. +// files shows the list of files that are used in a build. func files(args []string) int { b, err := newBuild(args) diff --git a/src/cli/functions.go b/src/cli/functions.go new file mode 100644 index 0000000..be87822 --- /dev/null +++ b/src/cli/functions.go @@ -0,0 +1,25 @@ +package cli + +import ( + "git.urbach.dev/cli/q/src/compiler" + "git.urbach.dev/cli/q/src/verbose" +) + +// functions shows the list of functions that are used in a build. +func functions(args []string) int { + b, err := newBuild(args) + + if err != nil { + return exit(err) + } + + b.Dry = true + env, err := compiler.Compile(b) + + if err != nil { + return exit(err) + } + + verbose.Functions(env.Init) + return success +} \ No newline at end of file diff --git a/src/cli/help.txt b/src/cli/help.txt index 3055f9b..de17273 100644 --- a/src/cli/help.txt +++ b/src/cli/help.txt @@ -12,9 +12,13 @@ Compiler for the Q programming language. q build [file] - Show intermediate stages: + List build details: q files [file] + q functions [file] + + Show intermediate stages: + q ssa [file] q asm [file] diff --git a/src/verbose/Functions.go b/src/verbose/Functions.go new file mode 100644 index 0000000..4c22219 --- /dev/null +++ b/src/verbose/Functions.go @@ -0,0 +1,14 @@ +package verbose + +import ( + "fmt" + + "git.urbach.dev/cli/q/src/core" +) + +// Functions shows the list of live functions. +func Functions(root *core.Function) { + root.EachDependency(make(map[*core.Function]bool), func(f *core.Function) { + fmt.Println(f.FullName) + }) +} \ No newline at end of file -- 2.51.2