Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2ae0b40
forked PythonJS and started Gython.
hartsantler Sep 12, 2014
0424a9e
improved static type syntax: `[]int self.x = XXX`.
hartsantler Sep 14, 2014
a32946f
updated docs
hartsantler Sep 14, 2014
717a8a9
fixed `type self.x = XXX` in ast_utils.py.
hartsantler Sep 14, 2014
1bb0c67
go backend: array.append hack, new type syntax for attributes of self…
hartsantler Sep 17, 2014
80e1805
allow `[]int` to be used in function argument annotations `def f(x:[]…
hartsantler Sep 19, 2014
3f66f02
always take a pointer to array when creating a new one, always take p…
hartsantler Sep 20, 2014
105d7d4
always create map and take a pointer to it. always pass map pointers …
hartsantler Sep 21, 2014
cbc5828
adding 'simple' generator functions for Go.
hartsantler Sep 21, 2014
c77beb2
simple generator functions `yield`
hartsantler Sep 21, 2014
43b6c44
generics for Go, subclasses with a common base class can be passed to…
hartsantler Sep 23, 2014
174123e
fixed Generics
hartsantler Sep 23, 2014
6b08934
new option `--no-runtime` for translator.py will not insert pythonjs …
hartsantler Sep 23, 2014
4949857
starting on support for Go map comprehensions.
hartsantler Sep 23, 2014
d55301c
dict comprehensions.
hartsantler Sep 24, 2014
5121485
Go map comprehensions.
hartsantler Sep 24, 2014
aff2a6d
translator.py new option --fast-javascript that changes all settings …
hartsantler Sep 24, 2014
69f3a58
split runtime into two files, pythonjs-minimal.js contains just what …
hartsantler Sep 24, 2014
4aec0f4
translator.py new option --modules will output split the output into …
hartsantler Sep 25, 2014
29fa050
translator.py new option --fast-loops removes loop hacks that make fo…
hartsantler Sep 25, 2014
b6fc560
cleaner javascript output, and new option --pure-javascript that will…
hartsantler Sep 25, 2014
a60275e
fixed bug in typedpython.py, bad inference of a go fixed array, repor…
hartsantler Sep 28, 2014
9f9cbae
fixed array comprehensions, tests array of class instances.
hartsantler Sep 28, 2014
4331da4
support Go map of functions `map[string]func(int)(int){}`
hartsantler Sep 28, 2014
6d22df9
nested functions.
hartsantler Sep 29, 2014
a9fcae1
fixed list comprehension in javascript mode.
hartsantler Sep 29, 2014
d949a30
fixed `new new` bug caused when calling `new MyClass` where MyClass i…
hartsantler Oct 1, 2014
932aa18
callback as attribute in class.
hartsantler Oct 2, 2014
73aeb12
support make array of pointers to objects `a=[n]A`.
hartsantler Oct 4, 2014
7d7b0e3
allow a Generic to be passed to the __init__ function of a class. A …
hartsantler Oct 5, 2014
6090d32
improved generics.
hartsantler Oct 5, 2014
ee91868
Generics: support returning different subclass types.
hartsantler Oct 5, 2014
9af2162
improved Generics.
hartsantler Oct 6, 2014
650b638
fixed duplicate field in sub-structs.
hartsantler Oct 6, 2014
6d9f84c
Generics: return variable subclass using `go.type_assert(X, self)` to…
hartsantler Oct 7, 2014
beb4758
Generics: fixed return different subclass from a method defined on th…
hartsantler Oct 7, 2014
14d19b8
Generics: fixed return different subclass type from method defined in…
hartsantler Oct 8, 2014
3e7347e
fixed for loop over map
hartsantler Oct 9, 2014
b385d72
fixed for loop over array
hartsantler Oct 9, 2014
45c121d
fixed int slices. TODO how to get addr without slice_hack
hartsantler Oct 9, 2014
9523101
removed __slice_hack__
hartsantler Oct 9, 2014
d95fe44
fixed calling variable argument functions with `f(*arr)`
hartsantler Oct 9, 2014
22da368
fixed maps.
hartsantler Oct 9, 2014
9c7b57f
Generics: subclasses become union of all their attributes, so that a …
hartsantler Oct 9, 2014
4a52a7b
workaround for forcing a subclass to its true type using super class …
hartsantler Oct 9, 2014
8c6ee4c
Generics, allow return multiple subclasses from method call that retu…
hartsantler Oct 11, 2014
86c2b31
Generics: fixes and notes.
hartsantler Oct 11, 2014
0df3e06
Generics: fixed scope stack for methods that return multiple subclass…
hartsantler Oct 12, 2014
d5efc72
Generics: multiple subclass return needs to take pointer of subclass.
hartsantler Oct 12, 2014
f37d267
new test array of objects.
hartsantler Oct 13, 2014
77d1c8d
fixed creating new class instances at global scope.
hartsantler Oct 13, 2014
20a6bc3
notes for `go.type_assert( A, self)` where A could be an empty interf…
hartsantler Oct 22, 2014
c4dc262
fixed type assert an interface{} or struct pointer to some struct poi…
hartsantler Oct 22, 2014
14a7b1d
Generics: unpack an item from an array of subclasses, and generate sw…
hartsantler Nov 6, 2014
5c8395d
Generics: only warn about failed return at runtime when the function …
hartsantler Nov 6, 2014
83f048b
Generics: fixed when the generic has been forced to be of some subcla…
hartsantler Nov 6, 2014
464bb8c
Generics: fixed when returning self.
hartsantler Nov 6, 2014
52f4926
making sure bug 148 is fixed, `[0][0]`
hartsantler Nov 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
callback as attribute in class.
  • Loading branch information
hartsantler committed Oct 2, 2014
commit 932aa1895c651ed6d27e5bb095ce34bb35d3265d
5 changes: 4 additions & 1 deletion pythonjs/python_to_pythonjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,14 +1976,17 @@ def visit_Assign(self, node):
raise SyntaxError( self.format_error(targets) )
raise SyntaxError( self.format_error(xxx) )

elif self._with_go and isinstance(target, ast.Subscript) and isinstance(target.value, ast.Name) and target.value.id in ('__go__array__', '__go__class__', '__go__pointer__'):
elif self._with_go and isinstance(target, ast.Subscript) and isinstance(target.value, ast.Name) and target.value.id in ('__go__array__', '__go__class__', '__go__pointer__', '__go__func__'):
if len(targets)==2 and isinstance(targets[1], ast.Attribute) and isinstance(targets[1].value, ast.Name) and targets[1].value.id == 'self' and len(self._class_stack):
if target.value.id == '__go__array__':
self._class_stack[-1]._struct_vars[ targets[1].attr ] = '__go__array__(%s<<typedef)' %self.visit(target.slice)
elif target.value.id == '__go__class__':
self._class_stack[-1]._struct_vars[ targets[1].attr ] = self.visit(target.slice)
elif target.value.id == '__go__pointer__':
self._class_stack[-1]._struct_vars[ targets[1].attr ] = '"*%s"' %self.visit(target.slice)
elif target.value.id == '__go__func__':
self._class_stack[-1]._struct_vars[ targets[1].attr ] = self.visit(target.slice)


elif target.value.id == '__go__class__':
#self._class_stack[-1]._struct_vars[ targets[1].attr ] = self.visit(target.slice)
Expand Down
6 changes: 4 additions & 2 deletions pythonjs/pythonjs_to_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,10 @@ def visit_BinOp(self, node):
elif op == '<<':
if left in ('__go__receive__', '__go__send__'):
return '<- %s' %right
elif isinstance(node.left, ast.Call) and isinstance(node.left.func, ast.Name) and node.left.func.id in ('__go__array__', '__go__arrayfixed__', '__go__map__'):
if node.left.func.id == '__go__map__':
elif isinstance(node.left, ast.Call) and isinstance(node.left.func, ast.Name) and node.left.func.id in ('__go__array__', '__go__arrayfixed__', '__go__map__', '__go__func__'):
if node.left.func.id == '__go__func__':
raise SyntaxError('TODO - go.func')
elif node.left.func.id == '__go__map__':
key_type = self.visit(node.left.args[0])
value_type = self.visit(node.left.args[1])
if value_type == 'interface': value_type = 'interface{}'
Expand Down
15 changes: 12 additions & 3 deletions pythonjs/typedpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
'go.channel' : '__go_make_chan__',
'go.array' : '__go__array__',
'go.make' : '__go_make__',
'go.addr' : '__go__addr__'
'go.addr' : '__go__addr__',
'go.func' : '__go__func__',
}

OPERATORS = {
Expand Down Expand Up @@ -144,7 +145,8 @@ def transform_source( source, strip=False ):
b = b.strip()
is_class_type = b.startswith('class:') and len(b.split(':'))==2
is_pointer = b.startswith('*')
if (b in types or is_class_type or is_pointer) and nextchar != '=':
is_func = b.startswith('func(')
if (b in types or is_class_type or is_pointer or is_func) and nextchar != '=':
if strip:
a = a[ : -len(b) ]
elif is_class_type:
Expand All @@ -156,13 +158,18 @@ def transform_source( source, strip=False ):
cls = b.split('*')[-1]
a = a[ : -len('*')-len(cls)]
a.append('__go__pointer__[%s]=\t\t\t\t' %cls)

elif is_func:
u = ''.join(a)
u = u.replace('func(', '__go__func__["func(')
u += '"]=\t\t\t\t'
a = [w for w in u]
else:
if a[-1]=='*':
a.pop()
a.append('POINTER')
a.append('=\t\t\t\t')
#a.append( char )

else:
a.append( char )
else:
Expand Down Expand Up @@ -370,6 +377,8 @@ def transform_source( source, strip=False ):
typedef = '"*%s"' %typedef.strip()
elif typedef.startswith('map['):
typedef = '"*%s"' %typedef.strip()
elif typedef.startswith('func('):
typedef = '"%s"' %typedef.strip()

if chan:
output.append('%s@typedef_chan(%s=%s)' %(indent, arg_name, typedef))
Expand Down
29 changes: 29 additions & 0 deletions regtests/go/callback_in_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'''
callback in class
'''
class A:
def __init__(self, cb:func(int)(int), x:int, y:int, z:int=1):
int self.x = x
int self.y = y
int self.z = z
func(int)(int) self.callback = cb

def call(self, a:int ) -> int:
return self.callback( a + self.x + self.y + self.z )

def mycb( x:int ) ->int:
return x + 1000

def main():
a = A(
mycb,
100,
200,
z=300
)
#print( a.x )
#print( a.y )
#print( a.z )

TestError( a.call(-600)==1000 )