[OpenJade patch] map-constructor

Subject: [OpenJade patch] map-constructor
From: Matthias Clasen <clasen@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 18 Jun 1999 23:41:07 +0200
Just to keep the CVS maintainers busy, one more little patch.
This one implements map-constructor from 12.4.3.


--- jade-1.2.1/style/primitive.h	Wed Oct  7 07:16:34 1998
+++ jade-1.2.1+/style/primitive.h	Fri Jun 18 22:20:52 1999
@@ -61,6 +61,7 @@
 PRIMITIVE(Literal, "literal", 0, 0, 1)
 PRIMITIVE(ProcessChildren, "process-children", 0, 0, 0)
 PRIMITIVE(ProcessChildrenTrim, "process-children-trim", 0, 0, 0)
+PRIMITIVE(MapConstructor, "map-constructor", 2, 0, 0)
 PRIMITIVE(SosofoAppend, "sosofo-append", 0, 0, 1)
 PRIMITIVE(NextMatch, "next-match", 0, 1, 0)
 PRIMITIVE(EmptySosofo, "empty-sosofo", 0, 0, 0)
--- jade-1.2.1/style/primitive.cxx	Wed Oct  7 07:16:34 1998
+++ jade-1.2.1+/style/primitive.cxx	Fri Jun 18 22:39:47 1999
@@ -1848,6 +1862,43 @@
   return new (interp) ProcessNodeListSosofoObj(nl, context.processingMode);
 }
 
+DEFPRIMITIVE(MapConstructor, argc, argv, context, interp, loc)
+{
+  FunctionObj *func = argv[0]->asFunction();
+  if (!func)
+    return argError(interp, loc,
+		    InterpreterMessages::notAProcedure, 0, argv[0]);
+  if (func->totalArgs() > 0) {
+    interp.message(InterpreterMessages::tooManyArgs);
+    return interp.makeError();
+  }
+  NodeListObj *nl = argv[1]->asNodeList();
+  if (!nl)
+    return argError(interp, loc,
+		    InterpreterMessages::notANodeList, 1, argv[1]);
+  AppendSosofoObj *obj = new (interp) AppendSosofoObj;
+  NodePtr nd;
+  ELObj *ret;
+  while (nd = nl->nodeListFirst(context, interp)) {
+    nl = nl->nodeListRest(context, interp);
+    {
+      EvalContext::CurrentNodeSetter cns(nd, context.processingMode, context);
+      InsnPtr insn(func->makeCallInsn(0, interp, loc, InsnPtr()));
+      VM vm(context, interp);
+      ret = vm.eval(insn.pointer());
+    }
+    if (interp.isError(ret)) {
+      return interp.makeError();
+    }
+    SosofoObj *sosofo = ret->asSosofo();
+    if (!sosofo) {
+      return interp.makeError();
+    }
+    obj->append(sosofo);
+  }
+  return obj;
+}
+
 static
 void reverse(StringC &s)
 {
 

-- 
Matthias Clasen, 
Tel. 0761/203-5606
Email: clasen@xxxxxxxxxxxxxxxxxxxxxxxxxx
Mathematisches Institut, Albert-Ludwigs-Universitaet Freiburg


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread