[Scummvm-git-logs] scummvm master -> 1b83be60a4976526656642ab398b126a701a010f

moralrecordings code at moral.net.au
Mon Feb 17 14:27:46 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:
f744830bc9 DIRECTOR: LINGO: Implement list-related builtins
1b83be60a4 DIRECTOR: LINGO: Fix varAssign to support ARRAY


Commit: f744830bc91bc60f59aab5dc638425e4db0be227
    https://github.com/scummvm/scummvm/commit/f744830bc91bc60f59aab5dc638425e4db0be227
Author: Scott Percival (code at moral.net.au)
Date: 2020-02-17T21:56:19+08:00

Commit Message:
DIRECTOR: LINGO: Implement list-related builtins

Changed paths:
    engines/director/lingo/lingo-builtins.cpp
    engines/director/lingo/lingo-bytecode.cpp


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index e79bccf..7fc20ad 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -553,13 +553,29 @@ void LB::b_value(int nargs) {
 // Lists
 ///////////////////
 void LB::b_add(int nargs) {
-	g_lingo->printSTUBWithArglist("b_add", nargs);
-	g_lingo->dropStack(nargs);
+	// FIXME: when a list is "sorted", add should insert based on 
+	// the current ordering. otherwise, append to the end.
+	LB::b_append(nargs);
 }
 
 void LB::b_addAt(int nargs) {
-	g_lingo->printSTUBWithArglist("b_addAt", nargs);
-	g_lingo->dropStack(nargs);
+	if (nargs != 3) {
+		warning("b_addAt: expected 3 args, not %d", nargs);
+		g_lingo->dropStack(nargs);
+		return;
+	}
+	Datum value = g_lingo->pop();
+	Datum index = g_lingo->pop();
+	Datum list = g_lingo->pop();
+	if (index.type != INT) {
+		warning("b_addAt: index arg should be of type INT, not %s", index.type2str());
+		return;
+	}
+	if (list.type != ARRAY) {
+		warning("b_addAt: list arg should be of type ARRAY, not %s", list.type2str());
+		return;
+	}
+	list.u.farr->insert_at(index.u.i-1, value);
 }
 
 void LB::b_addProp(int nargs) {
@@ -568,18 +584,54 @@ void LB::b_addProp(int nargs) {
 }
 
 void LB::b_append(int nargs) {
-	g_lingo->printSTUBWithArglist("b_append", nargs);
-	g_lingo->dropStack(nargs);
+	if (nargs != 2) {
+		warning("b_append: expected 2 args, not %d", nargs);
+		g_lingo->dropStack(nargs);
+		return;
+	}
+	Datum value = g_lingo->pop();
+	Datum list = g_lingo->pop();
+	if (list.type != ARRAY) {
+		warning("b_append: list arg should be of type ARRAY, not %s", list.type2str());
+		return;
+	}
+	list.u.farr->push_back(value);
 }
 
 void LB::b_count(int nargs) {
-	g_lingo->printSTUBWithArglist("b_count", nargs);
-	g_lingo->dropStack(nargs);
+	if (nargs != 1) {
+		warning("b_count: expected 1 args, not %d", nargs);
+		g_lingo->dropStack(nargs);
+		return;
+	}
+	Datum list = g_lingo->pop();
+	if (list.type != ARRAY) {
+		warning("b_append: list arg should be of type ARRAY, not %s", list.type2str());
+		return;
+	}
+	Datum result;
+	result.type = INT;
+	result.u.i = list.u.farr->size();
+	g_lingo->push(result);
 }
 
 void LB::b_deleteAt(int nargs) {
-	g_lingo->printSTUBWithArglist("b_deleteAt", nargs);
-	g_lingo->dropStack(nargs);
+	if (nargs != 2) {
+		warning("b_deleteAt: expected 2 args, not %d", nargs);
+		g_lingo->dropStack(nargs);
+		return;
+	}
+	Datum index = g_lingo->pop();
+	Datum list = g_lingo->pop();
+	if (index.type != INT) {
+		warning("b_deleteAt: index arg should be of type INT, not %s", index.type2str());
+		return;
+	}
+	if (list.type != ARRAY) {
+		warning("b_deleteAt: list arg should be of type ARRAY, not %s", list.type2str());
+		return;
+	}
+	list.u.farr->remove_at(index.u.i-1);
 }
 
 void LB::b_deleteProp(int nargs) {
@@ -633,8 +685,14 @@ void LB::b_getPropAt(int nargs) {
 }
 
 void LB::b_list(int nargs) {
-	g_lingo->printSTUBWithArglist("b_list", nargs);
-	g_lingo->dropStack(nargs);
+	Datum result;
+	result.type = ARRAY;
+	result.u.farr = new DatumArray;
+
+	for (int i = 0; i < nargs; i++)
+		result.u.farr->insert_at(0, g_lingo->pop());
+
+	g_lingo->push(result);
 }
 
 void LB::b_listP(int nargs) {
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index 3a77271..190d1e1 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -320,14 +320,7 @@ void LC::cb_v4assign() {
 void LC::cb_list() {
 	Datum nargs = g_lingo->pop();
 	if ((nargs.type == ARGC) || (nargs.type == ARGCNORET)) {
-		Datum result;
-		warning("STUB: cb_list()");
-
-		for (int i = 0; i < nargs.u.i; i++)
-			g_lingo->pop();
-
-		result.type = VOID;
-		g_lingo->push(result);
+		LB::b_list(nargs.u.i);
 	} else {
 		warning("cb_list: first arg should be of type ARGC or ARGCNORET, not %s", nargs.type2str());
 	}


Commit: 1b83be60a4976526656642ab398b126a701a010f
    https://github.com/scummvm/scummvm/commit/1b83be60a4976526656642ab398b126a701a010f
Author: Scott Percival (code at moral.net.au)
Date: 2020-02-17T22:19:44+08:00

Commit Message:
DIRECTOR: LINGO: Fix varAssign to support ARRAY

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


diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index 6a902b2..693524e 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -499,7 +499,7 @@ void Lingo::varAssign(Datum &var, Datum &value) {
 		}
 
 		if (sym->type != INT && sym->type != VOID &&
-				sym->type != FLOAT && sym->type != STRING) {
+				sym->type != FLOAT && sym->type != STRING && sym->type != ARRAY) {
 			warning("varAssign: assignment to non-variable '%s'", sym->name.c_str());
 			return;
 		}
@@ -518,7 +518,7 @@ void Lingo::varAssign(Datum &var, Datum &value) {
 		} else if (value.type == STRING) {
 			sym->u.s = new Common::String(*value.u.s);
 			delete value.u.s;
-		} else if (value.type == POINT) {
+		} else if (value.type == POINT || value.type == ARRAY) {
 			sym->u.farr = new DatumArray(*value.u.farr);
 			delete value.u.farr;
 		} else if (value.type == SYMBOL) {
@@ -527,8 +527,6 @@ void Lingo::varAssign(Datum &var, Datum &value) {
 			sym->u.s = value.u.s;
 		} else if (value.type == VOID) {
 			sym->u.i = 0;
-		} else if (value.type == ARRAY) {
-			sym->u.farr = value.u.farr;
 		} else {
 			warning("varAssign: unhandled type: %s", value.type2str());
 			sym->u.s = value.u.s;




More information about the Scummvm-git-logs mailing list