From e538d15b836c6931bbd14b5fb26f57899a3bff54 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 2 Jun 2017 21:55:23 -0700 Subject: ffi: evaluate expressions in type notation. Places where an integer constant was previously allowed now allow an expression. The way enum syntax works is now different. A temporary lexical environment is created, and each enumeration is bound in that environment. The value expressions are evaluated in that environment. The decision to allow keyword symbols to be enumeration contants is retracted. * eval.h (special_s): Declared. * ffi.c (ffi_eval_expr): New static function. (make_ffi_type_enum): Enums are introduced into a temporary environment, in which the value expressions are evaluated. By this means, the expressions can refer can refer to previous enums and do arbitrary computation. Also, we drop the requirement that enums can be keyword symbols. (ffi_type_compile): Array dimension and buf size are evaluated as expresions. Array and buffer syntax is transformed by substitution of the evaluated size. * txr.1: Documented use of expressions in FFI type notation. --- txr.1 | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 99b49a25..a9ba02de 100644 --- a/txr.1 +++ b/txr.1 @@ -53539,6 +53539,12 @@ are instantiated with parameters. Each such expression has a type constructor symbol in the operator position, from a limited, fixed vocabulary, which cannot be extended. +Some constituents of compound type syntax are expressions which evaluate to +integer values: the dimension value for array types, the size for buffers, +and the value expressions for enumeration constants are such expressions. +These expressions allow full use of \*(TL. They are evaluated without +visibility into any apparent surrounding lexical scope. + Some predefined types which are provided are in fact typedef names. For instance, the .code size-t @@ -53963,15 +53969,20 @@ type. The remaining arguments specify the enumeration constants. In the enumeration constant syntax, each occurrence of .meta sym -They must be either a keyword symbol, or a symbols for which the +They must be a bindable symbol according to the .code bindable -function returns true. The symbols may not repeat. +function. The symbols may not repeat within the same enumerated type. +Unlike in the C language, different enumerations may use the same symbols; +they are in separate spaces. If a .meta sym is given, it is associated with an integer value which is one greater than the integer value associated with the previous symbol. -If there is no previous symbol, then the value is zero. +If there is no previous symbol, then the value is zero. If the previous +symbol has been assigned the highest possible value of the FFI +.code int +type, then an error exception is thrown. If .meti >> ( sym << value ) @@ -53979,12 +53990,13 @@ is given, then .code sym is given the specified value. The .meta value -argument may be either an integer token, or a symbol. If it is an integer -token, then the value must be in range of the FFI +is an expression which must evaluate to an integer value in range of the FFI .code int -type. If a symbol is given, it must be be one of the symbols already defined -in the same enumerated type. The new symbol is given the same value as that -symbol. +type. +It is evaluated in an environment in which the previous +symbols from the same enumeration appear as variables whose binding are the +their enumeration values, making it possible to use earlier enumerations in the +definition of later enumerations. The FFI .code enum @@ -54089,6 +54101,11 @@ Since Lisp arrays and C arrays do not share the same representation, temporary buffers are automatically created and destroyed by FFI to manage the conversion. +The +.code dim +argument is an ordinary Lisp expression expanded and evaluated in the +top-level environment. It must produce a non-negative integer value. + In addition, several types are treated specially: when .meta type is one of @@ -54539,8 +54556,10 @@ and .codn buf-d , respectively. The .meta size -argument must be an integer literal, which specifies the buffer -size. Because they have a size, these types have useful get +argument is an expression which is evaluated in the top-level +environment, and must produce a non-negative integer. + +Because they have a size, these types have useful get semantics. The get semantics of -- cgit v1.2.3