From baffee5455676a7359f755689421d4c00f5fc4c1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 6 May 2017 10:54:54 -0700 Subject: ffi: reduce (array void t) syntax to (array t). Omission of the dimension will be expressed by actual omission rather than the void placeholder. It's just a harmless bit of parsing providing a reasonably intuitive syntax that doesn't leave readers wondering what void is doing there. * ffi.c (ffi_type_compile): Rearrange array parsing code. Also diagnose if the form has more than thre elements. --- ffi.c | 61 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/ffi.c b/ffi.c index c4d3ee23..b693628b 100644 --- a/ffi.c +++ b/ffi.c @@ -1317,15 +1317,13 @@ val ffi_type_compile(val syntax) cons(sname, membs)); return make_ffi_type_struct(xsyntax, stype, slots, types); } else if (sym == array_s || sym == zarray_s) { - val dim = cadr(syntax); - val eltype_syntax = caddr(syntax); - val eltype = ffi_type_compile(eltype_syntax); - - if (dim == void_s) { - val type = make_ffi_type_pointer(syntax, vec_s, sizeof (mem_t *), - ffi_array_put, ffi_void_get, - ffi_array_in, ffi_array_out, - eltype); + if (length(syntax) == two) { + val eltype_syntax = cadr(syntax); + val eltype = ffi_type_compile(eltype_syntax); + val type = make_ffi_type_pointer(syntax, vec_s, sizeof (mem_t *), + ffi_array_put, ffi_void_get, + ffi_array_in, ffi_array_out, + eltype); struct txr_ffi_type *tft = ffi_type_struct(type); if (sym == zarray_s) tft->null_term = 1; @@ -1333,30 +1331,37 @@ val ffi_type_compile(val syntax) tft->alloc = ffi_varray_alloc; tft->free = free; return type; - } + } else if (length(syntax) == three) { + val dim = cadr(syntax); + val eltype_syntax = caddr(syntax); + val eltype = ffi_type_compile(eltype_syntax); - if (minusp(dim)) + if (minusp(dim)) uw_throwf(error_s, lit("~a: negative dimension in ~s"), self, syntax, nao); - { - val type = make_ffi_type_array(syntax, vec_s, dim, eltype); - struct txr_ffi_type *tft = ffi_type_struct(type); - - if (sym == zarray_s) { - tft->null_term = 1; - if (zerop(dim)) - uw_throwf(error_s, lit("~a: zero dimension in ~s"), - self, syntax, nao); + { + val type = make_ffi_type_array(syntax, vec_s, dim, eltype); + struct txr_ffi_type *tft = ffi_type_struct(type); + + if (sym == zarray_s) { + tft->null_term = 1; + if (zerop(dim)) + uw_throwf(error_s, lit("~a: zero dimension in ~s"), + self, syntax, nao); + } + + if (eltype_syntax == char_s) + tft->char_conv = 1; + else if (eltype_syntax == wchar_s) + tft->wchar_conv = 1; + else if (eltype_syntax == bchar_s) + tft->bchar_conv = 1; + return type; } - - if (eltype_syntax == char_s) - tft->char_conv = 1; - else if (eltype_syntax == wchar_s) - tft->wchar_conv = 1; - else if (eltype_syntax == bchar_s) - tft->bchar_conv = 1; - return type; + } else { + uw_throwf(error_s, lit("~a: excess elements in ~s"), + self, syntax, nao); } } else if (sym == ptr_in_s) { val target_type = ffi_type_compile(cadr(syntax)); -- cgit v1.2.3