File: mkcase.py

package info (click to toggle)
nqp 2014.07-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,596 kB
  • ctags: 7,993
  • sloc: ansic: 22,689; java: 20,240; cpp: 4,956; asm: 3,976; perl: 950; python: 267; sh: 245; makefile: 14
file content (64 lines) | stat: -rw-r--r-- 1,928 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python
#//////////////////////////////////////////////////////////////////////////////
#
# Copyright (c) 2007,2009 Daniel Adler <dadler@uni-goettingen.de>, 
#                         Tassilo Philipp <tphilipp@potion-studios.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#//////////////////////////////////////////////////////////////////////////////

import sys

# parameters

nargs  = 3

types  = ["DCbool","DCint","DClonglong","DCdouble","DCpointer","DCfloat"]

# generator

ntypes = len(types)

sys.stderr.write("/* auto generated by mkcase (on stderr) */\n");
sys.stderr.write("".join(["#define NARGS  ",str(nargs),"\n"]))
sys.stderr.write("".join(["#define NTYPES ",str(ntypes),"\n"]))

def powerfact(x, n):
  if n==0:
    return 0
  else:
    return x**n+powerfact(x,n-1)

x     = 0
end   = powerfact(ntypes,nargs)+1

sys.stdout.write("/* auto generated by mkcase.py (on stdout) */\n");

while x < end:
  args = [str(x)]
  sig  = ["f_"]
  pos  = 0
  y    = x
  while y > 0:
    s     = (y-1) % ntypes
    y     = (y-1) / ntypes
    args += [ types[s] ]
    sig  += [ types[s][2] ]
    pos  += 1
  sig   = "".join(sig)
  args += [ sig ]
  args  = ",".join(args)
  sys.stdout.write( "".join(["VF",str(pos),"(",args,")\n"]) )
  x += 1