aboutsummaryrefslogtreecommitdiff
path: root/guiletopy.h
blob: 00c3369c770c3c1676b2cfdd6d64ec2490d8c814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// guiletopy header file
// Functions for conversion from Guile SCMs into PyObjects.

#ifndef GUILETOPY_H
#define GUILETOPY_H

////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008 Omer Zak.
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library, in a file named COPYING; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA  02111-1307  USA
//
// For licensing issues, contact <w1@zak.co.il>.
//
////////////////////////////////////////////////////////////////////////

#include <Python.h>   // Must be first header file
#include <libguile.h>

////////////////////////////////////////////////////////////////////////
// The format of stemplate for SCM->PyObject conversions
////////////////////////////////////////////////////////////////////////
//
// The following cases are to be considered:
// -----------------------------------------
// All g2p* functions have a template argument.
// However, those which are genuine leaf conversion functions
// ignore it.
//
// 1. "Leaf" data item (such as a number or a string):
//    We want to try few g2p* functions until one succeeds.
//    The template in this case consists of 'g2p_leaf followed by
//    a list of one or more g2p* symbols.
//    It is possible for the template corresponding to a "leaf"
//    data item to consist of a single g2p* function.  In this case,
//    the function is directly applied to the data item.
// 2. Data item which is pair:
//    The template consists of list of g2p_pair2Tuple or g2p_pair2List,
//    and pair of two templates for processing the CAR and CDR of the
//    data item.  Example:
//    (list g2p_pair2Tuple
//        ((list g2p_leaf g2p_real2Float) . (list g2p_leaf g2p_num2Int)))
// 3. Data item which is a list:
//    The template data structure is a list of g2p_list2List or
//    g2p_list2Tuple followed by a list of one or more templates, which
//    are used to convert the list members.
//    It is possible for the data list to have more items than the
//    corresponding template list.  In this case, the template list
//    items are cyclically processed.
//    This way it is possible to use a single template to convert all
//    list items, if they are to be converted in the same way.
// 4. Data item which is an alist:
//    The data structure is TBD.
//    (need to consider handling of keys)
//
////////////////////////////////////////////////////////////////////////
// SCM -> PyObject
////////////////////////////////////////////////////////////////////////

// Basic conversion of a SCM object according to template.
extern PyObject *g2p_apply(SCM sobj,SCM stemplate);

// Convert a SCM object into a Python object.
// If cannot convert, abort.
extern PyObject *guile2python(SCM sobj,SCM stemplate);

// Treat the SCM object as an association list and convert it into
// Python hash, whose keys are strings corresponding to the
// association list's keys (which must be either strings or symbols).
//
// Checks:
// 1. Validity of keys.
// 2. No duplicate keys.
PyObject *guileassoc2pythondict(SCM sobj,SCM stemplate);

// Convert from Guile list into Python tuple.
// Need separate function because the default behavior is to convert
// it into Python list.
extern PyObject *g2p_list2Tuple(SCM sobj,SCM stemplate);

////////////////////////////////////////////////////////////////////////
// Extra initialization after registration of all g2p_* and p2g_*
// functions.

extern void init_default_guiletopy_templates(void);

////////////////////////////////////////////////////////////////////////

#endif /* GUILETOPY_H */

////////////////////////////////////////////////////////////////////////
// End of guiletopy.h