Commit b8babed7 authored by Russ Cox's avatar Russ Cox

new import/export format

    package flag
	export type flag.Flag struct { name flag.string; usage flag.string; \
		value flag.Value; next *flag.Flag }
	type flag.string string
	type flag.Value interface { AsBool () (? *flag.BoolValue); \
		AsInt () (? *flag.IntValue); AsString () (? *flag.StringValue); \
		IsBool () (? flag.bool); IsInt () (? flag.bool); IsString () (? flag.bool); \
		Str () (? flag.string); ValidValue (str flag.string) (? flag.bool) }
	type flag.BoolValue struct { val flag.bool; p *flag.bool }
	type flag.IntValue struct { val flag.int64; p *flag.int64 }
	type flag.StringValue struct { val flag.string; p *flag.string }
	type flag.bool bool
	func (e *flag.StringValue) AsBool () (? *flag.BoolValue)
	func (e *flag.StringValue) AsInt () (? *flag.IntValue)
	...

the \ continuations are for this message, not real.

changed delimiter for import from (( )) to $$ $$.

replaced mksys.bash with mksys.c

changed sys.go to use leading export,
	fake package name is now SYS not foop

don't always require ; on forward func decls

R=ken,r
DELTA=1827  (446 added, 1083 deleted, 298 changed)
OCL=16433
CL=16463
parent 8877d27b
......@@ -131,7 +131,7 @@ char *pkgdata; /* pkgdef data */
char *pkgstmt; /* string "package foo" */
int dupfound; /* flag for duplicate symbol */
Hashchain *hash[NHASH]; /* hash table of text symbols */
#define ARNAMESIZE sizeof(astart->tail->hdr.name)
char poname[ARNAMESIZE+1]; /* name of pivot member */
......@@ -630,7 +630,7 @@ int
strstrn(char *line, int len, char *sub)
{
int i;
int sublen;
int sublen;
sublen = strlen(sub);
for (i = 0; i < len - sublen; i++)
......@@ -654,20 +654,20 @@ scanpkg(Biobuf *b, long size)
int first;
/*
* scan until ((
* scan until $$
*/
for (n=0; n<size; ) {
c = Bgetc(b);
if(c == Beof)
break;
n++;
if(c != '(')
if(c != '$')
continue;
c = Bgetc(b);
if(c == Beof)
break;
n++;
if(c != '(')
if(c != '$')
continue;
goto foundstart;
}
......@@ -691,9 +691,9 @@ foundstart:
first = 0;
continue;
}
if (strstrn(line, Blinelen(b), "))"))
if (strstrn(line, Blinelen(b), "$$"))
goto foundend;
end = Boffset(b); // before closing ))
end = Boffset(b); // before closing $$
}
bad:
fprint(2, "ar: bad package import section in %s\n", file);
......@@ -706,9 +706,9 @@ foundend:
/* this is the first package */
pkgstmt = armalloc(strlen(pkg)+1);
strcpy(pkgstmt, pkg);
pkgdefsize = 7 + 3 + strlen(pkg); /* "import\n((\npackage foo\n" */
pkgdefsize = 7 + 3 + strlen(pkg); /* "import\n$$\npackage foo\n" */
pkgdata = armalloc(pkgdefsize);
sprint(pkgdata, "import\n((\n%s", pkgstmt);
sprint(pkgdata, "import\n$$\n%s", pkgstmt);
} else {
if (strcmp(pkg, pkgstmt) != 0) {
fprint(2, "ar: inconsistent package name\n");
......@@ -1018,7 +1018,7 @@ rl(int fd)
headlen = Boffset(&b);
len += headlen;
if (gflag) {
len += SAR_HDR + pkgdefsize + 3; /* +3 for "))\n" */
len += SAR_HDR + pkgdefsize + 3; /* +3 for "$$\n" */
if (len & 1)
len++;
}
......@@ -1037,7 +1037,7 @@ rl(int fd)
Bputc(&b, 0);
if (gflag) {
len = pkgdefsize + 3; /* for "))\n" at close */
len = pkgdefsize + 3; /* for "$$\n" at close */
sprint(a.date, "%-12ld", time(0));
sprint(a.uid, "%-6d", 0);
sprint(a.gid, "%-6d", 0);
......@@ -1053,7 +1053,7 @@ rl(int fd)
if (Bwrite(&b, pkgdata, pkgdefsize) != pkgdefsize)
wrerr();
if (Bwrite(&b, "))\n", 3) != 3)
if (Bwrite(&b, "$$\n", 3) != 3)
wrerr();
if(len&0x01)
Bputc(&b, 0);
......
......@@ -39,10 +39,12 @@ y.tab.h: $(YFILES)
y.tab.c: y.tab.h
test -f y.tab.c && touch y.tab.c
sysimport.c: sys.go mksys.bash
bash mksys.bash
sysimport.c: sys.go mksys.c
gcc -o mksys mksys.c
6g sys.go
./mksys sys.6 >_sysimport.c && mv _sysimport.c sysimport.c
clean:
rm -f $(OFILES) *.6 enam.c 6.out a.out y.tab.h y.tab.c $(LIB)
rm -f $(OFILES) *.6 enam.c 6.out a.out y.tab.h y.tab.c $(LIB) _sysimport.c
install: $(LIB)
......@@ -50,10 +50,10 @@ dodcltype(Type *n, Type *t)
t = nt;
t->sym = S;
}
if(exportadj)
exportsym(n->sym);
n->sym->local = 1;
addtyp(n, t, dclcontext);
if(exportadj)
exportsym(n->sym);
}
void
......@@ -70,8 +70,6 @@ loop:
n = n->right;
goto loop;
}
if(exportadj)
exportsym(n->sym);
if(n->op != ONAME)
fatal("dodclconst: not a name");
......@@ -85,6 +83,9 @@ loop:
s->oconst = e;
s->lexical = LACONST;
if(exportadj)
exportsym(n->sym);
r = autodcl;
if(dclcontext == PEXTERN)
r = externdcl;
......@@ -142,51 +143,6 @@ functype(Node *this, Node *in, Node *out)
return t;
}
void
funcnam(Type *t, char *nam)
{
Node *n;
Sym *s;
char buf[100];
if(nam == nil) {
vargen++;
snprint(buf, sizeof(buf), "_f%s_%.3ld", filename, vargen);
nam = buf;
}
if(t->etype != TFUNC)
fatal("funcnam: not func %T\n", t);
if(t->thistuple > 0) {
vargen++;
snprint(namebuf, sizeof(namebuf), "_t%s_%.3ld", filename, vargen);
s = lookup(namebuf);
addtyp(newtype(s), t->type, PEXTERN);
n = newname(s);
n->vargen = vargen;
t->type->nname = n;
}
if(t->outtuple > 0) {
vargen++;
snprint(namebuf, sizeof(namebuf), "_o%s_%.3ld", filename, vargen);
s = lookup(namebuf);
addtyp(newtype(s), t->type->down, PEXTERN);
n = newname(s);
n->vargen = vargen;
t->type->down->nname = n;
}
if(t->intuple > 0) {
vargen++;
snprint(namebuf, sizeof(namebuf), "_i%s_%.3ld", filename, vargen);
s = lookup(namebuf);
addtyp(newtype(s), t->type->down->down, PEXTERN);
n = newname(s);
n->vargen = vargen;
t->type->down->down->nname = n;
}
}
int
methcmp(Type *t1, Type *t2)
{
......@@ -218,6 +174,7 @@ Node*
methodname(Node *n, Type *t)
{
Sym *s;
char buf[NSYMB];
if(t == T)
goto bad;
......@@ -233,8 +190,8 @@ methodname(Node *n, Type *t)
if(s == S)
goto bad;
snprint(namebuf, sizeof(namebuf), "%s_%s", s->name, n->sym->name);
return newname(lookup(namebuf));
snprint(buf, sizeof(buf), "%s_%s", s->name, n->sym->name);
return newname(pkglookup(buf, t->sym->opackage));
bad:
yyerror("illegal <this> type: %T", t);
......@@ -366,7 +323,6 @@ funchdr(Node *n)
if(on == N) {
// initial declaration or redeclaration
// declare fun name, argument types and argument names
funcnam(n->type, s->name);
n->nname->type = n->type;
if(n->type->thistuple == 0)
addvar(n->nname, n->type, PEXTERN);
......@@ -462,6 +418,7 @@ stotype(Node *n, Type **t)
{
Type *f;
Iter save;
char buf[100];
n = listfirst(&save, &n);
......@@ -490,8 +447,8 @@ loop:
f->nname = n->left;
} else {
vargen++;
snprint(namebuf, sizeof(namebuf), "_e%s_%.3ld", filename, vargen);
f->nname = newname(lookup(namebuf));
snprint(buf, sizeof(buf), "_e%s_%.3ld", filename, vargen);
f->nname = newname(lookup(buf));
}
f->sym = f->nname->sym;
......@@ -600,6 +557,7 @@ poptodcl(void)
}
if(d == S)
fatal("poptodcl: no mark");
dclstack = d;
}
void
......@@ -689,17 +647,6 @@ addvar(Node *n, Type *t, int ctxt)
if(n==N || n->sym == S || n->op != ONAME || t == T)
fatal("addvar: n=%N t=%T nil", n, t);
ot = t;
if(isptr[ot->etype])
ot = ot->type;
if(ot->etype == TSTRUCT && ot->vargen == 0) {
vargen++;
snprint(namebuf, sizeof(namebuf), "_s%s_%.3ld", filename, vargen);
s = lookup(namebuf);
addtyp(newtype(s), ot, PEXTERN);
}
s = n->sym;
vargen++;
gen = vargen;
......@@ -783,7 +730,8 @@ addtyp(Type *n, Type *t, int ctxt)
pushdcl(s);
if(t->sym != S)
warn("addtyp: renaming %S/%lT to %S/%lT", t->sym, t->sym->otype, s, n);
warn("addtyp: renaming type %S/%lT to %S/%lT",
t->sym, t->sym->otype, s, n);
vargen++;
s->vargen = vargen;
......
This diff is collapsed.
......@@ -123,6 +123,7 @@ struct Type
uchar recur; // to detect loops
uchar trecur; // to detect loops
uchar methptr; // 1=direct 2=pointer
uchar printed;
// TFUNCT
uchar thistuple;
......@@ -464,6 +465,8 @@ EXTERN char* hunk;
EXTERN int32 nhunk;
EXTERN int32 thunk;
EXTERN int exporting;
/*
* y.tab.c
*/
......@@ -652,6 +655,7 @@ void fninit(Node*);
Node* nametoanondcl(Node*);
Node* nametodcl(Node*, Type*);
Node* anondcl(Type*);
void checkarglist(Node*);
/*
* export.c
......@@ -675,6 +679,12 @@ void doimport6(Node*, Node*);
void doimport7(Node*, Node*);
void doimport8(Node*, Val*, Node*);
void doimport9(Sym*, Node*);
void importconst(int, Node *ss, Type *t, Val *v);
void importmethod(Sym *s, Type *t);
void importtype(int, Node *ss, Type *t);
void importvar(int, Node *ss, Type *t);
void checkimports(void);
Type* pkgtype(char*, char*);
/*
* walk.c
......
......@@ -45,8 +45,6 @@
%type <node> vardcl_list_r vardcl Avardcl Bvardcl
%type <node> interfacedcl_list_r interfacedcl
%type <node> structdcl_list_r structdcl
%type <node> hidden_importsym_list_r ohidden_importsym_list hidden_importsym isym
%type <node> hidden_importfield_list_r ohidden_importfield_list hidden_importfield
%type <node> fnres Afnres Bfnres fnliteral xfndcl fndcl fnbody
%type <node> keyexpr_list keyval_list_r keyval
%type <node> typedcl Atypedcl Btypedcl
......@@ -58,6 +56,14 @@
%type <type> Achantype Bchantype
%type <val> hidden_constant
%type <node> hidden_dcl
%type <type> hidden_type hidden_type1 hidden_type2
%type <node> hidden_structdcl_list ohidden_structdcl_list hidden_structdcl_list_r
%type <node> hidden_interfacedcl_list ohidden_interfacedcl_list hidden_interfacedcl_list_r
%type <node> hidden_interfacedcl
%type <node> hidden_funarg_list ohidden_funarg_list hidden_funarg_list_r
%type <node> hidden_funres ohidden_funres hidden_importsym
%type <lint> oexport
%left LOROR
%left LANDAND
......@@ -65,6 +71,7 @@
%left LEQ LNE LLE LGE LLT LGT
%left '+' '-' '|' '^'
%left '*' '/' '%' '&' LLSH LRSH
%%
file:
package import_there imports oxdcl_list
......@@ -130,12 +137,12 @@ import_package:
}
import_there:
hidden_import_list_r ')' ')'
hidden_import_list_r '$' '$'
{
checkimports();
unimportfile();
}
| LIMPORT '(' '(' hidden_import_list_r ')' ')'
| LIMPORT '$' '$' hidden_import_list_r '$' '$'
{
checkimports();
}
......@@ -889,8 +896,7 @@ sym1:
| keyword
sym2:
sym
| keyword
sym1
/*
* keywords that we can
......@@ -1124,14 +1130,12 @@ Afntype:
'(' oarg_type_list ')' Afnres
{
$$ = functype(N, $2, $4);
funcnam($$, nil);
}
Bfntype:
'(' oarg_type_list ')' Bfnres
{
$$ = functype(N, $2, $4);
funcnam($$, nil);
}
fnlitdcl:
......@@ -1175,8 +1179,7 @@ fnbody:
if($$ == N)
$$ = nod(ORETURN, N, N);
}
| ';'
{
| {
$$ = N;
}
......@@ -1296,7 +1299,6 @@ indcl:
{
// without func keyword
$$ = functype(fakethis(), $2, $4);
funcnam($$, nil);
}
| latype
{
......@@ -1357,10 +1359,6 @@ arg_type_list_r:
$$ = nametoanondcl($1);
}
/*
* arg type is just list of arg_chunks, except for the
* special case of a simple comma-separated list of names.
*/
arg_type_list:
arg_type_list_r
{
......@@ -1493,18 +1491,43 @@ hidden_import_list_r:
hidden_import
| hidden_import_list_r hidden_import
hidden_importsym_list_r:
hidden_importsym
| hidden_importsym_list_r hidden_importsym
hidden_funarg_list_r:
hidden_dcl
| hidden_funarg_list_r ',' hidden_dcl
{
$$ = nod(OLIST, $1, $3);
}
hidden_funarg_list:
hidden_funarg_list_r
{
$$ = rev($1);
}
hidden_structdcl_list_r:
hidden_dcl
| hidden_structdcl_list_r ';' hidden_dcl
{
$$ = nod(OLIST, $1, $3);
}
hidden_structdcl_list:
hidden_structdcl_list_r
{
$$ = nod(OLIST, $1, $2);
$$ = rev($1);
}
hidden_importfield_list_r:
hidden_importfield
| hidden_importfield_list_r hidden_importfield
hidden_interfacedcl_list_r:
hidden_interfacedcl
| hidden_interfacedcl_list_r ';' hidden_interfacedcl
{
$$ = nod(OLIST, $1, $2);
$$ = nod(OLIST, $1, $3);
}
hidden_interfacedcl_list:
hidden_interfacedcl_list_r
{
$$ = rev($1);
}
keyval_list_r:
......@@ -1577,104 +1600,183 @@ oxdcl_list:
$$ = rev($1);
}
ohidden_importsym_list:
oarg_type_list:
{
$$ = N;
}
| hidden_importsym_list_r
| arg_type_list
ohidden_funarg_list:
{
$$ = rev($1);
$$ = N;
}
| hidden_funarg_list
ohidden_importfield_list:
ohidden_structdcl_list:
{
$$ = N;
}
| hidden_importfield_list_r
| hidden_structdcl_list
ohidden_interfacedcl_list:
{
$$ = rev($1);
$$ = N;
}
| hidden_interfacedcl_list
oarg_type_list:
oexport:
{
$$ = N;
$$ = 0;
}
| LEXPORT
{
$$ = 1;
}
| arg_type_list
/*
* import syntax from header of
* an output package
*/
hidden_import:
/* leftover import ignored */
LPACKAGE sym
LPACKAGE sym1
/* variables */
| LVAR hidden_importsym hidden_importsym
| oexport LVAR hidden_importsym hidden_type
{
importvar($1, $3, $4);
}
| oexport LCONST hidden_importsym '=' hidden_constant
{
importconst($1, $3, T, &$5);
}
| oexport LCONST hidden_importsym hidden_type '=' hidden_constant
{
importconst($1, $3, $4, &$6);
}
| oexport LTYPE hidden_importsym hidden_type
{
importtype($1, $3, $4);
}
| oexport LFUNC hidden_importsym '(' ohidden_funarg_list ')' ohidden_funres
{
// var
doimportv1($2, $3);
importvar($1, $3, functype(N, $5, $7));
}
| oexport LFUNC '(' hidden_funarg_list ')' sym1 '(' ohidden_funarg_list ')' ohidden_funres
{
// have to put oexport here to avoid shift/reduce
// with non-method func. but it isn't allowed.
if($1)
yyerror("cannot export method");
if($4->op != ODCLFIELD) {
yyerror("bad receiver in method");
YYERROR;
}
importmethod($6, functype($4, $8, $10));
}
hidden_type:
hidden_type1
| hidden_type2
/* constants */
| LCONST hidden_importsym hidden_constant
hidden_type1:
hidden_importsym
{
doimportc1($2, &$3);
$$ = pkgtype($1->sym->name, $1->psym->name);
}
| LCONST hidden_importsym hidden_importsym hidden_constant
| LATYPE
{
doimportc2($2, $3, &$4);
$$ = oldtype($1);
}
| '[' ']' hidden_type
{
$$ = aindex(N, $3);
}
| '[' LLITERAL ']' hidden_type
{
Node *n;
/* types */
| LTYPE hidden_importsym '[' hidden_importsym ']' hidden_importsym
n = nod(OLITERAL, N, N);
n->val = $2;
$$ = aindex(n, $4);
}
| LMAP '[' hidden_type ']' hidden_type
{
$$ = typ(TMAP);
$$->down = $3;
$$->type = $5;
}
| LSTRUCT '{' ohidden_structdcl_list '}'
{
// type map
doimport1($2, $4, $6);
$$ = dostruct($3, TSTRUCT);
}
| LTYPE hidden_importsym '[' LLITERAL ']' hidden_importsym
| LINTERFACE '{' ohidden_interfacedcl_list '}'
{
// type array
doimport2($2, &$4, $6);
$$ = dostruct($3, TINTER);
$$ = sortinter($$);
}
| LTYPE hidden_importsym '[' ']' hidden_importsym
| '*' hidden_type
{
// type array
doimport2($2, nil, $5);
dowidth($2);
$$ = ptrto($2);
}
| LTYPE hidden_importsym '(' ohidden_importsym_list ')'
| LCOMM LCHAN hidden_type
{
// type function
doimport3($2, $4);
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
}
| LTYPE hidden_importsym '{' ohidden_importfield_list '}'
| LCHAN LCOMM hidden_type1
{
// type structure
doimport4($2, $4);
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Csend;
}
| LTYPE hidden_importsym LLITERAL
hidden_type2:
LCHAN hidden_type
{
// type basic
doimport5($2, &$3);
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
}
| LTYPE hidden_importsym '*' hidden_importsym
| '(' ohidden_funarg_list ')' ohidden_funres
{
// type pointer
doimport6($2, $4);
$$ = functype(N, $2, $4);
}
| LTYPE hidden_importsym LLT ohidden_importfield_list LGT
hidden_dcl:
sym1 hidden_type
{
// type interface
doimport7($2, $4);
$$ = nod(ODCLFIELD, newname($1), N);
$$->type = $2;
}
| LTYPE hidden_importsym LLITERAL hidden_importsym
| '?' hidden_type
{
// type interface
doimport8($2, &$3, $4);
$$ = nod(ODCLFIELD, N, N);
$$->type = $2;
}
| LFUNC sym1 hidden_importsym
hidden_interfacedcl:
sym1 '(' ohidden_funarg_list ')' ohidden_funres
{
// method
doimport9($2, $3);
$$ = nod(ODCLFIELD, newname($1), N);
$$->type = functype(fakethis(), $3, $5);
}
ohidden_funres:
{
$$ = N;
}
| hidden_funres
hidden_funres:
'(' ohidden_funarg_list ')'
{
$$ = $2;
}
| hidden_type1
{
$$ = nod(ODCLFIELD, N, N);
$$->type = $1;
}
hidden_constant:
......@@ -1694,37 +1796,13 @@ hidden_constant:
}
}
isym:
hidden_importsym:
sym1 '.' sym2
{
$$ = nod(OIMPORT, N, N);
$$->osym = $1;
$$->psym = $1;
$$->sym = $3;
renamepkg($$);
}
| '(' sym1 ')' sym1 '.' sym2
{
$$ = nod(OIMPORT, N, N);
$$->osym = $2;
$$->psym = $4;
$$->sym = $6;
renamepkg($$);
}
hidden_importsym:
isym
| '!' isym
{
$$ = $2;
$$->etype = 1;
}
hidden_importfield:
sym1 isym
{
$$ = $2;
$$->fsym = $1;
}
/*
......@@ -1739,7 +1817,7 @@ hidden_importfield:
* to check whether the rest of the grammar is free of
* reduce/reduce conflicts, comment this section out by
* removing the slash on the next line.
*/
*
lpack:
LATYPE
{
......
......@@ -53,7 +53,7 @@ mainlex(int argc, char *argv[])
fmtinstall('Z', Zconv); // escaped string
fmtinstall('L', Lconv); // line number
fmtinstall('B', Bconv); // big numbers
lexinit();
lineno = 1;
block = 1;
......@@ -227,7 +227,7 @@ importfile(Val *f)
/*
* position the input right
* after (( and return
* after $$ and return
*/
pushedio = curio;
curio.bin = imp;
......@@ -237,12 +237,12 @@ importfile(Val *f)
c = getc();
if(c == EOF)
break;
if(c != '(')
if(c != '$')
continue;
c = getc();
if(c == EOF)
break;
if(c != '(')
if(c != '$')
continue;
return;
}
......@@ -586,9 +586,9 @@ l0:
lx:
if(c > 0xff)
DBG("lex: TOKEN %s\n", lexname(c));
DBG("%L lex: TOKEN %s\n", lineno, lexname(c));
else
DBG("lex: TOKEN '%c'\n", c);
DBG("%L lex: TOKEN '%c'\n", lineno, c);
return c;
asop:
......
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
#!/bin/bash
6g sys.go
echo '1,/((/d
/))/+1,$d
g/init_.*_function/d
1,$s/foop/sys/g
1,$s/^[ ]*/ "/g
1,$s/$/\\n"/g
1i
char* sysimport =
.
$a
;
.
w sysimport.c
q' | /bin/ed sys.6
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Extract import data from sys.6 and generate C string version.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
int
main(int argc, char **argv)
{
FILE *fin;
char buf[1024], *p, *q;
if(argc != 2) {
fprintf(stderr, "usage: mksys sys.6\n");
exit(1);
}
if((fin = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "open %s: %s\n", argv[1], strerror(errno));
exit(1);
}
// look for $$ that introduces imports
while(fgets(buf, sizeof buf, fin) != NULL)
if(strstr(buf, "$$"))
goto begin;
fprintf(stderr, "did not find beginning of imports\n");
exit(1);
begin:
printf("char *sysimport = \n");
// process imports, stopping at $$ that closes them
while(fgets(buf, sizeof buf, fin) != NULL) {
buf[strlen(buf)-1] = 0; // chop \n
if(strstr(buf, "$$"))
goto end;
// chop leading white space
for(p=buf; *p==' ' || *p == '\t'; p++)
;
// cut out decl of init_sys_function - it doesn't exist
if(strstr(buf, "init_sys_function"))
continue;
// sys.go claims to be in package SYS to avoid
// conflicts during "6g sys.go". rename SYS to sys.
for(q=p; *q; q++)
if(memcmp(q, "SYS", 3) == 0)
memmove(q, "sys", 3);
printf("\t\"%s\\n\"\n", p);
}
fprintf(stderr, "did not find end of imports\n");
exit(1);
end:
printf("\t\"$$\\n\";\n");
return 0;
}
......@@ -22,6 +22,8 @@ yyerror(char *fmt, ...)
va_start(arg, fmt);
vfprint(1, fmt, arg);
va_end(arg);
if(strcmp(fmt, "syntax error") == 0)
print(" near %s", namebuf);
print("\n");
if(debug['h'])
*(int*)0 = 0;
......@@ -921,6 +923,7 @@ Sconv(Fmt *fp)
if(s->name != nil)
nam = s->name;
if(!(fp->flags & FmtShort))
if(strcmp(pkg, package) || strcmp(opk, package) || (fp->flags & FmtLong)) {
if(strcmp(opk, pkg) == 0) {
snprint(buf, sizeof(buf), "%s.%s", pkg, nam);
......@@ -948,7 +951,7 @@ static char *basicnames[] = {
[TFLOAT64] "float64",
[TFLOAT80] "float80",
[TBOOL] "bool",
[TSTRING] "string"
[TANY] "any",
};
int
......@@ -956,41 +959,65 @@ Tpretty(Fmt *fp, Type *t)
{
Type *t1;
if(t->etype != TFIELD && t->sym != S && t->sym->name[0] != '_')
if(t->etype != TFIELD
&& t->sym != S
&& t->sym->name[0] != '_'
&& !(fp->flags&FmtLong))
return fmtprint(fp, "%S", t->sym);
if(t->etype < nelem(basicnames) && basicnames[t->etype] != nil)
return fmtprint(fp, "%s", basicnames[t->etype]);
switch(t->etype) {
case TPTR32:
case TPTR64:
if(t->type && t->type->etype == TSTRING)
return fmtprint(fp, "string");
return fmtprint(fp, "*%T", t->type);
case TFUNC:
// t->type is method struct
// t->type->down is result struct
// t->type->down->down is arg struct
if(t->thistuple && !(fp->flags&FmtSharp) && !(fp->flags&FmtShort)) {
fmtprint(fp, "method(");
for(t1=getthisx(t)->type; t1; t1=t1->down) {
fmtprint(fp, "%T", t1);
if(t1->down)
fmtprint(fp, ", ");
}
fmtprint(fp, ")");
}
fmtprint(fp, "(");
for(t1=t->type->down->down->type; t1; t1=t1->down) {
for(t1=getinargx(t)->type; t1; t1=t1->down) {
fmtprint(fp, "%T", t1);
if(t1->down)
fmtprint(fp, ", ");
}
fmtprint(fp, ")");
t1 = t->type->down->type;
if(t1 != T) {
if(t1->down == T && t1->etype != TFIELD)
switch(t->outtuple) {
case 0:
break;
case 1:
t1 = getoutargx(t)->type;
if(t1->etype != TFIELD) {
fmtprint(fp, " %T", t1);
else {
fmtprint(fp, " (");
for(; t1; t1=t1->down) {
fmtprint(fp, "%T", t1);
if(t1->down)
fmtprint(fp, ", ");
}
fmtprint(fp, ")");
break;
}
default:
t1 = getoutargx(t)->type;
fmtprint(fp, " (");
for(; t1; t1=t1->down) {
fmtprint(fp, "%T", t1);
if(t1->down)
fmtprint(fp, ", ");
}
fmtprint(fp, ")");
break;
}
return 0;
case TARRAY:
if(t->bound >= 0)
return fmtprint(fp, "[%d]%T", (int)t->bound, t->type);
......@@ -998,28 +1025,42 @@ Tpretty(Fmt *fp, Type *t)
case TCHAN:
return fmtprint(fp, "chan %T", t->type);
case TMAP:
return fmtprint(fp, "map[%T] %T", t->down, t->type);
case TINTER:
fmtprint(fp, "interface {");
for(t1=t->type; t1!=T; t1=t1->down) {
fmtprint(fp, " %S %T;", t1->sym, t1);
fmtprint(fp, " %hS %hT", t1->sym, t1->type);
if(t1->down)
fmtprint(fp, ";");
}
return fmtprint(fp, " }");
return fmtprint(fp, " }");
case TSTRUCT:
fmtprint(fp, "struct {");
for(t1=t->type; t1!=T; t1=t1->down) {
fmtprint(fp, " %T;", t1);
fmtprint(fp, " %T", t1);
if(t1->down)
fmtprint(fp, ";");
}
return fmtprint(fp, " }");
case TFIELD:
if(t->sym == S || t->sym->name[0] == '_')
if(t->sym == S || t->sym->name[0] == '_') {
if(exporting)
fmtprint(fp, "? ");
return fmtprint(fp, "%T", t->type);
return fmtprint(fp, "%S %T", t->sym, t->type);
}
return fmtprint(fp, "%hS %T", t->sym, t->type);
case TFORW:
if(exporting)
yyerror("undefined type %S", t->sym);
if(t->sym)
return fmtprint(fp, "undefined %S", t->sym);
return fmtprint(fp, "undefined");
}
// Don't know how to handle - fall back to detailed prints.
......@@ -1032,7 +1073,7 @@ Tconv(Fmt *fp)
char buf[500], buf1[500];
Type *t, *t1;
int et;
t = va_arg(fp->args, Type*);
if(t == T)
return fmtstrcpy(fp, "<T>");
......@@ -1417,6 +1458,9 @@ signame(Type *t)
{
Sym *s, *ss;
char *e;
Type *t1;
int n;
char buf[NSYMB];
if(t == T)
goto bad;
......@@ -1437,8 +1481,8 @@ signame(Type *t)
if(t->etype == TINTER)
e = "sigi";
snprint(namebuf, sizeof(namebuf), "%s_%s", e, s->name);
ss = pkglookup(namebuf, s->opackage);
snprint(buf, sizeof(buf), "%s_%s", e, s->name);
ss = pkglookup(buf, s->opackage);
if(ss->oname == N) {
ss->oname = newname(ss);
ss->oname->type = types[TUINT8];
......
......@@ -3,168 +3,80 @@
// license that can be found in the LICENSE file.
package foop // rename to avoid redeclaration
func mal(uint32) *any;
func breakpoint();
func throwindex();
func throwreturn();
func panicl(int32);
func printbool(bool);
func printfloat(double);
func printint(int64);
func printstring(string);
func printpointer(*any);
func printinter(any);
func printnl();
func printsp();
func catstring(string, string) string;
func cmpstring(string, string) int32;
func slicestring(string, int32, int32) string;
func indexstring(string, int32) byte;
func intstring(int64) string;
func byteastring(*byte, int32) string;
func arraystring(*[]byte) string;
func ifaceT2I(sigi *byte, sigt *byte, elem any) (ret any);
func ifaceI2T(sigt *byte, iface any) (ret any);
func ifaceI2I(sigi *byte, iface any) (ret any);
func argc() int32;
func envc() int32;
func argv(int32) string;
func envv(int32) string;
func frexp(float64) (float64, int32); // break fp into exp,fract
func ldexp(float64, int32) float64; // make fp from exp,fract
func modf(float64) (float64, float64); // break fp into double.double
func isInf(float64, int32) bool; // test for infinity
func isNaN(float64) bool; // test for not-a-number
func Inf(int32) float64; // return signed Inf
func NaN() float64; // return a NaN
func newmap(keysize uint32, valsize uint32,
keyalg uint32, valalg uint32,
hint uint32) (hmap *map[any]any);
func mapaccess1(hmap *map[any]any, key any) (val any);
func mapaccess2(hmap *map[any]any, key any) (val any, pres bool);
func mapassign1(hmap *map[any]any, key any, val any);
func mapassign2(hmap *map[any]any, key any, val any, pres bool);
func newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any);
func chanrecv1(hchan *chan any) (elem any);
func chanrecv2(hchan *chan any) (elem any, pres bool);
func chanrecv3(hchan *chan any, elem *any) (pres bool);
func chansend1(hchan *chan any, elem any);
func chansend2(hchan *chan any, elem any) (pres bool);
func newselect(size uint32) (sel *byte);
func selectsend(sel *byte, hchan *chan any, elem any) (selected bool);
func selectrecv(sel *byte, hchan *chan any, elem *any) (selected bool);
func selectgo(sel *byte);
func newarray(nel uint32, cap uint32, width uint32) (ary *[]any);
func arraysliced(old *[]any, lb uint32, hb uint32, width uint32) (ary *[]any);
func arrayslices(old *any, nel uint32, lb uint32, hb uint32, width uint32) (ary *[]any);
func arrays2d(old *any, nel uint32) (ary *[]any);
func gosched();
func goexit();
func readfile(string) (string, bool); // read file into string; boolean status
func writefile(string, string) (bool); // write string into file; boolean status
func bytestorune(*byte, int32, int32) (int32, int32); // convert bytes to runes
func stringtorune(string, int32, int32) (int32, int32); // convert bytes to runes
func exit(int32);
export
mal
breakpoint
throwindex
throwreturn
// print panic
panicl
printbool
printfloat
printint
printstring
printpointer
printinter
printnl
printsp
// op string
catstring
cmpstring
slicestring
indexstring
intstring
byteastring
arraystring
// interface
ifaceT2I
ifaceI2T
ifaceI2I
// args
argc
envc
argv
envv
// fp
frexp
ldexp
modf
isInf,
isNaN,
Inf,
NaN,
// map
newmap
mapaccess1
mapaccess2
mapassign1
mapassign2
// chan
newchan
chanrecv1
chanrecv2
chanrecv3
chansend1
chansend2
// select
newselect
selectsend
selectrecv
selectgo
// dynamic arrays
newarray
arraysliced
arrayslices
arrays2d
// go routines
gosched
goexit
// files
readfile
writefile
// runes and utf-8
bytestorune
stringtorune
// system calls
exit
;
package SYS // rename to avoid redeclaration
export func mal(uint32) *any;
export func breakpoint();
export func throwindex();
export func throwreturn();
export func panicl(int32);
export func printbool(bool);
export func printfloat(double);
export func printint(int64);
export func printstring(string);
export func printpointer(*any);
export func printinter(any);
export func printnl();
export func printsp();
export func catstring(string, string) string;
export func cmpstring(string, string) int32;
export func slicestring(string, int32, int32) string;
export func indexstring(string, int32) byte;
export func intstring(int64) string;
export func byteastring(*byte, int32) string;
export func arraystring(*[]byte) string;
export func ifaceT2I(sigi *byte, sigt *byte, elem any) (ret any);
export func ifaceI2T(sigt *byte, iface any) (ret any);
export func ifaceI2I(sigi *byte, iface any) (ret any);
export func argc() int32;
export func envc() int32;
export func argv(int32) string;
export func envv(int32) string;
export func frexp(float64) (float64, int32); // break fp into exp,fract
export func ldexp(float64, int32) float64; // make fp from exp,fract
export func modf(float64) (float64, float64); // break fp into double.double
export func isInf(float64, int32) bool; // test for infinity
export func isNaN(float64) bool; // test for not-a-number
export func Inf(int32) float64; // return signed Inf
export func NaN() float64; // return a NaN
export func newmap(keysize uint32, valsize uint32,
keyalg uint32, valalg uint32,
hint uint32) (hmap *map[any]any);
export func mapaccess1(hmap *map[any]any, key any) (val any);
export func mapaccess2(hmap *map[any]any, key any) (val any, pres bool);
export func mapassign1(hmap *map[any]any, key any, val any);
export func mapassign2(hmap *map[any]any, key any, val any, pres bool);
export func newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any);
export func chanrecv1(hchan *chan any) (elem any);
export func chanrecv2(hchan *chan any) (elem any, pres bool);
export func chanrecv3(hchan *chan any, elem *any) (pres bool);
export func chansend1(hchan *chan any, elem any);
export func chansend2(hchan *chan any, elem any) (pres bool);
export func newselect(size uint32) (sel *byte);
export func selectsend(sel *byte, hchan *chan any, elem any) (selected bool);
export func selectrecv(sel *byte, hchan *chan any, elem *any) (selected bool);
export func selectgo(sel *byte);
export func newarray(nel uint32, cap uint32, width uint32) (ary *[]any);
export func arraysliced(old *[]any, lb uint32, hb uint32, width uint32) (ary *[]any);
export func arrayslices(old *any, nel uint32, lb uint32, hb uint32, width uint32) (ary *[]any);
export func arrays2d(old *any, nel uint32) (ary *[]any);
export func gosched();
export func goexit();
export func readfile(string) (string, bool); // read file into string; boolean status
export func writefile(string, string) (bool); // write string into file; boolean status
export func bytestorune(*byte, int32, int32) (int32, int32); // convert bytes to runes
export func stringtorune(string, int32, int32) (int32, int32); // convert bytes to runes
export func exit(int32);
This diff is collapsed.
=========== ./func3.go
BUG: errchk func3
BUG: errchk: func3.go: missing expected error message on line 14: 'type'
=========== ./helloworld.go
......@@ -58,7 +57,7 @@ bugs/bug020.go:7: type of a structure field cannot be an open array
BUG should compile
=========== bugs/bug026.go
sys·printstring: main·sigs_I: not defined
sys·printnl: main·sigt_I: not defined
BUG: known to fail incorrectly
=========== bugs/bug032.go
......@@ -74,11 +73,11 @@ BUG: map increment
=========== bugs/bug064.go
bugs/bug064.go:15: illegal types for operand: CALL
int32
struct { u int32; v int32; }
struct { u int32; v int32 }
BUG: compilation should succeed
=========== bugs/bug074.go
bugs/bug074.go:6: syntax error
bugs/bug074.go:6: syntax error near string
bugs/bug074.go:7: x: undefined
BUG: compiler crashes - Bus error
......@@ -91,7 +90,7 @@ BUG: succeeds incorrectly
=========== bugs/bug080.go
bugs/bug080.go:12: illegal types for operand: CALL
int32
struct { x int32; y float32; }
struct { x int32; y float32 }
BUG: fails incorrectly
=========== bugs/bug083.go
......@@ -115,19 +114,19 @@ M
=========== bugs/bug094.go
bugs/bug094.go:11: left side of := must be a name
bad top
. LITERAL-I0 l(369)
. LITERAL-I0 l(81)
bugs/bug094.go:11: fatal error: walktype: top=3 LITERAL
BUG: fails incorrectly
=========== bugs/bug095.go
found 2, expected 1
panic on line 368 PC=xxx
panic on line 80 PC=xxx
BUG wrong result
=========== bugs/bug097.go
panic on line 370 PC=xxx
panic on line 82 PC=xxx
BUG wrong result
=========== bugs/bug098.go
......@@ -164,7 +163,7 @@ BUG: should compile
fixedbugs/bug016.go:7: overflow converting constant to uint32
=========== fixedbugs/bug025.go
fixedbugs/bug025.go:7: variable exported but not defined: Foo
fixedbugs/bug025.go:7: variable exported but not defined: main.Foo
=========== fixedbugs/bug027.go
hi
......@@ -181,8 +180,8 @@ hi
=========== fixedbugs/bug029.go
fixedbugs/bug029.go:6: f is not a type
fixedbugs/bug029.go:6: syntax error
fixedbugs/bug029.go:6: syntax error
fixedbugs/bug029.go:6: syntax error near func
fixedbugs/bug029.go:6: syntax error near int
=========== fixedbugs/bug035.go
fixedbugs/bug035.go:6: var i redeclared in this block
......@@ -192,7 +191,7 @@ fixedbugs/bug035.go:7: var f redeclared in this block
=========== fixedbugs/bug037.go
fixedbugs/bug037.go:6: vlong: undefined
fixedbugs/bug037.go:6: fatal error: addvar: n=NAME-s G0 a(1) l(364) t=<T> nil
fixedbugs/bug037.go:6: fatal error: addvar: n=NAME-s G0 a(1) l(76) t=<T> nil
=========== fixedbugs/bug039.go
fixedbugs/bug039.go:6: var x redeclared in this block
......@@ -203,7 +202,7 @@ fixedbugs/bug049.go:6: illegal conversion of constant to string
=========== fixedbugs/bug050.go
fixedbugs/bug050.go:3: package statement must be first
sys.6:1 fixedbugs/bug050.go:3: syntax error
sys.6:1 fixedbugs/bug050.go:3: syntax error near package
=========== fixedbugs/bug051.go
fixedbugs/bug051.go:10: expression must be a constant
......@@ -241,7 +240,7 @@ fixedbugs/bug073.go:9: illegal types for operand: RSH
int32
=========== fixedbugs/bug081.go
fixedbugs/bug081.go:5: syntax error
fixedbugs/bug081.go:5: syntax error near x
=========== fixedbugs/bug086.go
fixedbugs/bug086.go:5: function ends without a return statement
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment