summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/stack.cc
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-01-02 16:31:31 +0000
committerKarl Berry <karl@freefriends.org>2021-01-02 16:31:31 +0000
commit6457cd3f6e21e23e21db6dafff021d17f5457567 (patch)
tree08f169333e47c5fc1c50e828cf3a0f50bdf9b508 /Build/source/utils/asymptote/stack.cc
parentdc2504a4c02af0ec2fff00e6b833c6143a06b4cd (diff)
asy 2.68 sources
git-svn-id: svn://tug.org/texlive/trunk@57291 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/stack.cc')
-rw-r--r--Build/source/utils/asymptote/stack.cc130
1 files changed, 66 insertions, 64 deletions
diff --git a/Build/source/utils/asymptote/stack.cc b/Build/source/utils/asymptote/stack.cc
index 7ffb6bcb590..a854a9d9eff 100644
--- a/Build/source/utils/asymptote/stack.cc
+++ b/Build/source/utils/asymptote/stack.cc
@@ -32,21 +32,23 @@ void breakpoint(vm::stack *Stack, absyntax::runnable *r);
namespace vm {
+const char *dereferenceNullPointer="dereference of null pointer";
+
mem::list<bpinfo> bplist;
-
+
namespace {
position curPos = nullPos;
const program::label nulllabel;
}
inline stack::vars_t base_frame(
- size_t size,
- size_t parentIndex,
- stack::vars_t closure
+ size_t size,
+ size_t parentIndex,
+ stack::vars_t closure
#ifdef DEBUG_FRAME
- , string name
+ , string name
#endif
- )
+ )
{
stack::vars_t vars;
#ifdef SIMPLE_FRAME
@@ -149,7 +151,7 @@ void stack::marshall(size_t args, stack::vars_t vars)
#if SIMPLE_FRAME
vars[i-1] = pop();
#else
- (*vars)[i-1] = pop();
+ (*vars)[i-1] = pop();
#endif
}
@@ -211,7 +213,7 @@ void stack::run(func *f)
#endif
}
-void stack::breakpoint(absyntax::runnable *r)
+void stack::breakpoint(absyntax::runnable *r)
{
lastPos=curPos;
indebugger=true;
@@ -220,12 +222,12 @@ void stack::breakpoint(absyntax::runnable *r)
debugOp=(s.length() > 0) ? s[0] : (char) 0;
indebugger=false;
}
-
-void stack::debug()
+
+void stack::debug()
{
if(!curPos) return;
if(indebugger) {em.clear(); return;}
-
+
switch(debugOp) {
case 'i': // inst
breakpoint();
@@ -257,7 +259,7 @@ void stack::debug()
newline=false;
break;
}
- if(!newline &&
+ if(!newline &&
(curPos.match(lastPos.filename()) && !curPos.match(lastPos.Line())))
newline=true;
}
@@ -291,45 +293,45 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
// Set up the closure, if necessary.
if (vars == 0)
- {
+ {
#ifndef SIMPLE_FRAME
- assessClosure(l);
- if (l->closureReq == lambda::NEEDS_CLOSURE)
+ assessClosure(l);
+ if (l->closureReq == lambda::NEEDS_CLOSURE)
#endif
- {
- /* make new activation record */
- vars = vm::make_frame(l, parent);
- assert(vars);
- }
+ {
+ /* make new activation record */
+ vars = vm::make_frame(l, parent);
+ assert(vars);
+ }
#ifndef SIMPLE_FRAME
- else
- {
- assert(l->closureReq == lambda::DOESNT_NEED_CLOSURE);
+ else
+ {
+ assert(l->closureReq == lambda::DOESNT_NEED_CLOSURE);
- // Use the stack to store variables.
- varlink = &theStack;
+ // Use the stack to store variables.
+ varlink = &theStack;
- // Record where the parameters start on the stack.
- frameStart = theStack.size() - frameSize;
+ // Record where the parameters start on the stack.
+ frameStart = theStack.size() - frameSize;
- // Add the parent's closure to the frame.
- push(parent);
- ++frameSize;
+ // Add the parent's closure to the frame.
+ push(parent);
+ ++frameSize;
- size_t newFrameSize = (size_t)l->framesize;
+ size_t newFrameSize = (size_t)l->framesize;
- if (newFrameSize > frameSize) {
- theStack.resize(frameStart + newFrameSize);
- frameSize = newFrameSize;
- }
- }
+ if (newFrameSize > frameSize) {
+ theStack.resize(frameStart + newFrameSize);
+ frameSize = newFrameSize;
+ }
+ }
#endif
- }
+ }
if (vars) {
- marshall(l->parentIndex, vars);
+ marshall(l->parentIndex, vars);
- SET_VARLINK;
+ SET_VARLINK;
}
/* start the new function */
@@ -341,10 +343,10 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
for (;;) {
const inst &i = *ip;
curPos = i.pos;
-
- if(curPos.filename() == fileName)
- topPos=curPos;
-
+
+ if(curPos.filename() == fileName)
+ topPos=curPos;
+
#ifdef PROFILE
prof.recordInstruction();
#endif
@@ -352,16 +354,16 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
#ifdef DEBUG_STACK
printInst(cout, ip, l->code->begin());
cout << " (";
- i.pos.printTerse(cout);
- cout << ")\n";
+ i.pos.printTerse(cout);
+ cout << ")\n";
#endif
if(settings::verbose > 4) em.trace(curPos);
-
+
if(!bplist.empty()) debug();
-
+
if(errorstream::interrupt) throw interrupted();
-
+
switch (i.op)
{
case inst::varpush:
@@ -371,7 +373,7 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
case inst::varsave:
VAR(get<Int>(i)) = top();
break;
-
+
#ifdef COMBO
case inst::varpop:
VAR(get<Int>(i)) = pop();
@@ -411,7 +413,7 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
case inst::pushclosure:
assert(vars);
push(vars);
- break;
+ break;
case inst::nop:
break;
@@ -419,24 +421,24 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
case inst::pop:
pop();
break;
-
+
case inst::intpush:
case inst::constpush:
push(i.ref);
break;
-
+
case inst::fieldpush: {
vars_t frame = pop<vars_t>();
if (!frame)
- error("dereference of null pointer");
+ error(dereferenceNullPointer);
push(FRAMEVAR(frame, get<Int>(i)));
break;
}
-
+
case inst::fieldsave: {
vars_t frame = pop<vars_t>();
if (!frame)
- error("dereference of null pointer");
+ error(dereferenceNullPointer);
FRAMEVAR(frame, get<Int>(i)) = top();
break;
}
@@ -446,13 +448,13 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
#error NOT REIMPLEMENTED
vars_t frame = pop<vars_t>();
if (!frame)
- error("dereference of null pointer");
+ error(dereferenceNullPointer);
FRAMEVAR(get<Int>(i)) = pop();
break;
}
#endif
-
-
+
+
case inst::builtin: {
bltin func = get<bltin>(i);
#ifdef PROFILE
@@ -528,7 +530,7 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
push((callable*)f);
break;
}
-
+
default:
error("Internal VM error: Bad stack operand");
}
@@ -538,7 +540,7 @@ void stack::runWithOrWithoutClosure(lambda *l, vars_t vars, vars_t parent)
vm::draw(cerr,vars);
cerr << "\n";
#endif
-
+
++ip;
}
} catch (bad_item_value&) {
@@ -581,7 +583,7 @@ void stack::draw(ostream& out)
}
else
out << " ";
-
+
while (left != theStack.end())
{
if (left != theStack.begin())
@@ -595,7 +597,7 @@ void stack::draw(ostream& out)
void draw(ostream& out, frame* v)
{
out << "vars:" << endl;
-
+
while (!!v) {
item link=(*v)[v->getParentIndex()];
@@ -645,13 +647,13 @@ void errornothrow(const char* message)
em << message;
em.sync();
}
-
+
void error(const char* message)
{
errornothrow(message);
throw handled_error();
}
-
+
void error(const ostringstream& message)
{
const string& s=message.str();