with-c-syntax

API Reference

with-c-syntax

with-c-syntax is a fun package which introduces the C language syntax into Common Lisp.

WITH-C-SYNTAX

The with-c-syntax package, holding public APIs.
  • Macro WITH-C-SYNTAX ((&rest options &key (keyword-case (common-lisp:readtable-case common-lisp:*readtable*)) (case-sensitive (common-lisp:ecase with-c-syntax.core::keyword-case ((:upcase :downcase) common-lisp:nil) ((:preserve :invert) common-lisp:t))) (return :auto) (try-add-{} common-lisp:t)) &environment *wcs-expanding-environment* &body body)
    This macro is a entry point of the with-c-syntax system. BODY will be interpreted as C syntax, executed, and return values. CASE-SENSITIVE specifies case-sensitivity in interpreting symbols. If nil, C syntactic keyworks and Libc functions are treated case-insentisively. KEYWORD-CASE is used for calculating CASE-SENSITIVE parameter. If RETURN is `:auto', returns the last form's value if BODY is a compound statement. (If BODY is a compilation unit, this returns NIL now, but this behavior may be changed.) If RETURN is any other value, its valus is inserted after the compilation result translation units. (This feature is intended to access 'static' variables.) ?f TRY-ADD-{} is t and an error occurred at parsing, `with-c-syntax' adds '{' and '}' into the head and tail of FORM respectively, and tries to parse again.
  • Variable *WITH-C-SYNTAX-READER-LEVEL*
    nil
    Holds the reader level used by '#{' reader function. The value is one of 0, 1, 2, or nil (default). The default is nil, recognized same as `+with-c-syntax-default-reader-level+'. For inside '#{' and '}#', three syntaxes are defined. These syntaxes are selected by the infix parameter of the '#{' dispatching macro character. If it not specified, its default is this value. Available syntaxes are below: * Level 0 (conservative) In level 0, these reader macros are installed. - ',' :: ',' is read as a symbol. (In ANSI CL, a comma is defined as an invalid char outside the backquote syntax.) - ':' :: Reads a solely ':' as a symbol. Not a solely one (as a package marker) works as is. Level 0 is almost comatible with the standard syntax. However, we need many escapes using C symbols. * Level 1 (aggressive). In level 1, these reader macros are installed. - '{', '}', '[', ']' :: These become a terminating character, and read as a symbol. - '`' :: '`' reads a next s-exp in the previous syntax. This works as an escape from '#{' and '}#' The 'backquote' functionality is lost. - '.' :: Reads a solely '.' as a symbol. The 'consing dot' functionality is lost. - '' :: The '' becomes a ordinary constituent character. The 'multiple escaping' functionality is lost. - '/' :: '//' means a line comment, '/* ... */' means a block comment. '/' is still non-terminating, and has special meanings only if followed by '/' or '*'. Ex: 'a/b/c' or '/+aaa+/' are still valid symbols. - ''' (single-quote) :: The single-quote works as a character literal of C. The 'quote' functionality is lost. - '"' (double-quote) :: The double-quote works as a string literal of C. Especially, escaping is treated as C. The original functionality is lost. - ';' :: ';' becomes a terminating character, and read as a symbol. The 'comment' functionality is lost. - '(' and ')' :: parenthesis become a terminating character, and read as a symbol. The 'reading a list' functionality is lost. Level 1 overwrites macro characters in the standard syntax. Only constituent characters are left unchanged. Especially, '(' and ')' loses its functionalities. For constructing a list of Lisp, the '`' syntax must be used. * Level 2 (overkill) In this level, these characters become terminating, and read as a symbol listed below. - '?' :: '?' - '~' :: '~' - ':' :: ':' - '.' :: '.' - '=' :: '=' or '==' - '*' :: '*' or '*=' - '^' :: '^' or '^=' - '!' :: '!' or '!=' - '&' :: '&', '&&', or '&=' - '|' :: '|', '||', or '|=' - '+' :: '+', '++', or '+=' - '-' :: '-', '--', '-=', or '->' - '>' :: '>', '>>', or '>>=' - '<' :: '<', '<<', or '<<=' - '/' :: '/', or '/='. '//' means a line comment, and '/* ... */' means a block comment. In this level, there is no compatibilities between symbols of Common Lisp. Especially, for denoting a symbol has terminating characters, escapes are required. (ex. most-positive-fixnum)
  • Variable *WITH-C-SYNTAX-READER-CASE*
    nil
    Holds the reader case used by '#{' reader function. When this is not nil, it must be one of `:upcase', `:downcase', `:preserve', or `:invert'. The specified case is used as the readtable-case inside '#{' and '}#' and passed to the wrapping `with-c-syntax' form. When this is nil, it is used as the readtable-case of `*readtable*' at '#{'.

WITH-C-SYNTAX.SYNTAX

Holds symbols denoting C operators and keywords.
No exported symbols.

WITH-C-SYNTAX.CORE

with-c-syntax core package.
  • Condition WITH-C-SYNTAX-ERROR  (SIMPLE-ERROR)
    * Class Precedence List with-c-syntax-error, simple-error, ... * Description The type ~with-c-syntax-error~ consists of all errors in with-c-syntax system.
  • Condition WITH-C-SYNTAX-WARNING  (SIMPLE-WARNING)
    * Class Precedence List with-c-syntax-warning, simple-warning, ... * Description The type ~with-c-syntax-warning~ consists of all warnings in the with-c-syntax system.
  • Function FIND-STRUCT-SPEC (name)
    * Syntax ~find-struct-spec~ name => struct-spec * Arguments and Values - name :: a symbol - decl-spec :: a struct-spec instance, or nil. * Description Finds and returns a struct-spec. If no struct-specs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Function ADD-STRUCT-SPEC (name sspec)
    * Syntax ~add-struct-spec~ name sspec => struct-spec * Arguments and Values - name :: a symbol. - sspec :: a struct-spec instance. - struct-spec :: a struct-spec instance. * Description Establishes a new struct-spec definition named ~name~. * Affected By ~with-c-compilation-unit~.
  • Function REMOVE-STRUCT-SPEC (name)
    * Syntax ~remove-struct-spec~ name => struct-spec * Arguments and Values - name :: a symbol - struct-spec :: a struct-specs instance, or nil. * Description Removes a struct-spec definition named ~name~. Returns the removed struct-spec definition. If no struct-specs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Class STRUCT
    * Class Precedence List struct, standard-object, ... * Description A representation of C structs or unions.
    MEMBER-INDEX-TABLE   Reader: STRUCT-MEMBER-INDEX-TABLE
    MEMBER-VECTOR   Accessor: STRUCT-MEMBER-VECTOR
  • Function MAKE-STRUCT (spec-obj &rest init-args)
    * Syntax ~make-struct~ spec-obj &rest init-args => new-struct * Arguments and Values - spec-obj :: a symbol, or an instance of struct-spec. - init-args :: objects. - new-struct :: an instance of struct. * Description Makes a new struct instance based on the specification of ~spec-obj~. If ~spec-obj~ is a symbol, it must be a name of a globally defined struct or union. To define a struct or an union globally, use ~with-c-syntax~ and declare it in a toplevel of translation-unit. If ~spec-obj~ is an instance of struct-spec, it is used directly. ~init-args~ is used for initializing members of the newly created instance. If the number of ~init-args~ is less than the number of members, the rest members are initialized with the default values specified by the ~spec-obj~.
  • Function STRUCT-MEMBER (struct member-name)
    * Syntax ~struct-member~ struct member-name => object * Arguments and Values - struct :: an instance of struct - member-name :: a symbol - object :: an object * Description Returns the value of the member named ~member-name~ in the ~struct~.
  • Function (setf STRUCT-MEMBER) (val struct member-name)
    * Syntax (setf (~struct-member~ struct member-name) new-object) * Arguments and Values - struct :: an instance of struct - member-name :: a symbol - new-object :: an object * Description Sets the value of the member named ~member-name~ in the ~struct~.
  • Function FIND-TYPEDEF (name)
    * Syntax ~find-typedef~ name => decl-spec * Arguments and Values - name :: a symbol - decl-spec :: a decl-specs instance, or nil. * Description Finds and returns a typedef definition. If no typedefs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Function ADD-TYPEDEF (name spec)
    * Syntax ~add-typedef~ name spec => decl-spec * Arguments and Values - name :: a symbol - spec :: a decl-specs instance, or a type specifier. - decl-spec :: a decl-specs instance. * Description Establishes a new typedef definition named ~name~. * Affected By ~with-c-compilation-unit~.
  • Function REMOVE-TYPEDEF (name)
    * Syntax ~remove-typedef~ name => decl-spec * Arguments and Values - name :: a symbol - decl-spec :: a decl-specs instance, or nil. * Description Removes a typedef definition named ~name~. Returns the removed typedef definition. If no typedefs are found, returns nil. * Affected By ~with-c-compilation-unit~.
  • Type PSEUDO-POINTER (&optional (pointee-type t))
    The base type of internal representation of null and non-null pointers in with-c-syntax sysrem.
  • Macro WITH-PSEUDO-POINTER-SCOPE (nil &body body)
    In this macro, BODY is executed in a new environment for pseudo-pointers. A pointer made inside this macro is invalidated outside of this.
  • Function INVALIDATE-ALL-PSEUDO-POINTERS
    This function invalidates all pseudo-pointers in the scope it called, and returns the number of invalidates pointers. In `with-pseudo-pointer-scope', this call invalidates pseudo-pointers made in that. If out of that, this call invalidates all pseudo-pointers.
  • Function PSEUDO-POINTER-POINTABLE-P (object)
    Returns whether the OBJECT can be held by pseudo-pointers.
  • Function MAKE-PSEUDO-POINTER (pointee &optional (initial-offset 0))
    Makes and returns a new pseudo-pointer points POINTEE. INITIAL-OFFSET is added to the result at making.
  • Function PSEUDO-POINTER-DEREFERENCE (pointer)
    Dereferences the POINTER and returns the pointed object.
  • Function (setf PSEUDO-POINTER-DEREFERENCE) (new-object pointer)
    Makes the POINTER to point the NEW-OBJECT.
  • Function PSEUDO-POINTER-INVALIDATE (pointer)
    Makes the POINTER to point no objects. After that, calling `pseudo-pointer-dereference' to this pointer will be error.
  • Function BUILD-LIBC-SYMBOL-CACHE (&optional (package (find-package '#:with-c-syntax.libc)))
    Build a cache used by `intern-libc-symbol'
  • Function BUILD-LIBC-SYMBOL-CACHE (&optional (package (find-package '#:with-c-syntax.libc)))
    Build a cache used by `intern-libc-symbol'
  • Function FIND-PREPROCESSOR-MACRO (symbol)
    Finds and returns a preprocessor macro definition named SYMBOL, added by `add-preprocessor-macro'.
  • Function ADD-PREPROCESSOR-MACRO (symbol value)
    Establishes a new preprocessor macro to SYMBOL, which is corresponded to VALUE. Preprocessor macros are held in `symbol-plist' of SYMBOL, and indicated by `+preprocessor-macro+'.
  • Function REMOVE-PREPROCESSOR-MACRO (symbol)
    Removes a preprocessor macro named SYMBOL.
  • Macro DEFINE-PREPROCESSOR-CONSTANT (name value &environment env)
    Defines a new preprocessor symbol macro, named by NAME and its value is VALUE.
  • Macro DEFINE-PREPROCESSOR-FUNCTION (name lambda-list &body body)
    Defined a new preprocessor function, named by NAME.
  • Function PREPROCESSOR (lis case-sensitive)
    This function preprocesses LIS before parsing. Current workings are below: - Interning a symbol into this package when it has a same name as C keywords or operators, or libc symbols. - Concatenation of string literals. - Calling preprocessor macros, defined by `add-preprocessor-macro'. How preprocessor macros are expanded is described below. - A dirty hack for 'typedef'. Automatically adds 'void ;' after each typedef declarations. This is a workaround for avoiding the problem between 'the lexer hack' and the look-aheading of cl-yacc. CASE-SENSITIVE specifies interning C keywords or libc symbols is case-sensitively or case-insensitively. Expansion rules: - If VALUE is nil, no expansion is done. The original symbol is left. - If VALUE is a object not a function, it is used as an expansion. - If VALUE is a function, the function is called, and the returned value is used for expansion. Arguments for the function are datum between the following ( symbol and the next ) symbol, delimited by , symbol. Example: If MAC is defined for a macro and its value is a function, this sequence MAC ( a , b b , c c c ) calls the function like: (funcall #'a-func-of-MAC '(a) '(b b) '(c c c))
  • Type ENUM
    Represents the enum type.
  • Macro GET-VARIADIC-ARGUMENTS (&optional last-argument-name)
    It returns the variadic arguments of a function defined by with-c-syntax. If this is called outside of a variadic function, an error is signaled. When defining a variadic function, a local macro has same name is established. This is not intended for calling directly. The `va_start' macro uses this.

Also exports

  • WITH-C-SYNTAX:WITH-C-SYNTAX
  • WITH-C-SYNTAX:*WITH-C-SYNTAX-READER-LEVEL*
  • WITH-C-SYNTAX:*WITH-C-SYNTAX-READER-CASE*
  • WITH-C-SYNTAX:WITH-C-SYNTAX-READTABLE

WITH-C-SYNTAX.LIBC

with-c-syntax libc package.
  • Variable NDEBUG
  • Macro assert (&rest args)
    This emulates 'assert' of the C language. If `NDEBUG' is bound and its value is true, `|assert|' will be expanded to a no-op. If not (`NDEBUG' is unbound or bound to NIL), `|assert|' will be expanded to `cl:assert'. This macro sees `NDEBUG' value only when macroexpanding-time, not in runtime. (If you want to change `NDEBUG' locally, you should use `compiler-let'.)
  • Function isalnum (char)
  • Function isalpha (char)
  • Function islower (char)
  • Function isupper (char)
  • Function isdigit (char)
  • Function isxdigit (char)
  • Function iscntrl (char)
  • Function isgraph (char)
  • Function isspace (char)
  • Function isblank (char)
  • Function isprint (char)
  • Function ispunct (char)
  • Function tolower (char)
  • Function toupper (char)
  • Variable errno
    nil
    A symbol denoting 'errno' of C, or NIL. If a function of `with-c-syntax.libc' caught error, it will set the error to this. (If this has a symbol, that is usable as a condition type of 'osicat-posix'.)
  • Variable FLT_RADIX
    (float-radix 1.0d0)
  • Variable FLT_MANT_DIG
    (float-digits 1.0)
  • Variable FLT_EPSILON
    single-float-epsilon
  • Variable FLT_DIG
    (with-c-syntax.libc-implementation::mantissa-radix-change
     with-c-syntax.libc:flt_mant_dig (float-radix 1.0) 10)
  • Variable FLT_MIN_EXP
    (nth-value 1 (decode-float least-positive-normalized-single-float))
  • Variable FLT_MIN
    least-positive-normalized-single-float
  • Variable FLT_MIN_10_EXP
    (ceiling (log least-positive-normalized-single-float 10))
  • Variable FLT_MAX_EXP
    (nth-value 1 (decode-float most-positive-single-float))
  • Variable FLT_MAX
    most-positive-single-float
  • Variable FLT_MAX_10_EXP
    (floor (log most-positive-single-float 10))
  • Variable DBL_MANT_DIG
    (float-digits 1.0d0)
  • Variable DBL_EPSILON
    double-float-epsilon
  • Variable DBL_DIG
    (with-c-syntax.libc-implementation::mantissa-radix-change
     with-c-syntax.libc:dbl_mant_dig (float-radix 1.0d0) 10)
  • Variable DBL_MIN_EXP
    (nth-value 1 (decode-float least-positive-normalized-double-float))
  • Variable DBL_MIN
    least-positive-normalized-double-float
  • Variable DBL_MIN_10_EXP
    (ceiling (log least-positive-normalized-double-float 10))
  • Variable DBL_MAX_EXP
    (nth-value 1 (decode-float most-positive-double-float))
  • Variable DBL_MAX
    most-positive-double-float
  • Variable DBL_MAX_10_EXP
    (floor (log most-positive-double-float 10))
  • Variable LDBL_MANT_DIG
    (float-digits 1.0d0)
  • Variable LDBL_EPSILON
    long-float-epsilon
  • Variable LDBL_DIG
    (with-c-syntax.libc-implementation::mantissa-radix-change
     with-c-syntax.libc:ldbl_mant_dig (float-radix 1.0d0) 10)
  • Variable LDBL_MIN_EXP
    (nth-value 1 (decode-float least-positive-normalized-long-float))
  • Variable LDBL_MIN
    least-positive-normalized-long-float
  • Variable LDBL_MIN_10_EXP
    (ceiling (log least-positive-normalized-long-float 10))
  • Variable LDBL_MAX_EXP
    (nth-value 1 (decode-float most-positive-long-float))
  • Variable LDBL_MAX
    most-positive-long-float
  • Variable LDBL_MAX_10_EXP
    (floor (log most-positive-long-float 10))
  • Variable FLT_ROUNDS
    -1
  • Variable DECIMAL_DIG
    (max with-c-syntax.libc:flt_dig with-c-syntax.libc:dbl_dig
         with-c-syntax.libc:ldbl_dig)
  • Variable FLT_EVAL_METHOD
    -1
  • Variable and
    'with-c-syntax.syntax:&&
  • Variable and_eq
    'with-c-syntax.syntax:&=
  • Variable bitand
    'with-c-syntax.syntax:&
  • Variable bitor
    'with-c-syntax.syntax:|\||
  • Variable compl
    'with-c-syntax.syntax:~
  • Variable not
    'with-c-syntax.syntax:!
  • Variable not_eq
    'with-c-syntax.syntax:!=
  • Variable or
    'with-c-syntax.syntax:|\|\||
  • Variable or_eq
    'with-c-syntax.syntax:|\|=|
  • Variable xor
    'with-c-syntax.syntax:^
  • Variable xor_eq
    'with-c-syntax.syntax:^=
  • Variable CHAR_BIT
    8
  • Variable CHAR_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 8)
  • Variable CHAR_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 8)
  • Variable INT_MAX
    most-positive-fixnum
  • Variable INT_MIN
    most-negative-fixnum
  • Variable SHRT_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 16)
  • Variable SHRT_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 16)
  • Variable LONG_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 32)
  • Variable LONG_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 32)
  • Variable LLONG_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 64)
  • Variable LLONG_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 64)
  • Variable SCHAR_MAX
    (with-c-syntax.libc-implementation::signed-byte-max 8)
  • Variable SCHAR_MIN
    (with-c-syntax.libc-implementation::signed-byte-min 8)
  • Variable UCHAR_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 8)
  • Variable UINT_MAX
    (max most-positive-fixnum 65535)
  • Variable USHRT_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 16)
  • Variable ULONG_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 32)
  • Variable ULLONG_MAX
    (with-c-syntax.libc-implementation::unsigned-byte-max 64)
  • Variable MB_LEN_MAX
    (ceiling (1+ (floor (log char-code-limit 2))) with-c-syntax.libc:char_bit)
  • Function fabs (x)
  • Function fmod (x y)
  • Function remainder (x y)
  • Function REMQUO* (x y)
  • Function fmax (x y)
  • Function fmin (x y)
  • Function exp (x)
  • Function exp2 (x)
  • Function expm1 (x)
  • Function log (x)
  • Function log10 (x)
  • Function log2 (x)
  • Function log1p (x)
  • Function pow (x y)
  • Function sqrt (x)
  • Function cbrt (x)
  • Function hypot (x y)
  • Function sin (x)
  • Function cos (x)
  • Function tan (x)
  • Function asin (x)
  • Function acos (x)
  • Function atan (x)
  • Function atan2 (x y)
  • Function sinh (x)
  • Function cosh (x)
  • Function tanh (x)
  • Function asinh (x)
  • Function acosh (x)
  • Function atanh (x)
  • Function ceil (x)
  • Function floor (x)
  • Function trunc (x)
  • Function round (x)
  • Function FREXP* (x)
  • Function ldexp (x exp)
  • Function MODF* (x)
  • Function scalbn (x exp)
  • Function ilogb (x)
  • Variable FP_ILOGB0
    (nth-value 1 (decode-float 0.0d0))
  • Function logb (x)
  • Function copysign (abs sign)
  • Variable HUGE_VAL
    float-features:double-float-positive-infinity
  • Variable HUGE_VALF
    float-features:single-float-positive-infinity
  • Variable HUGE_VALL
    float-features:long-float-positive-infinity
  • Variable INFINITY
    float-features:single-float-positive-infinity
  • Function isnan (x)
  • Function isinf (x)
  • Function isfinite (x)
  • Function isnormal (x)
  • Variable FP_NAN
    :fp_nan
  • Variable FP_INFINITE
    :fp_infinite
  • Variable FP_ZERO
    :fp_zero
  • Variable FP_SUBNORMAL
    :fp_subnormal
  • Variable FP_NORMAL
    :fp_normal
  • Function fpclassify (x)
  • Function signbit (x)
  • Function lerp (a b v)
  • Macro va_start (ap last)
  • Macro va_end (ap)
  • Macro va_copy (dest src)
  • Variable NULL
    nil
    Holding `CL:NIL' for acting NULL of C language.
  • Function NULL (object)
    An alias for `CL:NULL'. This is for using 'NULL' as C constant and Lisp function both.
  • Variable offsetof
    'with-c-syntax.syntax:|__offsetof|
  • Function strcpy (dst src)
  • Function strncpy (dst src count)
  • Function strcat (dst src)
  • Function strncat (dst src count)
  • Function strlen (str)
  • Function strcmp (str1 str2)
  • Function strncmp (str1 str2 count)
  • Function strchr (str ch)
  • Function strrchr (str ch)
  • Function strspn (str accept)
  • Function strcspn (str reject)
  • Function strpbrk (str accept)
  • Function strstr (haystack needle)
  • Function strtok (str delim)
  • Function memchr (ptr ch count)
  • Function memcmp (lhs rhs count &key (test #'common-lisp:eql) (predicate #'common-lisp:<))
  • Function memset (dest ch count)
  • Function memcpy (dest src count)
  • Function memmove (dest src count)

Also exports

  • OSICAT-POSIX:EDOM
  • OSICAT-POSIX:EILSEQ
  • OSICAT-POSIX:ERANGE

WITH-C-SYNTAX.LIBC-IMPLEMENTATION

with-c-syntax libc implemetation package.
No exported symbols.