Procházet zdrojové kódy

подбираюсь к NEW

p.kushnir před 10 roky
rodič
revize
ed775c45a5
5 změnil soubory, kde provedl 59 přidání a 31 odebrání
  1. 1 2
      rt2/rules/assign.go
  2. 6 2
      rt2/rules/seq.go
  3. 2 0
      rt2/scope/area.go
  4. 26 3
      rt2/scope/std/heap.go
  5. 24 24
      rt2/scope/std/scope.go

+ 1 - 2
rt2/rules/assign.go

@@ -171,8 +171,7 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		} else {
 			fmt.Println("NEW here")
 			heap := scope.This(f.Domain().Discover(context.HEAP))
-			fmt.Println(heap)
-			panic(0)
+			heap.Target().(scope.HeapAllocator).Allocate(a.Left())
 			return frame.End()
 		}
 	default:

+ 6 - 2
rt2/rules/seq.go

@@ -62,8 +62,12 @@ func Tail(x WAIT) Do {
 	return func(...IN) OUT { return OUT{next: x} }
 }
 
-func This(o OUT) (frame.Sequence, frame.WAIT) {
-	return Propose(o.do), o.next.wait()
+func This(o OUT) (seq frame.Sequence, ret frame.WAIT) {
+	ret = o.next.wait()
+	if ret != frame.STOP {
+		seq = Propose(o.do)
+	}
+	return seq, ret
 }
 
 func Propose(a Do) frame.Sequence {

+ 2 - 0
rt2/scope/area.go

@@ -58,6 +58,8 @@ type ScopeAllocator interface {
 
 type HeapAllocator interface {
 	Allocator
+	Allocate(n node.Node) ValueFor //указатель лежит в скоупе процедуры/модуля, а рекорд - в куче, поэтому нужно после создания экземпляра обновить указатель
+	Dispose(n node.Node)
 }
 
 //средство обновления значения

+ 26 - 3
rt2/scope/std/heap.go

@@ -1,20 +1,43 @@
 package std
 
 import (
+	"fmt"
+	"fw/cp/node"
+	"fw/cp/object"
 	"fw/rt2/context"
 	"fw/rt2/scope"
+	"reflect"
 )
 
 type heap struct {
-	d context.Domain
+	d    context.Domain
+	data *area
+	next int64
 }
 
 func nh() scope.Manager {
-	return &heap{}
+	return &heap{data: &area{ready: true, root: nil, x: make(map[scope.ID]interface{})}}
+}
+
+func (h *heap) Allocate(n node.Node) scope.ValueFor {
+	switch v := n.(type) {
+	case node.VariableNode:
+		switch t := v.Object().Complex().(type) {
+		case object.PointerType:
+
+		default:
+			panic(fmt.Sprintln("unsupported type", reflect.TypeOf(t)))
+		}
+	default:
+		panic(fmt.Sprintln("unsupported node", reflect.TypeOf(v)))
+	}
+}
+
+func (h *heap) Dispose(n node.Node) {
 }
 
 func (h *heap) Target(...scope.Allocator) scope.Allocator {
-	return nil
+	return h
 }
 
 func (h *heap) Update(i scope.ID, val scope.ValueFor) {}

+ 24 - 24
rt2/scope/std/scope.go

@@ -187,7 +187,7 @@ func obj(o object.Object) (key scope.ID, val interface{}) {
 		case object.RecordType:
 			val = &rec{link: o}
 		case object.PointerType:
-			val = &basic{link: o}
+			val = &ref{link: o}
 		default:
 			fmt.Println("unexpected", reflect.TypeOf(t))
 		}
@@ -201,6 +201,28 @@ func obj(o object.Object) (key scope.ID, val interface{}) {
 	return key, val
 }
 
+func alloc(root node.Node, h KVarea, o object.Object) {
+	if k, v := obj(o); v != nil {
+		h.set(k, v)
+		switch rv := v.(type) {
+		case record:
+			rv.init(root)
+			switch t := o.Complex().(type) {
+			case object.RecordType:
+				for rec := t; rec != nil; {
+					for x := rec.Link(); x != nil; x = x.Link() {
+						//fmt.Println(o.Name(), ".", x.Name())
+						alloc(root, v.(KVarea), x)
+					}
+					rec = rec.BaseType()
+				}
+			}
+		}
+	} else {
+		//fmt.Println("nil allocated", reflect.TypeOf(o))
+	}
+}
+
 func (m *manager) Target(...scope.Allocator) scope.Allocator {
 	return m
 }
@@ -209,30 +231,8 @@ func (m *manager) Allocate(n node.Node, final bool) {
 	h := &area{ready: final, root: n, x: make(map[scope.ID]interface{})}
 	runtime.SetFinalizer(h, area_fin)
 	mod := rt_mod.DomainModule(m.Domain())
-	var alloc func(h KVarea, o object.Object)
-	alloc = func(h KVarea, o object.Object) {
-		if k, v := obj(o); v != nil {
-			h.set(k, v)
-			switch rv := v.(type) {
-			case record:
-				rv.init(n)
-				switch t := o.Complex().(type) {
-				case object.RecordType:
-					for rec := t; rec != nil; {
-						for x := rec.Link(); x != nil; x = x.Link() {
-							//fmt.Println(o.Name(), ".", x.Name())
-							alloc(v.(KVarea), x)
-						}
-						rec = rec.BaseType()
-					}
-				}
-			}
-		} else {
-			//fmt.Println("nil allocated", reflect.TypeOf(o))
-		}
-	}
 	for _, o := range mod.Objects[n] {
-		alloc(h, o)
+		alloc(n, h, o)
 	}
 	m.areas.PushFront(h)
 	//fmt.Println("allocate")