From 5a492abda1aa88d394611e3b6c5e6d03da7c9cc4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 13 Jun 2017 21:08:23 -0700 Subject: ffi: turn carray-sub into accessor. * lisplib.c (ffi_set_entries): Register carray-sub for autoload. * share/txr/stdlib/ffi.tl (carray-sub): New place macro, aliases to sub. This is not 100% correct since that means it will admit non-carray objects, but the alternative is to clone the entire sub expander with a few changes, or else factor out sub expansion into a shared routine. Bleh ... * txr.1: Documented. We don't cover up the ruse we perpetrated, and reveal that it's just a place macro targetting sub. --- lisplib.c | 2 +- share/txr/stdlib/ffi.tl | 3 +++ txr.1 | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lisplib.c b/lisplib.c index 2b57c578..3e57d627 100644 --- a/lisplib.c +++ b/lisplib.c @@ -526,7 +526,7 @@ static val ffi_set_entries(val dlt, val fun) lit("with-dyn-lib"), lit("deffi"), lit("deffi-type"), lit("deffi-cb"), lit("deffi-var"), lit("typedef"), lit("sizeof"), lit("alignof"), lit("offsetof"), lit("arraysize"), lit("elemsize"), lit("elemtype"), - lit("ffi"), lit("carray-ref"), + lit("ffi"), lit("carray-ref"), lit("carray-sub"), nil }; set_dlt_entries(dlt, name, fun); diff --git a/share/txr/stdlib/ffi.tl b/share/txr/stdlib/ffi.tl index da29c1e5..a041692f 100644 --- a/share/txr/stdlib/ffi.tl +++ b/share/txr/stdlib/ffi.tl @@ -133,3 +133,6 @@ ^(ffi-type-compile ',type)) (define-accessor carray-ref carray-refset) + +(define-place-macro carray-sub (carray : (from 0) (to t)) + ^(sub ,carray ,from ,to)) diff --git a/txr.1 b/txr.1 index 4aa99e06..451b219c 100644 --- a/txr.1 +++ b/txr.1 @@ -56928,9 +56928,10 @@ then the expected string conversion semantics applies. Both of these functions return .metn carray . -.coNP Function @ carray-sub +.coNP Accessor @ carray-sub .synb .mets (carray-sub < carray >> [ from <> [ to ]]) +.mets (set (carray-sub < carray >> [ from <> [ to ]]) << new-val ) .syne .desc The @@ -56965,6 +56966,12 @@ can be severed by invoking on the returned object, after which the two no longer share storage, and modifications in the original are not reflected in the subrange. +If +.code carray-sub +is used as a syntactic place, behaves exactly like the +.code sub +accessor, via a place macro substitution to that form. + .coNP Function @ carray-replace .synb .mets (carray-replace < carray < item-sequence >> [ from <> [ to ]]) -- cgit v1.2.3