From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: How to add pseudo vector types Date: Wed, 14 Jul 2021 13:47:19 -0400 Message-ID: References: <84B70E9B-E1E5-40D3-AFBE-033CACF15914@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5873"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 14 19:51:59 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3j34-00017X-OE for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Jul 2021 19:51:55 +0200 Original-Received: from localhost ([::1]:44636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3j33-00020y-KA for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Jul 2021 13:51:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3iys-0000lN-2Y for emacs-devel@gnu.org; Wed, 14 Jul 2021 13:47:34 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:49792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3iyo-0004Lr-Dr for emacs-devel@gnu.org; Wed, 14 Jul 2021 13:47:32 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 34BA24413A4; Wed, 14 Jul 2021 13:47:27 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 210F644013A; Wed, 14 Jul 2021 13:47:26 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1626284846; bh=OBFpytloP6Nr1EQ7E//M9be1umN8arjkqMU2giBC96E=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=onc0jK5ap6CDrMdYZb38y/HItQknzNB+sJ+n+nwk2yfU8XlrvC6RWSXdovs/4mEUA Gh8lLMOItGPyAc1YrpMnq+7ADA0v9JE2N6YiaG7CtekoZv0BQsfqzY2NP0Yuxb2kco Ao4Ojkc+rhek8WkZ6TwA0PKBgBVhVdLjJNQp1H5aCCJlI1U3QD7qZfoj0OMXGtXwb8 gUrJEwe0EO5djp0SgWxd0R8vyy3SsywyGzupzSVTX6ydijOi3lPRJAX1zcpkT+qmXp TBDfj01CxgpYHE1nVoUKtv8sRdyq29I7DnNWm+hm/FxRa+9WfEycA8uZwn826QXrWN BB66HOeVBXEfg== Original-Received: from alfajor (unknown [216.154.29.138]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C65B512031C; Wed, 14 Jul 2021 13:47:25 -0400 (EDT) In-Reply-To: <84B70E9B-E1E5-40D3-AFBE-033CACF15914@gmail.com> (Yuan Fu's message of "Wed, 14 Jul 2021 13:37:47 -0400") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271223 Archived-At: Yuan Fu [2021-07-14 13:37:47] wrote: > Say I want to expose tree-sitter=E2=80=99s parser to lisp, and I define i= t as a new pseudo vector. > > struct Lisp_TS_Parser > { > union vectorlike_header header; > Lisp_Object buffer; > TSParser *parser; > TSTree *tree; > TSInput input; > }; > > Now if I want to return a Lisp_Object, do I initialize this struct and ca= st > it into a Lisp_Object and return it? Like: > > Lisp_TS_parser lisp_parser; > ... > return (Lisp_Object)lisp_parser; > > > And how do I use a USER_PTR? Do I cast it into (struct Lisp_User_Ptr) and > use it normally, or is there some helper function that I should use? Most likely you'll want some of your functions to take objects that should be "tree sitter parsers", but you'll only receive a Lisp_Object so you'll need to be able to *test* that the object you received is indeed a "tree sitter parser". For that reason you'll probably want to add a new entry to `pvec_type` rather than use a USER_PTR. > Are there examples of using pseudo vectors? Thanks Lots of them: actual vectors, processes, threads, mutexes, overlays, you name it. Stefan