File tree 2 files changed +67
-0
lines changed
2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1
1
* ~
2
+ gpython
3
+ hello.py
4
+ hello.pyc
5
+ __pycache__
Original file line number Diff line number Diff line change
1
+ // Gpython binary
2
+
3
+ package main
4
+
5
+ import (
6
+ "flag"
7
+ "fmt"
8
+ "os"
9
+ //"github.com/ncw/gpython/vm"
10
+ "github.com/ncw/gpython/marshal"
11
+ "log"
12
+ "strings"
13
+ )
14
+
15
+ // Globals
16
+ var (
17
+ // Flags
18
+ debug = flag .Bool ("d" , false , "Print lots of debugging" )
19
+ )
20
+
21
+ // syntaxError prints the syntax
22
+ func syntaxError () {
23
+ fmt .Fprintf (os .Stderr , `GPython
24
+
25
+ A python implementation in Go
26
+
27
+ Full options:
28
+ ` )
29
+ flag .PrintDefaults ()
30
+ }
31
+
32
+ // Exit with the message
33
+ func fatal (message string , args ... interface {}) {
34
+ if ! strings .HasSuffix (message , "\n " ) {
35
+ message += "\n "
36
+ }
37
+ syntaxError ()
38
+ fmt .Fprintf (os .Stderr , message , args ... )
39
+ os .Exit (1 )
40
+ }
41
+
42
+ func main () {
43
+ flag .Usage = syntaxError
44
+ flag .Parse ()
45
+ args := flag .Args ()
46
+ if len (args ) != 1 {
47
+ fatal ("Need program to run" )
48
+ }
49
+ prog := args [0 ]
50
+ fmt .Printf ("Running %q\n " , prog )
51
+
52
+ f , err := os .Open (prog )
53
+ if err != nil {
54
+ log .Fatal (err )
55
+ }
56
+ defer f .Close ()
57
+ obj , err := marshal .ReadPyc (f )
58
+ if err != nil {
59
+ log .Fatal (err )
60
+ }
61
+ fmt .Println (obj )
62
+
63
+ }
You can’t perform that action at this time.
0 commit comments