]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/internal/asm/lexbody.go
[dev.cc] cmd/new5a etc, cmd/internal/asm: edit to produce working Go code
[gostls13.git] / src / cmd / internal / asm / lexbody.go
index d835e7b1172fcfd3dafa749f07495bd1225c363f..df0407c7a97fb1845ffaa80bb68ced2bd4a51308 100644 (file)
@@ -1,12 +1,12 @@
 // Inferno utils/cc/lexbody
-// http://code.google.com/p/inferno-os/source/browse/utils/cc/lexbody
+// http://code.Google.Com/p/inferno-os/source/browse/utils/cc/lexbody
 //
 //     Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
-//     Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+//     Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.Net)
 //     Portions Copyright © 1997-1999 Vita Nuova Limited
-//     Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+//     Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.Vitanuova.Com)
 //     Portions Copyright © 2004,2006 Bruce Ellis
-//     Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+//     Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.Net)
 //     Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
 //     Portions Copyright © 2009 The Go Authors.  All rights reserved.
 //
 
 package asm
 
+import (
+       "bytes"
+       "fmt"
+       "os"
+       "strconv"
+       "strings"
+       "unicode/utf8"
+
+       "cmd/internal/obj"
+)
+
 /*
  * common code for all the assemblers
  */
@@ -82,143 +93,90 @@ func pragincomplete() {
        }
 }
 
-func Alloc(n int32) interface{} {
-       var p interface{}
-
-       p = make([]byte, n)
-       if p == nil {
-               fmt.Printf("alloc out of mem\n")
-               main.Exits("alloc: out of mem")
-       }
-
-       main.Memset(p, 0, n)
-       return p
-}
-
-func Allocn(p interface{}, n int32, d int32) interface{} {
-       if p == nil {
-               return Alloc(n + d)
-       }
-       p = main.Realloc(p, int(n+d))
-       if p == nil {
-               fmt.Printf("allocn out of mem\n")
-               main.Exits("allocn: out of mem")
-       }
-
-       if d > 0 {
-               main.Memset(p.(string)[n:], 0, d)
-       }
-       return p
-}
-
-func Ensuresymb(n int32) {
-       if new5a.Symb == nil {
-               new5a.Symb = Alloc(new5a.NSYMB + 1).(string)
-               new5a.Nsymb = new5a.NSYMB
-       }
-
-       if n > new5a.Nsymb {
-               new5a.Symb = Allocn(new5a.Symb, new5a.Nsymb, n+1-new5a.Nsymb).(string)
-               new5a.Nsymb = n
-       }
-}
-
-func Setinclude(p string) {
+func setinclude(p string) {
        var i int
 
        if p == "" {
                return
        }
-       for i = 1; i < new5a.Ninclude; i++ {
-               if p == new5a.Include[i] {
+       for i = 1; i < len(include); i++ {
+               if p == include[i] {
                        return
                }
        }
 
-       if new5a.Ninclude%8 == 0 {
-               new5a.Include = Allocn(new5a.Include, new5a.Ninclude*sizeof(string), 8*sizeof(string)).(*string)
-       }
-       new5a.Include[new5a.Ninclude] = p
-       new5a.Ninclude++
+       include = append(include, p)
 }
 
-func Errorexit() {
-       obj.Bflush(&new5a.Bstdout)
-       if new5a.Outfile != "" {
-               main.Remove(new5a.Outfile)
+func errorexit() {
+       obj.Bflush(&bstdout)
+       if outfile != "" {
+               os.Remove(outfile)
        }
-       main.Exits("error")
+       os.Exit(2)
 }
 
 func pushio() {
-       var i *new5a.Io
+       var i *Io
 
-       i = new5a.Iostack
+       i = iostack
        if i == nil {
                Yyerror("botch in pushio")
-               Errorexit()
+               errorexit()
        }
 
-       i.P = new5a.Fi.p
-       i.C = int16(new5a.Fi.c)
+       i.P = fi.P
 }
 
 func newio() {
-       var i *new5a.Io
+       var i *Io
        var pushdepth int = 0
 
-       i = new5a.Iofree
+       i = iofree
        if i == nil {
                pushdepth++
                if pushdepth > 1000 {
                        Yyerror("macro/io expansion too deep")
-                       Errorexit()
+                       errorexit()
                }
-
-               i = Alloc(sizeof(*i)).(*new5a.Io)
+               i = new(Io)
        } else {
-
-               new5a.Iofree = i.Link
+               iofree = i.Link
        }
-       i.C = 0
-       i.F = -1
-       new5a.Ionext = i
+       i.F = nil
+       i.P = nil
+       ionext = i
 }
 
-func newfile(s string, f int) {
-       var i *new5a.Io
+func newfile(s string, f *os.File) {
+       var i *Io
 
-       i = new5a.Ionext
-       i.Link = new5a.Iostack
-       new5a.Iostack = i
-       i.F = int16(f)
-       if f < 0 {
-               i.F = int16(main.Open(s, 0))
-       }
-       if i.F < 0 {
-               Yyerror("%ca: %r: %s", new5a.Thechar, s)
-               Errorexit()
+       i = ionext
+       i.Link = iostack
+       iostack = i
+       i.F = f
+       if f == nil {
+               var err error
+               i.F, err = os.Open(s)
+               if err != nil {
+                       Yyerror("%ca: %v", Thechar, err)
+                       errorexit()
+               }
        }
 
-       new5a.Fi.c = 0
-       obj.Linklinehist(new5a.Ctxt, int(new5a.Lineno), s, 0)
-}
-
-func Slookup(s string) *new5a.Sym {
-       Ensuresymb(int32(len(s)))
-       new5a.Symb = s
-       return lookup()
+       fi.P = nil
+       obj.Linklinehist(Ctxt, int(Lineno), s, 0)
 }
 
 var thetext *obj.LSym
 
-func settext(s *obj.LSym) {
+func Settext(s *obj.LSym) {
        thetext = s
 }
 
-func labellookup(s *new5a.Sym) *new5a.Sym {
+func LabelLookup(s *Sym) *Sym {
        var p string
-       var lab *new5a.Sym
+       var lab *Sym
 
        if thetext == nil {
                s.Labelname = s.Name
@@ -226,134 +184,109 @@ func labellookup(s *new5a.Sym) *new5a.Sym {
        }
 
        p = string(fmt.Sprintf("%s.%s", thetext.Name, s.Name))
-       lab = Slookup(p)
+       lab = Lookup(p)
 
        lab.Labelname = s.Name
        return lab
 }
 
-func lookup() *new5a.Sym {
-       var s *new5a.Sym
-       var h uint32
-       var p string
-       var c int
-       var l int
-       var r string
-       var w string
-
-       if uint8(new5a.Symb[0]) == 0xc2 && uint8(new5a.Symb[1]) == 0xb7 {
-               // turn leading · into ""·
-               h = uint32(len(new5a.Symb))
-
-               Ensuresymb(int32(h + 2))
-               main.Memmove(new5a.Symb[2:], new5a.Symb, h+1)
-               new5a.Symb[0] = '"'
-               new5a.Symb[1] = '"'
-       }
-
-       w = new5a.Symb
-       for r = w; r[0] != 0; r = r[1:] {
-               // turn · (U+00B7) into .
-               // turn ∕ (U+2215) into /
-               if uint8(r[0]) == 0xc2 && uint8((r[1:])[0]) == 0xb7 {
-
-                       w[0] = '.'
-                       w = w[1:]
-                       r = r[1:]
-               } else if uint8(r[0]) == 0xe2 && uint8((r[1:])[0]) == 0x88 && uint8((r[2:])[0]) == 0x95 {
-                       w[0] = '/'
-                       w = w[1:]
-                       r = r[1:]
-                       r = r[1:]
-               } else {
-
-                       w[0] = r[0]
-                       w = w[1:]
-               }
+func Lookup(symb string) *Sym {
+       // turn leading · into ""·
+       if strings.HasPrefix(symb, "·") {
+               symb = `""` + symb
        }
 
-       w[0] = '\x00'
+       // turn · (U+00B7) into .
+       // turn ∕ (U+2215) into /
+       symb = strings.Replace(symb, "·", ".", -1)
+       symb = strings.Replace(symb, "∕", "/", -1)
 
-       h = 0
-       for p = new5a.Symb; ; p = p[1:] {
-               c = int(p[0])
-               if !(c != 0) {
-                       break
-               }
-               h = h + h + h + uint32(c)
-       }
-       l = (-cap(p) + cap(new5a.Symb)) + 1
-       h &= 0xffffff
-       h %= new5a.NHASH
-       c = int(new5a.Symb[0])
-       for s = new5a.Hash[h]; s != nil; s = s.Link {
-               if int(s.Name[0]) != c {
-                       continue
-               }
-               if s.Name == new5a.Symb {
-                       return s
-               }
+       s := hash[symb]
+       if s != nil {
+               return s
        }
 
-       s = Alloc(sizeof(*s)).(*new5a.Sym)
-       s.Name = Alloc(int32(l)).(string)
-       main.Memmove(s.Name, new5a.Symb, l)
-
-       s.Link = new5a.Hash[h]
-       new5a.Hash[h] = s
-       new5a.Syminit(s)
+       s = new(Sym)
+       s.Name = symb
+       syminit(s)
+       hash[symb] = s
        return s
 }
 
-func ISALPHA(c int) int {
-       if main.Isalpha(c) != 0 {
-               return 1
+func isalnum(c int) bool {
+       return isalpha(c) || isdigit(c)
+}
+
+func isalpha(c int) bool {
+       return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z'
+}
+
+func isspace(c int) bool {
+       return c == ' ' || c == '\t' || c == '\r' || c == '\n'
+}
+
+func ISALPHA(c int) bool {
+       if isalpha(c) {
+               return true
        }
-       if c >= main.Runeself {
-               return 1
+       if c >= utf8.RuneSelf {
+               return true
        }
-       return 0
+       return false
+}
+
+var yybuf bytes.Buffer
+
+func (yyImpl) Error(s string) {
+       Yyerror("%s", s)
+}
+
+type Yylval struct {
+       Sym  *Sym
+       Lval int64
+       Sval string
+       Dval float64
 }
 
-func yylex() int32 {
+func Yylex(yylval *Yylval) int {
        var c int
        var c1 int
-       var cp string
-       var s *new5a.Sym
+       var s *Sym
 
-       c = new5a.Peekc
-       if c != new5a.IGN {
-               new5a.Peekc = new5a.IGN
+       c = peekc
+       if c != IGN {
+               peekc = IGN
                goto l1
        }
 
 l0:
-       c = new5a.GETC()
+       c = GETC()
 
 l1:
-       if c == new5a.EOF {
-               new5a.Peekc = new5a.EOF
+       if c == EOF {
+               peekc = EOF
                return -1
        }
 
-       if main.Isspace(c) != 0 {
+       if isspace(c) {
                if c == '\n' {
-                       new5a.Lineno++
+                       Lineno++
                        return ';'
                }
 
                goto l0
        }
 
-       if ISALPHA(c) != 0 {
-               goto talph
+       if ISALPHA(c) {
+               yybuf.Reset()
+               goto aloop
        }
-       if main.Isdigit(c) != 0 {
+       if isdigit(c) {
                goto tnum
        }
        switch c {
        case '\n':
-               new5a.Lineno++
+               Lineno++
                return ';'
 
        case '#':
@@ -361,280 +294,256 @@ l1:
                goto l0
 
        case '.':
-               c = new5a.GETC()
-               if ISALPHA(c) != 0 {
-                       cp = new5a.Symb
-                       cp[0] = '.'
-                       cp = cp[1:]
+               c = GETC()
+               if ISALPHA(c) {
+                       yybuf.Reset()
+                       yybuf.WriteByte('.')
                        goto aloop
                }
 
-               if main.Isdigit(c) != 0 {
-                       cp = new5a.Symb
-                       cp[0] = '.'
-                       cp = cp[1:]
+               if isdigit(c) {
+                       yybuf.Reset()
+                       yybuf.WriteByte('.')
                        goto casedot
                }
 
-               new5a.Peekc = c
+               peekc = c
                return '.'
 
        case '_',
                '@':
-       talph:
-               cp = new5a.Symb
-
-       aloop:
-               cp[0] = byte(c)
-               cp = cp[1:]
-               c = new5a.GETC()
-               if ISALPHA(c) != 0 || main.Isdigit(c) != 0 || c == '_' || c == '$' {
-                       goto aloop
-               }
-               cp = ""
-               new5a.Peekc = c
-               s = lookup()
-               if s.Macro != "" {
-                       newio()
-                       cp = new5a.Ionext.B
-                       macexpand(s, cp)
-                       pushio()
-                       new5a.Ionext.Link = new5a.Iostack
-                       new5a.Iostack = new5a.Ionext
-                       new5a.Fi.p = cp
-                       new5a.Fi.c = len(cp)
-                       if new5a.Peekc != new5a.IGN {
-                               cp[new5a.Fi.c] = byte(new5a.Peekc)
-                               new5a.Fi.c++
-                               cp[new5a.Fi.c] = 0
-                               new5a.Peekc = new5a.IGN
-                       }
-
-                       goto l0
-               }
-
-               if s.Type_ == 0 {
-                       s.Type_ = new5a.LNAME
-               }
-               if s.Type_ == new5a.LNAME || s.Type_ == new5a.LVAR || s.Type_ == new5a.LLAB {
-                       new5a.Yylval.sym = s
-                       return int32(s.Type_)
-               }
-
-               new5a.Yylval.lval = s.Value
-               return int32(s.Type_)
-
-       tnum:
-               cp = new5a.Symb
-               if c != '0' {
-                       goto dc
-               }
-               cp[0] = byte(c)
-               cp = cp[1:]
-               c = new5a.GETC()
-               c1 = 3
-               if c == 'x' || c == 'X' {
-                       c1 = 4
-                       c = new5a.GETC()
-               } else if c < '0' || c > '7' {
-                       goto dc
-               }
-               new5a.Yylval.lval = 0
-               for {
-                       if c >= '0' && c <= '9' {
-                               if c > '7' && c1 == 3 {
-                                       break
-                               }
-                               new5a.Yylval.lval = int32(uint64(new5a.Yylval.lval) << uint(c1))
-                               new5a.Yylval.lval += int32(c) - '0'
-                               c = new5a.GETC()
-                               continue
-                       }
-
-                       if c1 == 3 {
-                               break
-                       }
-                       if c >= 'A' && c <= 'F' {
-                               c += 'a' - 'A'
-                       }
-                       if c >= 'a' && c <= 'f' {
-                               new5a.Yylval.lval = int32(uint64(new5a.Yylval.lval) << uint(c1))
-                               new5a.Yylval.lval += int32(c) - 'a' + 10
-                               c = new5a.GETC()
-                               continue
-                       }
-
-                       break
-               }
-
-               goto ncu
-
-       dc:
-               for {
-                       if !(main.Isdigit(c) != 0) {
-                               break
-                       }
-                       cp[0] = byte(c)
-                       cp = cp[1:]
-                       c = new5a.GETC()
-               }
-
-               if c == '.' {
-                       goto casedot
-               }
-               if c == 'e' || c == 'E' {
-                       goto casee
-               }
-               cp = ""
-               if sizeof(new5a.Yylval.lval) == sizeof(int64) {
-                       new5a.Yylval.lval = int32(main.Strtoll(new5a.Symb, nil, 10))
-               } else {
-
-                       new5a.Yylval.lval = int32(main.Strtol(new5a.Symb, nil, 10))
-               }
-
-       ncu:
-               for c == 'U' || c == 'u' || c == 'l' || c == 'L' {
-                       c = new5a.GETC()
-               }
-               new5a.Peekc = c
-               return new5a.LCONST
-
-       casedot:
-               for {
-                       cp[0] = byte(c)
-                       cp = cp[1:]
-                       c = new5a.GETC()
-                       if !(main.Isdigit(c) != 0) {
-                               break
-                       }
-               }
-
-               if c == 'e' || c == 'E' {
-                       goto casee
-               }
-               goto caseout
-
-       casee:
-               cp[0] = 'e'
-               cp = cp[1:]
-               c = new5a.GETC()
-               if c == '+' || c == '-' {
-                       cp[0] = byte(c)
-                       cp = cp[1:]
-                       c = new5a.GETC()
-               }
-
-               for main.Isdigit(c) != 0 {
-                       cp[0] = byte(c)
-                       cp = cp[1:]
-                       c = new5a.GETC()
-               }
-
-       caseout:
-               cp = ""
-               new5a.Peekc = c
-               if new5a.FPCHIP != 0 /*TypeKind(100016)*/ {
-                       new5a.Yylval.dval = main.Atof(new5a.Symb)
-                       return new5a.LFCONST
-               }
-
-               Yyerror("assembler cannot interpret fp constants")
-               new5a.Yylval.lval = 1
-               return new5a.LCONST
+               yybuf.Reset()
+               goto aloop
 
        case '"':
-               main.Memmove(new5a.Yylval.sval, new5a.Nullgen.U.Sval, sizeof(new5a.Yylval.sval))
-               cp = new5a.Yylval.sval
+               var buf bytes.Buffer
                c1 = 0
                for {
                        c = escchar('"')
-                       if c == new5a.EOF {
+                       if c == EOF {
                                break
                        }
-                       if c1 < sizeof(new5a.Yylval.sval) {
-                               cp[0] = byte(c)
-                               cp = cp[1:]
-                       }
-                       c1++
-               }
-
-               if c1 > sizeof(new5a.Yylval.sval) {
-                       Yyerror("string constant too long")
+                       buf.WriteByte(byte(c))
                }
-               return new5a.LSCONST
+               yylval.Sval = buf.String()
+               return LSCONST
 
        case '\'':
                c = escchar('\'')
-               if c == new5a.EOF {
+               if c == EOF {
                        c = '\''
                }
-               if escchar('\'') != new5a.EOF {
+               if escchar('\'') != EOF {
                        Yyerror("missing '")
                }
-               new5a.Yylval.lval = int32(c)
-               return new5a.LCONST
+               yylval.Lval = int64(c)
+               return LCONST
 
        case '/':
-               c1 = new5a.GETC()
+               c1 = GETC()
                if c1 == '/' {
                        for {
-                               c = new5a.GETC()
+                               c = GETC()
                                if c == '\n' {
                                        goto l1
                                }
-                               if c == new5a.EOF {
+                               if c == EOF {
                                        Yyerror("eof in comment")
-                                       Errorexit()
+                                       errorexit()
                                }
                        }
                }
 
                if c1 == '*' {
                        for {
-                               c = new5a.GETC()
+                               c = GETC()
                                for c == '*' {
-                                       c = new5a.GETC()
+                                       c = GETC()
                                        if c == '/' {
                                                goto l0
                                        }
                                }
 
-                               if c == new5a.EOF {
+                               if c == EOF {
                                        Yyerror("eof in comment")
-                                       Errorexit()
+                                       errorexit()
                                }
 
                                if c == '\n' {
-                                       new5a.Lineno++
+                                       Lineno++
                                }
                        }
                }
 
        default:
-               return int32(c)
+               return int(c)
+       }
+
+       peekc = c1
+       return int(c)
+
+casedot:
+       for {
+               yybuf.WriteByte(byte(c))
+               c = GETC()
+               if !(isdigit(c)) {
+                       break
+               }
+       }
+
+       if c == 'e' || c == 'E' {
+               goto casee
+       }
+       goto caseout
+
+casee:
+       yybuf.WriteByte('e')
+       c = GETC()
+       if c == '+' || c == '-' {
+               yybuf.WriteByte(byte(c))
+               c = GETC()
+       }
+
+       for isdigit(c) {
+               yybuf.WriteByte(byte(c))
+               c = GETC()
+       }
+
+caseout:
+       peekc = c
+       if FPCHIP != 0 /*TypeKind(100016)*/ {
+               last = yybuf.String()
+               yylval.Dval = atof(last)
+               return LFCONST
+       }
+
+       Yyerror("assembler cannot interpret fp constants")
+       yylval.Lval = 1
+       return LCONST
+
+aloop:
+       yybuf.WriteByte(byte(c))
+       c = GETC()
+       if ISALPHA(c) || isdigit(c) || c == '_' || c == '$' {
+               goto aloop
+       }
+       peekc = c
+       last = yybuf.String()
+       s = Lookup(last)
+       if s.Macro != nil {
+               newio()
+               ionext.P = macexpand(s)
+               pushio()
+               ionext.Link = iostack
+               iostack = ionext
+               fi.P = ionext.P
+               if peekc != IGN {
+                       fi.P = append(fi.P, byte(peekc))
+                       peekc = IGN
+               }
+
+               goto l0
+       }
+
+       if s.Type == 0 {
+               s.Type = LNAME
+       }
+       if s.Type == LNAME || s.Type == LVAR || s.Type == LLAB {
+               yylval.Sym = s
+               yylval.Sval = last
+               return int(s.Type)
+       }
+
+       yylval.Lval = s.Value
+       yylval.Sval = last
+       return int(s.Type)
+
+tnum:
+       yybuf.Reset()
+       if c != '0' {
+               goto dc
+       }
+       yybuf.WriteByte(byte(c))
+       c = GETC()
+       c1 = 3
+       if c == 'x' || c == 'X' {
+               c1 = 4
+               c = GETC()
+       } else if c < '0' || c > '7' {
+               goto dc
+       }
+       yylval.Lval = 0
+       for {
+               if c >= '0' && c <= '9' {
+                       if c > '7' && c1 == 3 {
+                               break
+                       }
+                       yylval.Lval = int64(uint64(yylval.Lval) << uint(c1))
+                       yylval.Lval += int64(c) - '0'
+                       c = GETC()
+                       continue
+               }
+
+               if c1 == 3 {
+                       break
+               }
+               if c >= 'A' && c <= 'F' {
+                       c += 'a' - 'A'
+               }
+               if c >= 'a' && c <= 'f' {
+                       yylval.Lval = int64(uint64(yylval.Lval) << uint(c1))
+                       yylval.Lval += int64(c) - 'a' + 10
+                       c = GETC()
+                       continue
+               }
+
+               break
        }
 
-       new5a.Peekc = c1
-       return int32(c)
+       goto ncu
+
+dc:
+       for {
+               if !(isdigit(c)) {
+                       break
+               }
+               yybuf.WriteByte(byte(c))
+               c = GETC()
+       }
+
+       if c == '.' {
+               goto casedot
+       }
+       if c == 'e' || c == 'E' {
+               goto casee
+       }
+       last = yybuf.String()
+       yylval.Lval = strtoll(last, nil, 10)
+
+ncu:
+       for c == 'U' || c == 'u' || c == 'l' || c == 'L' {
+               c = GETC()
+       }
+       peekc = c
+       return LCONST
 }
 
 func getc() int {
        var c int
 
-       c = new5a.Peekc
-       if c != new5a.IGN {
-               new5a.Peekc = new5a.IGN
+       c = peekc
+       if c != IGN {
+               peekc = IGN
                return c
        }
 
-       c = new5a.GETC()
+       c = GETC()
        if c == '\n' {
-               new5a.Lineno++
+               Lineno++
        }
-       if c == new5a.EOF {
+       if c == EOF {
                Yyerror("End of file")
-               Errorexit()
+               errorexit()
        }
 
        return c
@@ -645,16 +554,16 @@ func getnsc() int {
 
        for {
                c = getc()
-               if !(main.Isspace(c) != 0) || c == '\n' {
+               if !isspace(c) || c == '\n' {
                        return c
                }
        }
 }
 
 func unget(c int) {
-       new5a.Peekc = c
+       peekc = c
        if c == '\n' {
-               new5a.Lineno--
+               Lineno--
        }
 }
 
@@ -666,12 +575,12 @@ loop:
        c = getc()
        if c == '\n' {
                Yyerror("newline in string")
-               return new5a.EOF
+               return EOF
        }
 
        if c != '\\' {
                if c == e {
-                       return new5a.EOF
+                       return EOF
                }
                return c
        }
@@ -689,7 +598,7 @@ loop:
                        }
                }
 
-               new5a.Peekc = c
+               peekc = c
                return l
        }
 
@@ -717,88 +626,109 @@ loop:
        return c
 }
 
-func Pinit(f string) {
-       var i int
-       var s *new5a.Sym
-
-       new5a.Lineno = 1
+func pinit(f string) {
+       Lineno = 1
        newio()
-       newfile(f, -1)
-       new5a.Pc = 0
-       new5a.Peekc = new5a.IGN
-       new5a.Sym = 1
-       for i = 0; i < new5a.NHASH; i++ {
-               for s = new5a.Hash[i]; s != nil; s = s.Link {
-                       s.Macro = ""
-               }
+       newfile(f, nil)
+       PC = 0
+       peekc = IGN
+       sym = 1
+       for _, s := range hash {
+               s.Macro = nil
        }
 }
 
 func filbuf() int {
-       var i *new5a.Io
+       var i *Io
+       var n int
 
 loop:
-       i = new5a.Iostack
+       i = iostack
        if i == nil {
-               return new5a.EOF
+               return EOF
        }
-       if i.F < 0 {
+       if i.F == nil {
                goto pop
        }
-       new5a.Fi.c = main.Read(int(i.F), i.B, new5a.BUFSIZ) - 1
-       if new5a.Fi.c < 0 {
-               main.Close(int(i.F))
-               obj.Linklinehist(new5a.Ctxt, int(new5a.Lineno), "", 0)
+       n, _ = i.F.Read(i.B[:])
+       if n == 0 {
+               i.F.Close()
+               obj.Linklinehist(Ctxt, int(Lineno), "<pop>", 0)
                goto pop
        }
-
-       new5a.Fi.p = i.B[1:]
+       fi.P = i.B[1:n]
        return int(i.B[0]) & 0xff
 
 pop:
-       new5a.Iostack = i.Link
-       i.Link = new5a.Iofree
-       new5a.Iofree = i
-       i = new5a.Iostack
+       iostack = i.Link
+       i.Link = iofree
+       iofree = i
+       i = iostack
        if i == nil {
-               return new5a.EOF
+               return EOF
        }
-       new5a.Fi.p = i.P
-       new5a.Fi.c = int(i.C)
-       new5a.Fi.c--
-       if new5a.Fi.c < 0 {
+       fi.P = i.P
+       if len(fi.P) == 0 {
                goto loop
        }
-       tmp8 := new5a.Fi.p
-       new5a.Fi.p = new5a.Fi.p[1:]
+       tmp8 := fi.P
+       fi.P = fi.P[1:]
        return int(tmp8[0]) & 0xff
 }
 
-func Yyerror(a string, args ...interface{}) {
-       var buf string
-       var arg []interface{}
+var last string
 
+func Yyerror(a string, args ...interface{}) {
        /*
         * hack to intercept message from yaccpar
         */
-       if a == "syntax error" {
-
-               Yyerror("syntax error, last name: %s", new5a.Symb)
+       if a == "syntax error" || len(args) == 1 && a == "%s" && args[0] == "syntax error" {
+               Yyerror("syntax error, last name: %s", last)
                return
        }
 
-       prfile(new5a.Lineno)
-       main.Va_start(arg, a)
-       obj.Vseprint(buf, buf[sizeof(buf):], a, arg)
-       main.Va_end(arg)
-       fmt.Printf("%s\n", buf)
-       new5a.Nerrors++
-       if new5a.Nerrors > 10 {
+       prfile(Lineno)
+       fmt.Printf("%s\n", fmt.Sprintf(a, args...))
+       nerrors++
+       if nerrors > 10 {
                fmt.Printf("too many errors\n")
-               Errorexit()
+               errorexit()
        }
 }
 
 func prfile(l int32) {
-       obj.Linkprfile(new5a.Ctxt, l)
+       obj.Linkprfile(Ctxt, int(l))
+}
+
+func GETC() int {
+       var c int
+       if len(fi.P) == 0 {
+               return filbuf()
+       }
+       c = int(fi.P[0])
+       fi.P = fi.P[1:]
+       return c
+}
+
+func isdigit(c int) bool {
+       return '0' <= c && c <= '9'
+}
+
+func strtoll(s string, p *byte, base int) int64 {
+       if p != nil {
+               panic("strtoll")
+       }
+       n, err := strconv.ParseInt(s, base, 64)
+       if err != nil {
+               return 0
+       }
+       return n
+}
+
+func atof(s string) float64 {
+       f, err := strconv.ParseFloat(s, 64)
+       if err != nil {
+               return 0
+       }
+       return f
 }