Пример #1
0
func MaterializeSystem(system interface{}, index, barrier Circuit) (residue interface{}) {
	defer func() {
		if r := recover(); r != nil {
			switch t := r.(type) {
			case Panic:
				fmt.Fprintf(os.Stderr, t.Msg)
				fmt.Fprintf(os.Stderr, PrintableMatter(t.Matter))
				runtime.PrintStack()
				os.Exit(1)
			default:
				panic(r)
			}
		}
	}()
	if barrier.IsNil() {
		barrier = New()
	}
	parent := New().
		Grow("Index", index).
		Grow("View", New()).
		Grow("System", system).
		Grow("Barrier", barrier)

	return route(system, nil, newSubMatter(parent))
}
Пример #2
0
func (g *gate) Cognize(eye *Eye, valve circuit.Name, value interface{}) {

	// Catch panics during cognizing and report their context to the user
	defer func() {
		if r := recover(); r != nil {
			fmt.Fprintf(os.Stderr, "%v\n\n%v\n", r, PrintableMatter(g.Matter))
			runtime.PrintStack()
			os.Exit(1)
		}
	}()

	// Resolve handler
	handler, ell := g.Ellipses, true
	if _, ok := valve.(string); ok {
		if h, ok := g.Fixed[valve]; ok {
			handler, ell = h, false
		}
	}

	// Invoke handler
	if ell {
		handler.Call(
			[]reflect.Value{
				reflect.ValueOf(eye),
				reflect.ValueOf(valve),
				reflect.ValueOf(value),
			},
		)
	} else {
		handler.Call(
			[]reflect.Value{
				reflect.ValueOf(eye),
				reflect.ValueOf(value),
			},
		)
	}
}