Changeset 321
- Timestamp:
- 06/28/08 10:40:43 (2 months ago)
- Files:
-
- branches/v2new/minid/baselib.d (modified) (76 diffs)
- branches/v2new/minid/ex.d (modified) (2 diffs)
- branches/v2new/minid/interpreter.d (modified) (6 diffs)
- branches/v2new/samples/simple.md (modified) (1 diff)
- branches/v2new/test.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/v2new/minid/baselib.d
r319 r321 40 40 import utf = tango.text.convert.Utf; 41 41 42 private void register(MDThread* t, dchar[] name, NativeFunc func )42 private void register(MDThread* t, dchar[] name, NativeFunc func, size_t numUpvals = 0) 43 43 { 44 newFunction(t, func, name );44 newFunction(t, func, name, numUpvals); 45 45 newGlobal(t, name); 46 46 } … … 112 112 register(t, "writef", &writef); 113 113 register(t, "writefln", &writefln); 114 // globals["dumpVal"d] = new MDClosure(globals.ns, &dumpVal, "dumpVal"); 115 // globals["readln"d] = new MDClosure(globals.ns, &readln, "readln"); 114 115 newTable(t); 116 register(t, "dumpVal", &dumpVal, 1); 117 118 // register(t, "readln", &readln); 116 119 117 120 // // Dynamic compilation stuff … … 168 171 // Object 169 172 170 size_t objectClone(MDThread* t, size_t numParams)173 nuint objectClone(MDThread* t, nuint numParams) 171 174 { 172 175 newObject(t, 0); … … 178 181 // Basic functions 179 182 180 size_t getTraceback(MDThread* t, size_t numParams)183 nuint getTraceback(MDThread* t, nuint numParams) 181 184 { 182 185 s.push(new MDString(s.context.getTracebackString())); … … 184 187 } 185 188 186 size_t haltThread(MDThread* t, size_t numParams)189 nuint haltThread(MDThread* t, nuint numParams) 187 190 { 188 191 if(numParams == 0) … … 199 202 */ 200 203 201 size_t currentThread(MDThread* t, size_t numParams)204 nuint currentThread(MDThread* t, nuint numParams) 202 205 { 203 206 if(t is mainThread(getVM(t))) … … 210 213 211 214 /* 212 size_t setModuleLoader(MDThread* t, size_t numParams)215 nuint setModuleLoader(MDThread* t, nuint numParams) 213 216 { 214 217 s.context.setModuleLoader(s.getParam!(dchar[])(0), s.getParam!(MDClosure)(1)); … … 216 219 } 217 220 218 size_t reloadModule(MDThread* t, size_t numParams)221 nuint reloadModule(MDThread* t, nuint numParams) 219 222 { 220 223 s.push(s.context.reloadModule(s.getParam!(MDString)(0).mData, s)); … … 222 225 } 223 226 224 size_t removeKey(MDThread* t, size_t numParams)227 nuint removeKey(MDThread* t, nuint numParams) 225 228 { 226 229 MDValue container = s.getParam(0u); … … 252 255 */ 253 256 254 size_t rawSet(MDThread* t, size_t numParams)257 nuint rawSet(MDThread* t, nuint numParams) 255 258 { 256 259 if(numParams < 3) … … 270 273 } 271 274 272 size_t rawGet(MDThread* t, size_t numParams)275 nuint rawGet(MDThread* t, nuint numParams) 273 276 { 274 277 if(numParams < 2) … … 288 291 } 289 292 290 size_t runMain(MDThread* t, size_t numParams) 291 { 292 if(!isNamespace(t, 1)) 293 throwException(t, "namespace expected"); 293 nuint runMain(MDThread* t, nuint numParams) 294 { 295 checkParam(t, 1, MDValue.Type.Namespace); 294 296 295 297 auto main = field(t, 1, "main"); … … 297 299 if(isFunction(t, main)) 298 300 { 299 dup(t, 1); 300 301 for(size_t i = 2; i <= numParams; i++) 302 dup(t, i); 303 304 rawCall(t, main, 0); 301 insert(t, 1); 302 rawCall(t, 1, 0); 305 303 } 306 304 … … 311 309 // Functional stuff 312 310 313 size_t curry(MDThread* t, size_t numParams)314 { 315 static size_t call(MDThread* t, size_t numParams)311 nuint curry(MDThread* t, nuint numParams) 312 { 313 static nuint call(MDThread* t, nuint numParams) 316 314 { 317 315 auto funcReg = getUpval(t, 0); … … 325 323 } 326 324 327 if(numParams != 2) 328 throwException(t, "need function and context"); 329 330 if(!isFunction(t, 1)) 331 throwException(t, "function expected"); 325 checkParam(t, 1, MDValue.Type.Function); 326 checkAnyParam(t, 2); 332 327 333 328 newFunction(t, &call, "curryClosure", 2); … … 335 330 } 336 331 337 size_t bindContext(MDThread* t, size_t numParams)338 { 339 static size_t call(MDThread* t, size_t numParams)332 nuint bindContext(MDThread* t, nuint numParams) 333 { 334 static nuint call(MDThread* t, nuint numParams) 340 335 { 341 336 auto funcReg = getUpval(t, 0); … … 347 342 return rawCall(t, funcReg, -1); 348 343 } 349 350 if(numParams != 2) 351 throwException(t, "need function and context"); 352 353 if(!isFunction(t, 1)) 354 throwException(t, "function expected"); 344 345 checkParam(t, 1, MDValue.Type.Function); 346 checkAnyParam(t, 2); 355 347 356 348 newFunction(t, &call, "boundFunction", 2); … … 362 354 // Reflection-esque stuff 363 355 364 size_t findGlobal(MDThread* t, size_t numParams)356 nuint findGlobal(MDThread* t, nuint numParams) 365 357 { 366 358 auto ns = s.findGlobal(s.getParam!(MDString)(0), 1); … … 374 366 } 375 367 376 size_t isSet(MDThread* t, size_t numParams)368 nuint isSet(MDThread* t, nuint numParams) 377 369 { 378 370 s.push(s.findGlobal(s.getParam!(MDString)(0), 1) !is null); … … 380 372 } 381 373 382 size_t mdtypeof(MDThread* t, size_t numParams)374 nuint mdtypeof(MDThread* t, nuint numParams) 383 375 { 384 376 s.push(s.getParam(0u).typeString()); … … 386 378 } 387 379 388 size_t fieldsOf(MDThread* t, size_t numParams)380 nuint fieldsOf(MDThread* t, nuint numParams) 389 381 { 390 382 if(s.isParam!("object")(0)) … … 396 388 } 397 389 398 size_t allFieldsOf(MDThread* t, size_t numParams)390 nuint allFieldsOf(MDThread* t, nuint numParams) 399 391 { 400 392 auto o = s.getParam!(MDObject)(0); … … 404 396 MDObject obj; 405 397 406 size_t iter(MDThread* t, size_t numParams)398 nuint iter(MDThread* t, nuint numParams) 407 399 { 408 400 s.yield(0); … … 423 415 } 424 416 425 size_t hasField(MDThread* t, size_t numParams)417 nuint hasField(MDThread* t, nuint numParams) 426 418 { 427 419 s.push(s.hasField(s.getParam(0u), s.getParam!(MDString)(1))); … … 429 421 } 430 422 431 size_t hasMethod(MDThread* t, size_t numParams)423 nuint hasMethod(MDThread* t, nuint numParams) 432 424 { 433 425 s.push(s.hasMethod(s.getParam(0u), s.getParam!(MDString)(1))); … … 435 427 } 436 428 437 size_t hasAttributes(MDThread* t, size_t numParams)429 nuint hasAttributes(MDThread* t, nuint numParams) 438 430 { 439 431 MDTable ret; … … 450 442 } 451 443 452 size_t attributesOf(MDThread* t, size_t numParams)444 nuint attributesOf(MDThread* t, nuint numParams) 453 445 { 454 446 MDTable ret; … … 480 472 // Conversions 481 473 */ 482 size_t toString(MDThread* t, size_t numParams) 483 { 474 nuint toString(MDThread* t, nuint numParams) 475 { 476 checkAnyParam(t, 1); 477 484 478 if(isInt(t, 1)) 485 479 { … … 488 482 if(numParams > 1) 489 483 style = getChar(t, 2); 490 484 491 485 dchar[80] buffer = void; 492 486 pushString(t, Integer.format(buffer, getInt(t, 1), cast(Integer.Style)style)); // TODO: make this safe … … 498 492 } 499 493 500 size_t rawToString(MDThread* t, size_t numParams) 501 { 494 nuint rawToString(MDThread* t, nuint numParams) 495 { 496 checkAnyParam(t, 1); 502 497 pushToString(t, 1, true); 503 498 return 1; 504 499 } 505 500 506 size_t toBool(MDThread* t, size_t numParams) 507 { 501 nuint toBool(MDThread* t, nuint numParams) 502 { 503 checkAnyParam(t, 1); 508 504 pushBool(t, isTrue(t, 1)); 509 505 return 1; 510 506 } 511 507 512 size_t toInt(MDThread* t, size_t numParams) 513 { 508 nuint toInt(MDThread* t, nuint numParams) 509 { 510 checkAnyParam(t, 1); 511 514 512 switch(type(t, 1)) 515 513 { … … 528 526 } 529 527 530 size_t toFloat(MDThread* t, size_t numParams) 531 { 528 nuint toFloat(MDThread* t, nuint numParams) 529 { 530 checkAnyParam(t, 1); 531 532 532 switch(type(t, 1)) 533 533 { … … 546 546 } 547 547 548 size_t toChar(MDThread* t, size_t numParams)549 { 550 pushChar(t, cast(dchar) getInt(t, 1));551 return 1; 552 } 553 554 size_t format(MDThread* t, size_t numParams)548 nuint toChar(MDThread* t, nuint numParams) 549 { 550 pushChar(t, cast(dchar)checkIntParam(t, 1)); 551 return 1; 552 } 553 554 nuint format(MDThread* t, nuint numParams) 555 555 { 556 556 auto buf = StrBuffer(t); … … 563 563 // Console IO 564 564 565 size_t write(MDThread* t, size_t numParams)565 nuint write(MDThread* t, nuint numParams) 566 566 { 567 567 for(size_t i = 1; i <= numParams; i++) 568 568 { 569 569 pushToString(t, i); 570 Stdout .format("{}",getString(t, -1));570 Stdout(getString(t, -1)); 571 571 } 572 572 … … 575 575 } 576 576 577 size_t writeln(MDThread* t, size_t numParams)577 nuint writeln(MDThread* t, nuint numParams) 578 578 { 579 579 for(size_t i = 1; i <= numParams; i++) 580 580 { 581 581 pushToString(t, i); 582 Stdout .format("{}",getString(t, -1));582 Stdout(getString(t, -1)); 583 583 } 584 584 … … 587 587 } 588 588 589 size_t writef(MDThread* t, size_t numParams)589 nuint writef(MDThread* t, nuint numParams) 590 590 { 591 591 uint sink(dchar[] data) 592 592 { 593 Stdout .format("{}",data);593 Stdout(data); 594 594 return data.length; 595 595 } … … 600 600 } 601 601 602 size_t writefln(MDThread* t, size_t numParams)602 nuint writefln(MDThread* t, nuint numParams) 603 603 { 604 604 uint sink(dchar[] data) 605 605 { 606 Stdout .format("{}",data);606 Stdout(data); 607 607 return data.length; 608 608 } … … 613 613 } 614 614 615 /* 616 size_t dumpVal(MDThread* t, size_t numParams) 617 { 618 void outputRepr(ref MDValue v) 619 { 620 if(s.hasPendingHalt()) 621 throw new MDHaltException(); 622 623 static bool[MDBaseObject] shown; 624 615 nuint dumpVal(MDThread* t, nuint numParams) 616 { 617 checkAnyParam(t, 1); 618 auto newline = optBoolParam(t, 2, true); 619 620 auto shown = getUpval(t, 0); 621 622 void outputRepr(nint v) 623 { 624 v = absIndex(t, v); 625 626 // TODO: this 627 // if(s.hasPendingHalt()) 628 // throw new MDHaltException(); 629 625 630 void escape(dchar c) 626 631 { … … 637 642 case '\t': Stdout(`\t`); break; 638 643 case '\v': Stdout(`\v`); break; 639 644 640 645 default: 641 646 if(c <= 0x7f && isprint(c)) … … 648 653 } 649 654 } 650 651 void delegate(MDArray) outputArray; 652 void delegate(MDTable) outputTable; 653 654 void outputArray_(MDArray a) 655 656 void outputArray(nint arr) 655 657 { 656 if( a in shown)658 if(opin(t, arr, shown)) 657 659 { 658 660 Stdout("[...]"); 659 661 return; 660 662 } 661 662 shown[a] = true; 663 664 dup(t, arr); 665 pushBool(t, true); 666 idxa(t, shown); 667 668 scope(exit) 669 { 670 dup(t, arr); 671 pushNull(t); 672 idxa(t, shown); 673 } 674 675 Stdout('['); 663 676 664 scope(exit) 665 shown.remove(a); 666 667 Stdout('['); 668 669 if(a.length > 0) 677 auto length = len(t, arr); 678 679 if(length > 0) 670 680 { 671 outputRepr(*a[0]); 672 673 for(int i = 1; i < a.length; i++) 681 pushInt(t, 0); 682 idx(t, arr); 683 outputRepr(-1); 684 pop(t); 685 686 for(size_t i = 1; i < length; i++) 674 687 { 675 if(s.hasPendingHalt()) 676 throw new MDHaltException(); 677 688 // TODO: this 689 // if(s.hasPendingHalt()) 690 // throw new MDHaltException(); 691 678 692 Stdout(", "); 679 outputRepr(*a[i]); 693 pushInt(t, i); 694 idx(t, arr); 695 outputRepr(-1); 696 pop(t); 680 697 } 681 698 } 682 699 683 700 Stdout(']'); 684 701 } 685 686 void outputTable _(MDTable t)702 703 void outputTable(nint tab) 687 704 { 688 if( t in shown)705 if(opin(t, tab, shown)) 689 706 { 690 707 Stdout("{...}"); 691 708 return; 692 709 } 693 694 shown[t] = true; 695 710 711 dup(t, tab); 712 pushBool(t, true); 713 idxa(t, shown); 714 715 scope(exit) 716 { 717 dup(t, tab); 718 pushNull(t); 719 idxa(t, shown); 720 } 721 696 722 Stdout('{'); 697 698 if(t.length > 0) 699 { 700 if(t.length == 1) 701 { 702 foreach(k, v; t) 703 { 704 if(s.hasPendingHalt()) 705 throw new MDHaltException(); 706 707 Stdout('['); 708 outputRepr(k); 709 Stdout("] = "); 710 outputRepr(v); 711 } 712 } 713 else 714 { 715 bool first = true; 716 717 foreach(k, v; t) 718 { 719 if(first) 720 first = !first; 721 else 722 Stdout(", "); 723 724 if(s.hasPendingHalt()) 725 throw new MDHaltException(); 726 727 Stdout('['); 728 outputRepr(k); 729 Stdout("] = "); 730 outputRepr(v); 731 } 732 } 733 } 734 723 724 auto length = len(t, tab); 725 726 // TODO: this 727 // if(length > 0) 728 // { 729 // if(length == 1) 730 // { 731 // foreach(k, v; t) 732 // { 733 // if(s.hasPendingHalt()) 734 // throw new MDHaltException(); 735 // 736 // Stdout('['); 737 // outputRepr(k); 738 // Stdout("] = "); 739 // outputRepr(v); 740 // } 741 // } 742 // else 743 // { 744 // bool first = true; 745 // 746 // foreach(k, v; t) 747 // { 748 // if(first) 749 // first = !first; 750 // else 751 // Stdout(", "); 752 // 753 // if(s.hasPendingHalt()) 754 // throw new MDHaltException(); 755 // 756 // Stdout('['); 757 // outputRepr(k); 758 // Stdout("] = "); 759 // outputRepr(v); 760 // } 761 // } 762 // } 763 Stdout('!'); 764 735 765 Stdout('}'); 736 737 shown.remove(t);738 766 } 739 740 outputArray = &outputArray_; 741 outputTable = &outputTable_; 742 743 if(v.isString) 767 768 if(isString(t, v)) 744 769 { 745 770 Stdout('"'); 746 771 747 auto s = v.as!(MDString); 748 749 for(int i = 0; i < s.length; i++) 750 escape(s[i]); 751 772 foreach(c; getString(t, v)) 773 escape(c); 774 752 775 Stdout('"'); 753 776 } 754 else if( v.isChar)777 else if(isChar(t, v)) 755 778 { 756 779 Stdout("'"); 757 escape( v.as!(dchar));780 escape(getChar(t, v)); 758 781 Stdout("'"); 759 782 } 760 else if(v.isArray) 761 outputArray(v.as!(MDArray)); 762 else if(v.isTable) 783 else if(isArray(t, v)) 784 outputArray(v); 785 else if(isTable(t, v) && !hasMethod(t, v, "toString")) 786 outputTable(v); 787 else 763 788 { 764 if(s.hasMethod(v, toStringStr)) 765 Stdout(s.valueToString(v)); 766 else 767 outputTable(v.as!(MDTable)); 789 pushToString(t, v); 790 Stdout(getString(t, -1)); 791 pop(t); 768 792 } 769 else 770 Stdout(s.valueToString(v)); 771 } 772 773 outputRepr(s.getParam(0u)); 774 775 if(numParams == 1 || (numParams > 1 && s.getParam!(bool)(1))) 793 } 794 795 outputRepr(1); 796 797 if(newline) 776 798 Stdout.newline; 777 799 … … 779 801 } 780 802 781 size_t readln(MDThread* t, size_t numParams) 782 { 783 s.push(Cin.copyln()); 803 /* 804 nuint readln(MDThread* t, nuint numParams) 805 { 806 pushString(t, Cin.copyln()); 784 807 return 1; 785 808 } … … 789 812 // Dynamic Compilation 790 813 791 size_t loadString(MDThread* t, size_t numParams)814 nuint loadString(MDThread* t, nuint numParams) 792 815 { 793 816 char[] name; … … 819 842 } 820 843 821 size_t eval(MDThread* t, size_t numParams)844 nuint eval(MDThread* t, nuint numParams) 822 845 { 823 846 MDFuncDef def = Compiler().compileExpression(s.getParam!(dchar[])(0), "<loaded by eval>"); … … 832 855 } 833 856 834 size_t loadJSON(MDThread* t, size_t numParams)857 nuint loadJSON(MDThread* t, nuint numParams) 835 858 { 836 859 s.push(Compiler().loadJSON(s.getParam!(dchar[])(0))); … … 838 861 } 839 862 840 size_t toJSON(MDThread* t, size_t numParams)863 nuint toJSON(MDThread* t, nuint numParams) 841 864 { 842 865 MDValue root = s.getParam(0u); … … 858 881 // Namespace metatable 859 882 860 size_t namespaceIterator(MDThread* t, size_t numParams)883 nuint namespaceIterator(MDThread* t, nuint numParams) 861 884 { 862 885 MDNamespace namespace = s.getUpvalue!(MDNamespace)(0); … … 876 899 } 877 900 878 size_t namespaceApply(MDThread* t, size_t numParams)901 nuint namespaceApply(MDThread* t, nuint numParams) 879 902 { 880 903 MDNamespace ns = s.getContext!(MDNamespace); … … 892 915 // Thread metatable 893 916 894 size_t threadReset(MDThread* t, size_t numParams)917 nuint threadReset(MDThread* t, nuint numParams) 895 918 { 896 919 MDClosure cl; … … 903 926 } 904 927 905 size_t threadState(MDThread* t, size_t numParams)928 nuint threadState(MDThread* t, nuint numParams) 906 929 { 907 930 s.push(s.getContext!(MDState).stateString()); … … 909 932 } 910 933 911 size_t isInitial(MDThread* t, size_t numParams)934 nuint isInitial(MDThread* t, nuint numParams) 912 935 { 913 936 s.push(s.getContext!(MDState).state() == MDState.State.Initial); … … 915 938 } 916 939 917 size_t isRunning(MDThread* t, size_t numParams)940 nuint isRunning(MDThread* t, nuint numParams) 918 941 { 919 942 s.push(s.getContext!(MDState).state() == MDState.State.Running); … … 921 944 } 922 945 923 size_t isWaiting(MDThread* t, size_t numParams)946 nuint isWaiting(MDThread* t, nuint numParams) 924 947 { 925 948 s.push(s.getContext!(MDState).state() == MDState.State.Waiting); … … 927 950 } 928 951 929 size_t isSuspended(MDThread* t, size_t numParams)952 nuint isSuspended(MDThread* t, nuint numParams) 930 953 { 931 954 s.push(s.getContext!(MDState).state() == MDState.State.Suspended); … … 933 956 } 934 957 935 size_t isDead(MDThread* t, size_t numParams)958 nuint isDead(MDThread* t, nuint numParams) 936 959 { 937 960 s.push(s.getContext!(MDState).state() == MDState.State.Dead); … … 939 962 } 940 963 941 size_t threadIterator(MDThread* t, size_t numParams)964 nuint threadIterator(MDThread* t, nuint numParams) 942 965 { 943 966 MDState thread = s.getContext!(MDState); … … 957 980 } 958 981 959 size_t threadApply(MDThread* t, size_t numParams)982 nuint threadApply(MDThread* t, nuint numParams) 960 983 { 961 984 MDState thread = s.getContext!(MDState); … … 979 1002 // Function metatable 980 1003 981 size_t functionEnvironment(MDThread* t, size_t numParams)1004 nuint functionEnvironment(MDThread* t, nuint numParams) 982 1005 { 983 1006 MDClosure cl = s.getContext!(MDClosure); … … 991 1014 } 992 1015 993 size_t functionIsNative(MDThread* t, size_t numParams)1016 nuint functionIsNative(MDThread* t, nuint numParams) 994 1017 { 995 1018 s.push(s.getContext!(MDClosure).isNative); … … 997 1020 } 998 1021 999 size_t functionNumParams(MDThread* t, size_t numParams)1022 nuint functionNumParams(MDThread* t, nuint numParams) 1000 1023 { 1001 1024 s.push(s.getContext!(MDClosure).numParams); … … 1003 1026 } 1004 1027 1005 size_t functionIsVararg(MDThread* t, size_t numParams)1028 nuint functionIsVararg(MDThread* t, nuint numParams) 1006 1029 { 1007 1030 s.push(s.getContext!(MDClosure).isVararg); … … 1046 1069 } 1047 1070 1048 public size_t clone(MDThread* t, size_t numParams)1071 public nuint clone(MDThread* t, nuint numParams) 1049 1072 { 1050 1073 MDStringBuffer ret; … … 1066 1089 } 1067 1090 1068 public size_t opCatAssign(MDThread* t, size_t numParams)1091 public nuint opCatAssign(MDThread* t, nuint numParams) 1069 1092 { 1070 1093 MDStringBuffer i = s.getContext!(MDStringBuffer); … … 1096 1119 } 1097 1120 1098 public size_t insert(MDThread* t, size_t numParams)1121 public nuint insert(MDThread* t, nuint numParams) 1099 1122 { 1100 1123 MDStringBuffer i = s.getContext!(MDStringBuffer); … … 1122 1145 } 1123 1146 1124 public size_t remove(MDThread* t, size_t numParams)1147 public nuint remove(MDThread* t, nuint numParams) 1125 1148 { 1126 1149 MDStringBuffer i = s.getContext!(MDStringBuffer); … … 1135 1158 } 1136 1159 1137 public size_t toString(MDThread* t, size_t numParams)1160 public nuint toString(MDThread* t, nuint numParams) 1138 1161 { 1139 1162 s.push(s.getContext!(MDStringBuffer).toMDString()); … … 1141 1164 } 1142 1165 1143 public size_t opLengthAssign(MDThread* t, size_t numParams)1166 public nuint opLengthAssign(MDThread* t, nuint numParams) 1144 1167 { 1145 1168 int newLen = s.getParam!(int)(0); … … 1152 1175 } 1153 1176 1154 public size_t opLength(MDThread* t, size_t numParams)1177 public nuint opLength(MDThread* t, nuint numParams) 1155 1178 { 1156 1179 s.push(s.getContext!(MDStringBuffer).length); … … 1158 1181 } 1159 1182 1160 public size_t opIndex(MDThread* t, size_t numParams)1183 public nuint opIndex(MDThread* t, nuint numParams) 1161 1184 { 1162 1185 s.push(s.getContext!(MDStringBuffer)()[s.getParam!(int)(0)]); … … 1164 1187 } 1165 1188 1166 public size_t opIndexAssign(MDThread* t, size_t numParams)1189 public nuint opIndexAssign(MDThread* t, nuint numParams) 1167 1190 { 1168 1191 s.getContext!(MDStringBuffer)()[s.getParam!(int)(0)] = s.getParam!(dchar)(1); … … 1170 1193 } 1171 1194 1172 public size_t iterator(MDThread* t, size_t numParams)1195 public nuint iterator(MDThread* t, nuint numParams) 1173 1196 { 1174 1197 MDStringBuffer i = s.getContext!(MDStringBuffer); … … 1186 1209 } 1187 1210 1188 public size_t iteratorReverse(MDThread* t, size_t numParams)1211 public nuint iteratorReverse(MDThread* t, nuint numParams) 1189 1212 { 1190 1213 MDStringBuffer i = s.getContext!(MDStringBuffer); … … 1202 1225 } 1203 1226 1204 public size_t opApply(MDThread* t, size_t numParams)1227 public nuint opApply(MDThread* t, nuint numParams) 1205 1228 { 1206 1229 MDStringBuffer i = s.getContext!(MDStringBuffer); … … 1222 1245 } 1223 1246 1224 public size_t opSlice(MDThread* t, size_t numParams)1247 public nuint opSlice(MDThread* t, nuint numParams) 1225 1248 { 1226 1249 s.push(s.getContext!(MDStringBuffer)()[s.getParam!(int)(0) .. s.getParam!(int)(1)]); … … 1228 1251 } 1229 1252 1230 public size_t opSliceAssign(MDThread* t, size_t numParams)1253 public nuint opSliceAssign(MDThread* t, nuint numParams) 1231 1254 { 1232 1255 s.getContext!(MDStringBuffer)()[s.getParam!(int)(0) .. s.getParam!(int)(1)] = s.getParam!(dchar[])(2); … … 1234 1257 } 1235 1258 1236 public size_t reserve(MDThread* t, size_t numParams)1259 public nuint reserve(MDThread* t, nuint numParams) 1237 1260 { 1238 1261 s.getContext!(MDStringBuffer).reserve(s.getParam!(uint)(0)); … … 1240 1263 } 1241 1264 1242 public size_t format(MDThread* t, size_t numParams)1265 public nuint format(MDThread* t, nuint numParams) 1243 1266 { 1244 1267 auto self = s.getContext!(MDStringBuffer); … … 1254 1277 } 1255 1278 1256 public size_t formatln(MDThread* t, size_t numParams)1279 public nuint formatln(MDThread* t, nuint numParams) 1257 1280 { 1258 1281 auto self = s.getContext!(MDStringBuffer); branches/v2new/minid/ex.d
r319 r321 213 213 public void checkAnyParam(MDThread* t, nint index) 214 214 { 215 215 if(!isValidIndex(t, index)) 216 throwException(t, "Too few parameters (expected at least {}, got {})", index, stackSize(t) - 1); 217 } 218 219 public bool checkBoolParam(MDThread* t, nint index) 220 { 221 checkAnyParam(t, index); 222 223 if(!isBool(t, index)) 224 paramTypeError(t, index, "bool"); 225 226 return getBool(t, index); 227 } 228 229 public mdint checkIntParam(MDThread* t, nint index) 230 { 231 checkAnyParam(t, index); 232 233 if(!isInt(t, index)) 234 paramTypeError(t, index, "int"); 235 236 return getInt(t, index); 237 } 238 239 public mdfloat checkFloatParam(MDThread* t, nint index) 240 { 241 checkAnyParam(t, index); 242 243 if(!isFloat(t, index)) 244 paramTypeError(t, index, "float"); 245 246 return getFloat(t, index); 247 } 248 249 public dchar checkCharParam(MDThread* t, nint index) 250 { 251 checkAnyParam(t, index); 252 253 if(!isChar(t, index)) 254 paramTypeError(t, index, "char"); 255 256 return getChar(t, index); 257 } 258 259 public dchar[] checkStringParam(MDThread* t, nint index) 260 { 261 checkAnyParam(t, index); 262 263 if(!isString(t, index)) 264 paramTypeError(t, index, "string"); 265 266 return getString(t, index); 216 267 } 217 268 … … 246 297 247 298 pop(t); 299 } 300 301 // EPOCH FAIL. 302 public void checkParam(MDThread* t, nint index, nuint typeMask) 303 { 304 assert(typeMask != 0, "typemask must be something"); 305 306 checkAnyParam(t, index); 307 308 if(!((1 << type(t, index)) & typeMask)) 309 { 310 auto buf = StrBuffer(t); 311 312 bool first = true; 313 314 for(auto type = cast(uint)MDValue.Type.Null; type <= cast(uint)MDValue.Type.NativeObj; type++) 315 { 316 if(!(typeMask & (1 << type))) 317 continue; 318 319 if(first) 320 first = false; 321 else 322 buf.addChar('|'); 323 324 buf.addString(MDValue.typeString(cast(MDValue.Type)type)); 325 } 326 327 buf.finish(); 328 329 paramTypeError(t, index, getString(t, -1)); 330
