Re: Command Languages Versus Programming Languages

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Command Languages Versus Programming Languages
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.misc
Date : 30. Mar 2024, 20:46:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240330112105.553@kylheku.com>
References : 1 2 3 4 5 6 7 8
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-30, Muttley@dastardlyhq.com <Muttley@dastardlyhq.com> wrote:
On Fri, 29 Mar 2024 17:58:41 -0000 (UTC)
Kaz Kylheku <643-408-1753@kylheku.com> wrote:
On 2024-03-29, Muttley@dastardlyhq.com <Muttley@dastardlyhq.com> wrote:
Were the mucky bits actually written in Lisp or was Lisp simply calling some
routines written in assembler?
>
Sorry, could you demarcate where exactly the goalposts are? Which mucky
bits?
>
Oh I dunno, the parts that walk a kernel memory structure for example.

Well, since the kernel is written in Lisp, of course Lisp walks its own
data structures.

In a kernel, there often occur externally imposed memory structures,
like for instance lists of entries in a DMA buffer ring above an
ethernet device. Or banks of registers.

The kernel-writing Lisp dialect would have provisions for dealing
with binary structures like that.

The following example is not from a Lisp operating system, or a Lisp
that is known for operating system work. It's from my own application.

It shows how in CCL (Clozure Common Lisp) (note: note the Z, not Clojure
with a J) we can obtain a linked list C data structure and walk it,
using some CCL-specific concepts; CCL provides #> notations for C
types, and offsets into C structures and such.

The GetAdaptersInfo Win32 API is called, filling the list into a
stack-allocated buffer, with the help of CCL's %stack-block operator.
We get a list of adapters, each of which is a list consisting of
a list of the mac bytes, IP address list, name and description.

(The information is then encrypted, hashed and tied to a software license,
along with other bits of system info.)

(defun get-network-interface-list ()
  (open-shared-library "iphlpapi.dll")
  (let ((blk-size 65536) ;; crude!
        (get-adapters-info (foreign-symbol-address "GetAdaptersInfo")))
      (if get-adapters-info
        (%stack-block ((blk blk-size))
          (rlet ((len-inout #>ULONG blk-size))
            (if (zerop (ff-call get-adapters-info :address blk
                                                  :address len-inout
                                                  #>DWORD))
              (loop for ptr = blk then (pref ptr #>IP_ADAPTER_INFO.Next)
                    until (%null-ptr-p ptr)
                    collecting
                      (let ((alen (pref ptr #>IP_ADAPTER_INFO.AddressLength))
                            (addr (pref ptr #>IP_ADAPTER_INFO.Address))
                            (aname (pref ptr #>IP_ADAPTER_INFO.AdapterName))
                            (descr (pref ptr #>IP_ADAPTER_INFO.Description))
                            (iplist (pref ptr #>IP_ADAPTER_INFO.IpAddressList))
                            (type (pref ptr #>IP_ADAPTER_INFO.Type)))
                        (list type
                              (loop for i below alen
                                    collecting (%get-unsigned-byte addr i)
                                      into mac-bytes
                                    finally
                                      (return (mac-bytes-to-string mac-bytes)))
                              (get-ip-address-list iplist)
                              (%get-cstring aname)
                              (%get-cstring descr))))))))))

CCL is compiled; this just turns into a machine language function
poking at stack memory.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
20 Sep 24 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal