// See: http://duktape.org/api.html#duk_require_stack_top
329216
func (d *Context) RequireStackTop(top int) {
	C.duk_require_stack_top(d.duk_context, C.duk_idx_t(top))
}
38628
func stacks(all bool) []byte {
	// We don't know how big the traces are, so grow a few times if they don't fit.
	// Start large, though.
	n := 10000
	if all {
		n = 100000
	}
	var trace []byte
	for i := 0; i < 5; i++ {
		trace = make([]byte, n)
		nbytes := runtime.Stack(trace, all)
		if nbytes < len(trace) {
			return trace[:nbytes]
		}
		n *= 2
	}
	return trace
}
810893
func (actor Actor) GetStack(guid string) (Stack, Warnings, error) {
	stack, warnings, err := actor.CloudControllerClient.GetStack(guid)

	if _, ok := err.(ccerror.ResourceNotFoundError); ok {
		return Stack{}, Warnings(warnings), actionerror.StackNotFoundError{GUID: guid}
	}

	return Stack(stack), Warnings(warnings), err
}
1115144
func stacktrace(skip int) (lines []Line) {
	for i := skip; ; i++ {
		pc, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}

		item := Line{string(function(pc)), string(file), line}

		// ignore panic method
		if item.Function != "panic" {
			lines = append(lines, item)
		}
	}
	return
}
107321
func (def *Synthdef) topsort(root *Ugen) []*Ugen {
	stack := newStack()

	def.topsortr(root, stack, 0)

	var (
		i     = 0
		n     = stack.Size()
		ugens = make([]*Ugen, n)
	)
	for v := stack.Pop(); v != nil; v = stack.Pop() {
		ugens[i] = v.(*Ugen)
		i = i + 1
	}
	return ugens
}
1312163
func (s *Stack) Push(value interface{}) {
	s.top = &stackElement{value, s.top}
	s.size++
}
179445
func (d *Context) SetTop(index int) {
	C.duk_set_top(d.duk_context, C.duk_idx_t(index))
}
539302
func ErrorWithStackSkip(level string, err error, skip int, fields ...*Field) {
	stack := BuildStack(2 + skip)
	ErrorWithStack(level, err, stack, fields...)
}
231471
func OpenStack(dataDir string) (*Stack, error) {
	var err error

	// Create a new Stack.
	s := &Stack{
		DataDir: dataDir,
		db:      &leveldb.DB{},
		head:    0,
		tail:    0,
		isOpen:  false,
	}

	// Open database for the stack.
	s.db, err = leveldb.OpenFile(dataDir, nil)
	if err != nil {
		return s, err
	}

	// Check if this Goque type can open the requested data directory.
	ok, err := checkGoqueType(dataDir, goqueStack)
	if err != nil {
		return s, err
	}
	if !ok {
		return s, ErrIncompatibleType
	}

	// Set isOpen and return.
	s.isOpen = true
	return s, s.init()
}
1144403
func (d *Context) ToPrimitive(index int, hint int) {
	C.duk_to_primitive(d.duk_context, C.duk_idx_t(index), C.duk_int_t(hint))
}
40601
func NewStacktrace(skip int) (Stacktrace, error) {
	// Create the actual stacktrace as a slice of frames.
	var stacktrace Stacktrace

	// Loop from skip and forever. We therefor rely on the execution of the loop
	// to provide termination.
	for i := skip; ; i++ {

		// Get the program counter, path and line number for the frame i.
		pc, filePath, lineNumber, ok := runtime.Caller(i)

		// If not ok, we break and subsequently return the generated stacktrace.
		if !ok {
			break
		}

		// Call our own API to get the package and function names.
		packageName, functionName := FunctionInfo(pc)

		// We extract the context of a frame, e.g. the line it self, preceding and
		// proceding lines.
		fileName := filePath
		parts := strings.Split(fileName, "/")
		for i, part := range parts {
			if part == "src" {
				fileName = path.Join(parts[i+1:]...)
			}
		}

		// If this is the first frame or the frame has the same package as the first
		// frame then mark it as in domain.
		InDomain := i == skip || stacktrace[0].PackageName == packageName

		// Create our frame.
		frame := Frame{
			fileName,
			functionName,
			packageName,
			filePath,
			lineNumber,
			InDomain,
			nil,
			nil,
			"",
		}

		// Get the actual context, a slice of strings.
		context, offset, err := ContextInfo(filePath, lineNumber)
		if err == nil {
			frame.PreContext = context[:offset-1]
			frame.PostContext = context[offset:]
			frame.Context = context[offset-1]
		}

		// Append the frame to the stacktrace.
		stacktrace = append(stacktrace, frame)
	}

	return stacktrace, nil
}
92243
func (d *Context) RequireValidIndex(index int) {
	C.duk_require_valid_index(d.duk_context, C.duk_idx_t(index))
}
315327
func (p *parser) pushV() {
	if cap(p.vstack) == len(p.vstack) {
		// create new empty slot in the stack
		p.vstack = append(p.vstack, nil)
	} else {
		// slice to 1 more
		p.vstack = p.vstack[:len(p.vstack)+1]
	}

	// get the last args set
	m := p.vstack[len(p.vstack)-1]
	if m != nil && len(m) == 0 {
		// empty map, all good
		return
	}

	m = make(map[string]interface{})
	p.vstack[len(p.vstack)-1] = m
}
1174522
func (d *Context) RequireContext(index int) *Context {
	return contextFromPointer(C.duk_require_context(d.duk_context, C.duk_idx_t(index)))
}
305326
func (c Context) Stack() Context {
	c.l = c.l.Hook(sh)
	return c
}
947604
func (l *State) CheckStack(size int) bool {
	callInfo := l.callInfo
	ok := l.stackLast-l.top > size
	if !ok && l.top+extraStack <= maxStack-size {
		ok = l.protect(func() { l.growStack(size) }) == nil
	}
	if ok && callInfo.top < l.top+size {
		callInfo.setTop(l.top + size)
	}
	return ok
}
877187
func BuildStack(skip int) Stack {
	stack := make(Stack, 0)

	for i := skip; ; i++ {
		pc, file, line, ok := runtime.Caller(i)
		if !ok {
			break
		}
		file = shortenFilePath(file)
		stack = append(stack, Frame{file, functionName(pc), line})
	}

	return stack
}