source-academy / js-slang

Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python
https://source-academy.github.io/source/
Apache License 2.0
70 stars 104 forks source link

CSE Machine: Array expressions evaluated in wrong order. #1519

Closed blackening closed 9 months ago

blackening commented 1 year ago

For input [1,2,3]; image

Should be the opposite order: arr 3, 3,2,1.

The CSE machine in the lecture is correct.

NhatMinh0208 commented 9 months ago

@martin-henz Are we sure we want to handle array literals this way? The current approach shown above makes more sense: We push values into the control in the order encountered in the parse tree, and then when the array literal instruction is called the values in the stack are in reverse order, so the machine can just pop the values and put them into the array in order.

Edit: Nevermind, I was wrong.