From: Helmut Eller <eller.helmut@gmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: Andrea Corallo <acorallo@gnu.org>, Eli Zaretskii <eliz@gnu.org>,
emacs-devel@gnu.org
Subject: Re: MPS: Loaded pdump
Date: Thu, 16 May 2024 22:03:14 +0200 [thread overview]
Message-ID: <87msop4j99.fsf@gmail.com> (raw)
In-Reply-To: <m2bk55wttu.fsf@pro2.fritz.box> ("Gerd Möllmann"'s message of "Thu, 16 May 2024 19:27:25 +0200")
[-- Attachment #1: Type: text/plain, Size: 186 bytes --]
On Thu, May 16 2024, Gerd Möllmann wrote:
> As I said, nothing cames out of this. And nothing will.
The script below uses the libclang Python bindings to produce this
output:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: x.c --]
[-- Type: text/x-csrc, Size: 1200 bytes --]
static void
mirror_Lisp_Symbol (struct igc_mirror *m, struct Lisp_Symbol *x)
{
mirror_lisp_obj (m, &x->u.s.name);
mirror_lisp_obj (m, &x->u.s.function);
mirror_lisp_obj (m, &x->u.s.plist);
mirror_ptr (m, &x->u.s.next);
}
static void
mirror_Lisp_String (struct igc_mirror *m, struct Lisp_String *x)
{
mirror_ptr (m, &x->u.next);
mirror_ptr (m, &x->u.s.intervals);
}
static void
mirror_interval (struct igc_mirror *m, struct interval *x)
{
mirror_ptr (m, &x->left);
mirror_ptr (m, &x->right);
mirror_lisp_obj (m, &x->plist);
mirror_ptr (m, &x->up.interval);
mirror_lisp_obj (m, &x->up.obj);
}
static void
mirror_itree_node (struct igc_mirror *m, struct itree_node *x)
{
mirror_ptr (m, &x->parent);
mirror_ptr (m, &x->left);
mirror_ptr (m, &x->right);
mirror_lisp_obj (m, &x->data);
}
static void
mirror_image (struct igc_mirror *m, struct image *x)
{
mirror_lisp_obj (m, &x->spec);
mirror_lisp_obj (m, &x->dependencies);
mirror_lisp_obj (m, &x->lisp_data);
mirror_ptr (m, &x->next);
mirror_ptr (m, &x->prev);
}
static void
mirror_Lisp_Cons (struct igc_mirror *m, struct Lisp_Cons *x)
{
mirror_lisp_obj (m, &x->u.s.car);
mirror_lisp_obj (m, &x->u.s.u.cdr);
}
[-- Attachment #3: Type: text/plain, Size: 28 bytes --]
Would this be acceptable?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: igc_codegen.py --]
[-- Type: text/x-python, Size: 2123 bytes --]
import clang.cindex as cindex
import sys
import re
index = cindex.Index.create()
tu = index.parse("igc.c")
MPS_STRUCTS = ["Lisp_Symbol",
"Lisp_String",
"interval",
"itree_node",
"image",
"Lisp_Cons"];
EXCLUDE_FIELDS = {
"Lisp_Symbol": re.compile('u s val.*'),
"Lisp_Cons": re.compile('.* chain'),
}
def type_for_struct_name (name) -> cindex.Type:
for c in tu.cursor.get_children():
if (c.kind == cindex.CursorKind.STRUCT_DECL and c.spelling == name):
return c.type.get_canonical()
raise Exception("struct type not found: " + name)
mps_types = [type_for_struct_name(name) for name in MPS_STRUCTS]
lisp_obj_type = next(c.type.get_canonical()
for c in tu.cursor.get_children()
if c.spelling == 'Lisp_Object'
if c.kind == cindex.CursorKind.TYPEDEF_DECL)
def is_mps_ref (t:cindex.Type) -> bool:
return (t.get_canonical() == lisp_obj_type or
(t.get_pointee().get_canonical() in mps_types))
def field_paths (t:cindex.Type):
l1 = [([f.spelling], f.type.get_canonical()) for f in t.get_fields()]
l2 = [(p1 + p2,t2) for (p1,t1) in l1 for (p2,t2) in field_paths(t1)]
return l1 + l2
def ref_fields (t:cindex.Type):
excluded = EXCLUDE_FIELDS.get(t.get_declaration().spelling, re.compile(""))
return [(p,t) for (p,t) in field_paths(t)
if is_mps_ref (t)
if not excluded.fullmatch(' '.join(p))]
def emit_function_signature (t:cindex.Type):
print("""static void
mirror_%(fname)s (struct igc_mirror *m, %(atype)s *x)
{"""% { "fname": t.get_declaration().spelling,
"atype": t.spelling })
def emit_mirror (t:cindex.Type):
emit_function_signature(t)
for (path, type) in ref_fields(t):
if type == lisp_obj_type:
print(" mirror_lisp_obj (m, &x->%s);" % '.'.join(path))
else:
print(" mirror_ptr (m, &x->%s);" % '.'.join(path))
print("}")
def main():
for t in mps_types:
emit_mirror(t)
if __name__ == "__main__":
main()
next prev parent reply other threads:[~2024-05-16 20:03 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 10:52 MPS: Loaded pdump Gerd Möllmann
2024-05-09 11:00 ` Eli Zaretskii
2024-05-09 11:20 ` Gerd Möllmann
2024-05-09 12:28 ` Helmut Eller
2024-05-09 13:37 ` Gerd Möllmann
2024-05-09 16:10 ` Helmut Eller
2024-05-09 16:43 ` Gerd Möllmann
2024-05-09 17:57 ` Helmut Eller
2024-05-09 18:10 ` Gerd Möllmann
2024-05-09 13:38 ` Helmut Eller
2024-05-09 14:18 ` Gerd Möllmann
2024-05-09 15:01 ` Helmut Eller
2024-05-09 15:07 ` Gerd Möllmann
2024-05-10 7:59 ` Gerd Möllmann
2024-05-10 8:09 ` Helmut Eller
2024-05-10 8:35 ` Gerd Möllmann
2024-05-10 8:51 ` Helmut Eller
2024-05-10 8:54 ` Gerd Möllmann
2024-05-10 10:25 ` Eli Zaretskii
2024-05-10 11:31 ` Gerd Möllmann
2024-05-10 12:52 ` Gerd Möllmann
2024-05-10 13:37 ` Helmut Eller
2024-05-10 13:59 ` Gerd Möllmann
2024-05-10 14:31 ` Helmut Eller
2024-05-10 14:36 ` Gerd Möllmann
2024-05-13 9:11 ` Gerd Möllmann
2024-05-14 8:23 ` Gerd Möllmann
2024-05-14 14:22 ` Helmut Eller
2024-05-14 15:46 ` Gerd Möllmann
2024-05-14 17:49 ` Eli Zaretskii
2024-05-14 18:10 ` Gerd Möllmann
2024-05-16 4:25 ` Gerd Möllmann
2024-05-16 8:36 ` Helmut Eller
2024-05-16 8:46 ` Gerd Möllmann
2024-05-16 9:01 ` Gerd Möllmann
2024-05-16 9:31 ` Helmut Eller
2024-05-16 9:42 ` Gerd Möllmann
2024-05-16 9:54 ` Gerd Möllmann
2024-05-16 12:43 ` Helmut Eller
2024-05-16 12:47 ` Gerd Möllmann
2024-05-16 12:08 ` Eli Zaretskii
2024-05-16 12:27 ` Gerd Möllmann
2024-05-16 12:07 ` Eli Zaretskii
2024-05-16 12:21 ` Gerd Möllmann
2024-05-16 12:27 ` Eli Zaretskii
2024-05-16 12:43 ` Gerd Möllmann
2024-05-16 14:09 ` Helmut Eller
2024-05-16 14:24 ` Gerd Möllmann
2024-05-16 15:48 ` Eli Zaretskii
2024-05-16 16:56 ` Andrea Corallo
2024-05-16 17:27 ` Gerd Möllmann
2024-05-16 17:50 ` Andrea Corallo
2024-05-16 20:03 ` Helmut Eller [this message]
2024-05-17 4:04 ` Gerd Möllmann
2024-05-17 6:09 ` Eli Zaretskii
2024-05-18 18:55 ` Helmut Eller
2024-05-18 20:16 ` Andrea Corallo
2024-05-19 5:27 ` Eli Zaretskii
2024-05-19 3:48 ` Gerd Möllmann
2024-05-19 6:39 ` Eli Zaretskii
2024-05-09 18:24 ` Gerd Möllmann
2024-05-09 18:35 ` Gerd Möllmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87msop4j99.fsf@gmail.com \
--to=eller.helmut@gmail.com \
--cc=acorallo@gnu.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=gerd.moellmann@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.