From acc40a6d2a06ab1fcfbd488030e091bd9215a1b2 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 18 Jun 2013 18:43:15 +0200 Subject: Code mapping generating text code from blocks, first experimental iteration --- threads.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'threads.js') diff --git a/threads.js b/threads.js index 2a1802c..d98d2b5 100644 --- a/threads.js +++ b/threads.js @@ -83,7 +83,7 @@ ArgLabelMorph, localize*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2013-May-14'; +modules.threads = '2013-June-18'; var ThreadManager; var Process; @@ -2284,6 +2284,53 @@ Process.prototype.reportTimer = function () { return 0; }; +// Process code mapping + +/* + for generating textual source code using + blocks - not needed to run or debug Snap +*/ + +Process.prototype.doMapCode = function (aContext, aString) { + if (aContext instanceof Context) { + if (aContext.expression instanceof SyntaxElementMorph) { + return aContext.expression.mapCode(aString || ''); + } + } +}; + +Process.prototype.doMapStringCode = function (aString) { + StageMorph.prototype.codeMappings.string = aString || '<#1>'; +}; + +Process.prototype.doMapListCode = function (part, kind, aString) { + var key1 = '', + key2 = 'delim'; + + if (this.inputOption(kind) === 'parameters') { + key1 = 'parms_'; + } else if (this.inputOption(kind) === 'variables') { + key1 = 'tempvars_'; + } + + if (this.inputOption(part) === 'list') { + key2 = 'list'; + } else if (this.inputOption(part) === 'item') { + key2 = 'item'; + } + + StageMorph.prototype.codeMappings[key1 + key2] = aString || ''; +}; + +Process.prototype.reportMappedCode = function (aContext) { + if (aContext instanceof Context) { + if (aContext.expression instanceof SyntaxElementMorph) { + return aContext.expression.mappedCode(); + } + } + return ''; +}; + // Process music primitives Process.prototype.doRest = function (beats) { -- cgit v1.3.1