gotopython

module
v0.0.0-...-97278e4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2017 License: MIT

README

A work-in-progress Go to Python transpiler. It can currently only compile toy programs.

Build Status

Example usage

This will compile the package at path ./mypackage into a Python module mypackage.py:

gotopython -o mypackage.py ./mypackage

Implementation status

The parts of the Go language spec that are implemented are:

Expression Example Implemented
BadExpr n/a
Ident myVar
Ellipsis ...
BasicLit 42
FuncLit func(t T) {}
CompositeLit T{x: 1, y: 2}
ParenExpr (x)
SelectorExpr x.y
IndexExpr x[y]
SliceExpr x[y:z]
TypeAssertExpr x.(T)
CallExpr x(y,z)
StarExpr *x
UnaryExpr -x
BinaryExpr x+y
KeyValueExpr x: y
ArrayType []T
StructType struct { T x }
FuncType func(T) U
InterfaceType interface {}
MapType map[T]U
ChanType chan<- T
Statement Example Implemented
BadStmt n/a
DeclStmt var x T const x = 1
EmptyStmt
LabeledStmt label: ...
ExprStmt x
SendStmt x <- y
IncDecStmt x++
AssignStmt x, y := z
GoStmt go f()
DeferStmt defer f()
ReturnStmt return x, y 1
BranchStmt break
BlockStmt {...}
IfStmt if x; y {...}
CaseClause case x>y:
SwitchStmt switch x; y {...} 2
TypeSwitchStmt switch x.(type) {...}
CommClause case x = <-y: ...
SelectStmt select { ... }
ForStmt for x; y; z {...}
RangeStmt for x, y := range z {...} 3
  1. No argumentless return in functions with named return values
  2. No fallthrough
  3. Only for array/slice
Spec Example Implemented
ImportSpec import "x"
ValueSpec var x T const x = 1
TypeSpec type T U
Built-in function Implemented
close
len
cap 1
new
make([]T)
make(map[T]U)
make(chan T)
append
copy
delete
complex
real
imag
panic
recover
print
println
  1. cap is translated to len
Language feature Implemented
fixed width integers
struct copying
pass by value
package unsafe
goroutines
Imports
Name collisions
Scoping rules
fallthrough
goto
cgo

References

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL