' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Meta:
'
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Begin BI-component.
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Hard arrays to store actual data:
'
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Temp variable(s):
'
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Nodes:
'
' Node structure
Identity
AS LONG ' Address in identity register Reference
AS LONG ' Pointer to hard array index
MaxNodes = 10000
' Node identity register
IdentityRegister(k) = -1
' Node storage
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Soft arrays:
'
' Soft array structure
MaxSoftArrays = MaxNodes / 2
' Soft array register
SoftArrayRegister(k) = -1
' Soft array storage
DIM SHARED SoftArray
(MaxSoftArrays
) AS SoftArrayStructure
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Processing
'
LambdaIndex = 0
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' End BI-component.
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Visual Nodes (OPTIONAL)
'
' Visual node structure
TYPE VisualNodesStructure
Reference
AS LONG ' Points to a node.
MaxVisualNodess = 512
VisualNodesCount = 0
' Visual node storage
DIM SHARED VisualNodes
(MaxVisualNodess
) AS VisualNodesStructure
' Visual node extras
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Pre-Main
'
ScrollPosition.x = 0
ScrollPosition.y = 0
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Main
'
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Interface (OPTIONAL)
'
PRINT PrintAllSoftArrays$
(1)
k = ClearSelections(1)
a = DeleteAllSoftArrays(1)
k = ClearSelections(1)
ScrollPosition.x = 0
ScrollPosition.y = 0
t = MemoryProbe$("")
i = MouseOver(x0, y0)
MB1 = 0
i = MouseOver(xx, yy)
j = i
i = MouseOver(xx, yy)
j = i
MB1 = -1
i = j
ScrollPosition.x = ScrollPosition.x + (xx - VisualNodes(i).BoxCenter.x)
ScrollPosition.y = ScrollPosition.y + (yy - VisualNodes(i).BoxCenter.y)
CALL MoveVisualNodesRecur
(i
, VisualNodes
(i
).Reference
, xx
- VisualNodes
(i
).BoxCenter.x
, yy
- VisualNodes
(i
).BoxCenter.y
)
i = -1
j = i
MB1 = 0
ScrollPosition.x = ScrollPosition.x + (xx - x0)
ScrollPosition.y = ScrollPosition.y + (yy - y0)
CALL MoveAllVisualNodes
(xx
- x0
, yy
- y0
) x0 = xx
y0 = yy
CALL MoveAllVisualNodes
(0, 30 * MW
) ScrollPosition.y = ScrollPosition.y + 30 * MW
IF (xx
> VisualNodes
(i
).BoxCenter.x
- VisualNodes
(i
).BoxWidth
/ 2) AND (xx
< VisualNodes
(i
).BoxCenter.x
+ VisualNodes
(i
).BoxWidth
/ 2) THEN IF (yy
> VisualNodes
(i
).BoxCenter.y
- VisualNodes
(i
).BoxHeight
/ 2) AND (yy
< VisualNodes
(i
).BoxCenter.y
+ VisualNodes
(i
).BoxHeight
/ 2) THEN
' Press-and-hold keys
CtrlKey = 1
CtrlKey = 0
AltWires = 1
AltWires = 0
' Single-tap keys
IF (SelectionIndex
(1) <> -1) THEN a = Evaluate(VisualNodes(SelectionIndex(1)).Reference)
i = ClearSelections(1)
IF (SelectionIndex
(1) <> -1) THEN a = DeleteNodes(VisualNodes(SelectionIndex(1)).Reference)
i = ClearSelections(1)
ScrollPosition.y
= ScrollPosition.y
- .9 * _HEIGHT / 2 ScrollPosition.y
= ScrollPosition.y
+ .9 * _HEIGHT / 2 IF (SelectionIndex
(1) <> -1) THEN Nodes(VisualNodes(SelectionIndex(1)).Reference).Species = "integer"
Nodes(VisualNodes(SelectionIndex(1)).Reference).Reference = NewIntegerData(0)
CALL DefineVisualNode
(SelectionIndex
(1), VisualNodes
(SelectionIndex
(1)).Reference
, VisualNodes
(SelectionIndex
(1)).BoxCenter.x
, VisualNodes
(SelectionIndex
(1)).BoxCenter.y
) IF (SelectionIndex
(1) <> -1) THEN Nodes(VisualNodes(SelectionIndex(1)).Reference).Species = "double"
Nodes(VisualNodes(SelectionIndex(1)).Reference).Reference = NewDoubleData(0)
CALL DefineVisualNode
(SelectionIndex
(1), VisualNodes
(SelectionIndex
(1)).Reference
, VisualNodes
(SelectionIndex
(1)).BoxCenter.x
, VisualNodes
(SelectionIndex
(1)).BoxCenter.y
) IF (SelectionIndex
(1) <> -1) THEN Nodes(VisualNodes(SelectionIndex(1)).Reference).Species = "text"
Nodes(VisualNodes(SelectionIndex(1)).Reference).Reference = NewTextData("")
CALL DefineVisualNode
(SelectionIndex
(1), VisualNodes
(SelectionIndex
(1)).Reference
, VisualNodes
(SelectionIndex
(1)).BoxCenter.x
, VisualNodes
(SelectionIndex
(1)).BoxCenter.y
) IF (SoftArrayRegister
(k
) <> -1) THEN IF (SoftArray
(k
).Label
= Literal$
(VisualNodes
(SelectionIndex
(1)).Reference
)) THEN a = SoftArray(k).HeadNode
b = Nodes(a).East
Nodes(b).West = -1
SoftArrayRegister(k) = -1
IdentityRegister(a) = -1
a = VisualNodes(SelectionIndex(2)).Reference
c = Nodes(a).East
c = DeleteNodes(c)
Nodes(a).East = b
Nodes(b).West = a
IF (SelectionIndex
(1) <> -1) THEN SELECT CASE Nodes
(VisualNodes
(SelectionIndex
(1)).Reference
).Species
a = InsertEast(VisualNodes(SelectionIndex(1)).Reference, NewIntegerNode(0))
a = InsertEast(VisualNodes(SelectionIndex(1)).Reference, NewTextNode("e"))
a = InsertEast(VisualNodes(SelectionIndex(1)).Reference, NewDoubleNode(0))
IF (SoftArrayRegister
(k
) <> -1) THEN IF (SoftArray
(k
).Label
= Literal$
(VisualNodes
(SelectionIndex
(1)).Reference
)) THEN a = SoftArray(k).HeadNode
b = Nodes(a).East
Nodes(b).West = -1
SoftArrayRegister(k) = -1
IdentityRegister(a) = -1
a = VisualNodes(SelectionIndex(2)).Reference
c = Nodes(a).South
c = DeleteRecur(c)
Nodes(a).South = b
Nodes(b).North = a
IF (SelectionIndex
(1) <> -1) THEN SELECT CASE Nodes
(VisualNodes
(SelectionIndex
(1)).Reference
).Species
a = InsertSouth(VisualNodes(SelectionIndex(1)).Reference, NewIntegerNode(0))
a = InsertSouth(VisualNodes(SelectionIndex(1)).Reference, NewTextNode("s"))
a = InsertSouth(VisualNodes(SelectionIndex(1)).Reference, NewDoubleNode(0))
IF (SelectionIndex
(1) <> -1) THEN SELECT CASE Nodes
(VisualNodes
(SelectionIndex
(1)).Reference
).Species
Nodes
(VisualNodes
(SelectionIndex
(1)).Reference
).Reference
= NewIntegerData
(INT(VAL(t
))) a = VisualNodes(SelectionIndex(1)).Reference
Nodes(a).Reference = NewTextData(t)
IF (SoftArrayRegister
(k
) <> -1) THEN IF (SoftArray
(k
).HeadNode
= a
) THEN SoftArray(k).Label = t
Nodes
(VisualNodes
(SelectionIndex
(1)).Reference
).Reference
= NewDoubleData
(VAL(t
)) CALL DefineVisualNode
(SelectionIndex
(1), VisualNodes
(SelectionIndex
(1)).Reference
, VisualNodes
(SelectionIndex
(1)).BoxCenter.x
, VisualNodes
(SelectionIndex
(1)).BoxCenter.y
) IF (SelectionIndex
(1) <> -1) THEN a = VisualNodes(SelectionIndex(1)).Reference
IF (Nodes
(a
).North
<> -1) THEN Nodes(Nodes(a).North).South = -1
Nodes(a).North = -1
Nodes(Nodes(a).West).East = -1
b = LinkEast(b, a)
PRINT #1, PrintAllSoftArrays$
(1)
ScreenHandleTemp = ScreenHandle
CALL DrawAllVisualNodes
(AltWires
)
IF (VisualNodes
(i
).Reference
<> -1) THEN CALL DrawSingleNode
(i
, _RGBA(255, 25, 50, 255), _RGBA(255, 255, 0, 255))
CALL lprintstring
(1, 3, "Selection history:") IF (SelectionIndex
(k
) <> -1) THEN IF (VisualNodes
(SelectionIndex
(k
)).Reference
<> -1) THEN CALL lprintstring
(1, 3 + k
, LTRIM$(RTRIM$(STR$(k
))) + ") " + Literal$
(VisualNodes
(SelectionIndex
(k
)).Reference
) + " (@ " + LTRIM$(RTRIM$(STR$(VisualNodes
(SelectionIndex
(k
)).Reference
))) + ")")
i
= UBOUND(SelectionIndex
) + 4 i
= i
+ 1:
CALL lprintstring
(1, i
, "View:") i
= i
+ 1:
CALL lprintstring
(1, i
, " Space = select") i
= i
+ 1:
CALL lprintstring
(1, i
, " Mouse1 = scroll recur") i
= i
+ 1:
CALL lprintstring
(1, i
, " Mouse2 = scroll all") i
= i
+ 1:
CALL lprintstring
(1, i
, " W = all wires") i
= i
+ 1:
CALL lprintstring
(1, i
, "Create:") i
= i
+ 1:
CALL lprintstring
(1, i
, " E = append east") i
= i
+ 1:
CALL lprintstring
(1, i
, " S = append south") i
= i
+ 1:
CALL lprintstring
(1, i
, " I = new integer") i
= i
+ 1:
CALL lprintstring
(1, i
, " T = new text") i
= i
+ 1:
CALL lprintstring
(1, i
, " D = new double") i
= i
+ 1:
CALL lprintstring
(1, i
, "Edit node:") i
= i
+ 1:
CALL lprintstring
(1, i
, " X = edit content") i
= i
+ 1:
CALL lprintstring
(1, i
, " Ctrl+I = to integer") i
= i
+ 1:
CALL lprintstring
(1, i
, " Ctrl+T = to text") i
= i
+ 1:
CALL lprintstring
(1, i
, " Ctrl+D = to double") i
= i
+ 1:
CALL lprintstring
(1, i
, "Edit list:") i
= i
+ 1:
CALL lprintstring
(1, i
, " Enter = evaluate") i
= i
+ 1:
CALL lprintstring
(1, i
, " Delete = delete") i
= i
+ 1:
CALL lprintstring
(1, i
, " V = sever") i
= i
+ 1:
CALL lprintstring
(1, i
, " Ctrl+S = ins (1)s(2)") i
= i
+ 1:
CALL lprintstring
(1, i
, " Ctrl+E = ins (1)e(2)") i
= i
+ 1:
CALL lprintstring
(1, i
, "Report:") i
= i
+ 1:
CALL lprintstring
(1, i
, " L = print all") i
= i
+ 1:
CALL lprintstring
(1, i
, " Ctrl+L = write file") i
= i
+ 1:
CALL lprintstring
(1, i
, " M = mem probe")
CALL rprintstring
(3, "Scroll position:")
CALL cprintstring
(_HEIGHT / 2, "--Soft Array Editor--") CALL cprintstring
(-_HEIGHT / 2 + 16, "Press ESC to finish.")
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Visual Nodes (OPTIONAL)
'
h = 22
w
= 12 + 8 * LEN(Literal$
(x
)) VisualNodes(i).Reference = x
VisualNodes(i).BoxCenter.x = cx
VisualNodes(i).BoxCenter.y = cy
VisualNodes(i).BoxHeight = h
VisualNodes(i).BoxWidth = w
VisualNodes(i).CornerNE.x = cx + .5 * w
VisualNodes(i).CornerNE.y = cy + .5 * h
VisualNodes(i).CornerNW.x = cx - .5 * w
VisualNodes(i).CornerNW.y = cy + .5 * h
VisualNodes(i).CornerSE.x = cx + .5 * w
VisualNodes(i).CornerSE.y = cy - .5 * h
VisualNodes(i).CornerSW.x = cx - .5 * w
VisualNodes(i).CornerSW.y = cy - .5 * h
VisualNodes(i).AntennaN.x = cx
VisualNodes(i).AntennaN.y = cy + .5 * h + 3
VisualNodes(i).AntennaS.x = cx
VisualNodes(i).AntennaS.y = cy - .5 * h - 3
VisualNodes(i).AntennaE.x = cx + .5 * w + 3
VisualNodes(i).AntennaE.y = cy
VisualNodes(i).AntennaW.x = cx - .5 * w - 3
VisualNodes(i).AntennaW.y = cy
TheReturn = -1
FOR j
= 1 TO VisualNodesCount
IF (VisualNodes
(j
).Reference
= x
) THEN TheReturn = j
VisualNodeIndexFromReference = TheReturn
VisualNodesCount = 0
y0 = Origin.y + ScrollPosition.y
IF (SoftArrayRegister
(k
) <> -1) THEN CALL BuildVisualList
(SoftArray
(k
).HeadNode
, Origin.x
+ ScrollPosition.x
, y0
) y0 = y0 - 30
s = Nodes(x).South
e = Nodes(x).East
VisualNodesCount = VisualNodesCount + 1
CALL DefineVisualNode
(VisualNodesCount
, x
, x0
, y0
) y0 = y0 - 30
dxtmp
= 8 * .5 * (LEN(Literal$
(x
)) + LEN(Literal$
(e
))) IF (dxtmp
< 30) THEN dxtmp
= 30 CALL BuildVisualList
(e
, x0
+ dxtmp
, y0
) CALL BuildVisualList
(s
, x0
, y0
)
FOR k
= 1 TO VisualNodesCount
CALL MoveSingleVisualNode
(k
, dx
, dy
)
s = Nodes(x).South
e = Nodes(x).East
f = 0
FOR k
= 1 TO VisualNodesCount
IF (VisualNodes
(k
).Reference
= e
) THEN f = 1
CALL MoveVisualNodesRecur
(k
, e
, dx
, dy
) f = 0
FOR k
= 1 TO VisualNodesCount
IF (VisualNodes
(k
).Reference
= s
) THEN f = 1
CALL MoveVisualNodesRecur
(k
, s
, dx
, dy
) CALL MoveSingleVisualNode
(i
, dx
, dy
)
CALL DefineVisualNode
(i
, VisualNodes
(i
).Reference
, VisualNodes
(i
).BoxCenter.x
+ dx
, VisualNodes
(i
).BoxCenter.y
+ dy
)
FOR k
= 1 TO VisualNodesCount
SELECT CASE Nodes
(VisualNodes
(k
).Reference
).Species
CALL DrawSingleNode
(k
, _RGBA(255, 255, 255, 255), _RGBA(155, 55, 55, 255)) CALL DrawSingleNode
(k
, _RGBA(255, 255, 255, 255), _RGBA(55, 155, 55, 255)) CALL DrawSingleNode
(k
, _RGBA(255, 255, 255, 255), _RGBA(55, 55, 155, 255)) CALL DrawSingleNode
(k
, _RGBA(255, 255, 255, 255), _RGBA(55, 55, 55, 255))
CALL clinebf
(VisualNodes
(x
).CornerNE.x
, VisualNodes
(x
).CornerNE.y
, VisualNodes
(x
).CornerSW.x
, VisualNodes
(x
).CornerSW.y
, c2
) CALL bprintstring
(VisualNodes
(x
).CornerNW.x
+ 6, VisualNodes
(x
).CornerNW.y
- 4, Literal$
(VisualNodes
(x
).Reference
)) CALL clineb
(VisualNodes
(x
).CornerNE.x
+ 0, VisualNodes
(x
).CornerNE.y
+ 0, VisualNodes
(x
).CornerSW.x
- 0, VisualNodes
(x
).CornerSW.y
- 0, _RGB32(155, 155, 155, 255))
i = VisualNodes(x).Reference
s = Nodes(i).South
e = Nodes(i).East
k = VisualNodeIndexFromReference(s)
CALL cline
(VisualNodes
(x
).AntennaS.x
, VisualNodes
(x
).AntennaS.y
, VisualNodes
(k
).BoxCenter.x
, VisualNodes
(k
).BoxCenter.y
, _RGBA(155, 155, 155, 255)) CALL ccircle
(VisualNodes
(x
).AntennaS.x
, VisualNodes
(x
).AntennaS.y
, 3, _RGBA(155, 155, 155, 255)) k = VisualNodeIndexFromReference(e)
'IF (k <> -1) THEN
CALL cline
(VisualNodes
(x
).AntennaE.x
, VisualNodes
(x
).AntennaE.y
, VisualNodes
(k
).BoxCenter.x
, VisualNodes
(k
).BoxCenter.y
, _RGBA(155, 155, 155, 255)) CALL ccircle
(VisualNodes
(x
).AntennaE.x
, VisualNodes
(x
).AntennaE.y
, 3, _RGBA(155, 155, 155, 255)) 'END IF
i = VisualNodes(x).Reference
n = Nodes(i).North
w = Nodes(i).West
k = VisualNodeIndexFromReference(n)
CALL cline
(VisualNodes
(x
).AntennaN.x
, VisualNodes
(x
).AntennaN.y
, VisualNodes
(k
).BoxCenter.x
, VisualNodes
(k
).BoxCenter.y
, _RGBA(255, 55, 55, 255)) CALL ccircle
(VisualNodes
(x
).AntennaN.x
, VisualNodes
(x
).AntennaN.y
, 3, _RGBA(255, 55, 55, 255)) k = VisualNodeIndexFromReference(w)
CALL cline
(VisualNodes
(x
).AntennaW.x
, VisualNodes
(x
).AntennaW.y
, VisualNodes
(k
).BoxCenter.x
, VisualNodes
(k
).BoxCenter.y
, _RGBA(255, 55, 55, 255)) CALL ccircle
(VisualNodes
(x
).AntennaW.x
, VisualNodes
(x
).AntennaW.y
, 3, _RGBA(255, 55, 55, 255))
'x0 = (x0 - _WIDTH / 2)
'y0 = (-y0 + _HEIGHT / 2)
r = 9999
TheReturn = -1
FOR k
= 1 TO VisualNodesCount
IF (x0
> VisualNodes
(k
).BoxCenter.x
- VisualNodes
(k
).BoxWidth
/ 2) AND (x0
< VisualNodes
(k
).BoxCenter.x
+ VisualNodes
(k
).BoxWidth
/ 2) THEN IF (y0
> VisualNodes
(k
).BoxCenter.y
- VisualNodes
(k
).BoxHeight
/ 2) AND (y0
< VisualNodes
(k
).BoxCenter.y
+ VisualNodes
(k
).BoxHeight
/ 2) THEN d = (x0 - VisualNodes(k).BoxCenter.x) * (x0 - VisualNodes(k).BoxCenter.x) + (y0 - VisualNodes(k).BoxCenter.y) * (y0 - VisualNodes(k).BoxCenter.y)
r = d
TheReturn = k
MouseOver = TheReturn
IF (SelectionIndex
(1) <> x
) THEN SelectionIndex(k) = SelectionIndex(k - 1)
SelectionIndex(1) = x
SelectionIndex(k) = -1
TheReturn = -1
ClearSelections = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Cartesian graphics
'
'LOCATE y1, x1: PRINT a
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Demo cases:
'
TheName1 = "top part"
TheName2 = "bottom part"
a = NewSoftArray(TheName1)
a = LinkEast(a, NewTextNode("lambda"))
b = LinkEast(a, NewIntegerNode(4))
b = LinkSouth(b, NewIntegerNode(6))
a = NewUnitArray("cow", NewIntegerNode(5))
a = NewSoftArray(TheName2)
a = LinkEast(a, NewTextNode("cos"))
b = LinkEast(a, NewTextNode("*"))
b = LinkEast(b, NewIntegerNode(3))
b = LinkSouth(b, NewTextNode("[1]"))
b = LinkSouth(b, CopyIntegerNode(Content("cow")))
b = LinkSouth(b, NewTextNode("[2]"))
a = ListId(TheName2)
b = SoftArray(a).HeadNode
SoftArrayRegister(a) = -1
IdentityRegister(b) = -1
a = Nodes(SoftArray(ListId(TheName1)).HeadNode).East
b = Nodes(b).East
Nodes(b).West = -1
Nodes(b).North = a
Nodes(a).South = b
a = EvalAllSoftArrays(1)
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TheName = "Lambda Test"
a = NewUnitArray("cow", NewIntegerNode(7))
a = NewSoftArray(TheName)
a = LinkEast(a, NewTextNode("lambda"))
b = LinkEast(a, NewIntegerNode(4))
b = LinkSouth(b, NewIntegerNode(6))
a = LinkSouth(a, NewTextNode("cos"))
b = LinkEast(a, NewTextNode("*"))
b = LinkEast(b, NewIntegerNode(3))
b = LinkSouth(b, NewTextNode("[1]"))
b = LinkSouth(b, CopyIntegerNode(Content("cow")))
b = LinkSouth(b, NewTextNode("[2]"))
a = EvalAllSoftArrays(1)
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TheName = "List Test"
a = NewSoftArray(TheName)
a = LinkEast(a, NewTextNode("cos"))
b = LinkEast(a, NewTextNode("three"))
b = LinkSouth(b, NewTextNode("four"))
b = LinkSouth(b, NewTextNode("five"))
b = LinkSouth(b, NewTextNode("six"))
b = LinkSouth(b, NewTextNode("seven"))
a = LinkSouth(a, NewTextNode("cos"))
b = LinkEast(a, NewIntegerNode(3))
b = LinkSouth(b, NewIntegerNode(4))
b = LinkSouth(b, NewIntegerNode(5))
b = LinkSouth(b, NewIntegerNode(6))
b = LinkSouth(b, NewIntegerNode(7))
a = EvalAllSoftArrays(1)
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ListNames(1) = "Arithmetic Test1"
ListNames(2) = "Arithmetic Test2"
a = NewSoftArray(ListNames(1))
a = LinkEast(a, NewTextNode("*"))
b = LinkEast(a, NewIntegerNode(3))
b = LinkSouth(b, NewIntegerNode(4))
a = LinkSouth(b, NewTextNode("cos"))
b = LinkEast(a, NewTextNode("+"))
b = LinkEast(b, NewIntegerNode(4))
b = LinkSouth(b, NewIntegerNode(7))
b = LinkSouth(a, NewIntegerNode(2))
a = EvalAllSoftArrays(1)
a = NewSoftArray(ListNames(2))
a = LinkEast(a, NewTextNode("/"))
b = LinkEast(a, NewIntegerNode(3))
a = LinkSouth(b, NewTextNode("cos"))
b = LinkEast(a, NewTextNode("+"))
b = LinkEast(b, NewIntegerNode(4))
b = LinkSouth(b, NewDoubleNode(DoubleData(Nodes(Nodes(HeadId(ListNames(1))).East).Reference)))
a = EvalAllSoftArrays(1)
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TheName = "Tree Edit Test"
a = NewSoftArray(TheName)
a = LinkEast(a, NewTextNode("QB64 Buddy"))
a = LinkEast(a, NewTextNode("Handle"))
b = LinkEast(a, NewTextNode("flukiluke"))
a = LinkSouth(a, NewTextNode("Name"))
b = LinkEast(a, NewTextNode("Luke C."))
a = LinkSouth(a, NewTextNode("Country"))
b = LinkEast(a, NewTextNode("Australia"))
c = LinkEast(b, NewTextNode("Locality"))
b = LinkEast(c, NewTextNode("Down Under"))
a = LinkSouth(a, NewTextNode("Birthyear"))
b = LinkEast(a, NewIntegerNode(1523))
c = LinkSouth(b, NewTextNode("May???"))
a = InsertEast(SeekText("Down Under", HeadId(TheName), 1), NewTextNode("Get it?"))
a = InsertSouth(SeekText("QB64 Buddy", HeadId(TheName), 1), NewTextNode("QB64 Enemy"))
a = EditIntegerReference(StepUsing(SeekText("Birthyear", HeadId(TheName), 1), "e"), 1855)
a = DeleteNodes(SeekText("Name", HeadId(TheName), 1))
' Query tests
'PRINT "Inserting `Get it?' into list..."
'PRINT "Adding new entry to bottom of list..."
'PRINT "Editing Birthyear..."
'PRINT "Deleting Name..."
'PRINT
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TheName = "Tree of Friends"
a = NewSoftArray(TheName)
a = LinkEast(a, NewTextNode("QB64 Buddy")): d = a
a = LinkEast(a, NewTextNode("Handle"))
b = LinkEast(a, NewTextNode("SMcNeill"))
a = LinkSouth(a, NewTextNode("Name"))
b = LinkEast(a, NewTextNode("Steve SMcNeill"))
a = LinkSouth(a, NewTextNode("Country"))
b = LinkEast(a, NewTextNode("USA"))
c = LinkEast(b, NewTextNode("Locality"))
b = LinkEast(c, NewTextNode("Virginia"))
a = LinkSouth(a, NewTextNode("Birthyear"))
b = LinkEast(a, NewIntegerNode(1973))
c = LinkSouth(b, NewTextNode("May?"))
a = LinkSouth(d, NewTextNode("QB64 Buddy")): d = a
a = LinkEast(a, NewTextNode("Handle"))
b = LinkEast(a, NewTextNode("FellippeHeitor"))
a = LinkSouth(a, NewTextNode("Name"))
b = LinkEast(a, NewTextNode("Fellippe Heitor"))
a = LinkSouth(a, NewTextNode("Country"))
b = LinkEast(a, NewTextNode("Brazil"))
c = LinkEast(b, NewTextNode("Locality"))
b = LinkEast(c, NewTextNode("My <3"))
c = LinkEast(b, NewTextNode("JK, it's ___."))
a = LinkSouth(a, NewTextNode("Birthyear"))
b = LinkEast(a, NewIntegerNode(1983))
c = LinkSouth(b, NewTextNode("Sep?"))
b = LinkSouth(c, NewTextNode("... or was it May?"))
a = LinkSouth(d, NewTextNode("QB64 Buddy")): d = a
a = LinkEast(a, NewTextNode("Handle"))
b = LinkEast(a, NewTextNode("DanTurtle"))
'' Query tests
'PRINT "Height:";
'PRINT SquareListHeight(ListId(TheName))
'PRINT "Steve's locality: ";
'PRINT Literal$(StepUsing(HeadId(TheName), "eesseee"))
'PRINT "Fellippe's locality: ";
'PRINT Literal$(StepUsing(HeadId(TheName), "esesseee"))
'PRINT "Fellippe's birth month: ";
'PRINT Literal$(StepUsing(JumpFrom(StepUsing(HeadId(TheName), "ese"), "s", 3), "es"))
'PRINT "Width of Fellippe's Country branch:";
'PRINT Measure(SeekText("Country", HeadId(TheName), 2), "e")
'PRINT "Height under Fellippe's Birthyear branch:";
'PRINT Measure(Nodes(SeekText("Birthyear", HeadId(TheName), 2)).East, "s")
'PRINT
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TheName = "Three-Dimensional Array"
TestArray3D(1, 1, 1) = "one.one.one"
TestArray3D(1, 1, 2) = "one.one.two"
TestArray3D(1, 1, 3) = "one.one.three"
TestArray3D(1, 2, 1) = "one.two.one"
TestArray3D(1, 2, 2) = "one.two.two"
TestArray3D(1, 2, 3) = "one.two.three"
TestArray3D(2, 1, 1) = "two.one.one"
TestArray3D(2, 1, 2) = "two.one.two"
TestArray3D(2, 1, 3) = "two.one.three"
TestArray3D(2, 2, 1) = "two.two.one"
TestArray3D(2, 2, 2) = "two.two.two"
TestArray3D(2, 2, 3) = "two.two.three"
TestArray3D(3, 1, 1) = "three.one.one"
TestArray3D(3, 1, 2) = "three.one.two"
TestArray3D(3, 1, 3) = "three.one.three"
TestArray3D(3, 2, 1) = "three.two.one"
TestArray3D(3, 2, 2) = "three.two.two"
TestArray3D(3, 2, 3) = "three.two.three"
TestArray3D(4, 1, 1) = "four.one.one"
TestArray3D(4, 1, 2) = "four.one.two"
TestArray3D(4, 1, 3) = "four.one.three"
TestArray3D(4, 2, 1) = "four.two.one"
TestArray3D(4, 2, 2) = "four.two.two"
TestArray3D(4, 2, 3) = "four.two.three"
' Load 3D array as Soft array
a = NewSoftArray(TheName)
a = LinkEast(a, NewTextNode(TestArray3D(i, j, k)))
b = a
a = LinkSouth(a, NewTextNode(TestArray3D(i, j, k)))
b = a
b = LinkEast(b, NewTextNode(TestArray3D(i, j, k)))
'PRINT "Query tests:"
'PRINT PrintSoftArray$(HeadId(TheName))
'PRINT "Height:"; SquareListHeight(ListId(TheName))
'PRINT "Width:"; SquareListWidth(ListId(TheName))
'PRINT
'PRINT "Typical FOR loop:"
'FOR k = 1 TO Bottom(TheName)
' PRINT Literal$(JumpFrom(Content(TheName), "s", k))
'NEXT
'PRINT
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Begin BM-component.
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Processing
'
IF (SoftArrayRegister
(k
) <> -1) THEN TheReturn = Evaluate(SoftArray(k).HeadNode)
EvalAllSoftArrays = TheReturn
a = x
b = -1
a = EvalStep(FirstEmbedded(a))
a = Nodes(a).South
b = a
TheReturn = a
Evaluate = TheReturn
RefSpecies = ""
FunctionId = x
ReturnSpecies = ""
ReturnInteger = 0
ReturnText = ""
ReturnDouble = 0
' Pre-evaluation
SouthernId = x
i = x
n = Nodes(i).North
i = n
NorthernId = i
FunctionId = Nodes(NorthernId).West
ReturnSpecies = Nodes(FunctionId).Species
ReturnInteger = IntegerData(Nodes(FunctionId).Reference)
ReturnText = TextData(Nodes(FunctionId).Reference)
ReturnDouble = DoubleData(Nodes(FunctionId).Reference)
' Lambda substitution
i = NorthernId
lf = 0
IF (Nodes
(i
).Species
= "text") THEN IF (TextData
(Nodes
(i
).Reference
) = "[1]") THEN j = LambdaMatrix(LambdaIndex, 1)
Nodes(i).Species = Nodes(j).Species
Nodes(i).Reference = Nodes(j).Reference
lf = 1
IF (TextData
(Nodes
(i
).Reference
) = "[2]") THEN j = LambdaMatrix(LambdaIndex, 2)
Nodes(i).Species = Nodes(j).Species
Nodes(i).Reference = Nodes(j).Reference
lf = 1
s = Nodes(i).South
i = s
FOR k
= 1 TO LambdaArgCount
(LambdaIndex
) j = Unlink(LambdaMatrix(LambdaIndex, k))
LambdaArgCount(LambdaIndex) = 0
LambdaIndex = LambdaIndex - 1
' Determine return species
i = NorthernId
IF (Nodes
(i
).Species
= "text") THEN RefSpecies
= "text" IF ((Nodes
(i
).Species
= "double") AND (RefSpecies
<> "text")) THEN RefSpecies
= "double" IF ((Nodes
(i
).Species
= "integer") AND (RefSpecies
<> "text") AND (RefSpecies
<> "double")) THEN RefSpecies
= "integer" i = Nodes(i).South
' Single-pass evaluation
MultiPass = 0
MultiPass = 1
ReturnSpecies = RefSpecies
ReturnInteger = 1
ReturnDouble = 1
MultiPass = 1
ReturnSpecies = RefSpecies
ReturnInteger = 0
ReturnDouble = 0
MultiPass = 0
ReturnSpecies = "double"
ReturnDouble = IntegerData(Nodes(NorthernId).Reference) / IntegerData(Nodes(SouthernId).Reference)
ReturnDouble = IntegerData(Nodes(NorthernId).Reference) / DoubleData(Nodes(SouthernId).Reference)
ReturnSpecies = "text"
ReturnText = Literal$(NorthernId) + "/" + Literal$(SouthernId)
ReturnSpecies = "double"
ReturnDouble = DoubleData(Nodes(NorthernId).Reference) / IntegerData(Nodes(SouthernId).Reference)
ReturnDouble = DoubleData(Nodes(NorthernId).Reference) / DoubleData(Nodes(SouthernId).Reference)
i = Unlink(NorthernId)
i = Unlink(SouthernId)
IF (NorthernId
= SouthernId
) THEN MultiPass = 0
i = NorthernId
ReturnSpecies = "double"
ReturnDouble
= COS(IntegerData
(Nodes
(i
).Reference
)) ReturnSpecies = "text"
ReturnText = "cos" + "(" + Literal$(i) + ")"
ReturnSpecies = "double"
ReturnDouble
= COS(DoubleData
(Nodes
(i
).Reference
)) i = Unlink(i)
MultiPass = 1
ReturnSpecies = "text"
ReturnText = "(" + "cos" + ")"
MultiPass = 1
LambdaIndex = LambdaIndex + 1
ReturnSpecies = "text"
ReturnText = "(" + "lambda" + ")"
CASE "(" + "lambda" + ")" '
' Multi-pass evaluation
i = NorthernId
ReturnInteger = ReturnInteger * IntegerData(Nodes(i).Reference)
ReturnInteger = ReturnInteger * DoubleData(Nodes(i).Reference)
ReturnText = ReturnText + Literal$(i)
ReturnDouble = ReturnDouble * IntegerData(Nodes(i).Reference)
ReturnDouble = ReturnDouble * DoubleData(Nodes(i).Reference)
i = Unlink(i)
s = Nodes(i).South
i = Unlink(i)
i = s
ReturnInteger = ReturnInteger + IntegerData(Nodes(i).Reference)
ReturnInteger = ReturnInteger + DoubleData(Nodes(i).Reference)
ReturnText = ReturnText + Literal$(i)
ReturnDouble = ReturnDouble + IntegerData(Nodes(i).Reference)
ReturnDouble = ReturnDouble + DoubleData(Nodes(i).Reference)
i = Unlink(i)
s = Nodes(i).South
i = Unlink(i)
i = s
Nodes(i).Species = "double"
Nodes
(i
).Reference
= NewDoubleData
(COS(IntegerData
(Nodes
(i
).Reference
))) Nodes(i).Reference = NewTextData("cos" + "(" + Literal$(i) + ")")
Nodes(i).Species = "double"
Nodes
(i
).Reference
= NewDoubleData
(COS(DoubleData
(Nodes
(i
).Reference
))) s = Nodes(i).South
i = s
LambdaArgCount(LambdaIndex) = LambdaArgCount(LambdaIndex) + 1
LambdaMatrix(LambdaIndex, LambdaArgCount(LambdaIndex)) = i
s = Nodes(i).South
i = s
Nodes(FunctionId).Species = ReturnSpecies
Nodes(FunctionId).Reference = NewIntegerData(ReturnInteger)
Nodes(FunctionId).Species = ReturnSpecies
Nodes(FunctionId).Reference = NewTextData(ReturnText)
Nodes(FunctionId).Species = ReturnSpecies
Nodes(FunctionId).Reference = NewDoubleData(ReturnDouble)
TheReturn = FunctionId
EvalStep = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Seek and recall
'
TheReturn = MostEmbeddedRecur(x, -1)
FirstEmbedded = TheReturn
s = Nodes(x).South
e = Nodes(x).East
TheReturn = MostEmbeddedRecur(e, y)
TheReturn = MostEmbeddedRecur(s, y)
y = x
TheReturn = y
MostEmbeddedRecur = TheReturn
TheReturn = -1
s = Nodes(x).South
e = Nodes(x).East
IF (TextData
(Nodes
(x
).Reference
) = t
) THEN TheReturn = x
r = r - 1
TheReturn = SeekText(t, e, r)
TheReturn = SeekText(t, s, r)
SeekText = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Navigation
'
TheReturn = Nodes(HeadId(t)).East
Content = TheReturn
TheReturn = -1 + Measure(Content(t), "s")
Bottom = TheReturn
DIM TheReturn
AS LONG ' Change this to int. ? TheReturn = -1
IF (SoftArray
(k
).Label
= t
) THEN TheReturn = k
ListId = TheReturn
TheReturn = SoftArray(ListId(t)).HeadNode
HeadId = TheReturn
TheReturn = x
TheReturn = JumpFrom(Nodes(x).North, "n", r - 1)
TheReturn = JumpFrom(Nodes(x).South, "s", r - 1)
TheReturn = JumpFrom(Nodes(x).East, "e", r - 1)
TheReturn = JumpFrom(Nodes(x).West, "w", r - 1)
JumpFrom = TheReturn
i = x
j = Nodes(i).North
j = Nodes(i).South
j = Nodes(i).East
j = Nodes(i).West
TheReturn = i
StepUsing = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Internal metrics
'
TheReturn = Measure(Nodes(SoftArray(x).HeadNode).East, "s")
SquareListHeight = TheReturn
TheReturn = Measure(Nodes(SoftArray(x).HeadNode).East, "e")
SquareListWidth = TheReturn
TheReturn = CountSteps(x, -1, t)
Measure = TheReturn
TheReturn = 0
k = Nodes(x).North
k = Nodes(x).South
k = Nodes(x).East
k = Nodes(x).West
TheReturn = TheReturn + 1
TheReturn = TheReturn + 1 + CountSteps(k, y, t)
CountSteps = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Printing and Reporting
'
TheReturn = t
TheReturn
= TheReturn
+ "Begin memory probe..." + CHR$(10) TheReturn
= TheReturn
+ "Soft arrays:" + CHR$(10) IF (SoftArrayRegister
(k
) <> -1) THEN TheReturn
= TheReturn
+ " " + SoftArray
(k
).Label
+ " (@" + STR$(SoftArrayRegister
(k
)) + ")" + CHR$(10) TheReturn
= TheReturn
+ "Nodes:" + CHR$(10) IF (IdentityRegister
(k
) <> -1) THEN a = IdentityRegister(k)
TheReturn = TheReturn + " " + Literal$(a)
'TheReturn = TheReturn + " (" + Literal$(Nodes(a).North) + "," + Literal$(Nodes(a).South) + "," + Literal$(Nodes(a).East) + "," + Literal$(Nodes(a).West) + ")"
TheReturn
= TheReturn
+ " (@" + STR$(IdentityRegister
(k
)) + ")" + CHR$(10) TheReturn
= TheReturn
+ "End memory probe..." + CHR$(10) MemoryProbe$ = TheReturn
TheReturn = ""
IF (SoftArrayRegister
(k
) <> -1) THEN j = SoftArray(k).HeadNode
TheReturn = TheReturn + PrintSoftArray$(j)
TheReturn
= TheReturn
+ CHR$(10) PrintAllSoftArrays$ = TheReturn
t = ListNodesRecur$(0, x)
PrintSoftArray$ = TheReturn
s = Nodes(x).South
e = Nodes(x).East
TheReturn
= TheReturn
+ Spacer$
(i
, CHR$(9)) + Literal$
(x
) + CHR$(10) TheReturn = TheReturn + ListNodesRecur$(i + 1, e)
TheReturn = TheReturn + ListNodesRecur$(i, s)
ListNodesRecur$ = TheReturn
TheReturn = ""
TheReturn = TextData(Nodes(x).Reference)
Literal$ = TheReturn
TheReturn = TheReturn + t
TheReturn = ""
Spacer$ = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Soft array construction
'
TheReturn = NewSoftArray(t)
k = LinkEast(TheReturn, x)
NewUnitArray = TheReturn
TheReturn = NewTextNode(t)
i = NextOpenSoftArray(1)
SoftArrayRegister(i) = i
SoftArray(i).Label = TextData(Nodes(TheReturn).Reference)
SoftArray(i).HeadNode = TheReturn
NewSoftArray = TheReturn
TheReturn = -1
IF (SoftArrayRegister
(k
) = -1) THEN TheReturn = k
NextOpenSoftArray = TheReturn
Nodes(s).North = n
Nodes(n).South = s
TheReturn = s
LinkSouth = TheReturn
Nodes(w).East = e
Nodes(e).West = w
TheReturn = e
LinkEast = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Soft array editing
'
s = Nodes(n).South
Nodes(n).South = x
Nodes(x).North = n
Nodes(x).South = s
Nodes(s).North = x
InsertSouth = x
e = Nodes(w).East
Nodes(w).East = x
Nodes(x).West = w
Nodes(x).East = e
Nodes(e).West = x
InsertEast = x
n = Nodes(x).North
s = Nodes(x).South
e = Nodes(x).East
w = Nodes(x).West
IF (SoftArray
(k
).HeadNode
) = x
THEN SoftArrayRegister(k) = -1
IF (n
<> -1) THEN Nodes
(n
).South
= s
IF (s
<> -1) THEN Nodes
(s
).North
= n
IF (e
<> -1) THEN Nodes
(e
).West
= w
IF (w
<> -1) THEN Nodes
(w
).East
= e
IF (n
= -1) AND (w
<> -1) THEN ' content node Nodes(s).West = w
Nodes(s).North = -1
Nodes(w).East = s
IdentityRegister(x) = -1
Unlink = x
e = Nodes(x).East
TheReturn = DeleteRecur(e)
TheReturn = Unlink(x)
DeleteNodes = TheReturn
s = Nodes(x).South
e = Nodes(x).East
TheReturn = DeleteRecur(e)
TheReturn = DeleteRecur(s)
TheReturn = Unlink(x)
DeleteRecur = TheReturn
SoftArrayRegister(x) = -1
TheReturn = DeleteRecur(SoftArray(x).HeadNode)
DeleteSoftArray = TheReturn
IF (SoftArrayRegister
(k
) <> -1) THEN TheReturn = DeleteSoftArray(k)
DeleteAllSoftArrays = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Node creation
'
TheReturn = -1
IF (IdentityRegister
(k
) = -1) THEN TheReturn = k
NextOpenIdentity = TheReturn
i = NextOpenIdentity(x)
IdentityRegister(i) = i
Nodes(i).Identity = i
Nodes(i).Species = t
Nodes(i).Reference = r
Nodes(i).North = -1
Nodes(i).South = -1
Nodes(i).East = -1
Nodes(i).West = -1
NewNode = i
CopyIntegerNode = NewIntegerNode(IntegerData(Nodes(x).Reference))
NewIntegerNode = NewNode(1, "integer", NewIntegerData(x))
NewTextNode = NewNode(1, "text", NewTextData(x))
NewDoubleNode = NewNode(1, "double", NewDoubleData(x))
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Node editing
'
z = NewIntegerData(i)
Nodes(x).Reference = z
EditIntegerReference = z
z = NewTextData(t)
Nodes(x).Reference = z
EditTextReference = z
z = NewDoubleData(d)
Nodes(x).Reference = z
EditDoubleReference = z
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Data assimilation (prevents redundancy but can be disabled for more speed)
'
TheReturn = -1
TheReturn = k
IntegerData
(UBOUND(IntegerData
)) = x
TheReturn
= UBOUND(IntegerData
) NewIntegerData = TheReturn
TheReturn = -1
TheReturn = k
TextData
(UBOUND(Textdata
)) = x
NewTextData = TheReturn
TheReturn = -1
TheReturn = k
DoubleData
(UBOUND(DoubleData
)) = x
TheReturn
= UBOUND(DoubleData
) NewDoubleData = TheReturn
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' End BM-component.
' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''