Paste: symbol not found

Author: jedahu
Mode: factor
Date: Thu, 25 Feb 2010 03:50:12
Plain Text |
! Copyright (C) 2009 Jeremy Hughes.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays assocs biassocs
combinators fry kernel lexer locals math parser sequences
words.constant words.symbol ;
IN: alien.enums

TUPLE: enum { assoc assoc read-only } ;

TUPLE: enum-c-type < c-type ;
: <enum-c-type> ( -- enum-c-type )
    enum-c-type new ; inline

:: define-enum-type ( word enum -- )
    <enum-c-type>
        integer >>class
        symbol >>boxed-class
        enum assoc>> to>> '[ _ at ] >>boxer-quot
        enum assoc>> from>> '[ _ at ] >>unboxer-quot
        4 >>align
        4 >>size
        "box_signed_4" >>boxer
        "to_fixnum" >>unboxer
    word [ define-symbol ] [ typedef ] bi ;

: enum-step ( vector -- more? )
    scan {
        { ";" [ drop f ] }
        { "{" [ [ scan scan-word 2array ] dip push "}" expect t ] }
    } case ;

: define-enum ( word assoc -- )
    [ [ create-in dup define-symbol ] dip ] assoc-map >biassoc
    enum boa [ define-constant ] [ define-enum-type ] 2bi ;

SYNTAX: ENUM:
    CREATE-WORD V{ } clone dup
    '[ _ enum-step ] [ ] while define-enum ;

Annotation: test library

Author: jedahu
Mode: c
Date: Thu, 25 Feb 2010 03:50:57
Plain Text |
typedef enum _suit {
    CLUBS,
    SPADES,
    DIAMONDS,
    HEARTS
} suit_t;

suit_t switch_suit (suit_t x) {
switch (x) {
    case CLUBS: return SPADES;
    case SPADES: return CLUBS;
    case DIAMONDS: return HEARTS;
    case HEARTS: return DIAMONDS;
}
}

Annotation: fail

Author: jedahu
Mode: factor
Date: Thu, 25 Feb 2010 03:52:20
Plain Text |
( scratchpad ) LIBRARY: suits.so FUNCTION: suit_t switch_suit ( suit_t x ) ;

( scratchpad ) CLUBS switch_suit
The image refers to a library or symbol that was not found at load time

Annotation: full example

Author: jedahu
Mode: factor
Date: Thu, 25 Feb 2010 04:14:11
Plain Text |
( scratchpad ) USE: alien.enums
Loading resource:extra/alien/enums/enums.factor
( scratchpad ) USE: alien.libraries
( scratchpad ) "suits" "/home/jdh/proj/factor/alien-inline-libs/libalien.enums.tests_enums.so" "cdecl" add-library
( scratchpad ) ENUM: suit_t { CLUBS 0 } { SPADES 1 } { DIAMONDS 2 } { HEARTS 3 } ;
( scratchpad ) USE: alien.syntax
( scratchpad ) LIBRARY: suits FUNCTION: suit_t switch_suits ( suit_t x ) ;
( scratchpad ) CLUBS switch_suits
The image refers to a library or symbol that was not found at load time

Type :help for debugging help.
( scratchpad )

New Annotation

Summary:
Author:
Mode:
Body: