From 52903ee59787c0a35d0ff34bdd3b223dcc46bed8 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 13 Apr 2010 00:13:18 -0700 Subject: [PATCH] prettyprint ENUM: definitions --- basis/alien/enums/enums.factor | 4 ++++ basis/alien/prettyprint/prettyprint.factor | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/basis/alien/enums/enums.factor b/basis/alien/enums/enums.factor index 7cef34369d..bd508df075 100644 --- a/basis/alien/enums/enums.factor +++ b/basis/alien/enums/enums.factor @@ -8,8 +8,10 @@ TUPLE: enum-c-type base-type members ; CONSULT: c-type-protocol enum-c-type base-type>> ; + : enum-unboxer ( members -- quot ) [ first2 '[ _ ] 2array ] map-to-case '[ _ case ] ; @@ -36,3 +38,5 @@ PRIVATE> : define-enum ( word base-type members -- ) [ define-enum-members ] [ swap typedef ] bi ; +PREDICATE: enum-c-type-word < c-type-word + "c-type" word-prop enum-c-type? ; diff --git a/basis/alien/prettyprint/prettyprint.factor b/basis/alien/prettyprint/prettyprint.factor index c47dafbfce..8ba1328dcd 100644 --- a/basis/alien/prettyprint/prettyprint.factor +++ b/basis/alien/prettyprint/prettyprint.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel combinators alien alien.strings alien.c-types -alien.parser alien.syntax arrays assocs effects math.parser -prettyprint.backend prettyprint.custom prettyprint.sections -definitions see see.private sequences strings words ; +USING: accessors kernel combinators alien alien.enums +alien.strings alien.c-types alien.parser alien.syntax arrays +assocs effects math.parser prettyprint.backend prettyprint.custom +prettyprint.sections definitions see see.private sequences +strings words ; IN: alien.prettyprint M: alien pprint* @@ -110,3 +111,15 @@ M: alien-callback-type-word synopsis* ")" text block> ] } cleave ; + +M: enum-c-type-word definer + drop \ ENUM: \ ; ; +M: enum-c-type-word synopsis* + { + [ seeing-word ] + [ definer. ] + [ pprint-word ] + [ c-type base-type>> dup int eq? [ drop ] [ "<" text pprint-word ] if ] + } cleave ; +M: enum-c-type-word definition + c-type members>> ; -- 2.34.1