Ultima attività 2 months ago

A small modification to the original propagator code that adds scopes.

june's Avatar june ha revisionato questo gist 2 months ago. Vai alla revisione

1 file changed, 117 insertions

scoped-propagators.nv(file creato)

@@ -0,0 +1,117 @@
1 + || :@include: lib/rpn.nv
2 +
3 + ||:: (
4 + a = b + c ;
5 + var c ;
6 + a = 10 ;
7 + b <- 20 ;
8 + c <- 30 ;
9 + {
10 + a = b - c ;
11 + var b ;
12 + c = 20 ;
13 + b <- 30 ;
14 + }
15 + )
16 +
17 + |:: (var $x ;)| :: var $x
18 + |:: ($x <- $y ;)| :: $x <- $y
19 + |:: ($x = $y $op $z ;)| :: $x = $y $op $z
20 + |:: ($x = $y ;)| :: $x = $y
21 + |:: {| :: open a scope
22 + |:: }| :: close a scope
23 +
24 + |:: open a scope|
25 + :: open a variable scope
26 + :: open a propagator scope
27 +
28 + |:: open a variable scope| :variables:
29 + |:: open a propagator scope| :nodes:
30 +
31 + |:: close a scope|
32 + :: close a variable scope
33 + :: close a propagator scope
34 +
35 + |:: close a variable scope :variables:|
36 + |:: close a variable scope? :variables: $x $y|
37 + |:: close a variable scope|
38 +
39 + |:: close a propagator scope :nodes:|
40 + |:: close a propagator scope? :nodes: $op $x $y $z|
41 + |:: close a propagator scope|
42 +
43 + |:: $x <- $y|
44 + :: set $x to $y
45 + :: propagate variable $x
46 +
47 + |:: declare variables? :: $name| :: var $name
48 + |:: declare variables|
49 +
50 + |:: var $x :default value: $y?| :: $x = $y
51 + |:: var $x| :: $x = 0
52 +
53 + |:: $x = $y| :: set $x to $y
54 + |:: $z = $x $op $y|
55 + :nodes: $op $x $y $z
56 +
57 + |:: set $x to $y :variables: $x $z|
58 + :: reset variables
59 + :variables: $x $y
60 + |:: set $x to $y :not found: $x|
61 + :: reset variables
62 + :variables: $x $y
63 + |:: set $x to $y?|
64 + :: find $x
65 +
66 + |:: fetch the value of $x :variables: $x $y?|
67 + :: reset variables
68 + :values: $y
69 + |:: fetch the value of $x :not found: $x?|
70 + |:: fetch the value of $x?|
71 + :: find $x
72 +
73 + |:: propagate variable $x|
74 + :: fetch nodes that depend on $x
75 + :: propagate changes
76 + :: prime the network
77 +
78 + |:: propagate changes :dependencies: $op $x $y $z|
79 + :: fetch the value of $y
80 + :: fetch the value of $x
81 + :: compute $op and store it in $z
82 + :: propagate variable $z
83 + :visited: $op $x $y $z
84 + |:: propagate changes|
85 +
86 + |:: compute $op and store it in $z :@rpn data: $x|
87 + :: set $z to $x
88 + |:: compute $op and store it in $z? :values: ($x $y)|
89 + :@rpn: ($x $y $op)
90 +
91 + |:: fetch nodes that depend on $x? :nodes: $op $x $y $z|
92 + :dependencies: $op $x $y $z
93 + |:: fetch nodes that depend on $x? :nodes: $op $y $x $z|
94 + :dependencies: $op $y $x $z
95 + |:: fetch nodes that depend on $x? :nodes: $op $w $y $z|
96 + :checked nodes: $op $w $y $z
97 + |:: fetch nodes that depend on $x|
98 + :: reset nodes
99 +
100 + |:: find $x :variables: $x $y?|
101 + |:: find $x? :variables: $z $y|
102 + :checked variables: $z $y
103 + |:: find $x|
104 + :: reset variables
105 + :not found: $x
106 +
107 + |:: reset variables? :checked variables: $x $y|
108 + :variables: $x $y
109 + |:: reset variables|
110 +
111 + |:: reset nodes? :checked nodes: $op $x $y $z|
112 + :nodes: $op $x $y $z
113 + |:: reset nodes|
114 +
115 + |:: prime the network? :visited: $op $x $y $z|
116 + :nodes: $op $x $y $z
117 + |:: prime the network|
Più nuovi Più vecchi