spielwiese
Last change
on this file since 9218e1d was
9218e1d,
checked in by Michael Brickenstein <bricken@…>, 19 years ago
|
*bricken: better seperated
git-svn-id: file:///usr/local/Singular/svn/trunk@8659 2c84dea3-7e68-4137-9b89-c4e89433aadc
|
-
Property mode set to
100644
|
File size:
2.8 KB
|
Line | |
---|
1 | from Singular import * |
---|
2 | from _Singular import * |
---|
3 | try: |
---|
4 | import psyco |
---|
5 | def optimize(f): |
---|
6 | psyco.bind(f) |
---|
7 | except: |
---|
8 | def optimize(f): |
---|
9 | pass |
---|
10 | def debug_out(s): |
---|
11 | pass |
---|
12 | #print s |
---|
13 | #def build_arg_list(*args) |
---|
14 | def list2arg_list(args): |
---|
15 | l=i_arg_list() |
---|
16 | for a in args: |
---|
17 | if isinstance(a,list): |
---|
18 | l.append(list2arg_list(a)) |
---|
19 | # at=i_arg_list() |
---|
20 | # for a2 in a: |
---|
21 | # at.append(a2) |
---|
22 | # l.append(at) |
---|
23 | else: |
---|
24 | l.append(a) |
---|
25 | return l |
---|
26 | class singular_globals_proxy(object): |
---|
27 | def __getattr__(self,name): |
---|
28 | proc=get_idhdl(name) |
---|
29 | if proc.is_zero(): |
---|
30 | if is_builtin(name): |
---|
31 | def fun_wrapper(*args): |
---|
32 | return mycbm(name,*args) |
---|
33 | try: |
---|
34 | fun_wrapper.__name__=name |
---|
35 | except: |
---|
36 | pass |
---|
37 | return fun_wrapper |
---|
38 | else: |
---|
39 | raise AttributeError("Global variable " + name + " not present in the Singular interpreter") |
---|
40 | if proc.is_proc(): |
---|
41 | def fun_wrapper(*args): |
---|
42 | |
---|
43 | |
---|
44 | proc=get_idhdl(name) |
---|
45 | if not proc.is_proc(): |
---|
46 | proc.print_type() |
---|
47 | raise Exception |
---|
48 | prepare_ring(args) |
---|
49 | l=list2arg_list(args) |
---|
50 | erg= call_interpreter_method(proc, l) |
---|
51 | finish_ring() |
---|
52 | return erg |
---|
53 | try: |
---|
54 | fun_wrapper.__name__=name |
---|
55 | except: |
---|
56 | pass |
---|
57 | return fun_wrapper |
---|
58 | else: |
---|
59 | res=transfer_to_python(proc) |
---|
60 | if res is None: |
---|
61 | raise AttributeError("Global variable "+name+" has unknown type") |
---|
62 | return res |
---|
63 | def __setattr__(self,name,value): |
---|
64 | id=get_idhdl(name) |
---|
65 | if id.is_zero(): |
---|
66 | raise Expception |
---|
67 | else: |
---|
68 | if isinstance(value,list): |
---|
69 | value=list2arg_list(value) |
---|
70 | id.write(value) |
---|
71 | #for compatibility the old name |
---|
72 | global_functions=singular_globals_proxy |
---|
73 | |
---|
74 | def mycbm(name,*args): |
---|
75 | l=list2arg_list(args) |
---|
76 | prepare_ring(args) |
---|
77 | res= cbm(name,l) |
---|
78 | finish_ring() |
---|
79 | return res |
---|
80 | |
---|
81 | def find_rings(arglist): |
---|
82 | """FIXME: doesn't handle everything and depth""" |
---|
83 | for item in arglist: |
---|
84 | if isinstance(item,polynomial) or isinstance(item,ideal): |
---|
85 | return [item.ring()] |
---|
86 | return [] |
---|
87 | |
---|
88 | |
---|
89 | oldrings=[] |
---|
90 | def prepare_ring(arglist): |
---|
91 | rl=find_rings(arglist) |
---|
92 | debug_out("rl is" +str(rl)) |
---|
93 | if len(rl)==1: |
---|
94 | r=rl[0] |
---|
95 | oldrings.append(ring()) |
---|
96 | r.set() |
---|
97 | else: |
---|
98 | if len(rl)==0: |
---|
99 | oldrings.append(None) |
---|
100 | else: |
---|
101 | debug_out("Warning to many rings in call") |
---|
102 | oldrings.append(None) |
---|
103 | |
---|
104 | def finish_ring(): |
---|
105 | r=oldrings.pop() |
---|
106 | if r: |
---|
107 | r.set() |
---|
108 | #optimize(prepare_ring) |
---|
109 | #optimize(mycbm) |
---|
110 | #optimize(finish_ring) |
---|
Note: See
TracBrowser
for help on using the repository browser.