/* * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ "use strict";
const Basic = {};
Basic.NumberApply = function(state)
{ // I'd call this arguments but we're in strict mode.
let parameters = this.parameters.map(value => value.evaluate(state));
Basic.Next = function*(state)
{
let sideState = state.getSideState(this.target);
sideState.variable.assign(sideState.variable.value + sideState.stepValue); if (sideState.shouldStop()) return;
state.nextLineNumber = this.target.lineNumber + 1;
}
Basic.Next.isBlockEnd = true;
Basic.Print = function*(state)
{
let string = ""; for (let item of this.items) { switch (item.kind) { case"comma": while (string.length % 14)
string += " "; break; case"tab": {
let value = item.value.evaluate(state);
value = Math.max(Math.round(value), 1); while (string.length % value)
string += " "; break;
} case"string": case"number":
string += item.value.evaluate(state); break; default: thrownew Error("Bad item kind: " + item.kind);
}
}
yield {kind: "output", string};
}
Basic.Input = function*(state)
{
let results = yield {kind: "input", numItems: this.items.length};
state.validate(results != null && results.length == this.items.length, "Input did not get the right number of items"); for (let i = 0; i < results.length; ++i) this.items[i].evaluate(state).assign(results[i]);
}
Basic.Read = function*(state)
{ for (let item of this.items) {
state.validate(state.dataIndex < state.program.data.length, "Attempting to read past the end of data");
item.assign(state.program.data[state.dataIndex++]);
}
}
Basic.Program = function* programGenerator(state)
{
state.validate(state.program == this, "State must match program");
let maxLineNumber = Math.max(...this.statements.keys()); while (state.nextLineNumber != null) {
state.validate(state.nextLineNumber <= maxLineNumber, "Went out of bounds of the program");
let statement = this.statements.get(state.nextLineNumber++); if (statement == null || statement.process == null) continue;
state.statement = statement;
yield* statement.process(state);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.