ct_DEF.pyx 1.59 KB
Newer Older
1
__doc__ = u"""
Stefan Behnel's avatar
Stefan Behnel committed
2 3
    >>> c()
    120
4 5
    >>> i0() == -1
    True
6 7 8 9 10 11
    >>> i1() == 42
    True
    >>> i2() == 0x42
    True
    >>> i3() == 042
    True
12 13
    >>> i4() == -0x42
    True
Stefan Behnel's avatar
Stefan Behnel committed
14 15 16 17 18
    >>> l()
    666
    >>> f()
    12.5
    >>> s()
Stefan Behnel's avatar
Stefan Behnel committed
19
    u'spam'
Stefan Behnel's avatar
Stefan Behnel committed
20 21 22 23 24 25 26 27 28 29
    >>> two()
    2
    >>> five()
    5
    >>> true()
    True
    >>> false()
    False
"""

Stefan Behnel's avatar
Stefan Behnel committed
30 31 32 33 34 35 36 37 38
import sys
if sys.version_info[0] >= 3:
    __doc__ = __doc__.replace(u" u'", u" '")

import sys
if sys.version_info[0] >= 3:
    __doc__ = __doc__.replace(u" 042", u" 0o42")

DEF TUPLE = (1, 2, u"buckle my shoe")
Stefan Behnel's avatar
Stefan Behnel committed
39 40 41
DEF TRUE_FALSE = (True, False)

DEF CHAR = c'x'
42
DEF INT0 = -1
43 44 45
DEF INT1 = 42
DEF INT2 = 0x42
DEF INT3 = 042
46
DEF INT4 = -0x42
Stefan Behnel's avatar
Stefan Behnel committed
47 48
DEF LONG = 666L
DEF FLOAT = 12.5
Stefan Behnel's avatar
Stefan Behnel committed
49
DEF STR = u"spam"
Stefan Behnel's avatar
Stefan Behnel committed
50 51 52 53 54 55 56 57 58 59
DEF TWO = TUPLE[1]
DEF FIVE = TWO + 3
DEF TRUE  = TRUE_FALSE[0]
DEF FALSE = TRUE_FALSE[1]

def c():
    cdef char c
    c = CHAR
    return c

60 61 62 63 64
def i0():
    cdef int i
    i = INT0
    return i

65 66 67 68 69 70 71 72 73 74 75
def i1():
    cdef int i
    i = INT1
    return i

def i2():
    cdef int i
    i = INT2
    return i

def i3():
Stefan Behnel's avatar
Stefan Behnel committed
76
    cdef int i
77
    i = INT3
Stefan Behnel's avatar
Stefan Behnel committed
78 79
    return i

80 81 82 83 84
def i4():
    cdef int i
    i = INT4
    return i

Stefan Behnel's avatar
Stefan Behnel committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
def l():
    cdef long l
    l = LONG
    return l

def f():
    cdef float f
    f = FLOAT
    return f

def s():
    cdef char *s
    s = STR
    return s

# this does not work!
#def t():
#    cdef object t
#    t = TUPLE
#    return t

def two():
    cdef int two
    two = TWO
    return two

def five():
    cdef int five
    five = FIVE
    return five

def true():
    cdef bint true
    true = TRUE
    return true

def false():
    cdef bint false
    false = FALSE
    return false