Exemplo n.º 1
0
func loadPrimitiveObj(name string, id uint64, behaviorMap map[string]primitiveFn) rt.Value {
	obj := rt.CreateObject(&ast.Global{Value: name}, nil, id)
	obj.New()

	behaviorObj := rt.CreateObject(nil, nil, 0)
	startPrimitiveBehaviors(obj, behaviorObj, behaviorMap)

	rt.RT.Globals.Insert(name, obj.ID)
	return obj
}
Exemplo n.º 2
0
// TODO(mjs) Right now multiple peers are not handled for a given object
// this will have to get fixed once source code archives can also be
// posted to a broker.
//
func (r *RemoteObject) Eval(s *rt.Scope) rt.Value {
	var obj *rt.Object
	var start = false
	if oid, found, _ := rt.RT.Globals.Lookup(r.Receiver); !found {
		obj = rt.CreateObject(&Global{Value: r.Receiver}, nil, r.RID)
		rt.RT.Globals.Insert(r.Receiver, r.RID)

		obj.New()
		start = true
	} else {
		obj, _ = rt.RT.Heap.Lookup(oid).(*rt.Object)
	}

	o := rt.RT.Heap.Lookup(obj.Behaviors[r.Behavior])
	if o == nil {
		obj.Behaviors[r.Behavior] = r.BID

		start = true
	}

	if start {
		r.Peers[0].New()
	}

	return obj
}
Exemplo n.º 3
0
func NewBlock(b *Block, s *rt.Scope) rt.Value {
	base := rt.NewScope(nil)
	for _, arg := range b.Args {
		base.Insert(arg, 0)
	}

	scope := base.AppendScope(s)
	obj := rt.CreateObject(b, scope, 0)
	return obj
}
Exemplo n.º 4
0
func (d *Define) Eval(s *rt.Scope) rt.Value {
	body := NewBlock(d.Body, s)

	var obj *rt.Object
	if oid, found, _ := rt.RT.Globals.Lookup(d.Receiver); !found {
		obj = rt.CreateObject(&Global{Value: d.Receiver}, nil, 0)
		rt.RT.Globals.Insert(d.Receiver, obj.ID)
	} else {
		obj, _ = rt.RT.Heap.Lookup(oid).(*rt.Object)
	}

	obj.Behaviors[d.Behavior] = body.OID()

	rt.StartBehavior(body)
	obj.New()

	return obj
}