From e72c652f568a8a0b2b64503ccd49e4b80fdb9a7b Mon Sep 17 00:00:00 2001 From: Stan Hebben Date: Fri, 25 Oct 2024 20:36:13 +0200 Subject: [PATCH] Fixed IteratorMember and added a test for iterating over lists --- .../zenscript/codemodel/member/IteratorMember.java | 7 +++++++ .../resources/zencode_tests/stdlib/list_iterate.zc | 13 +++++++++++++ StdLibs | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ScriptingEngineTester/src/main/resources/zencode_tests/stdlib/list_iterate.zc diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IteratorMember.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IteratorMember.java index 8af51bee..9a070405 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IteratorMember.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/IteratorMember.java @@ -3,6 +3,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.*; import org.openzen.zenscript.codemodel.identifiers.MethodID; +import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; import org.openzen.zenscript.codemodel.statement.Statement; import org.openzen.zenscript.codemodel.type.IteratorTypeID; @@ -49,7 +50,13 @@ public String describe() { @Override public void registerTo(TypeID targetType, MemberSet.Builder members, GenericMapper mapper) { + TypeID[] instancedTypes = mapper.map(iteratorTypes); + IteratorTypeID iteratorTypeID = new IteratorTypeID(instancedTypes); + FunctionHeader header = new FunctionHeader(iteratorTypeID); + MethodInstance instance = new MethodInstance(this, header, targetType); + IteratorInstance iterator = new IteratorInstance(targetType, instancedTypes, instance); + members.iterator(iterator); } @Override diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/stdlib/list_iterate.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/stdlib/list_iterate.zc new file mode 100644 index 00000000..668386a6 --- /dev/null +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/stdlib/list_iterate.zc @@ -0,0 +1,13 @@ +#dependency: stdlib +#output: 1 +#output: thing + +import stdlib.List; + +var list = new List(); +list.add('thing'); + +println(list.length); +for item in list { + println(item); +} diff --git a/StdLibs b/StdLibs index e3728319..d21d9972 160000 --- a/StdLibs +++ b/StdLibs @@ -1 +1 @@ -Subproject commit e372831946b8e4127919e64707edbddde588cf43 +Subproject commit d21d9972e1bda49975d5151951782809560d29a4