Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
461 changes: 107 additions & 354 deletions README.md

Large diffs are not rendered by default.

34 changes: 32 additions & 2 deletions doc/go_syntax.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
PythonJS Go Syntax
Gython Syntax
===============

PythonJS supports a fully typed subset of Python with extra syntax to support the Golang backend.


General Features
================

go static types
go channel syntax
classes
multiple inheritance
list comprehensions
yield (generator functions) TODO
regular and lambda functions TODO nested functions
function calls with keywords and defaults

Language Keywords
=================

global, nonlocal
while, for, continue, break
if, elif, else
try, except, raise
def, lambda
new, class
from, import, as
pass, assert
and, or, is, in, not
return, yield



select
-------
Below `A` and `B` are typed as `chan int`. Data is read from a channel with `<-`.
Expand Down Expand Up @@ -161,4 +189,6 @@ list comprehensions

```
a = []int(x for x in range(3))
```
```


4 changes: 4 additions & 0 deletions gython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python
import sys, subprocess
cmd = ['./pythonjs/translator.py', '--go'] + sys.argv[1:]
subprocess.check_call( cmd )
31 changes: 23 additions & 8 deletions pythonjs/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ def retrieve_vars(body):
# local_vars.add( c.id )
if isinstance(n, ast.Assign):
user_typedef = None
#targets = list(n.targets)
#targets.reverse()
self_typedef = None
if len(n.targets) == 2:
if isinstance(n.targets[1], ast.Attribute) and isinstance(n.targets[1].value, ast.Name) and n.targets[1].value.id=='self':
continue

for i,u in enumerate(n.targets):
if isinstance(u, ast.Name):
if i==0:
Expand All @@ -43,6 +46,7 @@ def retrieve_vars(body):
else:
local_vars.add( u.id )
elif user_typedef:
#raise SyntaxError(user_typedef + u.id)
local_vars.add( '%s=%s' %(user_typedef, u.id) )
user_typedef = None
else:
Expand All @@ -65,12 +69,19 @@ def retrieve_vars(body):

if user_typedef: ## `int x`
if isinstance(n.value, ast.Name):
local_vars.add( '%s=%s' %(user_typedef, n.value.id))
x = '%s=%s' %(user_typedef, n.value.id)
#raise SyntaxError(x)
#if len(n.targets)==2: raise SyntaxError(n.targets)
local_vars.add( x )
elif isinstance(n.value, ast.Num):
local_vars.add( '%s=%s' %(user_typedef, n.value.n))
x = '%s=%s' %(user_typedef, n.value.n)
#if len(n.targets)==2: raise SyntaxError(n.targets)
local_vars.add( x )
else:
raise SyntaxError(n.value)

#raise SyntaxError(n.targets)
#raise SyntaxError(n.value.func.value.id)
#raise SyntaxError(user_typedef)
pass

elif isinstance(n, ast.Global):
global_vars.update( n.names )
Expand Down Expand Up @@ -112,8 +123,12 @@ def inspect_function( node ):
c = decorator
assert len(c.args) == 0 and len(c.keywords)
for kw in c.keywords:
assert isinstance( kw.value, ast.Name)
typedefs[ kw.arg ] = kw.value.id
if isinstance( kw.value, ast.Name):
typedefs[ kw.arg ] = kw.value.id
elif isinstance( kw.value, ast.Str):
typedefs[ kw.arg ] = '"%s"' %kw.value.s
else:
raise SyntaxError(kw.value)

info = {
'locals':local_vars,
Expand Down
7 changes: 7 additions & 0 deletions pythonjs/ministdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@
'os.path' : {
'dirname' : "function dirname(s) { return s.slice(0, s.lastIndexOf('/')+1)}; var os = {'path':{'dirname':dirname}}"
}
}

GO = {
'time': {
REQUIRES : ['time'],
'clock': 'func clock() float64 { return float64(time.Now().Unix()); }'
},
}
Loading