| 
									
										
										
										
											2008-07-15 15:37:14 -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 Exporter | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | import Platform "platform" | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | import Utils "utils" | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | import Globals "globals" | 
					
						
							|  |  |  | import Object "object" | 
					
						
							|  |  |  | import Type "type" | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | import Universe "universe" | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Exporter struct { | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	comp *Globals.Compilation; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	debug bool; | 
					
						
							|  |  |  | 	buf [4*1024] byte; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	buf_pos int; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	pkg_ref int; | 
					
						
							|  |  |  | 	type_ref int; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WriteObject(obj *Globals.Object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WriteByte(x byte) { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	E.buf[E.buf_pos] = x; | 
					
						
							|  |  |  | 	E.buf_pos++; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	/* | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print(" ", x); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WriteInt(x int) { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	x0 := x; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	for x < -64 || x >= 64 { | 
					
						
							|  |  |  | 		E.WriteByte(byte(x & 127)); | 
					
						
							|  |  |  | 		x = int(uint(x >> 7));  // arithmetic shift | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// -64 <= x && x < 64 | 
					
						
							|  |  |  | 	E.WriteByte(byte(x + 192)); | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print(" #", x0); | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WriteString(s string) { | 
					
						
							|  |  |  | 	n := len(s); | 
					
						
							|  |  |  | 	E.WriteInt(n); | 
					
						
							|  |  |  | 	for i := 0; i < n; i++ { | 
					
						
							|  |  |  | 		E.WriteByte(s[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print(` "`, s, `"`); | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (E *Exporter) WritePackageTag(tag int) { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	E.WriteInt(tag); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		if tag >= 0 { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			print(" [P", tag, "]");  // package ref | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			print("\nP", E.pkg_ref, ":"); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WriteTypeTag(tag int) { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	E.WriteInt(tag); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 		if tag >= 0 { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			print(" [T", tag, "]");  // type ref | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			print("\nT", E.type_ref, ": ", Type.FormStr(-tag)); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (E *Exporter) WriteObjectTag(tag int) { | 
					
						
							|  |  |  | 	if tag < 0 { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		panic("tag < 0"); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	E.WriteInt(tag); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print("\n", Object.KindStr(tag)); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WritePackage(pkg *Globals.Package) { | 
					
						
							|  |  |  | 	if E.comp.pkg_list[pkg.obj.pnolev] != pkg { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		panic("inconsistent package object"); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if pkg.ref >= 0 { | 
					
						
							|  |  |  | 		E.WritePackageTag(pkg.ref);  // package already exported | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	E.WritePackageTag(-1); | 
					
						
							|  |  |  | 	pkg.ref = E.pkg_ref; | 
					
						
							|  |  |  | 	E.pkg_ref++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	E.WriteString(pkg.obj.ident); | 
					
						
							|  |  |  | 	E.WriteString(pkg.file_name); | 
					
						
							|  |  |  | 	E.WriteString(pkg.key); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (E *Exporter) WriteScope(scope *Globals.Scope) { | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print(" {"); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for p := scope.entries.first; p != nil; p = p.next { | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 		if p.obj.exported { | 
					
						
							|  |  |  | 			E.WriteObject(p.obj); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | 	E.WriteObject(nil); | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print(" }"); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (E *Exporter) WriteType(typ *Globals.Type) { | 
					
						
							|  |  |  | 	if typ.ref >= 0 { | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 		E.WriteTypeTag(typ.ref);  // type already exported | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	if -typ.form >= 0 { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		panic("conflict with ref numbers"); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	E.WriteTypeTag(-typ.form); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	typ.ref = E.type_ref; | 
					
						
							|  |  |  | 	E.type_ref++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	// if we have a named type, export the type identifier and package | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	ident := ""; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	if typ.obj != nil { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		// named type | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 		if typ.obj.typ != typ { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			panic("inconsistent named type"); | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		ident = typ.obj.ident; | 
					
						
							|  |  |  | 		if !typ.obj.exported { | 
					
						
							|  |  |  | 			// the type is invisible (it's identifier is not exported) | 
					
						
							|  |  |  | 			// prepend "." to the identifier to make it an illegal | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 			// identifier for importing packages and thus inaccessible | 
					
						
							|  |  |  | 			// from those package's source code | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 			ident = "." + ident; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	E.WriteString(ident); | 
					
						
							|  |  |  | 	if len(ident) > 0 { | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		// named type | 
					
						
							|  |  |  | 		E.WritePackage(E.comp.pkg_list[typ.obj.pnolev]); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	switch typ.form { | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | 	case Type.FORWARD: | 
					
						
							|  |  |  | 		// corresponding package must be forward-declared too | 
					
						
							|  |  |  | 		if typ.obj == nil || E.comp.pkg_list[typ.obj.pnolev].key != "" { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			panic("inconsistency in package.type forward declaration"); | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 	case Type.ALIAS, Type.MAP: | 
					
						
							|  |  |  | 		E.WriteType(typ.aux); | 
					
						
							| 
									
										
										
										
											2008-07-31 10:47:10 -07:00
										 |  |  | 		E.WriteType(typ.elt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	case Type.ARRAY: | 
					
						
							|  |  |  | 		E.WriteInt(typ.len_); | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 		E.WriteType(typ.elt); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case Type.CHANNEL: | 
					
						
							|  |  |  | 		E.WriteInt(typ.flags); | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 		E.WriteType(typ.elt); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case Type.FUNCTION: | 
					
						
							|  |  |  | 		E.WriteInt(typ.flags); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		E.WriteScope(typ.scope); | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 		 | 
					
						
							|  |  |  | 	case Type.STRUCT, Type.INTERFACE: | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		E.WriteScope(typ.scope); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-23 16:04:11 -07:00
										 |  |  | 	case Type.POINTER, Type.REFERENCE: | 
					
						
							|  |  |  | 		E.WriteType(typ.elt); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		panic("UNREACHABLE"); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | func (E *Exporter) WriteObject(obj *Globals.Object) { | 
					
						
							|  |  |  | 	if obj == nil { | 
					
						
							|  |  |  | 		E.WriteObjectTag(Object.END); | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2008-07-31 10:47:10 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	E.WriteObjectTag(obj.kind); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if obj.kind == Object.TYPE { | 
					
						
							|  |  |  | 		// named types are handled entirely by WriteType() | 
					
						
							|  |  |  | 		if obj.typ.obj != obj { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 			panic("inconsistent named type"); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		E.WriteType(obj.typ); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	E.WriteString(obj.ident); | 
					
						
							|  |  |  | 	E.WriteType(obj.typ); | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	switch obj.kind { | 
					
						
							|  |  |  | 	case Object.CONST: | 
					
						
							|  |  |  | 		E.WriteInt(0);  // should be the correct value | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 20:40:37 -07:00
										 |  |  | 	case Object.VAR, Object.FIELD: | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 		E.WriteInt(0);  // should be the correct address/offset | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	case Object.FUNC: | 
					
						
							|  |  |  | 		E.WriteInt(0);  // should be the correct address/offset | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		panic("UNREACHABLE"); | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | func (E *Exporter) Export(comp* Globals.Compilation) string { | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 	E.comp = comp; | 
					
						
							|  |  |  | 	E.debug = comp.flags.debug; | 
					
						
							|  |  |  | 	E.buf_pos = 0; | 
					
						
							|  |  |  | 	E.pkg_ref = 0; | 
					
						
							|  |  |  | 	E.type_ref = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// write magic bits | 
					
						
							|  |  |  | 	magic := Platform.MAGIC_obj_file;  // TODO remove once len(constant) works | 
					
						
							|  |  |  | 	for i := 0; i < len(magic); i++ { | 
					
						
							|  |  |  | 		E.WriteByte(magic[i]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// Predeclared types are "pre-exported". | 
					
						
							|  |  |  | 	// TODO run the loop below only in debug mode | 
					
						
							|  |  |  | 	{	i := 0; | 
					
						
							|  |  |  | 		for p := Universe.types.first; p != nil; p = p.next { | 
					
						
							|  |  |  | 			if p.typ.ref != i { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 				panic("incorrect ref for predeclared type"); | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	E.type_ref = Universe.types.len_; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// export package 0 | 
					
						
							|  |  |  | 	pkg := comp.pkg_list[0]; | 
					
						
							|  |  |  | 	E.WritePackage(pkg); | 
					
						
							|  |  |  | 	E.WriteScope(pkg.scope); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if E.debug { | 
					
						
							| 
									
										
										
										
											2008-08-11 21:20:42 -07:00
										 |  |  | 		print("\n(", E.buf_pos, " bytes)\n"); | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return string(E.buf)[0 : E.buf_pos]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | export func Export(comp* Globals.Compilation) string { | 
					
						
							| 
									
										
										
										
											2008-08-11 09:45:40 -07:00
										 |  |  | 	var E Exporter; | 
					
						
							| 
									
										
										
										
											2008-08-11 18:44:41 -07:00
										 |  |  | 	return (&E).Export(comp); | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | } |