Skip to content

Commit

Permalink
wip typeof
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Jul 18, 2013
1 parent 9e4cc0f commit 2c9471d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion smop/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def wrapper(self,*args,**kwargs):
return f(self,*args,**kwargs)
except:
print "%s.%s()" % (self.__class__.__name__, f.__name__)
#import pdb; pdb.set_trace()
import pdb; pdb.set_trace()
raise
wrapper.__name__ = f.__name__
return wrapper
Expand Down Expand Up @@ -297,8 +297,10 @@ def __str__(self):
"add", # synthetic opcode
"all",
"any",
"cellfun",
"ceil",
"clazz",
"cumprod",
"cumsum",
"diff",
"dot", # Exists in numpy. Implements matlab .*
Expand Down
23 changes: 20 additions & 3 deletions smop/typeof.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
import node,options
from node import extend,exceptions

callstack = set()

@extend(node.function)
@exceptions
def apply(self,*args,**symtab):
print "%%%", self.head.ident.name
name = self.head.ident.name
if name in callstack:
return
#print "%%%", self.head.ident.name
callstack.add(name)

params = [(u.name,u.lineno) for u in self.head.args]
symtab.update(map(None,params,args))
self.body._typeof(symtab)
#return [symtab[u.name,u.lineno] for u in self.ret]
return [u._typeof(symtab) for u in self.head.ret]
return "".join([u._typeof(symtab) for u in self.head.ret])

@extend(node.node)
@exceptions
Expand Down Expand Up @@ -47,18 +54,23 @@ def _typeof(self,symtab):
symtab[self.ret.name,self.ret.lineno] = self.args._typeof(symtab)

@extend(node.param)
@extend(node.cellfun) # FIXME
@exceptions
def _typeof(self,symtab):
return ''

@extend(node.ident)
@exceptions
def _typeof(self,symtab):
"""
symtab maps pairs (name,lineno) to string
encoding of type.
"""
if self.defs is None:
try:
return symtab[self.name,self.lineno]
except:
print '+++ Missing type for',self.name
#print '+++ Missing type for',self.name
return ''
ts = set([u._typeof(symtab) for u in self.defs if u.defs is None])
if '' in ts:
Expand Down Expand Up @@ -91,6 +103,7 @@ def _typeof(self,symtab):
# return ''

@extend(node.arrayref)
@extend(node.cellarrayref)
@exceptions
def _typeof(self,symtab):
return self.func_expr._typeof(symtab)
Expand Down Expand Up @@ -154,6 +167,8 @@ def _typeof(self,symtab):
# sum is different from similar funcs.
# re-check this
@extend(node.sum)
@extend(node.cumsum)
@extend(node.cumprod)
@exceptions
def _typeof(self,symtab):
if self.args[0]._typeof(symtab) == 'l':
Expand All @@ -171,6 +186,7 @@ def _typeof(self,symtab):
@extend(node.inf)
@extend(node.dot)
@extend(node.nnz)
@extend(node.mod)
@exceptions
def _typeof(self,symtab):
return 'd'
Expand Down Expand Up @@ -206,6 +222,7 @@ def _typeof(self,symtab):
@extend(node.true)
@extend(node.isequal)
@extend(node.isnan)
@extend(node.isinf)
@extend(node.isempty)
@extend(node.all)
@extend(node.any)
Expand Down

0 comments on commit 2c9471d

Please sign in to comment.