sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
2,572 lines • 33.5 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: misceval</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Namespace: misceval</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="Sk.html">Sk</a>.</span>
misceval
</h2>
</header>
<article>
<div class="container-overview">
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Classes</h3>
<dl>
<dt><a href="Sk.misceval.Suspension.html">Suspension</a></dt>
<dd></dd>
</dl>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".swappedOp_"><span class="type-signature">(static) </span>swappedOp_<span class="type-signature"></span></h4>
<div class="description">
<p>for reversed comparison: Gt -> Lt, etc.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line201">line 201</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".apply"><span class="type-signature">(static) </span>apply<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Wrap Sk.misceval.applyOrSuspend, but throw an error if we suspend</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line838">line 838</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".applyOrSuspend"><span class="type-signature">(static) </span>applyOrSuspend<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>same as Sk.misceval.call except args is an actual array, rather than
varargs.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line1004">line 1004</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".applySlice"><span class="type-signature">(static) </span>applySlice<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>return u[v:w]</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line116">line 116</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".arrayFromArguments"><span class="type-signature">(static) </span>arrayFromArguments<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Used by min() and max() to get an array from arbitrary input.
Note that this does no validation, just coercion.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line164">line 164</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".assignSlice"><span class="type-signature">(static) </span>assignSlice<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>u[v:w] = x</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line137">line 137</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".asyncToPromise"><span class="type-signature">(static) </span>asyncToPromise<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Wraps anything that can return an Sk.misceval.Suspension, and returns a
JS Promise with the result. Also takes an object map of suspension handlers:
pass in {"suspType": function (susp) {} }, and your function will be called
with the Suspension object if susp.type=="suspType". The type "*" will match
all otherwise unhandled suspensions.</p>
<p>A suspension handler should return a Promise yielding the return value of
r.resume() - ie, either the final return value of this call or another
Suspension. That is, the null suspension handler is:</p>
<pre class="prettyprint source"><code>function handler(susp) {
return new Promise(function(resolve, reject) {
try {
resolve(susp.resume());
} catch(e) {
reject(e);
}
});
}</code></pre><p>Alternatively, a handler can return null to perform the default action for
that suspension type.</p>
<p>(Note: do <em>not</em> call asyncToPromise() in a suspension handler; this will
create a new Promise object for each such suspension that occurs)</p>
<p>asyncToPromise() returns a Promise that will be resolved with the final
return value, or rejected with an exception if one is thrown.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line881">line 881</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".buildClass"><span class="type-signature">(static) </span>buildClass<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Constructs a class object given a code object representing the body
of the class, the name of the class, and the list of bases.</p>
<p>There are no "old-style" classes in Skulpt, so use the user-specified
metaclass (todo;) if there is one, the type of the 0th base class if
there's bases, or otherwise the 'type' type.</p>
<p>The func code object is passed a (js) dict for its locals which it
stores everything into.</p>
<p>The metaclass is then called as metaclass(name, bases, locals) and
should return a newly constructed class object.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line1112">line 1112</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".call"><span class="type-signature">(static) </span>call<span class="signature">(func, kwdict<span class="signature-attributes">opt</span>, varargseq<span class="signature-attributes">opt</span>, kws<span class="signature-attributes">opt</span>, …args)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Notes on necessity for 'call()':</p>
<p>Classes are callable in python to create an instance of the class. If
we're calling "C()" we cannot tell at the call site whether we're
calling a standard function, or instantiating a class.</p>
<p>JS does not support user-level callables. So, we can't use the normal
prototype hierarchy to make the class inherit from a 'class' type
where the various tp$getattr, etc. methods would live.</p>
<p>Instead, we must copy all the methods from the prototype of our class
type onto every instance of the class constructor function object.
That way, both "C()" and "C.tp$getattr(...)" can still work. This is
of course quite expensive.</p>
<p>The alternative would be to indirect all calls (whether classes or
regular functions) through something like C.$call(...). In the case
of class construction, $call could then call the constructor after
munging arguments to pass them on. This would impose a penalty on
regular function calls unfortunately, as they would have to do the
same thing.</p>
<p>Note that the same problem exists for function objects too (a "def"
creates a function object that also has properties). It just happens
that attributes on classes in python are much more useful and common
that the attributes on functions.</p>
<p>Also note, that for full python compatibility we have to do the $call
method because any python object could have a <strong>call</strong> method which
makes the python object callable too. So, unless we were to make
<em>all</em> objects simply (function(){...}) and use the dict to create
hierarchy, there would be no way to call that python user function. I
think I'm prepared to sacrifice <strong>call</strong> support, or only support it
post-ECMA5 or something.</p>
<p>Is using (function(){...}) as the only object type too crazy?
Probably. Better or worse than having two levels of function
invocation for every function call?</p>
<p>For a class <code>C' with instance</code>inst' we have the following cases:</p>
<ol>
<li><p>C.attr</p>
</li>
<li><p>C.staticmeth()</p>
</li>
<li><p>x = C.staticmeth; x()</p>
</li>
<li><p>inst = C()</p>
</li>
<li><p>inst.attr</p>
</li>
<li><p>inst.meth()</p>
</li>
<li><p>x = inst.meth; x()</p>
</li>
<li><p>inst(), where C defines a <strong>call</strong></p>
</li>
</ol>
<p>Because in general these are accomplished by a helper function
(tp$getattr/setattr/slice/ass_slice/etc.) it seems appropriate to add
a call that generally just calls through, but sometimes handles the
unusual cases. Once ECMA-5 is more broadly supported we can revisit
and hopefully optimize.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>func</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the thing to call</p></td>
</tr>
<tr>
<td class="name"><code>kwdict</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>**kwargs</p></td>
</tr>
<tr>
<td class="name"><code>varargseq</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>**args</p></td>
</tr>
<tr>
<td class="name"><code>kws</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>keyword args or undef</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last"><p>stuff to pass it</p>
<p>TODO I think all the above is out of date.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line769">line 769</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".callAsync"><span class="type-signature">(static) </span>callAsync<span class="signature">(suspensionHandlers<span class="signature-attributes">nullable</span>, func, kwdict<span class="signature-attributes">opt</span>, varargseq<span class="signature-attributes">opt</span>, kws<span class="signature-attributes">opt</span>, …args)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>suspensionHandlers</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<nullable><br>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>func</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the thing to call</p></td>
</tr>
<tr>
<td class="name"><code>kwdict</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>**kwargs</p></td>
</tr>
<tr>
<td class="name"><code>varargseq</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>**args</p></td>
</tr>
<tr>
<td class="name"><code>kws</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>keyword args or undef</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last"><p>stuff to pass it</p>
<p>TODO I think all the above is out of date.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line788">line 788</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".callsim"><span class="type-signature">(static) </span>callsim<span class="signature">(func, …args)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>func</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the thing to call</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last"><p>stuff to pass it</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line807">line 807</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".callsimAsync"><span class="type-signature">(static) </span>callsimAsync<span class="signature">(suspensionHandlers<span class="signature-attributes">nullable</span>, func, …args)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>suspensionHandlers</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<nullable><br>
</td>
<td class="description last"><p>any custom suspension handlers</p></td>
</tr>
<tr>
<td class="name"><code>func</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the thing to call</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last"><p>stuff to pass it</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line818">line 818</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".callsimOrSuspend"><span class="type-signature">(static) </span>callsimOrSuspend<span class="signature">(func, …args)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>func</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the thing to call</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last"><p>stuff to pass it</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line829">line 829</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".chain"><span class="type-signature">(static) </span>chain<span class="signature">(initialValue, …chainedFns)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Chain together a set of functions, each of which might return a value or
an Sk.misceval.Suspension. Each function is called with the return value of
the preceding function, but does not see any suspensions. If a function suspends,
Sk.misceval.chain() returns a suspension that will resume the chain once an actual
return value is available.</p>
<p>The idea is to allow a Promise-like chaining of possibly-suspending steps without
repeating boilerplate suspend-and-resume code.</p>
<p>For example, imagine we call Sk.misceval.chain(x, f).</p>
<ul>
<li>If x is a value, we return f(x).</li>
<li>If x is a suspension, we suspend. We will suspend and resume until we get a
return value, and then we will return f(<resumed-value).
This can be expanded to an arbitrary number of functions
(eg Sk.misceval.chain(x, f, g), which is equivalent to chain(chain(x, f), g).)</li>
</ul>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>initialValue</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>chainedFns</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
<repeatable><br>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line982">line 982</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".isIndex"><span class="type-signature">(static) </span>isIndex<span class="signature">(o)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
<p>Check if the given object is valid to use as an index. Only ints, or if the object has an <code>__index__</code> method.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>o</code></td>
<td class="type">
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line63">line 63</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id=".loadname"><span class="type-signature">(static) </span>loadname<span class="signature">(name, other<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>name</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>other</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>generally globals</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line677">line 677</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".retryOptionalSuspensionOrThrow"><span class="type-signature">(static) </span>retryOptionalSuspensionOrThrow<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Well this seems pretty obvious by the name what it should do..</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="misceval.js.html">misceval.js</a>, <a href="misceval.js.html#line47">line 47</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Sk.abstr.iter-seqIter.html">seqIter</a></li><li><a href="Sk.builtin.bool.html">bool</a></li><li><a href="Sk.builtin.float_.html">float_</a></li><li><a href="Sk.builtin.func.html">func</a></li><li><a href="Sk.builtin.int_.html">int_</a></li><li><a href="Sk.builtin.none.html">none</a></li><li><a href="Sk.builtin.NotImplemented.html">NotImplemented</a></li><li><a href="Sk.builtin.numtype.html">numtype</a></li><li><a href="Sk.builtin.object.html">object</a></li><li><a href="Sk.builtin.seqtype.html">seqtype</a></li><li><a href="Sk.misceval.Suspension.html">Suspension</a></li></ul><h3>Namespaces</h3><ul><li><a href="Sk.html">Sk</a></li><li><a href="Sk.abstr.html">abstr</a></li><li><a href="Sk.builtin.html">builtin</a></li><li><a href="Sk.ffi.html">ffi</a></li><li><a href="Sk.misceval.html">misceval</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0</a> on Thu Aug 13 2015 08:14:27 GMT-0500 (CDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>