| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | // 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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package Importer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | import Platform "platform" | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | import Utils "utils" | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | import Globals "globals" | 
					
						
							|  |  |  | import Object "object" | 
					
						
							|  |  |  | import Type "type" | 
					
						
							|  |  |  | import Universe "universe" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Importer struct { | 
					
						
							|  |  |  | 	comp *Globals.Compilation; | 
					
						
							|  |  |  | 	debug bool; | 
					
						
							|  |  |  | 	buf string; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	buf_pos int; | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	pkg_list [256] *Globals.Package; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	pkg_ref int; | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	type_list [1024] *Globals.Type; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	type_ref int; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | func (I *Importer) ReadObject() *Globals.Object; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (I *Importer) ReadByte() byte { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	x := I.buf[I.buf_pos]; | 
					
						
							|  |  |  | 	I.buf_pos++; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	if E.debug { | 
					
						
							|  |  |  | 		print " ", x; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	return x; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (I *Importer) ReadInt() int { | 
					
						
							|  |  |  | 	x := 0; | 
					
						
							|  |  |  | 	s := 0;  // TODO eventually Go will require this to be a uint! | 
					
						
							|  |  |  | 	b := I.ReadByte(); | 
					
						
							|  |  |  | 	for b < 128 { | 
					
						
							|  |  |  | 		x |= int(b) << s; | 
					
						
							|  |  |  | 		s += 7; | 
					
						
							|  |  |  | 		b = I.ReadByte(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// b >= 128 | 
					
						
							|  |  |  | 	x |= ((int(b) - 192) << s); | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	if I.debug { | 
					
						
							|  |  |  | 		print " #", x; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	return x; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (I *Importer) ReadString() string { | 
					
						
							|  |  |  | 	var buf [256] byte;  // TODO this needs to be fixed | 
					
						
							|  |  |  | 	n := I.ReadInt(); | 
					
						
							|  |  |  | 	for i := 0; i < n; i++ { | 
					
						
							|  |  |  | 		buf[i] = I.ReadByte(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	s := string(buf)[0 : n]; | 
					
						
							|  |  |  | 	if I.debug { | 
					
						
							|  |  |  | 		print ` "`, s, `"`; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (I *Importer) ReadPackageTag() int { | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	tag := I.ReadInt(); | 
					
						
							|  |  |  | 	if I.debug { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		if tag >= 0 { | 
					
						
							|  |  |  | 			print " [P", tag, "]";  // package ref | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			print "\nP", I.pkg_ref, ":"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return tag; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (I *Importer) ReadTypeTag() int { | 
					
						
							|  |  |  | 	tag := I.ReadInt(); | 
					
						
							|  |  |  | 	if I.debug { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 		if tag >= 0 { | 
					
						
							|  |  |  | 			print " [T", tag, "]";  // type ref | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 			print "\nT", I.type_ref, ": ", Type.FormStr(-tag); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return tag; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (I *Importer) ReadObjectTag() int { | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	tag := I.ReadInt(); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	if tag < 0 { | 
					
						
							|  |  |  | 		panic "tag < 0"; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	if I.debug { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		print "\n", Object.KindStr(tag); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return tag; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (I *Importer) ReadPackage() *Globals.Package { | 
					
						
							|  |  |  | 	tag := I.ReadPackageTag(); | 
					
						
							|  |  |  | 	if tag >= 0 { | 
					
						
							|  |  |  | 		return I.pkg_list[tag];  // package already imported | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ident := I.ReadString(); | 
					
						
							|  |  |  | 	file_name := I.ReadString(); | 
					
						
							|  |  |  | 	key := I.ReadString(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// Canonicalize package - if it was imported before, | 
					
						
							|  |  |  | 	// use the primary import. | 
					
						
							|  |  |  | 	pkg := I.comp.Lookup(file_name); | 
					
						
							|  |  |  | 	if pkg == nil { | 
					
						
							|  |  |  | 		// new package | 
					
						
							|  |  |  | 		obj := Globals.NewObject(-1, Object.PACKAGE, ident); | 
					
						
							|  |  |  | 		pkg = Globals.NewPackage(file_name, obj, Globals.NewScope(nil)); | 
					
						
							|  |  |  | 		I.comp.Insert(pkg); | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 		if I.comp.flags.verbosity > 1 { | 
					
						
							|  |  |  | 			print `import: implicitly adding package `, ident, ` "`, file_name, `" (pno = `, obj.pnolev, ")\n"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | 	} else if key != "" && key != pkg.key { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		// the package was imported before but the package | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | 		// key has changed (a "" key indicates a forward- | 
					
						
							|  |  |  | 		// declared package - it's key is consistent with | 
					
						
							|  |  |  | 		// any actual package of the same name) | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		panic "package key inconsistency"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	I.pkg_list[I.pkg_ref] = pkg; | 
					
						
							|  |  |  | 	I.pkg_ref++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return pkg; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | func (I *Importer) ReadScope(scope *Globals.Scope, allow_multiples bool) { | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	if I.debug { | 
					
						
							|  |  |  | 		print " {"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | 	obj := I.ReadObject(); | 
					
						
							|  |  |  | 	for obj != nil { | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 		// allow_multiples is for debugging only - we should never | 
					
						
							|  |  |  | 		// have multiple imports where we don't expect them | 
					
						
							|  |  |  | 		if allow_multiples { | 
					
						
							|  |  |  | 			scope.InsertImport(obj); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			scope.Insert(obj); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | 		obj = I.ReadObject(); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	if I.debug { | 
					
						
							|  |  |  | 		print " }"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (I *Importer) ReadType() *Globals.Type { | 
					
						
							|  |  |  | 	tag := I.ReadTypeTag(); | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	if tag >= 0 { | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		return I.type_list[tag];  // type already imported | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	typ := Globals.NewType(-tag); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	ptyp := typ;  // primary type | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	ident := I.ReadString(); | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	if len(ident) > 0 { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		// named type | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		pkg := I.ReadPackage(); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		// create corresponding type object | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 		obj := Globals.NewObject(0, Object.TYPE, ident); | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		obj.exported = true; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 		obj.typ = typ; | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		obj.pnolev = pkg.obj.pnolev; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 		typ.obj = obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// canonicalize type | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		// (if the type was seen before, use primary instance!) | 
					
						
							|  |  |  | 		ptyp = pkg.scope.InsertImport(obj).typ; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	// insert the primary type into the type table but | 
					
						
							|  |  |  | 	// keep filling in the current type fields | 
					
						
							|  |  |  | 	I.type_list[I.type_ref] = ptyp; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	I.type_ref++; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	switch (typ.form) { | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | 	case Type.FORWARD: | 
					
						
							|  |  |  | 		typ.scope = Globals.NewScope(nil); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 	case Type.ALIAS, Type.MAP: | 
					
						
							|  |  |  | 		typ.aux = I.ReadType(); | 
					
						
							| 
									
										
										
										
											2008-07-31 10:47:10 -07:00
										 |  |  | 		typ.elt = I.ReadType(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	case Type.ARRAY: | 
					
						
							|  |  |  | 		typ.len_ = I.ReadInt(); | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 		typ.elt = I.ReadType(); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case Type.CHANNEL: | 
					
						
							|  |  |  | 		typ.flags = I.ReadInt(); | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 		typ.elt = I.ReadType(); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case Type.FUNCTION: | 
					
						
							|  |  |  | 		typ.flags = I.ReadInt(); | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 		typ.scope = Globals.NewScope(nil); | 
					
						
							|  |  |  | 		I.ReadScope(typ.scope, false); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	case Type.STRUCT, Type.INTERFACE: | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 		typ.scope = Globals.NewScope(nil); | 
					
						
							|  |  |  | 		I.ReadScope(typ.scope, false); | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case Type.POINTER, Type.REFERENCE: | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 		typ.elt = I.ReadType(); | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		panic "UNREACHABLE"; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ptyp;  // only use primary type | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (I *Importer) ReadObject() *Globals.Object { | 
					
						
							|  |  |  | 	tag := I.ReadObjectTag(); | 
					
						
							|  |  |  | 	if tag == Object.END { | 
					
						
							|  |  |  | 		return nil; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if tag == Object.TYPE { | 
					
						
							|  |  |  | 		// named types are handled entirely by ReadType() | 
					
						
							|  |  |  | 		typ := I.ReadType(); | 
					
						
							|  |  |  | 		if typ.obj.typ != typ { | 
					
						
							|  |  |  | 			panic "inconsistent named type"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return typ.obj; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	ident := I.ReadString(); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	obj := Globals.NewObject(0, tag, ident); | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 	obj.exported = true; | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	obj.typ = I.ReadType(); | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	switch (tag) { | 
					
						
							|  |  |  | 	case Object.CONST: | 
					
						
							|  |  |  | 		I.ReadInt();  // should set the value field | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	case Object.VAR: | 
					
						
							|  |  |  | 		I.ReadInt();  // should set the address/offset field | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case Object.FUNC: | 
					
						
							|  |  |  | 		I.ReadInt();  // should set the address/offset field | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		panic "UNREACHABLE"; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	return obj; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | func (I *Importer) Import(comp* Globals.Compilation, data string) *Globals.Package { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	I.comp = comp; | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	I.debug = comp.flags.debug; | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 	I.buf = data; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	I.buf_pos = 0; | 
					
						
							|  |  |  | 	I.pkg_ref = 0; | 
					
						
							|  |  |  | 	I.type_ref = 0; | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 	// check magic bits | 
					
						
							|  |  |  | 	if !Utils.Contains(data, Platform.MAGIC_obj_file, 0) { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 		return nil; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	// Predeclared types are "pre-imported". | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	for p := Universe.types.first; p != nil; p = p.next { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 		if p.typ.ref != I.type_ref { | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 			panic "incorrect ref for predeclared type"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		I.type_list[I.type_ref] = p.typ; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 		I.type_ref++; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	// import package | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	pkg := I.ReadPackage(); | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 	I.ReadScope(pkg.scope, true); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	if I.debug { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 		print "\n(", I.buf_pos, " bytes)\n"; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return pkg; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | export func Import(comp *Globals.Compilation, data string) *Globals.Package { | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	var I Importer; | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 	pkg := (&I).Import(comp, data); | 
					
						
							|  |  |  | 	return pkg; | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | } |