importpkg->name = $2->name;
importpkg->direct = 1;
- // PGNS: fixme
+ // NOTE(rsc): This is no longer a technical restriction:
+ // the 6g tool chain would work just fine without giving
+ // special meaning to a package being named main.
+ // Other implementations might need the restriction
+ // (gccgo does), so it stays in the language and the compiler.
if(strcmp($2->name, "main") == 0)
yyerror("cannot import package main");
-
- // PGNS: This should go away once we get
- // rid of the global package name space.
- if(localpkg->name && strcmp($2->name, localpkg->name) == 0 && !compiling_runtime)
- yyerror("package cannot import itself");
}
import_there:
Strlit *path;
char cleanbuf[1024];
- // TODO(rsc): don't bother reloading imports more than once
-
- // PGNS: canonicalize import path for ./ imports in findpkg.
+ // TODO(rsc): don't bother reloading imports more than once?
if(f->ctype != CTSTR) {
yyerror("import statement not a string");
void
ldpkg(Biobuf *f, char *pkg, int64 len, char *filename)
{
- char *data, *p0, *p1;
+ char *data, *p0, *p1, *name;
if(debug['g'])
return;
return;
}
p0 += 8;
- while(*p0 == ' ' || *p0 == '\t' || *p0 == '\n')
+ while(p0 < p1 && *p0 == ' ' || *p0 == '\t' || *p0 == '\n')
p0++;
- while(*p0 != ' ' && *p0 != '\t' && *p0 != '\n')
+ name = p0;
+ while(p0 < p1 && *p0 != ' ' && *p0 != '\t' && *p0 != '\n')
p0++;
+ if(p0 < p1) {
+ *p0++ = '\0';
+ if(strcmp(pkg, "main") == 0 && strcmp(name, "main") != 0)
+ fprint(2, "%s: %s: not package main (package %s)\n", argv0, filename, name);
+ else if(strcmp(pkg, "main") != 0 && strcmp(name, "main") == 0)
+ fprint(2, "%s: %s: importing %s, found package main", argv0, filename, pkg);
+ }
loadpkgdata(filename, pkg, p0, p1 - p0);
}
return;
}
- // PGNS: Should be using import path, not pkg.
loadpkgdata(filename, pkg, p0, p1 - p0);
// look for dynld section