From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: Re: Dynamic loading progress Date: Mon, 16 Mar 2015 13:02:16 -0500 Message-ID: <85a8zcu8gn.fsf@stephe-leake.org> References: <83pp9cwky8.fsf@gnu.org> <85a90ggf2d.fsf@stephe-leake.org> <54E0A40F.5080603@dancol.org> <83sie7un20.fsf@gnu.org> <54E0D181.2080802@dancol.org> <83r3trulse.fsf@gnu.org> <54E0D7E0.305@87.69.4.28> <83h9unukbg.fsf@gnu.org> <54E0DEF8.7020901@dancol> <83egpruiyp.fsf@gnu.org> <54E0FF93.2000104@dancol.org> <833865vp4d.fsf@gnu.org> <54E2355A.90@87.69.4.28> <83vbj1u020.fsf@gnu.org> <54E24CA4.9020601@dancol.org> <83h9uk7ddb.fsf@gnu.org> <54E382A5.5030408@dancol.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1426529039 12914 80.91.229.3 (16 Mar 2015 18:03:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Mar 2015 18:03:59 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 16 19:03:47 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YXZLo-00025V-JO for ged-emacs-devel@m.gmane.org; Mon, 16 Mar 2015 19:02:52 +0100 Original-Received: from localhost ([::1]:50968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXZLn-0000H9-U2 for ged-emacs-devel@m.gmane.org; Mon, 16 Mar 2015 14:02:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXZLj-0000Gl-Dn for emacs-devel@gnu.org; Mon, 16 Mar 2015 14:02:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXZLg-0007RF-6D for emacs-devel@gnu.org; Mon, 16 Mar 2015 14:02:47 -0400 Original-Received: from gproxy6-pub.mail.unifiedlayer.com ([67.222.39.168]:44014) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1YXZLf-0007Qh-VG for emacs-devel@gnu.org; Mon, 16 Mar 2015 14:02:44 -0400 Original-Received: (qmail 23563 invoked by uid 0); 16 Mar 2015 18:02:34 -0000 Original-Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy6.mail.unifiedlayer.com with SMTP; 16 Mar 2015 18:02:34 -0000 Original-Received: from host114.hostmonster.com ([74.220.207.114]) by cmgw4 with id 4Q2Q1q01k2UdiVW01Q2TB1; Mon, 16 Mar 2015 18:02:32 -0600 X-Authority-Analysis: v=2.1 cv=Se5kKJhu c=1 sm=1 tr=0 a=CQdxDb2CKd3SRg4I0/XZPQ==:117 a=CQdxDb2CKd3SRg4I0/XZPQ==:17 a=DsvgjBjRAAAA:8 a=f5113yIGAAAA:8 a=2wGvvwaKUHMA:10 a=IkcTkHD0fZMA:10 a=9i_RQKNPAAAA:8 a=hEr_IkYJT6EA:10 a=jrwKn-8xaegA:10 a=emO1SXQWCLwA:10 a=pGLkceISAAAA:8 a=bb1N3tO0udc4DlRALa4A:9 a=0cQWNkGVttrfgvCK:21 a=4Ex_OBtshkei7ifG:21 a=QEXdDO2ut3YA:10 Original-Received: from [70.94.38.149] (port=53184 helo=TAKVER) by host114.hostmonster.com with esmtpa (Exim 4.82) (envelope-from ) id 1YXZLO-0005BD-2J for emacs-devel@gnu.org; Mon, 16 Mar 2015 12:02:26 -0600 In-Reply-To: (=?utf-8?Q?=22Aur=C3=A9lien?= Aptel"'s message of "Sat, 28 Feb 2015 19:20:41 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (windows-nt) X-Identified-User: {2442:host114.hostmonster.com:stephele:stephe-leake.org} {sentby:smtp auth 70.94.38.149 authed with stephen_leake@stephe-leake.org} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 67.222.39.168 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:183915 Archived-At: Aur=C3=A9lien Aptel writes: > I've tried to implement modules using Daniel's plan. It turned out to > be pretty easy, mostly because I'm more familiar with the Emacs > codebase now and because it's a lot less intrusive than my previous > attempt. > > It's not finished but I have a basic module working on linux. It's a > proof of concept, basically. I've implemented a test module that calls two Ada mode parser actions (see below). The real module will call the actual parser and build the action args from the parse results. I did not have to modify anything in the Emacs C code to make this work, so it shows this module design is adquate for my use case so far. I still need to implement the lexer level, which will either need to call the current elisp lexer, or access the buffer text directly. Any comments on the coding style? I don't think I need GCPRO on any of the static emacs_values, because they are all declared at global level in elisp. -- -- Stephe /* Emacs module for Ada mode, providing a fast generalized LALR parser */ #include int plugin_is_GPL_compatible; /* elisp functions */ static emacs_value aref; static emacs_value cons; static emacs_value length; static emacs_value nil; static emacs_value set; static emacs_value symbol_value; static emacs_value vector; static emacs_value wisi_containing_action; static emacs_value wisi_statement_action; /* variables */ static emacs_value wisi_tokens; /* array of symbols used in grammar actions */ static emacs_value* ada_grammar_names; static emacs_value Fcons (emacs_env *env, emacs_value a, emacs_value b) { emacs_value args[] =3D { a, b }; return env->funcall (env, cons, 2, args); } /* Parse BUFFER, using parser in current module. */ static void parse (emacs_env *env, emacs_value buffer) { /* For now, just execute the actions from parsing second line in: procedure Foo is begin A :=3D 1; end Foo; ada_grammar.adb assignment_statement_0 wisi-tokens: [(name 24 . 25) (COLON_EQUAL 26 . 28) (expression 29 . 30= ) (SEMICOLON 30 . 31)] action: (wisi-statement-action [1 statement-start 2 statement-other 4 = statement-end]) */ /* Set `wisi-tokens'; wisi-tokens is let-bound in calling elisp function. */ emacs_value tokens[] =3D { /* name "A" */ Fcons (env, ada_grammar_names[245], Fcons (env, env->make_fixnum (env= , 24), env->make_fixnum (env, 25))), /* COLON_EQUAL ":=3D" */ Fcons (env, ada_grammar_names[ 81], Fcons (env, env->make_fixnum (env= , 26), env->make_fixnum (env, 28))), /* expression "1" */ Fcons (env, ada_grammar_names[194], Fcons (env, env->make_fixnum (env= , 29), env->make_fixnum (env, 30))), /* SEMICOLON ";" */ Fcons (env, ada_grammar_names[ 95], Fcons (env, env->make_fixnum (env= , 30), env->make_fixnum (env, 31))) }; emacs_value args_1[] =3D { wisi_tokens, env->funcall (env, vector, 4, tok= ens) }; env->funcall (env, set, 2, args_1); emacs_value pairs[] =3D { env->make_fixnum (env, 1), ada_grammar_names[341], /* statement-start= */ env->make_fixnum (env, 2), ada_grammar_names[342], /* statement-other= */ env->make_fixnum (env, 4), ada_grammar_names[343] /* statement-end */ }; emacs_value args_2[] =3D { env->funcall (env, vector, 6, pairs) }; env->funcall (env, wisi_statement_action, 1, args_2); emacs_value args_3[] =3D { env->make_fixnum (env, 2), env->make_fixnum (e= nv, 3) }; env->funcall (env, wisi_containing_action, 2, args_3); } /* elisp-callable wrapper for `parse' args: BUFFER */ static emacs_value Fparse (emacs_env *env, int nargs, emacs_value args[]) { parse (env, args[0]); return nil; } /* Binds NAME to FUN */ static void bind_function (emacs_env *env, const char *name, emacs_value Ff= un) { emacs_value Qfset =3D env->intern (env, "fset"); emacs_value Qsym =3D env->intern (env, name); emacs_value args[] =3D { Qsym, Ffun }; env->funcall (env, Qfset, 2, args); } /* standard Emacs module init */ int emacs_module_init (struct emacs_runtime *ert) { emacs_env *env =3D ert->get_environment (ert); aref =3D env->intern (env, "aref"); cons =3D env->intern (env, "cons"); length =3D env->intern (env, "length"); nil =3D env->intern (env, "nil"); set =3D env->intern (env, "set"); symbol_value =3D env->intern (env, "symbol-value"); vector =3D env->intern (env, "vector"); wisi_statement_action =3D env->intern (env, "wisi-statement-action"); wisi_containing_action =3D env->intern (env, "wisi-containing-action"); wisi_tokens =3D env->intern (env, "wisi-tokens"); emacs_value names_1 =3D env->intern (env, "ada_grammar-names"); emacs_value args_1[] =3D { names_1 }; emacs_value names_2 =3D env->funcall (env, symbol_value, 1, args_1); emacs_value args_2[] =3D { names_2 }; int64_t names_length =3D env->fixnum_to_int (env, env->funcall (env, leng= th, 1, args_2)); ada_grammar_names =3D malloc (names_length * sizeof (int64_t)); for (int i =3D 0; i < names_length; i++) { emacs_value args[] =3D {names_2, env->make_fixnum (env, i)}; ada_grammar_names[i] =3D env->funcall (env, aref, 2, args); }; bind_function (env, "wisi-module-parse", env->make_function (env, 1, 1, F= parse)); return 0; }