FAUST compiler  0.9.9.6b8
prim2.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 extern int gFloatSize;
23 
24 
25 #include "prim2.hh"
26 #include "stdlib.h"
27 
28 Sym FFUN = symbol ("ForeignFunction");
29 
30 Tree ffunction (Tree signature, Tree incfile, Tree libfile)
31 {
32  return tree(FFUN, signature, incfile, libfile);
33 }
34 
36 {
37  return t->node() == Node(FFUN);
38 }
39 
41 {
42  return ff->branch(0);
43 }
44 
45 const char* ffincfile(Tree ff)
46 {
47  return tree2str(ff->branch(1));
48 }
49 
50 const char* fflibfile(Tree ff)
51 {
52  return tree2str(ff->branch(2));
53 }
54 
56 {
57  return tree2int(hd(ffsignature(t)));
58 }
59 
60 const char* ffname(Tree t)
61 {
62  Tree namelist = nth(ffsignature(t),1);
63  //cerr << "ffname " << tree2str(nth(namelist,gFloatSize-1)) << endl;
64  return tree2str(nth(namelist,gFloatSize-1));
65 }
66 
67 int ffarity(Tree t)
68 {
69  return len(ffsignature(t))-2;
70 }
71 
72 int ffargtype(Tree t, int i)
73 {
74  return tree2int(nth(ffsignature(t), i+2));
75 }
Sym FFUN
Definition: prim2.cpp:28
Tree ffunction(Tree signature, Tree incfile, Tree libfile)
Definition: prim2.cpp:30
Class Node = (type x (int + double + Sym + void*))
Definition: node.hh:75
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
bool isffunction(Tree t)
Definition: prim2.cpp:35
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * ffname(Tree t)
Definition: prim2.cpp:60
int ffarity(Tree t)
Definition: prim2.cpp:67
Tree hd(Tree l)
Definition: list.hh:133
const Node & node() const
return the content of the tree
Definition: tree.hh:143
Tree ffsignature(Tree ff)
Definition: prim2.cpp:40
const char * ffincfile(Tree ff)
Definition: prim2.cpp:45
int ffrestype(Tree t)
Definition: prim2.cpp:55
Tree tree(const Node &n)
Definition: tree.hh:186
const char * fflibfile(Tree ff)
Definition: prim2.cpp:50
Symbols are unique objects with a name stored in a hash table.
Definition: symbol.hh:53
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
Definition: symbol.hh:95
int ffargtype(Tree t, int i)
Definition: prim2.cpp:72
int gFloatSize
Definition: main.cpp:153
int len(Tree l)
Definition: list.cpp:198
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
Tree nth(Tree l, int i)
Definition: list.cpp:182