(PutTask task0, Map<String, term_t> varnames_to_vars)
| 607 | } |
| 608 | |
| 609 | protected static void putLoop(PutTask task0, Map<String, term_t> varnames_to_vars) { |
| 610 | PutTask top = task0; // initially, our stack is just the given task |
| 611 | while (top != null) { // while there's a (top-most) task to do |
| 612 | if (top.n > top.t.arity()) { // we have populated a vector of term refs for a Compound, and (only) now can we cons it |
| 613 | if (top.termP != null) { // it's time to stash the populated Compound into this "parent" term ref |
| 614 | Prolog.cons_functor_v(top.termP, Prolog.new_functor(Prolog.new_atom(top.t.name()), top.t.arity()), top.term); |
| 615 | } else { |
| 616 | // we were presumably just stashing args for Query.open() |
| 617 | } |
| 618 | top = top.prev; // pop this completed task and iterate |
| 619 | } else { |
| 620 | Term t; // the Term which the switch will deal with in this iteration |
| 621 | term_t term; // the term ref into which the switch will put t in this iteration |
| 622 | if (top.n == 0) { // put t into term |
| 623 | t = top.t; // the Term to be put |
| 624 | term = top.term; // the term ref to put it in |
| 625 | top = top.prev; // pop this imminently completed task now lest we enstack a Compound task |
| 626 | } else { // put n-th arg of t into corresponding element of (0-based) term ref array |
| 627 | t = top.t.arg(top.n); // Term.arg() is 1-based |
| 628 | if (top.n == 1) { |
| 629 | term = top.term; // put t into the given term ref |
| 630 | } else { // top.n > 1 |
| 631 | term = new term_t(); // there isn't a term_t(long value) constructor :-/ |
| 632 | term.value = top.term.value + (top.n - 1); // n is 1-based but term ref array is 0-based |
| 633 | } |
| 634 | top.n++; // increment n for a subsequent iteration (safe: not referred to in switch) |
| 635 | } |
| 636 | switch (t.type()) { |
| 637 | case Prolog.ATOM: |
| 638 | if (t.equals(JPL.LIST_NIL)) { |
| 639 | Prolog.put_nil(term); |
| 640 | } else { |
| 641 | Prolog.put_atom_chars(term, t.name()); |
| 642 | } |
| 643 | break; |
| 644 | case Prolog.COMPOUND: |
| 645 | top = new PutTask(1, t, Prolog.new_term_refs(t.arity()), term, top); // push a new task, to put t's args starting with the first |
| 646 | break; |
| 647 | case Prolog.DICT: |
| 648 | Prolog.put_rational(term, t.toString()); // works because it is purely syntactic |
| 649 | break; |
| 650 | case Prolog.FLOAT: |
| 651 | Prolog.put_float(term, t.floatValue()); |
| 652 | break; |
| 653 | case Prolog.INTEGER: |
| 654 | if (t.isBig()) { |
| 655 | Prolog.put_integer_big(term, t.bigValue().toString()); |
| 656 | } else { |
| 657 | Prolog.put_integer(term, t.longValue()); |
| 658 | } |
| 659 | break; |
| 660 | case Prolog.JREF: |
| 661 | Prolog.put_jref(term, t.object()); |
| 662 | break; |
| 663 | case Prolog.RATIONAL: |
| 664 | Prolog.put_rational(term, t.toString()); |
| 665 | break; |
| 666 | case Prolog.VARIABLE: |
no test coverage detected