Changeset 324
- Timestamp:
- 06/28/08 23:46:42 (2 months ago)
- Files:
-
- branches/v2new/docs/minid.alloc.html (modified) (1 diff)
- branches/v2new/docs/minid.api.html (modified) (1 diff)
- branches/v2new/docs/minid.bind.html (deleted)
- branches/v2new/docs/minid.compiler.html (deleted)
- branches/v2new/docs/minid.ex.html (modified) (2 diffs)
- branches/v2new/docs/minid.gc.html (modified) (1 diff)
- branches/v2new/docs/minid.interpreter.html (modified) (3 diffs)
- branches/v2new/docs/minid.minid.html (deleted)
- branches/v2new/docs/minid.types.html (modified) (3 diffs)
- branches/v2new/docs/minid.utils.html (modified) (1 diff)
- branches/v2new/docs/minid.vm.html (modified) (1 diff)
- branches/v2new/minid/gc.d (modified) (1 diff)
- branches/v2new/minid/interpreter.d (modified) (14 diffs)
- branches/v2new/minid/thread.d (modified) (1 diff)
- branches/v2new/minid/types.d (modified) (6 diffs)
- branches/v2new/test.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/v2new/docs/minid.alloc.html
r319 r324 114 114 Page was generated with 115 115 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 116 on Fri Jun 27 20:33:212008116 on Sat Jun 28 22:13:14 2008 117 117 118 118 </td></tr> branches/v2new/docs/minid.api.html
r319 r324 142 142 Page was generated with 143 143 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 144 on Fri Jun 27 20:33:212008144 on Sat Jun 28 22:13:14 2008 145 145 146 146 </td></tr> branches/v2new/docs/minid.ex.html
r319 r324 232 232 233 233 <script>explorer.outline.writeEnabled = true;</script> 234 <dt><span class="decl"> mdint234 <dt><span class="decl">nint 235 235 <span class="currsymbol">lookupCT</span> 236 236 <script>explorer.outline.addDecl('lookupCT');</script> … … 259 259 Page was generated with 260 260 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 261 on Fri Jun 27 20:33:222008261 on Sat Jun 28 22:13:15 2008 262 262 263 263 </td></tr> branches/v2new/docs/minid.gc.html
r319 r324 114 114 Page was generated with 115 115 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 116 on Fri Jun 27 20:33:202008116 on Sat Jun 28 22:13:13 2008 117 117 118 118 </td></tr> branches/v2new/docs/minid.interpreter.html
r319 r324 721 721 722 722 <script>explorer.outline.writeEnabled = true;</script> 723 <dt><span class="decl">int 724 <span class="currsymbol">absIndex</span> 725 <script>explorer.outline.addDecl('absIndex');</script> 726 727 (MDThread* <span class="funcparam">t</span>, int <span class="funcparam">idx</span>); 728 </span></dt> 729 <script>explorer.outline.writeEnabled = false;</script> 730 731 732 <dd>Given an index, returns the absolute index that corresponds to it. This is useful for converting 733 relative (negative) indices to indices that will never change. If the index is already absolute, 734 just returns it. Throws an error if the index is out of range. 735 <br><br> 736 737 </dd> 738 739 <script>explorer.outline.writeEnabled = true;</script> 740 <dt><span class="decl">bool 741 <span class="currsymbol">isValidIndex</span> 742 <script>explorer.outline.addDecl('isValidIndex');</script> 743 744 (MDThread* <span class="funcparam">t</span>, int <span class="funcparam">idx</span>); 745 </span></dt> 746 <script>explorer.outline.writeEnabled = false;</script> 747 748 749 <dd>Sees if a given stack index (negative or positive) is valid. Valid positive stack indices range 750 from [0 .. stackSize(<span class="funcparam">t</span>). Valid negative stack indices range from [-stackSize(<span class="funcparam">t</span>) .. 0. 751 <br><br> 752 753 </dd> 754 755 <script>explorer.outline.writeEnabled = true;</script> 723 756 <dt><span class="decl">uint 724 757 <span class="currsymbol">rawCall</span> … … 2640 2673 <script>explorer.outline.writeEnabled = true;</script> 2641 2674 <dt><span class="decl">int 2642 <span class="currsymbol">super of</span>2643 <script>explorer.outline.addDecl('super of');</script>2675 <span class="currsymbol">superOf</span> 2676 <script>explorer.outline.addDecl('superOf');</script> 2644 2677 2645 2678 (MDThread* <span class="funcparam">t</span>, int <span class="funcparam">slot</span>); … … 2917 2950 Page was generated with 2918 2951 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 2919 on Fri Jun 27 20:33:2220082952 on Sat Jun 28 22:13:14 2008 2920 2953 2921 2954 </td></tr> branches/v2new/docs/minid.types.html
r319 r324 44 44 <script>explorer.outline.incSymbolLevel();</script> 45 45 <dl> 46 <script>explorer.outline.writeEnabled = true;</script> 47 <dt><span class="decl">alias 48 <span class="currsymbol">nint</span> 49 <script>explorer.outline.addDecl('nint');</script> 50 51 ; 52 </span></dt> 53 <script>explorer.outline.writeEnabled = false;</script> 54 55 56 <dd>The native signed integer type on this platform. This is the same as ptrdiff_t but with a better name. 57 <br><br> 58 59 </dd> 60 61 <script>explorer.outline.writeEnabled = true;</script> 62 <dt><span class="decl">alias 63 <span class="currsymbol">nuint</span> 64 <script>explorer.outline.addDecl('nuint');</script> 65 66 ; 67 </span></dt> 68 <script>explorer.outline.writeEnabled = false;</script> 69 70 71 <dd>The native unsigned integer type on this platform. This is the same as size_t but with a better name. 72 <br><br> 73 74 </dd> 75 46 76 <script>explorer.outline.writeEnabled = true;</script> 47 77 <dt><span class="decl">alias … … 102 132 103 133 104 <dd>An alias for the type signature of a native function. 134 <dd>An alias for the type signature of a native function. It is defined as nuint function(MDThread*, nuint). 105 135 <br><br> 106 136 … … 133 163 Page was generated with 134 164 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 135 on Fri Jun 27 20:33:212008165 on Sat Jun 28 22:13:13 2008 136 166 137 167 </td></tr> branches/v2new/docs/minid.utils.html
r319 r324 662 662 Page was generated with 663 663 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 664 on Fri Jun 27 20:33:192008664 on Sat Jun 28 22:13:12 2008 665 665 666 666 </td></tr> branches/v2new/docs/minid.vm.html
r319 r324 66 66 Page was generated with 67 67 <img src="candydoc/img/candydoc.gif" style="vertical-align:middle; position:relative; top:-1px"> 68 on Fri Jun 27 20:33:20200868 on Sat Jun 28 22:13:13 2008 69 69 70 70 </td></tr> branches/v2new/minid/gc.d
r319 r324 260 260 markObj(vm, o.coroFunc); 261 261 262 if(o.coroFiber) 263 markObj(vm, o.coroFiber); 262 version(MDRestrictedCoro) {} else 263 { 264 if(o.coroFiber) 265 markObj(vm, o.coroFiber); 266 } 264 267 } 265 268 branches/v2new/minid/interpreter.d
r323 r324 26 26 import Float = tango.text.convert.Float; 27 27 import Integer = tango.text.convert.Integer; 28 import tango.core.Thread; 28 29 version(MDRestrictedCoro) {} else 30 import tango.core.Thread; 31 29 32 import tango.core.Vararg; 30 33 import tango.stdc.string; … … 468 471 } 469 472 473 version(MDRestrictedCoro) 474 { 475 if(f.isNative) 476 throwException(t, "newThread - Native functions may not be used as the body of a coroutine"); 477 } 478 470 479 maybeGC(t.vm); 471 472 480 return pushThread(t, thread.create(t.vm, f)); 473 481 } … … 2478 2486 checkNumParams(t, 1); 2479 2487 2480 if(!isFunction(t, -1)) 2488 auto f = getFunction(t, -1); 2489 2490 if(f is null) 2481 2491 { 2482 2492 pushTypeString(t, -1); 2483 2493 throwException(t, "Attempting to reset a coroutine with a '{}' instead of a 'function'", getString(t, -1)); 2484 2494 } 2485 2486 t.coroFunc = getFunction(t, -1); 2495 2496 version(MDRestrictedCoro) 2497 { 2498 if(f.isNative) 2499 throwException(t, "newThread - Native functions may not be used as the body of a coroutine"); 2500 } 2501 2502 t.coroFunc = f; 2487 2503 pop(t); 2488 2504 } 2489 2505 2490 if(t.coroFiber) 2491 t.getFiber().reset(); 2506 version(MDRestrictedCoro) {} else 2507 { 2508 if(t.coroFiber) 2509 { 2510 assert(t.getFiber().state == Fiber.State.TERM); 2511 t.getFiber().reset(); 2512 } 2513 } 2492 2514 2493 2515 t.state = MDThread.State.Initial; … … 2762 2784 private size_t commonCall(MDThread* t, AbsStack slot, nint numReturns, bool isScript) 2763 2785 { 2786 version(MDExtendedCoro) {} else 2787 { 2788 t.nativeCallDepth++; 2789 scope(exit) t.nativeCallDepth--; 2790 } 2791 2764 2792 if(isScript) 2765 2793 execute(t); … … 3991 4019 throwException(t, "No implementation of {} for type '{}'", MetaNames[MM.CatEq], getString(t, -1)); 3992 4020 } 3993 4021 4022 version(MDExtendedCoro) {} else 4023 { 4024 t.nativeCallDepth++; 4025 scope(exit) t.nativeCallDepth--; 4026 } 4027 3994 4028 if(callPrologue2(t, method, firstSlot, 0, firstSlot, num, null)) 3995 4029 execute(t); … … 4070 4104 } 4071 4105 4072 private class ThreadFiber : Fiber 4073 { 4074 private MDThread* t; 4075 4076 private this(MDThread* t) 4077 { 4078 super(&run); 4079 this.t = t; 4080 } 4081 4082 private void run() 4083 { 4084 assert(t.state == MDThread.State.Initial); 4085 t.stack[0] = t.coroFunc; 4086 rawCall(t, 0, -1); 4106 version(MDRestrictedCoro) {} else 4107 { 4108 private class ThreadFiber : Fiber 4109 { 4110 private MDThread* t; 4111 4112 private this(MDThread* t) 4113 { 4114 super(&run); 4115 this.t = t; 4116 } 4117 4118 private void run() 4119 { 4120 assert(t.state == MDThread.State.Initial); 4121 t.stack[0] = t.coroFunc; 4122 rawCall(t, 0, -1); 4123 } 4087 4124 } 4088 4125 } … … 4090 4127 private nuint resume(MDThread* t, size_t numParams) 4091 4128 { 4092 if(t.coroFiber is null) 4093 t.coroFiber = nativeobj.create(t.vm, new ThreadFiber(t)); 4129 version(MDExtendedCoro) 4130 { 4131 if(t.coroFiber is null) 4132 t.coroFiber = nativeobj.create(t.vm, new ThreadFiber(t)); 4133 else 4134 (cast(ThreadFiber)cast(void*)t.coroFiber.obj).t = t; 4135 4136 t.getFiber().call(); 4137 return t.numYields; 4138 } 4139 else version(MDRestrictedCoro) 4140 { 4141 if(t.state == MDThread.State.Initial) 4142 { 4143 t.stack[0] = t.coroFunc; 4144 auto result = callPrologue(t, cast(AbsStack)0, -1, numParams, null); 4145 assert(result == true, "resume callPrologue must return true"); 4146 execute(t); 4147 } 4148 else 4149 { 4150 callEpilogue(t, true); 4151 execute(t, t.savedCallDepth); 4152 } 4153 4154 return t.numYields; 4155 } 4094 4156 else 4095 (cast(ThreadFiber)cast(void*)t.coroFiber.obj).t = t; 4096 4097 t.getFiber().call(); 4098 return t.numYields; 4099 4100 // if(t.state == MDThread.State.Initial) 4101 // { 4102 // 4103 // 4104 // if(t.coroFunc.isNative) 4105 // { 4106 // mixin(Unimpl); 4107 // // assert(mCoroFiber !is null, "no coroutine fiber for native coroutine"); 4108 // // 4109 // // nativeCallPrologue(mCoroFunc, 0, -1, 1, numParams, MDValue.nullValue); 4110 // // mCoroFiber.call(); 4111 // // 4112 // // if(mCoroFiber.state == Fiber.State.HOLD) 4113 // // mState = State.Suspended; 4114 // // else if(mCoroFiber.state == Fiber.State.TERM) 4115 // // mState = State.Dead; 4116 // } 4117 // else 4118 // { 4119 // auto result = callPrologue(t, cast(AbsStack)0, -1, numParams, null); 4120 // assert(result == true, "resume callPrologue must return true"); 4121 // execute(t); 4122 // } 4123 // 4124 // return t.numYields; 4125 // } 4126 // else 4127 // { 4128 // if(t.coroFunc.isNative) 4129 // { 4130 // mixin(Unimpl); 4131 // // mCoroFiber.call(); 4132 // // 4133 // // if(mCoroFiber.state == Fiber.State.HOLD) 4134 // // mState = State.Suspended; 4135 // // else if(mCoroFiber.state == Fiber.State.TERM) 4136 // // mState = State.Dead; 4137 // } 4138 // else 4139 // { 4140 // callEpilogue(t, true); 4141 // execute(t, t.savedCallDepth); 4142 // } 4143 // 4144 // return t.numYields; 4145 // } 4157 { 4158 if(t.state == MDThread.State.Initial) 4159 { 4160 if(t.coroFunc.isNative) 4161 { 4162 if(t.coroFiber is null) 4163 t.coroFiber = nativeobj.create(t.vm, new ThreadFiber(t)); 4164 else 4165 (cast(ThreadFiber)cast(void*)t.coroFiber.obj).t = t; 4166 4167 t.getFiber().call(); 4168 } 4169 else 4170 { 4171 t.stack[0] = t.coroFunc; 4172 auto result = callPrologue(t, cast(AbsStack)0, -1, numParams, null); 4173 assert(result == true, "resume callPrologue must return true"); 4174 execute(t); 4175 } 4176 4177 return t.numYields; 4178 } 4179 else 4180 { 4181 if(t.coroFunc.isNative) 4182 { 4183 assert(t.coroFiber !is null); 4184 t.getFiber().call(); 4185 } 4186 else 4187 { 4188 callEpilogue(t, true); 4189 execute(t, t.savedCallDepth); 4190 } 4191 4192 return t.numYields; 4193 } 4194 } 4146 4195 } 4147 4196 … … 4258 4307 case MDValue.Type.Function: 4259 4308 return callPrologue2(t, func.mFunction, slot, numReturns, slot + 1, numParams, proto); 4260 4309 4261 4310 case MDValue.Type.Thread: 4262 4311 auto thread = func.mThread; … … 4408 4457 4409 4458 try 4459 { 4460 version(MDExtendedCoro) {} else 4461 { 4462 t.nativeCallDepth++; 4463 scope(exit) t.nativeCallDepth--; 4464 } 4465 4410 4466 actualReturns = func.nativeFunc(t, numParams - 1); 4467 } 4411 4468 catch(MDException e) 4412 4469 { … … 4417 4474 { 4418 4475 // TODO: investigate? 4419 // if(t.nativeCallDepth > 0) 4420 // { 4421 callEpilogue(t, false); 4422 throw e; 4423 // } 4424 // 4425 // saveResults(t, t, cast(AbsStack)0, 0); 4426 // callEpilogue(t, true); 4427 // 4428 // if(t.arIndex > 0) 4429 // throw e; 4430 // 4431 // return false; 4476 version(MDExtendedCoro) 4477 { 4478 if(t.arIndex > 0) 4479 { 4480 callEpilogue(t, false); 4481 throw e; 4482 } 4483 4484 return false; 4485 } 4486 else 4487 { 4488 if(t.nativeCallDepth > 0) 4489 { 4490 callEpilogue(t, false); 4491 throw e; 4492 } 4493 4494 saveResults(t, t, cast(AbsStack)0, 0); 4495 callEpilogue(t, true); 4496 4497 if(t.arIndex > 0) 4498 throw e; 4499 4500 return false; 4501 } 4432 4502 } 4433 4503 … … 5667 5737 5668 5738 case Op.Yield: 5739 version(MDRestrictedCoro) 5740 { 5741 if(t.nativeCallDepth > 0) 5742 throwException(t, "Attempting to yield across native / metamethod call boundary"); 5743 } 5744 else version(MDExtendedCoro) {} else 5745 { 5746 if(t.nativeCallDepth > 0 && (t.coroFunc !is null && !t.coroFunc.isNative)) 5747 throwException(t, "Attempting to yield from script coroutine across native / metamethod call boundary"); 5748 } 5749 5669 5750 auto firstValue = stackBase + i.rd; 5670 5751 auto ar = pushAR(t); … … 5685 5766 t.numYields = i.rs - 1; 5686 5767 } 5768 5769 version(MDExtendedCoro) {} else 5770 t.savedCallDepth = depth; 5687 5771 5688 5772 t.state = MDThread.State.Suspended; 5689 Fiber.yield(); 5690 t.state = MDThread.State.Running; 5691 callEpilogue(t, true); 5692 break; 5773 5774 version(MDRestrictedCoro) 5775 return; 5776 else version(MDExtendedCoro) 5777 { 5778 Fiber.yield(); 5779 t.state = MDThread.State.Running; 5780 callEpilogue(t, true); 5781 break; 5782 } 5783 else 5784 { 5785 if(t.coroFunc.isNative) 5786 { 5787 Fiber.yield(); 5788 t.state = MDThread.State.Running; 5789 callEpilogue(t, true); 5790 break; 5791 } 5792 else 5793 return; 5794 } 5693 5795 5694 5796 case Op.CheckParams: … … 5885 5987 throwException(t, "Coroutines must be created with a function, not '{}'", getString(t, -1)); 5886 5988 } 5989 5990 version(MDRestrictedCoro) 5991 { 5992 if(RS.mFunction.isNative) 5993 throwException(t, "Native functions may not be used as the body of a coroutine"); 5994 } 5887 5995 5888 5996 *get(i.rd) = thread.create(t.vm, RS.mFunction); … … 5993 6101 5994 6102 // TODO: investigate? 5995 // if(t.nativeCallDepth > 0) 5996 throw e; 5997 5998 // return; 6103 version(MDExtendedCoro) 6104 { 6105 if(t.arIndex > 0) 6106 throw e; 6107 } 6108 else 6109 { 6110 if(t.nativeCallDepth > 0) 6111 throw e; 6112 } 6113 6114 return; 5999 6115 } 6000 6116 } branches/v2new/minid/thread.d
r319 r324 101 101 alloc.free(t); 102 102 } 103 104 private bool[Fiber] fiberPool;103 104 // private bool[Fiber] fiberPool; 105 105 } branches/v2new/minid/types.d
r319 r324 24 24 module minid.types; 25 25 26 import tango.core.Thread; 26 version(MDRestrictedCoro) {} else 27 import tango.core.Thread; 28 27 29 import tango.text.convert.Layout; 28 30 … … 49 51 50 52 /** 51 The underlying D type used to store the MiniD 'int' type. Also used throughout the API.52 Defaults to the native word-sized integer type (ptrdiff_t). If you define the MDForceLongInts53 version, it will force MiniD to use 64-bit integers even on 32-bit platforms. If you define 54 the MDForceShortInts version, it will force MiniD to use 32-bitintegers even on 64-bit platforms.53 The underlying D type used to store the MiniD 'int' type. Defaults to the native word-sized signed integer 54 type (ptrdiff_t). If you define the MDForceLongInts version, it will force MiniD to use 64-bit integers 55 even on 32-bit platforms. If you define the MDForceShortInts version, it will force MiniD to use 32-bit 56 integers even on 64-bit platforms. 55 57 */ 56 58 version(MDForceLongInts) 57 59 { 58 60 version(MDForceShortInts) 59 static assert(false, "Defining both MDForceLongInts and MDForceShortInts is illegal"); 61 { 62 pragma(msg, "The 'MDForceLongInts' and 'MDForceShortInts' versions are mutually exclusive."); 63 pragma(msg, "Please define one or the other (or neither), not both.\n"); 64 static assert(false, "FAILCOPTER."); 65 } 60 66 61 67 public alias long mdint; … … 85 91 86 92 /** 87 93 The MiniD exception type. This is the type that is thrown whenever you throw an exception from within 94 MiniD, or when you use the throwException API call. You can't directly instantiate this class, though, 95 since it would be bad if you did (the interpreter needs to keep track of some internal state, which 96 throwException does). See throwException and catchException in minid.interpreter for more info 97 on MiniD exception handling. 88 98 */ 89 99 class MDException : Exception 90 100 { 91 p ublicthis(char[] msg)101 package this(char[] msg) 92 102 { 93 103 super(msg); … … 95 105 } 96 106 97 class MDCompileException : MDException 98 { 99 bool atEOF = false; 100 bool solitaryExpression = false; 101 102 public this(char[] msg) 107 /** 108 An exception type representing a compilation error. The message will be in the form "filename(line:column): 109 error message". Again, you can't directly instantiate this exception type. 110 */ 111 final class MDCompileException : MDException 112 { 113 /** 114 Indicates whether the compiler threw this at the end of the file or not. If this is 115 true, this might be because the compiler ran out of input, in which case the code could 116 be made to compile by adding more code. 117 */ 118 public bool atEOF = false; 119 120 /** 121 Indicates whether the compiler threw this because of a statement that consisted of a no-effect expression. 122 If true, the code might be able to be compiled and evaluated as an expression. 123 */ 124 public bool solitaryExpression = false; 125 126 package this(char[] msg) 103 127 { 104 128 super(msg); … … 106 130 } 107 131 108 class MDHaltException : Exception 109 { 110 public this() 132 /** 133 This is a semi-internal exception type. Normally you won't need to know about it or catch it. This is 134 thrown when a coroutine (thread) needs to be halted. It should never propagate out of the coroutine. 135 The only time you might encounter it is if, in the middle of a native MiniD function, one of these 136 is thrown, you might be able to catch it and clean up some resources, but you should rethrow it. 137 138 Like the other exception types, you can't instantiate this directly, but you can halt threads with the 139 "haltThread" function in minid.interpreter. 140 */ 141 final class MDHaltException : Exception 142 { 143 package this() 111 144 { 112 145 super("MiniD interpreter halted"); 113 146 } 114 147 } 148 149 version(MDRestrictedCoro) 150 version(MDExtendedCoro) 151 { 152 pragma(msg, "The 'MDRestrictedCoro' and 'MDExtendedCoro' versions are mutually exclusive."); 153 pragma(msg, "Please define one or the other (or neither), not both.\n"); 154 static assert(false, "FAILCOPTER."); 155 } 115 156 116 157 // ================================================================================================================================================ … … 556 597 package bool shouldHalt = false; 557 598 558 // References a Fiber object559 package MDNativeObj* coroFiber;560 599 package MDFunction* coroFunc; 561 600 package State state = State.Initial; 562 601 package size_t numYields; 563 602 564 package Fiber getFiber() 565 { 566 assert(coroFiber !is null); 567 return cast(Fiber)cast(void*)coroFiber.obj; 603 version(MDExtendedCoro) {} else 604 { 605 package size_t savedCallDepth; 606 package size_t nativeCallDepth = 0; 607 } 608 609 version(MDRestrictedCoro) {} else 610 { 611 // References a Fiber object 612 package MDNativeObj* coroFiber; 613 614 package Fiber getFiber() 615 { 616 assert(coroFiber !is null); 617 return cast(Fiber)cast(void*)coroFiber.obj; 618 } 568 619 } 569 620 } branches/v2new/test.d
r323 r324 26 26 lookupCT!("Timer")(t); 27 27 28 auto funcReg = loadFunc(t, ` samples\simple.md`);28 auto funcReg = loadFunc(t, `benchmark\cheapconcurrency.md`); 29 29 pushNull(t); 30 30 rawCall(t, funcReg, 0);
