"now we're cooking with gas"
Brought to you by:
johnston
|
From: <ivt...@li...> - 2001-10-04 17:26:40
|
Patch: ivtools-011004-johnston-067
For: ivtools-0.9.6
Author: joh...@us...
Subject: now we're cooking with gas
Requires:
This is an intermediate patch to ivtools-0.9.6. To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:
patch -p0 <ThisFile
Summary of Changes:
- Now the streams are really flowing. The ",," concatenation operator
works for the most part, allowing for the composition of complex
streams like this:
s=0,,1,,2,,3**3,,4+100
which generates the sequence:
100 101 102 103 103 103 104 nil
Probably a few minor issues left to clean up. So far I've discovered:
0,1**2
works partially as expected, generating a {0,1} followed by a {0,1}.
But then it generates a {0,nil} repeatedly, never terminating. Hmmmm.
Index: ComUtil/optable.c
diff -c ComUtil/optable.c:1.3 ComUtil/optable.c:1.4
*** ComUtil/optable.c:1.3 Fri Sep 28 14:34:01 2001
--- src/ComUtil/optable.c Thu Oct 4 10:21:34 2001
***************
*** 90,96 ****
{"--", "decr_after", 110, TRUE, OPTYPE_UNARY_POSTFIX },
{"**", "repeat", 90, FALSE, OPTYPE_BINARY },
{"..", "iterate", 80, FALSE, OPTYPE_BINARY },
! {",,", "stream", 75, FALSE, OPTYPE_BINARY },
{"%", "mod", 70, FALSE, OPTYPE_BINARY },
{"*", "mpy", 70, FALSE, OPTYPE_BINARY },
{"/", "div", 70, FALSE, OPTYPE_BINARY },
--- 90,96 ----
{"--", "decr_after", 110, TRUE, OPTYPE_UNARY_POSTFIX },
{"**", "repeat", 90, FALSE, OPTYPE_BINARY },
{"..", "iterate", 80, FALSE, OPTYPE_BINARY },
! {",,", "concat", 75, FALSE, OPTYPE_BINARY },
{"%", "mod", 70, FALSE, OPTYPE_BINARY },
{"*", "mpy", 70, FALSE, OPTYPE_BINARY },
{"/", "div", 70, FALSE, OPTYPE_BINARY },
***************
*** 912,918 ****
-- decr_after 110 Y UNARY POSTFIX
** repeat 90 N BINARY
.. iterate 80 N BINARY
! ,, stream 75 N BINARY
% mod 70 N BINARY
* mpy 70 N BINARY
/ div 70 N BINARY
--- 912,918 ----
-- decr_after 110 Y UNARY POSTFIX
** repeat 90 N BINARY
.. iterate 80 N BINARY
! ,, concat 75 N BINARY
% mod 70 N BINARY
* mpy 70 N BINARY
/ div 70 N BINARY
Index: ComTerp/comterp.c
diff -c ComTerp/comterp.c:1.9 ComTerp/comterp.c:1.10
*** ComTerp/comterp.c:1.9 Fri Sep 28 14:34:04 2001
--- src/ComTerp/comterp.c Thu Oct 4 10:21:36 2001
***************
*** 931,936 ****
--- 931,937 ----
add_command("lt_or_eq", new LessThanOrEqualFunc(this));
add_command("stream", new StreamFunc(this));
+ add_command("concat", new ConcatFunc(this));
add_command("repeat", new RepeatFunc(this));
add_command("iterate", new IterateFunc(this));
add_command("next", new NextFunc(this));
Index: ComTerp/strmfunc.c
diff -c ComTerp/strmfunc.c:1.3 ComTerp/strmfunc.c:1.4
*** ComTerp/strmfunc.c:1.3 Fri Sep 28 14:34:04 2001
--- src/ComTerp/strmfunc.c Thu Oct 4 10:21:36 2001
***************
*** 48,125 ****
void StreamFunc::execute() {
ComValue operand1(stack_arg(0));
! if (nargs()==1) {
! reset_stack();
! if (operand1.is_stream()) {
!
! /* invoked by the next command */
! AttributeValueList* avl = operand1.stream_list();
! if (avl) {
! Iterator i;
! avl->First(i);
! AttributeValue* retval = avl->Done(i) ? nil : avl->GetAttrVal(i);
! if (retval) {
! push_stack(*retval);
! avl->Remove(retval);
! delete retval;
! } else {
! operand1.stream_list(nil);
! push_stack(ComValue::nullval());
! }
! } else
push_stack(ComValue::nullval());
-
- } else {
-
- /* conversion operator */
- if (operand1.is_array()) {
- AttributeValueList* avl = new AttributeValueList(operand1.array_val());
- ComValue stream(this, avl);
- stream.stream_mode(-1); // for internal use (use by this func)
- push_stack(stream);
}
!
! }
} else {
! #if 0
! if (operand1.is_stream()) {
! reset_stack();
! AttributeValueList* avl = operand1.stream_list();
! if (avl) {
! Iterator i;
! avl->First(i);
! AttributeValue* repval = avl->GetAttrVal(i);
! avl->Next(i);
! AttributeValue* cntval = avl->GetAttrVal(i);
! if (cntval->int_val()>0)
! push_stack(*repval);
! else
! push_stack(ComValue::nullval());
! cntval->int_ref()--;
! } else
! push_stack(ComValue::nullval());
! return;
}
! ComValue* operand2 = new ComValue(stack_arg(1));
! reset_stack();
! if (!operand1->is_type(ComValue::ArrayType)) {
! AttributeValueList* avl = new AttributeValueList();
! avl->Append(operand1);
! avl->Append(operand2);
! ComValue retval(avl);
! push_stack(retval);
! } else {
! AttributeValueList* avl = operand1->array_val();
! avl->Append(operand2);
! push_stack(*operand1);
! delete operand1;
}
! #endif
! }
}
/*****************************************************************************/
--- 48,171 ----
void StreamFunc::execute() {
ComValue operand1(stack_arg(0));
! reset_stack();
!
! if (operand1.is_stream()) {
! /* invoked by the next command */
! AttributeValueList* avl = operand1.stream_list();
! if (avl) {
! Iterator i;
! avl->First(i);
! AttributeValue* retval = avl->Done(i) ? nil : avl->GetAttrVal(i);
! if (retval) {
! push_stack(*retval);
! avl->Remove(retval);
! delete retval;
! } else {
! operand1.stream_list(nil);
push_stack(ComValue::nullval());
}
! } else
! push_stack(ComValue::nullval());
!
} else {
! /* conversion operator */
! if (operand1.is_array()) {
! AttributeValueList* avl = new AttributeValueList(operand1.array_val());
! ComValue stream(this, avl);
! stream.stream_mode(-1); // for internal use (use by this func)
! push_stack(stream);
}
! }
! }
!
! /*****************************************************************************/
!
! int ConcatFunc::_symid;
!
! ConcatFunc::ConcatFunc(ComTerp* comterp) : StrmFunc(comterp) {
! }
!
! void ConcatFunc::execute() {
! ComValue operand1(stack_arg_post_eval(0));
! ComValue operand2(stack_arg_post_eval(1));
! reset_stack();
!
! /* setup for concatenation */
! static ConcatNextFunc* cnfunc = new ConcatNextFunc(comterp());
! AttributeValueList* avl = new AttributeValueList();
! avl->Append(new AttributeValue(operand1));
! avl->Append(new AttributeValue(operand2));
! ComValue stream(cnfunc, avl);
! stream.stream_mode(-1); // for internal use (use by ConcatNextFunc)
! push_stack(stream);
! }
!
! /*****************************************************************************/
!
! int ConcatNextFunc::_symid;
!
! ConcatNextFunc::ConcatNextFunc(ComTerp* comterp) : StrmFunc(comterp) {
! }
!
! void ConcatNextFunc::execute() {
! ComValue operand1(stack_arg(0));
!
! /* invoked by next func */
! reset_stack();
! AttributeValueList* avl = operand1.stream_list();
! if (avl) {
! Iterator i;
! avl->First(i);
! AttributeValue* oneval = avl->GetAttrVal(i);
! avl->Next(i);
! AttributeValue* twoval = avl->GetAttrVal(i);
! boolean done = false;
! /* stream first argument until nil */
! if (oneval->is_known()) {
! if (oneval->is_stream()) {
! NextFunc nextfunc(comterp());
! push_stack(*oneval);
! push_funcstate(1,0);
! nextfunc.execute();
! pop_funcstate();
! if (comterp()->stack_top().is_unknown()) {
! *oneval = ComValue::nullval();
! comterp()->pop_stack();
! } else
! done = true;
! } else {
! push_stack(*oneval);
! *oneval = ComValue::nullval();
! done = true;
! }
}
!
! /* stream 2nd argument until nil */
! if (twoval->is_known() && !done) {
! if (twoval->is_stream()) {
! NextFunc nextfunc(comterp());
! push_stack(*twoval);
! push_funcstate(1,0);
! nextfunc.execute();
! pop_funcstate();
! if (comterp()->stack_top().is_unknown())
! *twoval = ComValue::nullval();
! } else {
! push_stack(*twoval);
! *twoval = ComValue::nullval();
! }
! } else if (!done)
! push_stack(ComValue::nullval());
!
! } else
! push_stack(ComValue::nullval());
!
! return;
}
/*****************************************************************************/
Index: ComTerp/strmfunc.h
diff -c ComTerp/strmfunc.h:1.3 ComTerp/strmfunc.h:1.4
*** ComTerp/strmfunc.h:1.3 Fri Sep 28 14:34:04 2001
--- src/ComTerp/strmfunc.h Thu Oct 4 10:21:36 2001
***************
*** 41,56 ****
};
! //: , (stream) operator.
class StreamFunc : public StrmFunc {
public:
StreamFunc(ComTerp*);
virtual void execute();
virtual const char* docstring() {
! return ",, is the stream operator"; }
CLASS_SYMID("StreamFunc");
};
--- 41,83 ----
};
! //: stream command
class StreamFunc : public StrmFunc {
public:
StreamFunc(ComTerp*);
virtual void execute();
virtual const char* docstring() {
! return "strm=%s(list) -- convert list to stream"; }
CLASS_SYMID("StreamFunc");
+
+ };
+
+ //: ,, (concat) operator.
+ class ConcatFunc : public StrmFunc {
+ public:
+ ConcatFunc(ComTerp*);
+
+ virtual void execute();
+ virtual boolean post_eval() { return true; }
+ virtual const char* docstring() {
+ return ",, is the concat operator"; }
+
+ CLASS_SYMID("ConcatFunc");
+
+ };
+
+ //: hidden func used by next command for ,, (concat) operator.
+ class ConcatNextFunc : public StrmFunc {
+ public:
+ ConcatNextFunc(ComTerp*);
+
+ virtual void execute();
+ virtual const char* docstring() {
+ return "hidden func used by next command for ,, (concat) operator."; }
+
+ CLASS_SYMID("ConcatNextFunc");
};
Index: comterp/README
diff -c comterp/README:1.5 comterp/README:1.6
*** comterp/README:1.5 Fri Sep 28 14:34:06 2001
--- src/comterp_/README Thu Oct 4 10:21:38 2001
***************
*** 85,91 ****
-- decr_after 110 R-to-L unary-postfix
** repeat 90 L-to-R binary
.. iterate 80 L-to-R binary
! ,, stream 75 L-to-R binary
% mod 70 L-to-R binary
* mpy 70 L-to-R binary
/ div 70 L-to-R binary
--- 85,91 ----
-- decr_after 110 R-to-L unary-postfix
** repeat 90 L-to-R binary
.. iterate 80 L-to-R binary
! ,, concat 75 L-to-R binary
% mod 70 L-to-R binary
* mpy 70 L-to-R binary
/ div 70 L-to-R binary
Index: man1_ivtools/comterp.1
diff -c man1_ivtools/comterp.1:1.5 man1_ivtools/comterp.1:1.6
*** man1_ivtools/comterp.1:1.5 Fri Sep 28 14:34:39 2001
--- src/man/man1/comterp.1 Thu Oct 4 10:22:06 2001
***************
*** 95,101 ****
-- decr_after 110 R-to-L unary-postfix
** repeat 90 L-to-R binary
.. iterate 80 L-to-R binary
! ,, stream 75 L-to-R binary
% mod 70 L-to-R binary
* mpy 70 L-to-R binary
/ div 70 L-to-R binary
--- 95,101 ----
-- decr_after 110 R-to-L unary-postfix
** repeat 90 L-to-R binary
.. iterate 80 L-to-R binary
! ,, concat 75 L-to-R binary
% mod 70 L-to-R binary
* mpy 70 L-to-R binary
/ div 70 L-to-R binary
*** /dev/null Thu Oct 4 10:22:09 PDT 2001
--- patches/ivtools-011004-johnston-067
*************** patches/ivtools-011004-johnston-067
*** 0 ****
--- 1 ----
+ ivtools-011004-johnston-067
|