[Scummvm-git-logs] scummvm master -> 77461e636e57e6a67181d339ae5c44a57c4fa977

sev- sev at scummvm.org
Sat Feb 15 21:22:13 UTC 2020


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
391335f09c DIRECTOR: LINGO: Implement repeat with var in array
77461e636e DIRECTOR: LINGO: Implement advice from Sev.


Commit: 391335f09cb44e1be9ac9151e5ec557431ac8aa3
    https://github.com/scummvm/scummvm/commit/391335f09cb44e1be9ac9151e5ec557431ac8aa3
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-02-15T22:22:09+01:00

Commit Message:
DIRECTOR: LINGO: Implement repeat with var in array

Lingo implements the for each loop as `repeat with VAR in ARRAY`.
1) The `ARRAY` is evaluated,
2) a loop counter is created of size(ARRAY),
3) consume the loop counter, starting at 0.
3) the ARRAY[counter] item is assiged to `VAR` and
4) the loop body executed.
5) update the loop counter with + 1
6) goto 3 till the loop counter is exhausted.

Changed paths:
    engines/director/lingo/lingo-code.cpp


diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index 5c4e44b..3758f7a 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -1038,7 +1038,21 @@ void LC::c_repeatwithcode(void) {
 	Symbol *counter = g_lingo->lookupVar(countername.c_str());
 
 	if (finish == 0 && inc == 0) {
-		warning("STUB: 'repeat with' over list ");
+		// Handle repeat with  X in ARRAY
+		g_lingo->execute(init + savepc -1); // eval the list
+		Datum array = g_lingo->pop(); // get the list from the stack
+		int arraySize = array.u.farr->size();
+		for (uint i = 0; i < arraySize; i++) {
+
+			Datum loop_var;
+			loop_var.type = VAR;
+			loop_var.u.sym = g_lingo->lookupVar(countername.c_str());
+
+			Datum source = (*array.u.farr)[i];
+
+			g_lingo->varAssign(loop_var, source);
+			g_lingo->execute(body + savepc -1);
+		}
 		g_lingo->_pc = end + savepc - 1; /* next stmt */
 		return;
 	}


Commit: 77461e636e57e6a67181d339ae5c44a57c4fa977
    https://github.com/scummvm/scummvm/commit/77461e636e57e6a67181d339ae5c44a57c4fa977
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-02-15T22:22:09+01:00

Commit Message:
DIRECTOR: LINGO: Implement advice from Sev.

- loop_var is out of the loop and
- extra Datum assignment for array element is removed.

Changed paths:
    engines/director/lingo/lingo-code.cpp


diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index 3758f7a..1a937f0 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -1041,16 +1041,14 @@ void LC::c_repeatwithcode(void) {
 		// Handle repeat with  X in ARRAY
 		g_lingo->execute(init + savepc -1); // eval the list
 		Datum array = g_lingo->pop(); // get the list from the stack
-		int arraySize = array.u.farr->size();
-		for (uint i = 0; i < arraySize; i++) {
-
-			Datum loop_var;
-			loop_var.type = VAR;
-			loop_var.u.sym = g_lingo->lookupVar(countername.c_str());
 
-			Datum source = (*array.u.farr)[i];
+		Datum loop_var;
+		loop_var.type = VAR;
+		loop_var.u.sym = g_lingo->lookupVar(countername.c_str());
 
-			g_lingo->varAssign(loop_var, source);
+		int arraySize = array.u.farr->size();
+		for (uint i = 0; i < arraySize; i++) {
+			g_lingo->varAssign(loop_var, array.u.farr->operator[](i));
 			g_lingo->execute(body + savepc -1);
 		}
 		g_lingo->_pc = end + savepc - 1; /* next stmt */




More information about the Scummvm-git-logs mailing list