From 31264bf1a353de70e14bdeb5a2c97bf59a5e246e Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 30 Mar 2025 10:59:32 -0400 Subject: [PATCH 1/3] package: use latest version of testworks Less likely to cause dependency conflicts --- dylan-package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dylan-package.json b/dylan-package.json index 90a13e3..fca29f3 100644 --- a/dylan-package.json +++ b/dylan-package.json @@ -10,7 +10,7 @@ "xml-parser@0.1" ], "dev-dependencies": [ - "testworks@2.1" + "testworks" ], "url": "https://github.com/dylan-lang/melange", "version": "0.1.1" From c479de389fa9711cf9dde8d0b3c9a5746a200519 Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 30 Mar 2025 11:28:13 -0400 Subject: [PATCH 2/3] Fully convert to using Deft instead of submodules * Remove submodules * Remove registry * Update package file * Update README --- .github/workflows/build-and-test.yml | 28 ++++++++++++++-------------- .gitmodules | 6 ------ README.rst | 27 +++++++++++---------------- dylan-package.json | 6 ++---- ext/command-line-parser | 1 - ext/sphinx-extensions | 1 - registry/generic/command-line-parser | 1 - registry/generic/melange | 1 - registry/generic/parsergen | 1 - registry/x86-freebsd/melange-core | 1 - registry/x86-linux/melange-core | 1 - registry/x86-win32/melange-core | 1 - registry/x86_64-darwin/melange-core | 1 - registry/x86_64-linux/melange-core | 1 - 14 files changed, 27 insertions(+), 50 deletions(-) delete mode 160000 ext/command-line-parser delete mode 160000 ext/sphinx-extensions delete mode 100644 registry/generic/command-line-parser delete mode 100644 registry/generic/melange delete mode 100644 registry/generic/parsergen delete mode 100644 registry/x86-freebsd/melange-core delete mode 100644 registry/x86-linux/melange-core delete mode 100644 registry/x86-win32/melange-core delete mode 100644 registry/x86_64-darwin/melange-core delete mode 100644 registry/x86_64-linux/melange-core diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 29176d2..a722815 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,4 +1,4 @@ -name: build-and-test +name: tests on: push: @@ -12,22 +12,22 @@ on: workflow_dispatch: jobs: - build-and-test: - runs-on: ubuntu-latest - steps: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + steps: - uses: actions/checkout@v4 - with: - submodules: recursive - - uses: dylan-lang/install-opendylan@v2 + - uses: dylan-lang/install-opendylan@v3 - - name: Build melange + - name: Build run: | - ./dylan-compiler -build parsergen - _build/bin/parsergen melange-core/c-parse.input melange-core/c-parse.dylan - _build/bin/parsergen melange/int-parse.input melange/int-parse.dylan - ./dylan-compiler -build melange + dylan update + make - - name: Run melange-tests - run: tests/run.sh + - name: Run tests + run: | + make check diff --git a/.gitmodules b/.gitmodules index 48ec8da..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "ext/command-line-parser"] - path = ext/command-line-parser - url = https://github.com/dylan-lang/command-line-parser.git -[submodule "ext/sphinx-extensions"] - path = ext/sphinx-extensions - url = https://github.com/dylan-lang/sphinx-extensions diff --git a/README.rst b/README.rst index a8305c7..032f1fc 100644 --- a/README.rst +++ b/README.rst @@ -1,35 +1,30 @@ -``melange`` is used to generate C-FFI bindings to libraries with a C API +Melange is used to generate C-FFI bindings to libraries with a C API by parsing C header files. -``melange`` was originally part of Gwydion Dylan. It has been converted to -work with Open Dylan and ``c-ffi``. +Melange was originally part of Gwydion Dylan. It has been converted to work with Open +Dylan and the `C-FFI library +`_. Build ----- -Be sure that you cloned this repository recursively or have otherwise -initialized and updated the git submodules. This will not build without -the submodules present. +You should be using Open Dylan 2024.1 or later. -:: +.. code:: shell - dylan-compiler -build parsergen - _build/bin/parsergen melange-core/c-parse.input melange-core/c-parse.dylan - _build/bin/parsergen melange/int-parse.input melange/int-parse.dylan - dylan-compiler -build melange - -You should be using Open Dylan 2012.1 or later. + $ dylan update # 'deft update' after the 2025.1 release. + $ make + $ make check Usage ----- -The documentation for this tool is available at http://opendylan.org/documentation/melange/. +The documentation for this tool is available at https://package.opendylan.org/melange/index.html Tests ----- -Tests can be run via ``make check`` or just running ``run.sh`` within the -``tests`` directory. +Tests can be run via ``make check``. Adding new tests is done by: diff --git a/dylan-package.json b/dylan-package.json index fca29f3..ac6cdf1 100644 --- a/dylan-package.json +++ b/dylan-package.json @@ -4,12 +4,10 @@ "contact": "dylan-lang@googlegroups.com", "description": "Generates C-FFI bindings by parsing C header files", "dependencies": [ - "command-line-parser@3.1.1", - "meta@0.1", - "sphinx-extensions@0.1", - "xml-parser@0.1" + "command-line-parser", ], "dev-dependencies": [ + "sphinx-extensions", "testworks" ], "url": "https://github.com/dylan-lang/melange", diff --git a/ext/command-line-parser b/ext/command-line-parser deleted file mode 160000 index a888954..0000000 --- a/ext/command-line-parser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a888954762b6c8b19a1ccf9b7bd8f465b265b7de diff --git a/ext/sphinx-extensions b/ext/sphinx-extensions deleted file mode 160000 index 333fdd2..0000000 --- a/ext/sphinx-extensions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 333fdd249e53b331da4011c032d5ce85926912b8 diff --git a/registry/generic/command-line-parser b/registry/generic/command-line-parser deleted file mode 100644 index cfd0a04..0000000 --- a/registry/generic/command-line-parser +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/ext/command-line-parser/command-line-parser.lid diff --git a/registry/generic/melange b/registry/generic/melange deleted file mode 100644 index eebaa5d..0000000 --- a/registry/generic/melange +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/melange/melange.lid diff --git a/registry/generic/parsergen b/registry/generic/parsergen deleted file mode 100644 index f53c4a3..0000000 --- a/registry/generic/parsergen +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/parsergen/parsergen.lid diff --git a/registry/x86-freebsd/melange-core b/registry/x86-freebsd/melange-core deleted file mode 100644 index baf21ba..0000000 --- a/registry/x86-freebsd/melange-core +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/melange-core/x86-freebsd-melange-core.lid diff --git a/registry/x86-linux/melange-core b/registry/x86-linux/melange-core deleted file mode 100644 index 9173b85..0000000 --- a/registry/x86-linux/melange-core +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/melange-core/x86-linux-melange-core.lid diff --git a/registry/x86-win32/melange-core b/registry/x86-win32/melange-core deleted file mode 100644 index edb58dc..0000000 --- a/registry/x86-win32/melange-core +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/melange-core/x86-win32-melange-core.lid diff --git a/registry/x86_64-darwin/melange-core b/registry/x86_64-darwin/melange-core deleted file mode 100644 index 8efd118..0000000 --- a/registry/x86_64-darwin/melange-core +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/melange-core/x86_64-darwin-melange-core.lid diff --git a/registry/x86_64-linux/melange-core b/registry/x86_64-linux/melange-core deleted file mode 100644 index 931bb56..0000000 --- a/registry/x86_64-linux/melange-core +++ /dev/null @@ -1 +0,0 @@ -abstract://dylan/melange-core/x86_64-linux-melange-core.lid From 15d16be72bf1275cc73469456e9fb11cf923dc7c Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 30 Mar 2025 13:20:23 -0400 Subject: [PATCH 3/3] Use newer command-line-parser features Less parsing by hand, more done by the command-line-parser library. Note that there is one thing that could be considered a regression here: the --help output isn't quite as nice because the auto-generated output isn't wrapped nicely the way it was when done by hand. That will be fixed with https://github.com/dylan-lang/command-line-parser/issues/51. --- melange/interface.dylan | 123 ++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 80 deletions(-) diff --git a/melange/interface.dylan b/melange/interface.dylan index 9f6fe26..5df2a1f 100644 --- a/melange/interface.dylan +++ b/melange/interface.dylan @@ -624,25 +624,6 @@ define method show-copyright (stream :: ) => () format(stream, "Copyright 2005-2015 Dylan Hackers\n"); end method show-copyright; -define method show-usage (stream :: ) => () - format(stream, -"Usage: melange [-v] [--headers]\n" -" [--Ttarget]\n" -" [-Ddef[=val]...] [-Uundef...]\n" -" [-Iincdir...] [--framework name...]\n" -" [-m modulefile] infile [outfile]\n" -" melange --defines\n" -" melange --undefines\n" -" melange --includes\n" -" melange --help\n" -" melange --version\n"); -end method show-usage; - -define method show-usage-and-exit () => () - show-usage(*standard-error*); - exit-application(1); -end method show-usage-and-exit; - define method show-default-defines (stream :: ) => () for (i from 0 below $default-defines.size by 2) let name = $default-defines[i]; @@ -678,41 +659,6 @@ define method show-default-includes (stream :: ) => () end for; end method show-default-includes; -define method show-help (stream :: ) => () - show-copyright(stream); - format(stream, "\n"); - show-usage(stream); - format(stream, "\n" -"Options:\n" -" -v, --verbose Print progress messages while parsing.\n" -" (Includes --headers.)\n" -" --headers Print each header file included while parsing.\n" -" -T, --target Generate output for use only with the named target.\n" -" Target can be one of: c-ffi, mindy. Defaults to c-ffi.\n" -" -D, --define Define a C preprocessor macro for use by C headers.\n" -" If no value is given, defaults to 1.\n" -" -U, --undefine Prevent definition of a default preprocessor macro.\n" -" (Use --defines to see the defaults. Use --undefines to" -" see the default undefines.)\n" -" -I, --includedir Extra directories to search for C headers.\n" -" --framework The name of a framework bundle to search for C headers\n" -" and child frameworks. Required when a child framework\n" -" is directly referred to in an interface definition\n" -" with no previous references to its parent; once a\n" -" parent is seen,either via this option or in a clause\n" -" of the interface definition, its children will be\n" -" found automatically. (Note: Parent --framework\n" -" options must be given before child framework options.)\n" -" -m, --module-file Create a Dylan interchange file with a module\n" -" definition that exports the interface names.\n" -" --defines Show the default C preprocessor definitions.\n" -" --undefines Show the default platform undefinitions.\n" -" --includes Show the default C preprocessor include directories.\n" -" --help Show this help text.\n" -" --version Show version number.\n" -); -end method show-help; - //---------------------------------------------------------------------- // The main program @@ -725,55 +671,85 @@ end method show-help; define method main (program, args) // Describe our arguments and create appropriate parser objects. - let *argp* = make(); - add-option(*argp*, - make(, - names: #("help", "h"))); + let *argp* = make(, + help: "Melange"); add-option(*argp*, make(, + help: "Show copyright info.", names: #("version"))); add-option(*argp*, make(, + help: "Show the default C preprocessor definitions.", names: #("defines"))); add-option(*argp*, make(, + help: "Show the default platform undefinitions.", names: #("undefines"))); add-option(*argp*, make(, + help: "Show the default C preprocessor include directories.", names: #("includes"))); add-option(*argp*, make(, + help: "Print progress messages while parsing (includes --headers).", names: #("verbose", "v"))); add-option(*argp*, make(, + help: "Print each header file included while parsing.", names: #("headers"))); add-option(*argp*, make(, + help: "Generate output for use only with the named target. " + "Target can be one of: c-ffi, mindy. [%default%]", names: #("target", "T"), choices: #("c-ffi", "mindy"), test: string-equal-ic?, default: "c-ffi")); add-option(*argp*, make(, + help: "Create a Dylan interchange file with a module definition " + "that exports the interface names.", names: #("module-file", "m"))); add-option(*argp*, make(, + help: "Extra directories to search for C headers.", names: #("includedir", "I"))); add-option(*argp*, make(, + help: "Define a C preprocessor macro for use by C headers. " + "If no value is given, defaults to 1.", names: #("define", "D"))); add-option(*argp*, make(, + help: "Prevent definition of a default preprocessor macro. " + "(Use --defines to see the defaults. Use --undefines to " + "see the default undefines.)", names: #("undefine", "U"))); add-option(*argp*, make(, + help: "The name of a framework bundle to search for C headers " + "and child frameworks. Required when a child framework is directly " + "referred to in an interface definition with no previous references " + "to its parent; once a parent is seen, either via this option or in " + "a clause of the interface definition, its children will be found " + "automatically. (Note: Parent --framework options must be given " + "before child framework options.)", names: #("framework"))); + add-option(*argp*, + make(, + help: "Input file with interface specification.", + names: #("infile"))); + add-option(*argp*, + make(, + help: "Output file for generated Dylan code.", + names: #("outfile"), + required?: #f)); // Parse our command-line arguments. block () parse-command-line(*argp*, args); - exception (ex :: ) - show-usage-and-exit(); + exception (ex :: ) + exit-application(1); end; // Handle our informational options. @@ -789,10 +765,6 @@ define method main (program, args) show-default-includes(*standard-output*); exit-application(0); end if; - if (get-option-value(*argp*, "help")) - show-help(*standard-output*); - exit-application(0); - end if; if (get-option-value(*argp*, "version")) show-copyright(*standard-output*); exit-application(0); @@ -806,7 +778,6 @@ define method main (program, args) let include-dirs = get-option-value(*argp*, "includedir"); let defines = get-option-value(*argp*, "define"); let undefines = get-option-value(*argp*, "undefine"); - let regular-args = positional-options(*argp*); let framework-dirs = get-option-value(*argp*, "framework"); // Handle --headers. @@ -834,21 +805,13 @@ define method main (program, args) end for; find-frameworks(*framework-paths*); - // Handle regular arguments. - let in-file = #f; - let out-file = #f; - select (regular-args.size) - 1 => - in-file := regular-args[0]; - 2 => - in-file := regular-args[0]; - out-file := make(, - locator: regular-args[1], - direction: #"output"); - otherwise => - show-usage-and-exit(); - end select; - + let in-file = get-option-value(*argp*, "infile"); + let out-file = get-option-value(*argp*, "outfile"); + if (out-file) + out-file := make(, + locator: out-file, + direction: #"output"); + end; let module-stream = module-file & make(, locator: module-file, direction: #"output");