Skip to content

Bring up-to-date with current libraries #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build-and-test
name: tests

on:
push:
Expand All @@ -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
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
27 changes: 11 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://opendylan.org/library-reference/c-ffi/index.html>`_.

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:

Expand Down
8 changes: 3 additions & 5 deletions dylan-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"contact": "[email protected]",
"description": "Generates C-FFI bindings by parsing C header files",
"dependencies": [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
"command-line-parser",
],
"dev-dependencies": [
"[email protected]"
"sphinx-extensions",
"testworks"
],
"url": "https://github.com/dylan-lang/melange",
"version": "0.1.1"
Expand Down
1 change: 0 additions & 1 deletion ext/command-line-parser
Submodule command-line-parser deleted from a88895
1 change: 0 additions & 1 deletion ext/sphinx-extensions
Submodule sphinx-extensions deleted from 333fdd
123 changes: 43 additions & 80 deletions melange/interface.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -624,25 +624,6 @@ define method show-copyright (stream :: <stream>) => ()
format(stream, "Copyright 2005-2015 Dylan Hackers\n");
end method show-copyright;

define method show-usage (stream :: <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 :: <stream>) => ()
for (i from 0 below $default-defines.size by 2)
let name = $default-defines[i];
Expand Down Expand Up @@ -678,41 +659,6 @@ define method show-default-includes (stream :: <stream>) => ()
end for;
end method show-default-includes;

define method show-help (stream :: <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
Expand All @@ -725,55 +671,85 @@ end method show-help;

define method main (program, args)
// Describe our arguments and create appropriate parser objects.
let *argp* = make(<command-line-parser>);
add-option(*argp*,
make(<flag-option>,
names: #("help", "h")));
let *argp* = make(<command-line-parser>,
help: "Melange");
add-option(*argp*,
make(<flag-option>,
help: "Show copyright info.",
names: #("version")));
add-option(*argp*,
make(<flag-option>,
help: "Show the default C preprocessor definitions.",
names: #("defines")));
add-option(*argp*,
make(<flag-option>,
help: "Show the default platform undefinitions.",
names: #("undefines")));
add-option(*argp*,
make(<flag-option>,
help: "Show the default C preprocessor include directories.",
names: #("includes")));
add-option(*argp*,
make(<flag-option>,
help: "Print progress messages while parsing (includes --headers).",
names: #("verbose", "v")));
add-option(*argp*,
make(<flag-option>,
help: "Print each header file included while parsing.",
names: #("headers")));
add-option(*argp*,
make(<choice-option>,
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(<parameter-option>,
help: "Create a Dylan interchange file with a module definition "
"that exports the interface names.",
names: #("module-file", "m")));
add-option(*argp*,
make(<repeated-parameter-option>,
help: "Extra directories to search for C headers.",
names: #("includedir", "I")));
add-option(*argp*,
make(<keyed-option>,
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(<repeated-parameter-option>,
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(<repeated-parameter-option>,
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(<positional-option>,
help: "Input file with interface specification.",
names: #("infile")));
add-option(*argp*,
make(<positional-option>,
help: "Output file for generated Dylan code.",
names: #("outfile"),
required?: #f));

// Parse our command-line arguments.
block ()
parse-command-line(*argp*, args);
exception (ex :: <usage-error>)
show-usage-and-exit();
exception (ex :: <abort-command-error>)
exit-application(1);
end;

// Handle our informational options.
Expand All @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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(<file-stream>,
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(<file-stream>,
locator: out-file,
direction: #"output");
end;
let module-stream = module-file & make(<file-stream>,
locator: module-file,
direction: #"output");
Expand Down
1 change: 0 additions & 1 deletion registry/generic/command-line-parser

This file was deleted.

1 change: 0 additions & 1 deletion registry/generic/melange

This file was deleted.

1 change: 0 additions & 1 deletion registry/generic/parsergen

This file was deleted.

1 change: 0 additions & 1 deletion registry/x86-freebsd/melange-core

This file was deleted.

1 change: 0 additions & 1 deletion registry/x86-linux/melange-core

This file was deleted.

1 change: 0 additions & 1 deletion registry/x86-win32/melange-core

This file was deleted.

1 change: 0 additions & 1 deletion registry/x86_64-darwin/melange-core

This file was deleted.

1 change: 0 additions & 1 deletion registry/x86_64-linux/melange-core

This file was deleted.

Loading