Skip to content

Commit

Permalink
fix input port order
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 31, 2023
1 parent 29d64d7 commit 8f7f1eb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 46 deletions.
18 changes: 12 additions & 6 deletions docs/tests/DiffList.inet
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
defnode sole -- value! end
defnode sole
------
value!
end

defnode null -- value! end
defnode null
------
value!
end

defnode cons
tail
head
tail
-------
value!
end

defnode diff
left
right
left
------
value!
end

defnode diff_append
rest
target!
rest
------
return
end
Expand All @@ -30,8 +36,8 @@ defrule diff diff_append
end

defnode diff_open
list
target!
list
------
return
end
Expand Down
7 changes: 4 additions & 3 deletions docs/tests/List.inet
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ defnode null
end

defnode cons
tail
head
tail
-------
value!
end

defnode append
rest
target!
rest
------
return
end

defrule null append
(append)-rest return-(append)
(append)-rest
return-(append)
end

defrule cons append
Expand Down
24 changes: 15 additions & 9 deletions docs/tests/Nat.inet
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
defnode zero -- value! end
defnode zero
------
value!
end

defnode add1 prev -- value! end
defnode add1
prev
------
value!
end

defnode add
target!
Expand All @@ -10,24 +17,23 @@ defnode add
end

defrule zero add
(add)-addend return-(add)
(add)-addend
return-(add)
end

defrule add1 add
(add1)-prev (add)-addend add add1
(add1)-prev
(add)-addend
add add1
return-(add)
end

show zero zero add end
run zero zero add end

defnet one zero add1 end

defnet two one one add end

defnet four
two two add
end
defnet four two two add end

show two end
run two end
Expand Down
52 changes: 26 additions & 26 deletions docs/tests/Nat.inet.out
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
(zero)-value!target-(add₂)
(zero)-value addend-(add₂)
(zero)-value!target-(add₂)
(zero)-value addend-(add₂)
(add₂)-return

(zero)-value
(zero)-value

(add1)-value!target-(add₁₁)
(add1₁₀)-value addend-(add₁₁)
(add1₁₀)-value!target-(add₁₁)
(add1)-value addend-(add₁₁)
(zero₉)-value prev-(add1₁₀)
(zero₇)-value prev-(add1₈)
(add₁₁)-return

(add1₁₅)-value prev-(add1₁₉)
(zero₁₄)-value prev-(add1₁)
(zero₁₂)-value prev-(add1₂₁)
(add1₂₁)-value prev-(add1₁)
(add1₁₉)-value

(add1₂₆)-value!target-(add₂₉)
(add1₂₁)-value!target-(add₂₄)
(add₂₄)-return target-(add₃₀)
(add₂₉)-return addend-(add₃₀)
(add1₂₈)-value addend-(add₂₉)
(add1₃₀)-value!target-(add₃₁)
(add1₂₅)-value!target-(add₂₆)
(add₂₆)-return addend-(add₃₂)
(add₃₁)-return target-(add₃₂)
(add1₂₈)-value addend-(add₃₁)
(zero₂₉)-value prev-(add1₃₀)
(zero₂₇)-value prev-(add1₂₈)
(zero₂₅)-value prev-(add1₂₆)
(add1₂₃)-value addend-(add₂₄)
(add1₂₃)-value addend-(add₂₆)
(zero₂₄)-value prev-(add1₂₅)
(zero₂₂)-value prev-(add1₂₃)
(zero₂₀)-value prev-(add1₂₁)
(add₃₀)-return
(add₃₂)-return

(add1₄₄)-value prev-(add1₀)
(add1₀)-value prev-(add1₄₈)
(add1₃₉)-value prev-(add1₄)
(zero₃₈)-value prev-(add1₃₉)
(zero₃₃)-value prev-(add1₀)
(add1₀)-value prev-(add1₅₆)
(add1₅₆)-value prev-(add1₄)
(add1₅₄)-value prev-(add1₄₈)
(add1₄₈)-value

(zero₅₁)-value!target-(add₄)
(add1₅₃)-value addend-(add₄)
(zero₂)-value prev-(add1₃)
(add₄)-return
(add1₆₃)-value!target-(add₄)
(zero₆₁)-value addend-(add₄)
(zero₂)-value prev-(add1₃)
(add₄)-return

(zero₅₆)-value prev-(add1₅₇)
(add1₅₇)-value
(zero₆₆)-value prev-(add1₇₁)
(add1₇₁)-value

7 changes: 5 additions & 2 deletions src/lang/definitions/NodeDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ export class NodeDefinition implements Definition {
meaning(net: Net): Node {
const node = createNode(this.mod, this.name, this.input, this.output)

// NOTE Be careful about the order.
for (const port of [...node.input].reverse()) {
// Be careful about the order:
// The first input port connects
// with the port on the top of the stack.

for (const port of node.input) {
const top = net.ports.pop()
if (top === undefined) {
throw new Error(`I expect a port on top of the stack`)
Expand Down

0 comments on commit 8f7f1eb

Please sign in to comment.