| 
									
										
										
										
											2008-07-10 17:21:23 -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. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 18:05:00 -07:00
										 |  |  | package Globals | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The following types should really be in their respective files | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | // (object.go, type.go, scope.go, package.go, compilation.go, etc.) but | 
					
						
							| 
									
										
										
										
											2008-07-17 15:11:46 -07:00
										 |  |  | // they refer to each other and we don't know how to handle forward | 
					
						
							|  |  |  | // declared pointers across packages yet. | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Object struct { | 
					
						
							| 
									
										
										
										
											2008-07-29 12:03:06 -07:00
										 |  |  | 	exported bool; | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | 	pos int;  // source position (< 0 if unknown position) | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 	kind int; | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	ident string; | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	typ *Type;  // nil for packages | 
					
						
							|  |  |  | 	pnolev int;  // >= 0: package no., <= 0: function nesting level, 0: global level | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Type struct { | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 	ref int;  // for exporting only: >= 0 means already exported | 
					
						
							|  |  |  | 	form int; | 
					
						
							|  |  |  | 	flags int;  // channels, functions | 
					
						
							|  |  |  | 	size int;  // in bytes | 
					
						
							|  |  |  | 	len_ int;  // array length, no. of parameters (w/o recv) | 
					
						
							|  |  |  | 	obj *Object;  // primary type object or NULL | 
					
						
							| 
									
										
										
										
											2008-08-05 15:20:58 -07:00
										 |  |  | 	aux *Type;  // alias base type or map key | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 	elt *Type;  // aliases, arrays, maps, channels, pointers | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	scope *Scope;  // structs, interfaces, functions | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Package struct { | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	ref int;  // for exporting only: >= 0 means already exported | 
					
						
							|  |  |  | 	file_name string; | 
					
						
							|  |  |  | 	key string; | 
					
						
							|  |  |  | 	obj *Object; | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	scope *Scope;  // holds the (global) objects in this package | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type List struct { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	len_ int; | 
					
						
							|  |  |  | 	first, last *Elem; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Scope struct { | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 	parent *Scope; | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	entries *List; | 
					
						
							| 
									
										
										
										
											2008-07-15 19:59:00 -07:00
										 |  |  | 	// entries *map[string] *Object;  // doesn't work properly | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Flags struct { | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	debug bool; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	print_export bool; | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	semantic_checks bool; | 
					
						
							|  |  |  | 	verbose int; | 
					
						
							| 
									
										
										
										
											2008-07-30 21:26:15 -07:00
										 |  |  | 	sixg bool; | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Compilation struct { | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	flags *Flags; | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	// TODO use open arrays eventually | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	pkg_list [256] *Package;  // pkg_list[0] is the current package | 
					
						
							|  |  |  | 	pkg_ref int; | 
					
						
							| 
									
										
										
										
											2008-07-17 15:11:46 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Expr interface { | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 	typ() *Type; | 
					
						
							|  |  |  | 	// ... more to come here | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export type Stat interface { | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 	// ... more to come here | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-05 18:52:37 -07:00
										 |  |  | // TODO This is hideous! We need to have a decent way to do lists. | 
					
						
							|  |  |  | // Ideally open arrays that allow '+'. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Elem struct { | 
					
						
							|  |  |  | 	next *Elem; | 
					
						
							|  |  |  | 	val int; | 
					
						
							|  |  |  | 	str string; | 
					
						
							|  |  |  | 	obj *Object; | 
					
						
							|  |  |  | 	typ *Type; | 
					
						
							|  |  |  | 	expr Expr | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | // ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | // Creation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | export var Universe_undef_t *Type  // initialized by Universe to Universe.undef_t | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func NewObject(pos, kind int, ident string) *Object { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	obj := new(Object); | 
					
						
							| 
									
										
										
										
											2008-07-29 12:03:06 -07:00
										 |  |  | 	obj.exported = false; | 
					
						
							| 
									
										
										
										
											2008-07-15 15:37:14 -07:00
										 |  |  | 	obj.pos = pos; | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	obj.kind = kind; | 
					
						
							|  |  |  | 	obj.ident = ident; | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 	obj.typ = Universe_undef_t; | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	obj.pnolev = 0; | 
					
						
							|  |  |  | 	return obj; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func NewType(form int) *Type { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	typ := new(Type); | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 	typ.ref = -1;  // not yet exported | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	typ.form = form; | 
					
						
							|  |  |  | 	return typ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func NewPackage(file_name string, obj *Object, scope *Scope) *Package { | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	pkg := new(Package); | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | 	pkg.ref = -1;  // not yet exported | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	pkg.file_name = file_name; | 
					
						
							| 
									
										
										
										
											2008-07-18 14:04:21 -07:00
										 |  |  | 	pkg.key = "<the package key>";  // TODO fix this | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	pkg.obj = obj; | 
					
						
							| 
									
										
										
										
											2008-08-04 13:27:05 -07:00
										 |  |  | 	pkg.scope = scope; | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	return pkg; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func NewList() *List { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	return new(List); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func NewScope(parent *Scope) *Scope { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	scope := new(Scope); | 
					
						
							|  |  |  | 	scope.parent = parent; | 
					
						
							|  |  |  | 	scope.entries = NewList(); | 
					
						
							|  |  |  | 	return scope; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func NewCompilation(flags *Flags) *Compilation { | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	comp := new(Compilation); | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	comp.flags = flags; | 
					
						
							| 
									
										
										
										
											2008-07-17 18:02:10 -07:00
										 |  |  | 	return comp; | 
					
						
							| 
									
										
										
										
											2008-07-17 14:53:13 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-31 13:35:30 -07:00
										 |  |  | // ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | // Object methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (obj *Object) Copy() *Object { | 
					
						
							|  |  |  | 	copy := new(Object); | 
					
						
							|  |  |  | 	copy.exported = obj.exported; | 
					
						
							|  |  |  | 	copy.pos = obj.pos; | 
					
						
							|  |  |  | 	copy.kind = obj.kind; | 
					
						
							|  |  |  | 	copy.ident = obj.ident; | 
					
						
							|  |  |  | 	copy.typ = obj.typ; | 
					
						
							|  |  |  | 	copy.pnolev = obj.pnolev; | 
					
						
							|  |  |  | 	return copy; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | // ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | // List methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (L* List) len_() int { | 
					
						
							|  |  |  | 	return L.len_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (L *List) at(i int) *Elem { | 
					
						
							|  |  |  | 	if i < 0 || L.len_ <= i { | 
					
						
							|  |  |  | 		panic "index out of bounds"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p := L.first; | 
					
						
							|  |  |  | 	for ; i > 0; i-- { | 
					
						
							|  |  |  | 		p = p.next; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	return p; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 09:35:03 -07:00
										 |  |  | func (L *List) Clear() { | 
					
						
							|  |  |  | 	L.len_, L.first, L.last = 0, nil, nil; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | func (L *List) Add() *Elem { | 
					
						
							|  |  |  | 	L.len_++; | 
					
						
							|  |  |  | 	e := new(Elem); | 
					
						
							|  |  |  | 	if L.first == nil { | 
					
						
							|  |  |  | 		L.first = e; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		L.last.next = e; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	L.last = e; | 
					
						
							|  |  |  | 	return e; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-25 09:35:03 -07:00
										 |  |  | func (L *List) IntAt(i int) int { | 
					
						
							|  |  |  | 	return L.at(i).val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | func (L *List) StrAt(i int) string { | 
					
						
							|  |  |  | 	return L.at(i).str; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (L *List) ObjAt(i int) *Object { | 
					
						
							|  |  |  | 	return L.at(i).obj; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (L *List) TypAt(i int) *Type { | 
					
						
							|  |  |  | 	return L.at(i).typ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-24 17:00:58 -07:00
										 |  |  | func (L *List) AddInt(val int) { | 
					
						
							|  |  |  | 	L.Add().val = val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | func (L *List) AddStr(str string) { | 
					
						
							|  |  |  | 	L.Add().str = str; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (L *List) AddObj(obj *Object) { | 
					
						
							|  |  |  | 	L.Add().obj = obj; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (L *List) AddTyp(typ *Type) { | 
					
						
							|  |  |  | 	L.Add().typ = typ; | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-05 18:52:37 -07:00
										 |  |  | func (L *List) AddExpr(expr Expr) { | 
					
						
							|  |  |  | 	L.Add().expr = expr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | // ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | // Scope methods | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | func (scope *Scope) Lookup(ident string) *Object { | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | 	for p := scope.entries.first; p != nil; p = p.next { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 		if p.obj.ident == ident { | 
					
						
							|  |  |  | 			return p.obj; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | 	return nil; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (scope *Scope) Insert(obj *Object) { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	if scope.Lookup(obj.ident) != nil { | 
					
						
							| 
									
										
										
										
											2008-07-14 18:06:41 -07:00
										 |  |  | 		panic "obj already inserted"; | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	scope.entries.AddObj(obj); | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (scope *Scope) InsertImport(obj *Object) *Object { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 	 p := scope.Lookup(obj.ident); | 
					
						
							|  |  |  | 	 if p == nil { | 
					
						
							|  |  |  | 		scope.Insert(obj); | 
					
						
							|  |  |  | 		p = obj; | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | 	 return p; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (scope *Scope) Print() { | 
					
						
							|  |  |  | 	print "scope {"; | 
					
						
							| 
									
										
										
										
											2008-08-01 13:33:31 -07:00
										 |  |  | 	for p := scope.entries.first; p != nil; p = p.next { | 
					
						
							| 
									
										
										
										
											2008-07-14 16:57:42 -07:00
										 |  |  | 		print "\n  ", p.obj.ident; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	print "\n}\n"; | 
					
						
							| 
									
										
										
										
											2008-07-10 17:21:23 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2008-07-17 15:11:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ---------------------------------------------------------------------------- | 
					
						
							|  |  |  | // Compilation methods | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (C *Compilation) Lookup(file_name string) *Package { | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	for i := 0; i < C.pkg_ref; i++ { | 
					
						
							|  |  |  | 		pkg := C.pkg_list[i]; | 
					
						
							| 
									
										
										
										
											2008-07-17 15:11:46 -07:00
										 |  |  | 		if pkg.file_name == file_name { | 
					
						
							|  |  |  | 			return pkg; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (C *Compilation) Insert(pkg *Package) { | 
					
						
							|  |  |  | 	if C.Lookup(pkg.file_name) != nil { | 
					
						
							|  |  |  | 		panic "package already inserted"; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-04 10:19:36 -07:00
										 |  |  | 	pkg.obj.pnolev = C.pkg_ref; | 
					
						
							|  |  |  | 	C.pkg_list[C.pkg_ref] = pkg; | 
					
						
							|  |  |  | 	C.pkg_ref++; | 
					
						
							| 
									
										
										
										
											2008-07-17 15:11:46 -07:00
										 |  |  | } |