├── .gitignore ├── docs ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.woff │ ├── OpenSans-Semibold-webfont.eot │ ├── OpenSans-Semibold-webfont.ttf │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ ├── OpenSans-Semibold-webfont.woff │ ├── OpenSans-LightItalic-webfont.woff │ ├── OpenSans-SemiboldItalic-webfont.eot │ ├── OpenSans-SemiboldItalic-webfont.ttf │ └── OpenSans-SemiboldItalic-webfont.woff ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── lang-css.js │ │ ├── Apache-License-2.0.txt │ │ └── prettify.js ├── styles │ ├── prettify-jsdoc.css │ ├── prettify-tomorrow.css │ └── jsdoc-default.css ├── index.html ├── module-Wren.html └── wren.js.html ├── test └── test.mjs ├── README.md ├── package.json ├── LICENSE ├── scripts └── exports.js └── src ├── shim.c └── wren.js /.gitignore: -------------------------------------------------------------------------------- 1 | wren 2 | emsdk 3 | .idea 4 | *~ 5 | node_modules 6 | -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Semibold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Semibold-webfont.ttf -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-Semibold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-SemiboldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ppvk/wrenjs/HEAD/docs/fonts/OpenSans-SemiboldItalic-webfont.woff -------------------------------------------------------------------------------- /test/test.mjs: -------------------------------------------------------------------------------- 1 | import * as Wren from "../out/wren.js"; 2 | 3 | for await (const dirEntry of Deno.readDir("./wren/test/benchmark")) { 4 | if (dirEntry.name.includes(".wren")) { 5 | let source = await Deno.readTextFile("./wren/test/benchmark/" + dirEntry.name); 6 | 7 | let vm = new Wren.VM(); 8 | 9 | console.log([dirEntry.name]); 10 | vm.interpret(dirEntry.name, source); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Using [emscripten](https://emscripten.org/) 2 | to transpile Bob Nystrom's [wren](http:wren.io) programming language to Javascript. 3 | 4 | wren: 0.4.0 | emscripten: 2.0.21 5 | 6 | 7 | 8 | 9 | 10 | 11 | # Build Instructions 12 | 13 | These instructions are for an Ubuntu-like system. 14 | 15 | You will need: 16 | - build-essential 17 | - cmake 18 | - python2.7 19 | - python3 20 | - nodejs 21 | - java 22 | - deno 23 | 24 | After these are ready to go, run `./build.sh` 25 | 26 | For a detailed explanation of what this bash script does, 27 | check out the comments in the file itself. 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wrenjs", 3 | "version": "0.4.0", 4 | "description": "Using emscripten to transpile the wren programming language to Javascript.", 5 | "main": "out/wren.min.js", 6 | "scripts": { 7 | "test": "deno run --allow-read ./test/test.mjs" 8 | }, 9 | "directories": { 10 | "example": "examples" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/ppvk/wrenjs.git" 15 | }, 16 | "author": "Paul VanKeuren and friends", 17 | "license": "MIT", 18 | "homepage": "https://github.com/ppvk/wrenjs#readme", 19 | "devDependencies": { 20 | "jsdoc": "^3.6.7", 21 | "minami": "^1.2.3", 22 | "rollup": "^2.52.1", 23 | "uglify-js": "^3.13.9" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Paul VanKeuren 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /scripts/exports.js: -------------------------------------------------------------------------------- 1 | let fs = require('fs'); 2 | 3 | let wren_h = fs.readFileSync('wren/src/include/wren.h', 'utf8'); 4 | let lines = wren_h.split('\n'); 5 | 6 | let functions = []; 7 | 8 | for (let l = 0; l < lines.length; l++) { 9 | let line = lines[l]; 10 | if (line.startsWith('WREN_API')) { 11 | line = line.split('(')[0]; 12 | let splitOnSpace = line.split(' '); 13 | line = splitOnSpace[splitOnSpace.length - 1]; 14 | functions.push(line); 15 | } 16 | } 17 | 18 | fs.writeFileSync('src/generated/exports', functions.join('\n')); 19 | 20 | // Log the C API functions that don't have a JS API function associated with them. 21 | let shim_c = fs.readFileSync('src/wren.js', 'utf8'); 22 | let firstWarning = true; 23 | for (let f = 0; f < functions.length; f++) { 24 | let shimFunction = functions[f].replace('wren', ''); 25 | if (!shim_c.toLowerCase().includes(shimFunction.toLowerCase())) { 26 | if (firstWarning == true) { 27 | firstWarning = false; 28 | 29 | console.warn(` 30 | The following C functions do not have JS functions in src/wren.js defined for them. 31 | This should only display if you are hacking on a new version. 32 | `); 33 | }; 34 | 35 | console.warn(' ' + functions[f]); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: hsl(104, 100%, 24%); 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /docs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: hsl(104, 100%, 24%); } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: hsl(240, 100%, 50%); } 17 | 18 | /* a comment */ 19 | .com { 20 | color: hsl(0, 0%, 60%); } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: hsl(240, 100%, 32%); } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: hsl(240, 100%, 40%); } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #000000; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #000000; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #000000; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /src/shim.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "emscripten.h" 4 | #include "wren.h" 5 | 6 | /* 7 | This C file contains the bindings that connect the world of wren to the 8 | world of JavaScript. 9 | */ 10 | 11 | void modulePushString(const char* string) { 12 | EM_ASM({ 13 | Module._values.push( 14 | UTF8ToString($0) 15 | ); 16 | }, string); 17 | } 18 | 19 | void modulePushDouble(double number) { 20 | EM_ASM({ 21 | Module._values.push($0); 22 | }, number); 23 | } 24 | 25 | 26 | const char* moduleShiftString() { 27 | int length = EM_ASM_INT({ 28 | let index = Module._values.length - 1; 29 | return lengthBytesUTF8("" + Module._values[index]) + 1; 30 | }); 31 | 32 | const char* string = malloc(length); 33 | 34 | EM_ASM({ 35 | let s = "" + Module._values.shift(); 36 | stringToUTF8( s, $0, lengthBytesUTF8(s) + 1); 37 | }, string); 38 | 39 | return string; 40 | } 41 | 42 | double moduleShiftDouble() { 43 | return EM_ASM_DOUBLE({ 44 | let value = Module._values.shift(); 45 | return value; 46 | }); 47 | } 48 | 49 | /* 50 | The following are wrappers for functions normally attached to a WrenConfiguration. 51 | */ 52 | 53 | const char* shimResolveModuleFn(WrenVM* vm, 54 | const char* importer, const char* name) { 55 | modulePushString(importer); 56 | modulePushString(name); 57 | 58 | EM_ASM({ 59 | let importer = Module._values.shift(); 60 | let name = Module._values.shift(); 61 | 62 | let output = Module._VMs[$0]._resolveModuleFn(importer, name); 63 | Module._values.push(output); 64 | }, vm); 65 | 66 | const char* output = moduleShiftString(); 67 | 68 | if (strcmp(output, "null") == 1) { 69 | return NULL; 70 | } else { 71 | return output; 72 | } 73 | } 74 | 75 | void loadModuleComplete(WrenVM* vm, const char* module, WrenLoadModuleResult result) { 76 | if(result.source) { 77 | free((void*) result.source); 78 | } 79 | } 80 | 81 | WrenLoadModuleResult shimLoadModuleFn(WrenVM* vm, const char* name) { 82 | WrenLoadModuleResult result; 83 | memset(&result, 0, sizeof(WrenLoadModuleResult)); 84 | 85 | modulePushString(name); 86 | 87 | EM_ASM({ 88 | let name = Module._values.shift(); 89 | let module = Module._VMs[$0]._loadModuleFn(name); 90 | 91 | if (module == null) { 92 | // Could not find module 93 | Module._values.push(0); 94 | } else { 95 | // Could find module 96 | Module._values.push(1); 97 | Module._values.push(module); 98 | } 99 | 100 | }, vm); 101 | 102 | bool found = moduleShiftDouble(); 103 | if (found == 1) { 104 | result.source = moduleShiftString(); 105 | result.onComplete = loadModuleComplete; 106 | } else { 107 | result.source = NULL; 108 | result.onComplete = NULL; 109 | } 110 | 111 | return result; 112 | } 113 | 114 | 115 | // This pointer and the function right below it are meant to be reusable. 116 | // Everytime we set a ForeignMethodFn, we use this pointer as a way to send that 117 | // Function pointer to C 118 | WrenForeignMethodFn shimForeignMethod; 119 | 120 | EMSCRIPTEN_KEEPALIVE 121 | void setCurrentForeignMethod(WrenForeignMethodFn foreignMethod) { 122 | shimForeignMethod = foreignMethod; 123 | } 124 | 125 | // This is easily the most complicated part of these shim files. 126 | // It warrants a detailed explanation. 127 | WrenForeignMethodFn shimBindForeignMethodFn(WrenVM* vm, 128 | const char* module, const char* className, bool isStatic, 129 | const char* signature) { 130 | 131 | // Pepare to send the arguments to JavaScript 132 | modulePushString(module); 133 | modulePushString(className); 134 | if (isStatic) { 135 | modulePushDouble(1); // true 136 | } else { 137 | modulePushDouble(0); // false 138 | } 139 | modulePushString(signature); 140 | 141 | 142 | EM_ASM({ 143 | // Get those arguments 144 | let module = Module._values.shift(); 145 | let className = Module._values.shift(); 146 | let isStatic = Module._values.shift() == 1; 147 | let signature = Module._values.shift(); 148 | 149 | let foreignMethodFn = Module._VMs[$0]._bindForeignMethod( 150 | module, className, isStatic, signature 151 | ); 152 | 153 | // We use a Bool in slot 0 to let our C code know that we're missing the 154 | // JavaScript function to bind. 155 | if (foreignMethodFn == null) { 156 | // We did not find a method 157 | Module._values.push(0); 158 | } else { 159 | // We did find a method 160 | Module._values.push(1); 161 | 162 | let fnPointer = addFunction(foreignMethodFn, 'vi'); 163 | // this sets our reusable pointer to the JavaScript function we just 164 | // wrapped. 165 | 166 | ccall('setCurrentForeignMethod', 167 | null, 168 | ['number'], 169 | [fnPointer] 170 | ); 171 | } 172 | 173 | }, vm); 174 | 175 | if (moduleShiftDouble() == 0) { 176 | return NULL; 177 | } else { 178 | return shimForeignMethod; 179 | } 180 | } 181 | 182 | 183 | WrenForeignMethodFn shimAllocate; 184 | WrenFinalizerFn shimFinalize; 185 | 186 | EMSCRIPTEN_KEEPALIVE 187 | void setClassMethods(WrenForeignMethodFn allocate, WrenFinalizerFn finalize) { 188 | shimAllocate = allocate; 189 | shimFinalize = finalize; 190 | } 191 | 192 | WrenForeignClassMethods shimBindForeignClassFn( 193 | WrenVM* vm, const char* module, const char* className) { 194 | 195 | modulePushString(module); 196 | modulePushString(className); 197 | 198 | EM_ASM({ 199 | let module = Module._values.shift(); 200 | let className = Module._values.shift(); 201 | 202 | let classMethods = Module._VMs[$0]._bindForeignClass(module, className); 203 | 204 | if (classMethods == null) { 205 | // We did not find this class 206 | Module._values.push(0); 207 | } else { 208 | // We did find this class 209 | Module._values.push(1); 210 | 211 | // Convert the JS functions to pointers 212 | let allocatePtr = addFunction(classMethods.allocate, 'vi'); 213 | let finalizePtr = addFunction(classMethods.finalize, 'vi'); 214 | 215 | // Send those pointers to C 216 | ccall('setClassMethods', 217 | null, 218 | ['number', 'number'], 219 | [allocatePtr, finalizePtr] 220 | ); 221 | } 222 | 223 | }, vm); 224 | 225 | WrenForeignClassMethods methods; 226 | 227 | if (moduleShiftDouble() == 0) { 228 | methods.allocate = NULL; 229 | methods.finalize = NULL; 230 | return methods; 231 | } else { 232 | methods.allocate = shimAllocate; 233 | methods.finalize = shimFinalize; 234 | return methods; 235 | } 236 | 237 | } 238 | 239 | 240 | void shimWriteFn(WrenVM* vm, const char* text) { 241 | if (strcmp(text, "\n") == 0) { 242 | return; 243 | } 244 | 245 | modulePushString(text); 246 | 247 | EM_ASM({ 248 | let text = Module._values.shift(); 249 | Module._VMs[$0]._write(text); 250 | }, vm); 251 | } 252 | 253 | void shimErrorFn( 254 | WrenVM* vm, WrenErrorType type, const char* module, int line, 255 | const char* message) { 256 | 257 | modulePushDouble(type); 258 | modulePushString(module); 259 | modulePushDouble(line); 260 | modulePushString(message); 261 | 262 | EM_ASM({ 263 | let type = Module._values.shift(); 264 | let module = Module._values.shift(); 265 | let line = Module._values.shift(); 266 | let message = Module._values.shift(); 267 | 268 | Module._VMs[$0]._error(type, module, line, message); 269 | }, vm); 270 | } 271 | 272 | // Reusable WrenConfiguration 273 | WrenConfiguration config; 274 | 275 | EMSCRIPTEN_KEEPALIVE 276 | WrenVM* shimNewVM() { 277 | 278 | wrenInitConfiguration(&config); 279 | config.writeFn = shimWriteFn; 280 | config.errorFn = shimErrorFn; 281 | config.bindForeignMethodFn = shimBindForeignMethodFn; 282 | config.bindForeignClassFn = shimBindForeignClassFn; 283 | config.loadModuleFn = shimLoadModuleFn; 284 | config.resolveModuleFn = shimResolveModuleFn; 285 | 286 | WrenVM* vm = wrenNewVM(&config); 287 | return vm; 288 | } 289 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Home - Documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 29 | 30 |
31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
59 | 60 |
61 | 62 |

63 | wren.js 64 |

65 | 66 | 67 |
68 | 69 |
70 |
71 | 72 | 73 |
The wren programming language in your browser! 74 |
75 | 76 | 77 | 78 | 79 | 80 |
81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
Source:
108 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 |
119 | 120 | 121 | 122 |

Example

123 | 124 |
import * as Wren from "../out/wren.js";
125 | 
126 | let vm = new Wren.VM({
127 |   resolveModuleFn     : function(importer, name) {...},
128 |   loadModuleFn        : function(name) {...},
129 |   bindForeignMethodFn : function(moduleName, className, isStatic, signature) {...},
130 |   bindForeignClassFn  : function(moduleName, className) {...},
131 |   writeFn             : function(toLog) {...},
132 |   errorFn             : function(errorType, moduleName, line, msg) {...}
133 | });
134 | 
135 | vm.interpret("main", `
136 |   System.print("Hello from Wren!")
137 | `);
138 | 139 | 140 | 141 |
142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 |
161 | 162 |
163 | 164 | 165 | 166 | 167 |
168 | 169 |
170 | 171 |
172 | Generated by JSDoc 3.6.7 on Wed Oct 19 2022 18:29:41 GMT+0200 (Central European Summer Time) using the Minami theme. 173 |
174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /docs/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p code { 197 | font-size: 0.85em; 198 | } 199 | 200 | .readme table { 201 | margin-bottom: 1em; 202 | border-collapse: collapse; 203 | border-spacing: 0; 204 | } 205 | 206 | .readme table tr { 207 | background-color: #fff; 208 | border-top: 1px solid #ccc; 209 | } 210 | 211 | .readme table th, 212 | .readme table td { 213 | padding: 6px 13px; 214 | border: 1px solid #ddd; 215 | } 216 | 217 | .readme table tr:nth-child(2n) { 218 | background-color: #f8f8f8; 219 | } 220 | 221 | /** Nav **/ 222 | nav { 223 | float: left; 224 | display: block; 225 | width: 250px; 226 | background: #fff; 227 | overflow: auto; 228 | position: fixed; 229 | height: 100%; 230 | padding: 10px; 231 | border-right: 1px solid #eee; 232 | /* box-shadow: 0 0 3px rgba(0,0,0,0.1); */ 233 | } 234 | 235 | nav li { 236 | list-style: none; 237 | padding: 0; 238 | margin: 0; 239 | } 240 | 241 | .nav-heading { 242 | margin-top: 10px; 243 | font-weight: bold; 244 | } 245 | 246 | .nav-heading a { 247 | color: #888; 248 | font-size: 14px; 249 | display: inline-block; 250 | } 251 | 252 | .nav-item-type { 253 | /* margin-left: 5px; */ 254 | width: 18px; 255 | height: 18px; 256 | display: inline-block; 257 | text-align: center; 258 | border-radius: 0.2em; 259 | margin-right: 5px; 260 | font-weight: bold; 261 | line-height: 20px; 262 | font-size: 13px; 263 | } 264 | 265 | .type-function { 266 | background: #B3E5FC; 267 | color: #0288D1; 268 | } 269 | 270 | .type-class { 271 | background: #D1C4E9; 272 | color: #4527A0; 273 | } 274 | 275 | .type-member { 276 | background: #C8E6C9; 277 | color: #388E3C; 278 | } 279 | 280 | .type-module { 281 | background: #E1BEE7; 282 | color: #7B1FA2; 283 | } 284 | 285 | 286 | /** Footer **/ 287 | footer { 288 | color: hsl(0, 0%, 28%); 289 | margin-left: 250px; 290 | display: block; 291 | padding: 30px; 292 | font-style: italic; 293 | font-size: 90%; 294 | border-top: 1px solid #eee; 295 | } 296 | 297 | .ancestors { 298 | color: #999 299 | } 300 | 301 | .ancestors a { 302 | color: #999 !important; 303 | text-decoration: none; 304 | } 305 | 306 | .clear { 307 | clear: both 308 | } 309 | 310 | .important { 311 | font-weight: bold; 312 | color: #950B02; 313 | } 314 | 315 | .yes-def { 316 | text-indent: -1000px 317 | } 318 | 319 | .type-signature { 320 | color: #aaa 321 | } 322 | 323 | .name, .signature { 324 | font-family: Consolas, Monaco, 'Andale Mono', monospace 325 | } 326 | 327 | .details { 328 | margin-top: 14px; 329 | border-left: 2px solid #DDD; 330 | line-height: 30px; 331 | } 332 | 333 | .details dt { 334 | width: 120px; 335 | float: left; 336 | padding-left: 10px; 337 | } 338 | 339 | .details dd { 340 | margin-left: 70px 341 | } 342 | 343 | .details ul { 344 | margin: 0 345 | } 346 | 347 | .details ul { 348 | list-style-type: none 349 | } 350 | 351 | .details li { 352 | margin-left: 30px 353 | } 354 | 355 | .details pre.prettyprint { 356 | margin: 0 357 | } 358 | 359 | .details .object-value { 360 | padding-top: 0 361 | } 362 | 363 | .description { 364 | margin-bottom: 1em; 365 | margin-top: 1em; 366 | } 367 | 368 | .code-caption { 369 | font-style: italic; 370 | font-size: 107%; 371 | margin: 0; 372 | } 373 | 374 | .prettyprint { 375 | font-size: 13px; 376 | border: 1px solid #ddd; 377 | border-radius: 3px; 378 | box-shadow: 0 1px 3px hsla(0, 0%, 0%, 0.05); 379 | overflow: auto; 380 | } 381 | 382 | .prettyprint.source { 383 | width: inherit 384 | } 385 | 386 | .prettyprint code { 387 | font-size: 12px; 388 | line-height: 18px; 389 | display: block; 390 | background-color: #fff; 391 | color: #4D4E53; 392 | } 393 | 394 | .prettyprint code:empty:before { 395 | content: ''; 396 | } 397 | 398 | .prettyprint > code { 399 | padding: 15px 400 | } 401 | 402 | .prettyprint .linenums code { 403 | padding: 0 15px 404 | } 405 | 406 | .prettyprint .linenums li:first-of-type code { 407 | padding-top: 15px 408 | } 409 | 410 | .prettyprint code span.line { 411 | display: inline-block 412 | } 413 | 414 | .prettyprint.linenums { 415 | padding-left: 70px; 416 | -webkit-user-select: none; 417 | -moz-user-select: none; 418 | -ms-user-select: none; 419 | user-select: none; 420 | } 421 | 422 | .prettyprint.linenums ol { 423 | padding-left: 0 424 | } 425 | 426 | .prettyprint.linenums li { 427 | border-left: 3px #ddd solid 428 | } 429 | 430 | .prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { 431 | background-color: lightyellow 432 | } 433 | 434 | .prettyprint.linenums li * { 435 | -webkit-user-select: text; 436 | -moz-user-select: text; 437 | -ms-user-select: text; 438 | user-select: text; 439 | } 440 | 441 | .params, .props { 442 | border-spacing: 0; 443 | border: 1px solid #ddd; 444 | border-collapse: collapse; 445 | border-radius: 3px; 446 | box-shadow: 0 1px 3px rgba(0,0,0,0.1); 447 | width: 100%; 448 | font-size: 14px; 449 | /* margin-left: 15px; */ 450 | } 451 | 452 | .params .name, .props .name, .name code { 453 | color: #4D4E53; 454 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 455 | font-size: 100%; 456 | } 457 | 458 | .params td, .params th, .props td, .props th { 459 | margin: 0px; 460 | text-align: left; 461 | vertical-align: top; 462 | padding: 10px; 463 | display: table-cell; 464 | } 465 | 466 | .params td { 467 | border-top: 1px solid #eee 468 | } 469 | 470 | .params thead tr, .props thead tr { 471 | background-color: #fff; 472 | font-weight: bold; 473 | } 474 | 475 | .params .params thead tr, .props .props thead tr { 476 | background-color: #fff; 477 | font-weight: bold; 478 | } 479 | 480 | .params td.description > p:first-child, .props td.description > p:first-child { 481 | margin-top: 0; 482 | padding-top: 0; 483 | } 484 | 485 | .params td.description > p:last-child, .props td.description > p:last-child { 486 | margin-bottom: 0; 487 | padding-bottom: 0; 488 | } 489 | 490 | dl.param-type { 491 | /* border-bottom: 1px solid hsl(0, 0%, 87%); */ 492 | margin: 0; 493 | padding: 0; 494 | font-size: 16px; 495 | } 496 | 497 | .param-type dt, .param-type dd { 498 | display: inline-block 499 | } 500 | 501 | .param-type dd { 502 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 503 | display: inline-block; 504 | padding: 0; 505 | margin: 0; 506 | font-size: 14px; 507 | } 508 | 509 | .disabled { 510 | color: #454545 511 | } 512 | 513 | /* navicon button */ 514 | .navicon-button { 515 | display: none; 516 | position: relative; 517 | padding: 2.0625rem 1.5rem; 518 | transition: 0.25s; 519 | cursor: pointer; 520 | user-select: none; 521 | opacity: .8; 522 | } 523 | .navicon-button .navicon:before, .navicon-button .navicon:after { 524 | transition: 0.25s; 525 | } 526 | .navicon-button:hover { 527 | transition: 0.5s; 528 | opacity: 1; 529 | } 530 | .navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { 531 | transition: 0.25s; 532 | } 533 | .navicon-button:hover .navicon:before { 534 | top: .825rem; 535 | } 536 | .navicon-button:hover .navicon:after { 537 | top: -.825rem; 538 | } 539 | 540 | /* navicon */ 541 | .navicon { 542 | position: relative; 543 | width: 2.5em; 544 | height: .3125rem; 545 | background: #000; 546 | transition: 0.3s; 547 | border-radius: 2.5rem; 548 | } 549 | .navicon:before, .navicon:after { 550 | display: block; 551 | content: ""; 552 | height: .3125rem; 553 | width: 2.5rem; 554 | background: #000; 555 | position: absolute; 556 | z-index: -1; 557 | transition: 0.3s 0.25s; 558 | border-radius: 1rem; 559 | } 560 | .navicon:before { 561 | top: .625rem; 562 | } 563 | .navicon:after { 564 | top: -.625rem; 565 | } 566 | 567 | /* open */ 568 | .nav-trigger:checked + label:not(.steps) .navicon:before, 569 | .nav-trigger:checked + label:not(.steps) .navicon:after { 570 | top: 0 !important; 571 | } 572 | 573 | .nav-trigger:checked + label .navicon:before, 574 | .nav-trigger:checked + label .navicon:after { 575 | transition: 0.5s; 576 | } 577 | 578 | /* Minus */ 579 | .nav-trigger:checked + label { 580 | transform: scale(0.75); 581 | } 582 | 583 | /* × and + */ 584 | .nav-trigger:checked + label.plus .navicon, 585 | .nav-trigger:checked + label.x .navicon { 586 | background: transparent; 587 | } 588 | 589 | .nav-trigger:checked + label.plus .navicon:before, 590 | .nav-trigger:checked + label.x .navicon:before { 591 | transform: rotate(-45deg); 592 | background: #FFF; 593 | } 594 | 595 | .nav-trigger:checked + label.plus .navicon:after, 596 | .nav-trigger:checked + label.x .navicon:after { 597 | transform: rotate(45deg); 598 | background: #FFF; 599 | } 600 | 601 | .nav-trigger:checked + label.plus { 602 | transform: scale(0.75) rotate(45deg); 603 | } 604 | 605 | .nav-trigger:checked ~ nav { 606 | left: 0 !important; 607 | } 608 | 609 | .nav-trigger:checked ~ .overlay { 610 | display: block; 611 | } 612 | 613 | .nav-trigger { 614 | position: fixed; 615 | top: 0; 616 | clip: rect(0, 0, 0, 0); 617 | } 618 | 619 | .overlay { 620 | display: none; 621 | position: fixed; 622 | top: 0; 623 | bottom: 0; 624 | left: 0; 625 | right: 0; 626 | width: 100%; 627 | height: 100%; 628 | background: hsla(0, 0%, 0%, 0.5); 629 | z-index: 1; 630 | } 631 | 632 | .section-method { 633 | margin-bottom: 30px; 634 | padding-bottom: 30px; 635 | border-bottom: 1px solid #eee; 636 | } 637 | 638 | @media only screen and (min-width: 320px) and (max-width: 680px) { 639 | body { 640 | overflow-x: hidden; 641 | } 642 | 643 | nav { 644 | background: #FFF; 645 | width: 250px; 646 | height: 100%; 647 | position: fixed; 648 | top: 0; 649 | right: 0; 650 | bottom: 0; 651 | left: -250px; 652 | z-index: 3; 653 | padding: 0 10px; 654 | transition: left 0.2s; 655 | } 656 | 657 | .navicon-button { 658 | display: inline-block; 659 | position: fixed; 660 | top: 1.5em; 661 | right: 0; 662 | z-index: 2; 663 | } 664 | 665 | #main { 666 | width: 100%; 667 | min-width: 360px; 668 | } 669 | 670 | #main h1.page-title { 671 | margin: 1em 0; 672 | } 673 | 674 | #main section { 675 | padding: 0; 676 | } 677 | 678 | footer { 679 | margin-left: 0; 680 | } 681 | } 682 | 683 | @media only print { 684 | nav { 685 | display: none; 686 | } 687 | 688 | #main { 689 | float: none; 690 | width: 100%; 691 | } 692 | } 693 | -------------------------------------------------------------------------------- /docs/module-Wren.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Wren - Documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 29 | 30 |
31 | 32 |

Wren

33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 |
51 |
52 | 53 | 54 |
wrenjs is an ES6 module.
55 | 56 | 57 | 58 | 59 |
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 |
Source:
95 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 |
130 |
Example
131 | 132 |
import * as Wren from "./path/to/wren.js";
133 | 134 |
135 | 136 |
137 | 138 | 139 |
140 | 141 | 142 | 143 | 144 | 145 | 146 |

Classes

147 | 148 |
149 |
VM
150 |
151 |
152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 |

Members

160 | 161 | 162 | 163 |
164 |

(static) ErrorType

165 | 166 | 167 | 168 | 169 |
170 | The type of error returned by the [VM]. 171 |
172 | 173 | 174 | 175 | 176 | 177 |
Properties:
178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 |
NameTypeDescription
COMPILE 207 | 208 | 209 | number 210 | 211 | 212 | 213 | A syntax or resolution error detected at compile time.
RUNTIME 232 | 233 | 234 | number 235 | 236 | 237 | 238 | The error message for a runtime error.
STACK_TRACE 257 | 258 | 259 | number 260 | 261 | 262 | 263 | One entry of a runtime error's stack trace.
277 | 278 | 279 | 280 | 281 |
282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
Source:
309 |
312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 |
320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 |
328 | 329 | 330 | 331 |
332 |

(static) Result

333 | 334 | 335 | 336 | 337 |
338 | The result of a VM interpreting wren source. 339 |
340 | 341 | 342 | 343 | 344 | 345 |
Properties:
346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 |
NameTypeDescription
SUCCESS 375 | 376 | 377 | number 378 | 379 | 380 | 381 | the VM interpreted the source without error.
COMPILE_ERROR 400 | 401 | 402 | number 403 | 404 | 405 | 406 | the VM experienced a compile error.
RUNTIME_ERROR 425 | 426 | 427 | number 428 | 429 | 430 | 431 | the VM experienced a runtime error.
445 | 446 | 447 | 448 | 449 |
450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 |
Source:
477 |
480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 |
488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 |
496 | 497 | 498 | 499 | 500 | 501 |

Methods

502 | 503 | 504 | 505 |
506 | 507 | 508 | 509 |

(static) getVersionNumber() → {number}

510 | 511 | 512 | 513 | 514 | 515 |
516 | Get the current wren version number. 517 | 518 | Can be used to range checks over versions. 519 |
520 | 521 | 522 | 523 | 524 | 525 |
526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 |
Source:
553 |
556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 |
564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 |
586 |
Returns:
587 | 588 | 589 | 590 |
591 |
592 | Type: 593 |
594 |
595 | 596 | number 597 | 598 | 599 |
600 |
601 | 602 | 603 |
604 | A monotonically increasing numeric representation of the 605 | version number. 606 |
607 | 608 | 609 |
610 | 611 | 612 | 613 |
614 | 615 | 616 | 617 | 618 | 619 | 620 |
621 | 622 |
623 | 624 | 625 | 626 | 627 |
628 | 629 |
630 | 631 |
632 | Generated by JSDoc 3.6.7 on Wed Oct 19 2022 18:29:41 GMT+0200 (Central European Summer Time) using the Minami theme. 633 |
634 | 635 | 636 | 637 | 638 | -------------------------------------------------------------------------------- /src/wren.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @overview 3 | * The wren programming language in your browser! 4 | *
5 | * 6 | * @example 7 | * import * as Wren from "../out/wren.js"; 8 | * 9 | * let vm = new Wren.VM({ 10 | * resolveModuleFn : function(importer, name) {...}, 11 | * loadModuleFn : function(name) {...}, 12 | * bindForeignMethodFn : function(moduleName, className, isStatic, signature) {...}, 13 | * bindForeignClassFn : function(moduleName, className) {...}, 14 | * writeFn : function(toLog) {...}, 15 | * errorFn : function(errorType, moduleName, line, msg) {...} 16 | * }); 17 | * 18 | * vm.interpret("main", ` 19 | * System.print("Hello from Wren!") 20 | * `); 21 | */ 22 | 23 | /** 24 | * wrenjs is an ES6 module. 25 | * 26 | * @example 27 | * import * as Wren from "./path/to/wren.js"; 28 | * 29 | * @module Wren 30 | */ 31 | 32 | import libwren from './generated/libwren.js'; 33 | 34 | /* 35 | * 'libwren' represents our connection to the Wren C API, through emscripten's ccall function. 36 | * We attach an empty object to it so that we can store and lookup JS Wren.VMs from C and JS. 37 | */ 38 | var Module = libwren(); 39 | Module._VMs = {}; 40 | Module._values = []; 41 | 42 | /** 43 | * Get the current wren version number. 44 | * 45 | * Can be used to range checks over versions. 46 | * @return {number} A monotonically increasing numeric representation of the 47 | * version number. 48 | */ 49 | export function getVersionNumber() { 50 | let result = Module.ccall('wrenGetVersionNumber', 51 | 'number', 52 | [], [] 53 | ); 54 | 55 | return result; 56 | } 57 | 58 | 59 | /** 60 | * The type of error returned by the [VM]. 61 | * @property {number} COMPILE A syntax or resolution error detected at compile time. 62 | * @property {number} RUNTIME The error message for a runtime error. 63 | * @property {number} STACK_TRACE One entry of a runtime error's stack trace. 64 | */ 65 | export var ErrorType = { 66 | COMPILE: 0, 67 | RUNTIME: 1, 68 | STACK_TRACE: 2 69 | } 70 | 71 | /** 72 | * The result of a VM interpreting wren source. 73 | * @property {number} SUCCESS the VM interpreted the source without error. 74 | * @property {number} COMPILE_ERROR the VM experienced a compile error. 75 | * @property {number} RUNTIME_ERROR the VM experienced a runtime error. 76 | */ 77 | export var Result = { 78 | SUCCESS: 0, 79 | COMPILE_ERROR: 1, 80 | RUNTIME_ERROR: 2 81 | } 82 | 83 | 84 | /** 85 | * A single virtual machine for executing Wren code. 86 | */ 87 | export class VM { 88 | 89 | /** 90 | * Creates a new Wren virtual machine using the given [configuration]. 91 | * If [configuration] is undefined, uses a default 92 | * configuration. 93 | * @param {Object} configuration 94 | * an object containing any or all of the following properties: 95 | * resolveModuleFn, loadModuleFn, bindForeignMethodFn, bindForeignClassFn, 96 | * writeFn, errorFn. 97 | * 98 | * let vm = new Wren.VM({ 99 | * resolveModuleFn : function(importer, name) {...}, 100 | * loadModuleFn : function(name) {...}, 101 | * bindForeignMethodFn : function(moduleName, className, isStatic, signature) {...}, 102 | * bindForeignClassFn : function(moduleName, className) {...}, 103 | * writeFn : function(toLog) {...}, 104 | * errorFn : function(errorType, moduleName, line, msg) {...} 105 | * }); 106 | */ 107 | constructor(config) { 108 | // Replaces wrenInitConfiguration 109 | let default_config = { 110 | resolveModuleFn : VM.defaultResolveModuleFn, 111 | loadModuleFn : VM.defaultLoadModuleFn, 112 | bindForeignMethodFn : VM.defaultBindForeignMethodFn, 113 | bindForeignClassFn : VM.defaultBindForeignClassFn, 114 | writeFn : VM.defaultWriteFn, 115 | errorFn : VM.defaultErrorFn 116 | } 117 | this.config = Object.assign(default_config, config); 118 | 119 | this._pointer = Module.ccall('shimNewVM', 120 | 'number', 121 | [],[] 122 | ); 123 | 124 | Module._VMs[this._pointer] = this; 125 | 126 | this._foreignClasses = {}; 127 | } 128 | 129 | // Defaults // 130 | static defaultResolveModuleFn(importer, name) { 131 | return name; 132 | } 133 | 134 | static defaultLoadModuleFn(name) { 135 | return null; 136 | } 137 | 138 | static defaultBindForeignMethodFn(moduleName, className, isStatic, signature) { 139 | return null; 140 | } 141 | 142 | static defaultBindForeignClassFn(moduleName, className) { 143 | return null; 144 | } 145 | 146 | static defaultWriteFn(toLog) { 147 | let str = 'WRENJS: '; 148 | console.log(str + toLog); 149 | } 150 | 151 | static defaultErrorFn(errorType, moduleName, line, msg) { 152 | let str = 'WRENJS: '; 153 | if (errorType == 0) { 154 | console.warn( 155 | str + "["+moduleName+" line " +line+ "] [Error] "+msg+"\n" 156 | ); 157 | } 158 | if (errorType == 1) { 159 | console.warn( 160 | str + "["+moduleName+" line "+line+"] in "+msg+"\n" 161 | ); 162 | } 163 | if (errorType == 2) { 164 | console.warn( 165 | str + "[Runtime Error] "+msg+"\n" 166 | ); 167 | } 168 | } 169 | 170 | /* 171 | * The following methods are called from C, and should not be relied upon in 172 | * the JS context. 173 | * -------------------------------------------------------------------------- 174 | */ 175 | 176 | _resolveModuleFn(importer, name) { 177 | return this.config.resolveModuleFn(importer, name); 178 | } 179 | 180 | _loadModuleFn(name) { 181 | return this.config.loadModuleFn(name); 182 | } 183 | 184 | _bindForeignMethod(moduleName, className, isStatic, signature) { 185 | // This should return a function looking for a Wren.VM as its only arg. 186 | let method = this.config.bindForeignMethodFn(moduleName, className, 187 | isStatic, signature 188 | ); 189 | 190 | if (method == null) { 191 | return null; 192 | } 193 | 194 | // The wren C api expects a function looking for a pointer as its arg. 195 | let vm = this; 196 | let wrappedMethod = function(pointer) { 197 | method(vm); 198 | } 199 | return wrappedMethod; 200 | } 201 | 202 | _bindForeignClass(moduleName, className) { 203 | var methods = this.config.bindForeignClassFn(moduleName, className); 204 | 205 | if (methods == null) { 206 | return null; 207 | } 208 | 209 | // Similar to the bindForeignMethod fn above, C expects to pass these 210 | // a pointer to the VM, and we need to convert that to a JS Wren.VM 211 | let vm = this; 212 | 213 | return { 214 | allocate: function() { 215 | methods.allocate(vm); 216 | }, 217 | finalize: function() { 218 | methods.finalize(vm); 219 | 220 | let pointer = Module.ccall('wrenGetSlotForeign', 221 | 'number', 222 | ['number', 'number'], 223 | [vm._pointer, 0] 224 | ); 225 | 226 | delete vm._foreignClasses[pointer]; 227 | } 228 | } 229 | } 230 | 231 | _write(text) { 232 | this.config.writeFn(text); 233 | } 234 | 235 | _error(errorType, moduleName, line, msg) { 236 | this.config.errorFn(errorType, moduleName, line, msg); 237 | } 238 | 239 | /* 240 | * The following methods are implementations of the Wren C API, callable 241 | * from the JS context. 242 | * -------------------------------------------------------------------------- 243 | */ 244 | 245 | /** 246 | * Disposes of all resources in use by the VM. 247 | */ 248 | free() { 249 | Module.ccall('wrenFreeVM', 250 | null, 251 | ['number'], 252 | [this._pointer] 253 | ); 254 | delete VM[this._pointer] 255 | this._pointer = undefined; 256 | } 257 | 258 | /** 259 | * Immediately run the garbage collector to free unused memory. 260 | */ 261 | collectGarbage() { 262 | Module.ccall('wrenCollectGarbage', 263 | null, 264 | ['number'], 265 | [this._pointer] 266 | ); 267 | } 268 | 269 | /** 270 | * Runs [source], a string of Wren source code in a new fiber in [vm] in the 271 | * context of resolved [moduleName]. 272 | * @return {string} whether the result was a success or an error. 273 | * @param {string} moduleName the name of the wren module. 274 | * @param {string} src the wren source code to interpret 275 | */ 276 | interpret(moduleName, src) { 277 | let result = Module.ccall('wrenInterpret', 278 | 'number', 279 | ['number', 'string', 'string'], 280 | [this._pointer, moduleName, src]); 281 | 282 | return result; 283 | } 284 | 285 | /** 286 | * Creates a handle that can be used to invoke a method with [signature] on 287 | * using a receiver and arguments that are set up on the stack. 288 | * 289 | * This handle can be used repeatedly to directly invoke that method from JS 290 | * code using [call]. 291 | * 292 | * When you are done with this handle, it must be released using 293 | * [releaseHandle]. 294 | * @return {number} a handle for use with [VM.call]. 295 | * @param {string} signature a string depicting the signature of a wren method. 296 | */ 297 | makeCallHandle(signature) { 298 | let handle = Module.ccall('wrenMakeCallHandle', 299 | 'number', 300 | ['number', 'string'], 301 | [this._pointer, signature] 302 | ); 303 | return handle; 304 | } 305 | 306 | /** 307 | * Calls [method], using the receiver and arguments previously set up on the 308 | * stack. 309 | * 310 | * [method] must have been created by a call to [makeCallHandle]. The 311 | * arguments to the method must be already on the stack. The receiver should be 312 | * in slot 0 with the remaining arguments following it, in order. It is an 313 | * error if the number of arguments provided does not match the method's 314 | * signature. 315 | * 316 | * After this returns, you can access the return value from slot 0 on the stack. 317 | * @return {string} whether the result was a success or error. 318 | * @param {number} method the handle returned from makeCallHandle. 319 | */ 320 | call(method) { 321 | let result = Module.ccall('wrenCall', 322 | 'number', 323 | ['number', 'number'], 324 | [this._pointer, method] 325 | ); 326 | 327 | return result; 328 | } 329 | 330 | /** 331 | * Releases the reference stored in [handle]. After calling this, [handle] can 332 | * no longer be used. 333 | * @param {number} handle the handle returned from makeCallHandle. 334 | */ 335 | releaseHandle(handle) { 336 | Module.ccall('wrenReleaseHandle', 337 | null, 338 | ['number', 'number'], 339 | [this._pointer, 'handle'] 340 | ); 341 | } 342 | 343 | /** 344 | * Returns the number of slots available to the current foreign method. 345 | * @return {number} the number of slots. 346 | */ 347 | getSlotCount() { 348 | let count = Module.ccall('wrenGetSlotCount', 349 | 'number', 350 | ['number'], 351 | [this._pointer] 352 | ); 353 | return count; 354 | } 355 | 356 | /** 357 | * Ensures that the foreign method stack has at least [numSlots] available for 358 | * use, growing the stack if needed. 359 | * 360 | * Does not shrink the stack if it has more than enough slots. 361 | * 362 | * It is an error to call this from a finalizer. 363 | * @param {number} numSlots the number of slots needed. 364 | */ 365 | ensureSlots(numSlots) { 366 | Module.ccall('wrenEnsureSlots', 367 | null, 368 | ['number', 'number'], 369 | [this._pointer, numSlots] 370 | ); 371 | } 372 | 373 | /** 374 | * Gets the type of the object in [slot]. 375 | * @return {string} the type of the object. 376 | * @param {number} slot the index of the slot. 377 | */ 378 | getSlotType(slot) { 379 | let t = Module.ccall('wrenGetSlotType', 380 | 'number', 381 | ['number', 'number'], 382 | [this._pointer, slot] 383 | ); 384 | 385 | let types = [ 386 | 'WREN_TYPE_BOOL', 387 | 'WREN_TYPE_NUM', 388 | 'WREN_TYPE_FOREIGN', 389 | 'WREN_TYPE_LIST', 390 | 'WREN_TYPE_MAP', 391 | 'WREN_TYPE_NULL', 392 | 'WREN_TYPE_STRING', 393 | 'WREN_TYPE_UNKNOWN' 394 | ]; // TODO: pull out into an enum. 395 | 396 | return types[t]; 397 | } 398 | 399 | /** 400 | * Reads a boolean value from [slot]. 401 | * 402 | * It is an error to call this if the slot does not contain a boolean value. 403 | * @return {boolean} the value stored in the slot. 404 | * @param {number} slot the index of the slot. 405 | */ 406 | getSlotBool(slot) { 407 | let boolean = Module.ccall('wrenGetSlotBool', 408 | 'boolean', 409 | ['number', 'number'], 410 | [this._pointer, slot] 411 | ); 412 | return boolean; 413 | } 414 | 415 | /** 416 | * Reads a byte array from [slot]. 417 | * 418 | * The memory for the returned string is owned by Wren. You can inspect it 419 | * while in your foreign method, but cannot keep a pointer to it after the 420 | * function returns, since the garbage collector may reclaim it. 421 | * 422 | * Returns a pointer to the first byte of the array and fill [length] with the 423 | * number of bytes in the array. TODO: does it? 424 | * 425 | * It is an error to call this if the slot does not contain a string. 426 | * @return {string} the bytes as a string. 427 | * @param {number} slot the index of the slot. 428 | * @param {number} length the length of the bytes. 429 | */ 430 | getSlotBytes(slot, length) { 431 | let bytes = Module.ccall('wrenGetSlotBytes', 432 | 'string', 433 | ['number', 'number', 'number'], 434 | [this._pointer, slot, length] 435 | ); 436 | return bytes; 437 | } 438 | 439 | /** 440 | * Reads a number from [slot]. 441 | * 442 | * It is an error to call this if the slot does not contain a number. 443 | * @return {number} the value stored in the slot. 444 | * @param {number} slot the index of the slot. 445 | */ 446 | getSlotDouble(slot) { 447 | let double = Module.ccall('wrenGetSlotDouble', 448 | 'number', 449 | ['number', 'number'], 450 | [this._pointer, slot] 451 | ); 452 | return double; 453 | } 454 | 455 | /** 456 | * Reads a foreign object from [slot] and returns a pointer to the foreign data 457 | * stored with it. 458 | * 459 | * It is an error to call this if the slot does not contain an instance of a 460 | * foreign class. 461 | * @return {Object} the JavaScript Object stored in the slot. 462 | * @param {number} slot the index of the slot. 463 | */ 464 | getSlotForeign(slot) { 465 | let pointer = Module.ccall('wrenGetSlotForeign', 466 | 'number', 467 | ['number', 'number'], 468 | [this._pointer, slot] 469 | ); 470 | 471 | return this._foreignClasses[pointer]; 472 | } 473 | 474 | /** 475 | * Reads a string from [slot]. 476 | * 477 | * The memory for the returned string is owned by Wren. You can inspect it 478 | * while in your foreign method, but cannot keep a pointer to it after the 479 | * function returns, since the garbage collector may reclaim it. 480 | * TODO: Is it? 481 | * 482 | * It is an error to call this if the slot does not contain a string. 483 | * @return {string} the string stored in the slot. 484 | * @param {number} slot the index of the slot. 485 | */ 486 | getSlotString(slot) { 487 | let string = Module.ccall('wrenGetSlotString', 488 | 'string', 489 | ['number', 'number'], 490 | [this._pointer, slot] 491 | ); 492 | return string; 493 | } 494 | 495 | /** 496 | * Creates a handle for the value stored in [slot]. 497 | * 498 | * This will prevent the object that is referred to from being garbage collected 499 | * until the handle is released by calling [releaseHandle()]. 500 | * @return {number} a handle for use with [VM.call]. 501 | * @param {number} slot the index of the slot. 502 | */ 503 | getSlotHandle(slot) { 504 | let handle = Module.ccall('wrenGetSlotHandle', 505 | 'number', 506 | ['number', 'number'], 507 | [this._pointer, slot] 508 | ); 509 | return handle; 510 | } 511 | 512 | /** 513 | * Stores the boolean [value] in [slot]. 514 | * @param {number} slot the index of the slot. 515 | * @param {boolean} value the boolean to store. 516 | */ 517 | setSlotBool(slot, value) { 518 | Module.ccall('wrenSetSlotBool', 519 | null, 520 | ['number', 'number', 'boolean'], 521 | [this._pointer, slot, value] 522 | ); 523 | } 524 | 525 | /** 526 | * Stores the array [length] of [bytes] in [slot]. 527 | * 528 | * The bytes are copied to a new string within Wren's heap, so you can free 529 | * memory used by them after this is called. 530 | * @param {number} slot the index of the slot. 531 | * @param {string} bytes the bytes to store. 532 | * @param {number} length the length of the bytes. 533 | */ 534 | setSlotBytes(slot, bytes, length) { 535 | Module.ccall('wrenSetSlotBytes', 536 | null, 537 | ['number', 'number', 'string', 'number'], 538 | [this._pointer, slot, bytes, length] 539 | ); 540 | } 541 | 542 | /** 543 | * Stores the numeric [value] in [slot]. 544 | * @param {number} slot the index of the slot. 545 | * @param {number} value the value to store. 546 | */ 547 | setSlotDouble(slot, value) { 548 | Module.ccall('wrenSetSlotDouble', 549 | null, 550 | ['number', 'number', 'number'], 551 | [this._pointer, slot, value] 552 | ); 553 | } 554 | 555 | /** 556 | * Creates a new instance of the foreign class stored in [classSlot] with [size] 557 | * bytes of raw storage and places the resulting object in [slot]. 558 | * 559 | * This does not invoke the foreign class's constructor on the new instance. If 560 | * you need that to happen, call the constructor from Wren, which will then 561 | * call the allocator foreign method. In there, call this to create the object 562 | * and then the constructor will be invoked when the allocator returns. 563 | * 564 | * @return {Object} the same foreignObject you passed in. 565 | * @param {number} slot the index of the slot. 566 | * @param {number} classSlot the slot containing the foreign class. 567 | * @param {Object} foreignObject a JavaScript class. 568 | */ 569 | setSlotNewForeign(slot, classSlot, foreignObject) { 570 | let pointer = Module.ccall('wrenSetSlotNewForeign', 571 | 'number', 572 | ['number', 'number', 'number', 'number'], 573 | [this._pointer, slot, classSlot, 0] 574 | ); 575 | 576 | this._foreignClasses[pointer] = foreignObject; 577 | 578 | return foreignObject; 579 | } 580 | 581 | /** 582 | * Stores a new empty list in [slot]. 583 | * @param {number} slot the index of the slot. 584 | */ 585 | setSlotNewList(slot) { 586 | Module.ccall('wrenSetSlotNewList', 587 | null, 588 | ['number', 'number'], 589 | [this._pointer, slot] 590 | ); 591 | } 592 | 593 | /** 594 | * Stores a new empty map in [slot]. 595 | * @param {number} slot the index of the slot. 596 | */ 597 | setSlotNewMap(slot) { 598 | Module.ccall('wrenSetSlotNewMap', 599 | null, 600 | ['number', 'number'], 601 | [this._pointer, slot] 602 | ); 603 | } 604 | 605 | /** 606 | * Stores null in [slot]. 607 | * @param {number} slot the index of the slot. 608 | */ 609 | setSlotNull(slot) { 610 | Module.ccall('wrenSetSlotNull', 611 | null, 612 | ['number', 'number'], 613 | [this._pointer, slot] 614 | ); 615 | } 616 | 617 | /** 618 | * Stores the string [text] in [slot]. 619 | * 620 | * The [text] is copied to a new string within Wren's heap, so you can free 621 | * memory used by it after this is called. The length is calculated using 622 | * [strlen()]. If the string may contain any null bytes in the middle, then you 623 | * should use [setSlotBytes()] instead. 624 | * @param {number} slot the index of the slot. 625 | * @param {string} text the string to store. 626 | */ 627 | setSlotString(slot, text) { 628 | Module.ccall('wrenSetSlotString', 629 | null, 630 | ['number', 'number', 'string'], 631 | [this._pointer, slot, text] 632 | ); 633 | } 634 | 635 | /** 636 | * Stores the value captured in [handle] in [slot]. 637 | * 638 | * This does not release the handle for the value. 639 | * @param {number} slot the index of the slot. 640 | * @param {number} handle a handle returned from makeCallHandle. 641 | */ 642 | setSlotHandle(slot, handle) { 643 | Module.ccall('wrenSetSlotHandle', 644 | null, 645 | ['number', 'number', 'number'], 646 | [this._pointer, slot, handle] 647 | ); 648 | } 649 | 650 | /** 651 | * Returns the number of elements in the list stored in [slot]. 652 | * @return {number} the number of elements in the list. 653 | * @param {number} slot the index of the slot. 654 | */ 655 | getListCount(slot) { 656 | let count = Module.ccall('wrenGetListCount', 657 | 'number', 658 | ['number', 'number'], 659 | [this._pointer, slot] 660 | ); 661 | return count; 662 | } 663 | 664 | /** 665 | * Reads element [index] from the list in [listSlot] and stores it in 666 | * [elementSlot]. 667 | * @param {number} listSlot 668 | * @param {number} index 669 | * @param {number} elementSlot 670 | */ 671 | getListElement(listSlot, index, elementSlot) { 672 | Module.ccall('wrenGetListElement', 673 | null, 674 | ['number', 'number', 'number', 'number'], 675 | [this._pointer, listSlot, index, elementSlot] 676 | ); 677 | } 678 | 679 | /** 680 | * Sets the value stored at [index] in the list at [listSlot], 681 | * to the value from [elementSlot]. 682 | * @param {number} listSlot 683 | * @param {number} index 684 | * @param {number} elementSlot 685 | */ 686 | setListElement(listSlot, index, elementSlot) { 687 | Module.ccall('wrenSetListElement', 688 | null, 689 | ['number', 'number', 'number', 'number'], 690 | [this._pointer, listSlot, index, elementSlot] 691 | ); 692 | } 693 | 694 | /** 695 | * Takes the value stored at [elementSlot] and inserts it into the list stored 696 | * at [listSlot] at [index]. 697 | * 698 | * As in Wren, negative indexes can be used to insert from the end. To append 699 | * an element, use `-1` for the index. 700 | * @param {number} listSlot 701 | * @param {number} index 702 | * @param {number} elementSlot 703 | */ 704 | insertInList(listSlot, index, elementSlot) { 705 | Module.ccall('wrenInsertInList', 706 | null, 707 | ['number', 'number', 'number', 'number'], 708 | [this._pointer, listSlot, index, elementSlot] 709 | ); 710 | } 711 | 712 | /** 713 | * Returns the number of entries in the map stored in [slot]. 714 | * @return {number} the number of entries in the map. 715 | * @param {number} slot the index of the slot. 716 | */ 717 | getMapCount(slot) { 718 | let count = Module.ccall('wrenGetMapCount', 719 | 'number', 720 | ['number', 'number'], 721 | [this._pointer, slot] 722 | ); 723 | return count; 724 | } 725 | 726 | /** 727 | * Returns true if the key in [keySlot] is found in the map placed in [mapSlot]. 728 | * @return {boolean} whether the map contains the key. 729 | * @param {number} mapSlot a slot containing the map. 730 | * @param {number} keySlot a slot containing the key. 731 | */ 732 | getMapContainsKey(mapSlot, keySlot) { 733 | let boolean = Module.ccall('wrenGetMapContainsKey', 734 | 'boolean', 735 | ['number', 'number', 'number'], 736 | [this._pointer, mapSlot, keySlot] 737 | ); 738 | return boolean; 739 | } 740 | 741 | /** 742 | * Retrieves a value with the key in [keySlot] from the map in [mapSlot] and 743 | * stores it in [valueSlot]. 744 | * @param {number} mapSlot a slot containing the map. 745 | * @param {number} keySlot a slot containing the key. 746 | * @param {number} valueSlot a slot to place the value. 747 | */ 748 | getMapValue(mapSlot, keySlot, valueSlot) { 749 | Module.ccall('wrenGetMapValue', 750 | null, 751 | ['number', 'number', 'number', 'number'], 752 | [this._pointer, mapSlot, keySlot, valueSlot] 753 | ); 754 | } 755 | 756 | /** 757 | * Takes the value stored at [valueSlot] and inserts it into the map stored 758 | * at [mapSlot] with key [keySlot]. 759 | * @param {number} mapSlot a slot containing the map. 760 | * @param {number} keySlot a slot containing the key to add. 761 | * @param {number} valueSlot a slot containing the key's value. 762 | */ 763 | setMapValue(mapSlot, keySlot, valueSlot) { 764 | Module.ccall('wrenSetMapValue', 765 | null, 766 | ['number', 'number', 'number', 'number'], 767 | [this._pointer, mapSlot, keySlot, valueSlot] 768 | ); 769 | } 770 | 771 | /** 772 | * Removes a value from the map in [mapSlot], with the key from [keySlot], 773 | * and place it in [removedValueSlot]. If not found, [removedValueSlot] is 774 | * set to null, the same behaviour as the Wren Map API. 775 | * @param {number} mapSlot a slot containing the map. 776 | * @param {number} keySlot a slot containing the key to remove. 777 | * @param {number} removedValueSlot a slot to contain the removed value. 778 | */ 779 | removeMapValue(mapSlot, keySlot, removedValueSlot) { 780 | Module.ccall('wrenRemoveMapValue', 781 | null, 782 | ['number', 'number', 'number', 'number'], 783 | [this._pointer, mapSlot, keySlot, removedValueSlot] 784 | ); 785 | } 786 | 787 | /** 788 | * Looks up the top level variable with [name] in resolved [moduleName] and stores 789 | * it in [slot]. 790 | * @param {string} moduleName the name of the wren moduleName. 791 | * @param {string} name the name of the variable. 792 | * @param {number} slot the index of the slot. 793 | */ 794 | getVariable(moduleName, name, slot) { 795 | Module.ccall('wrenGetVariable', 796 | null, 797 | ['number', 'string', 'string', 'number'], 798 | [this._pointer, moduleName, name, slot] 799 | ); 800 | } 801 | 802 | /** 803 | * Looks up the top level variable with [name] in resolved [moduleName], 804 | * returns false if not found. The module must be imported at the time, 805 | * use wrenHasModule to ensure that before calling. 806 | * @return {boolean} whether the variable exists in module. 807 | * @param {string} moduleName the name of the wren module. 808 | * @param {string} name the name of the variable. 809 | */ 810 | hasVariable(moduleName, name) { 811 | let boolean = Module.ccall('wrenHasVariable', 812 | 'boolean', 813 | ['number', 'string', 'string'], 814 | [this._pointer, moduleName, name] 815 | ); 816 | return boolean; 817 | } 818 | 819 | /** 820 | * Returns true if [moduleName] has been imported/resolved before, false if not. 821 | * @return {boolean} whether the module has been imported/resolved before. 822 | * @param {string} moduleName the name of the wren module. 823 | */ 824 | hasModule(moduleName) { 825 | let boolean = Module.ccall('wrenHasModule', 826 | 'boolean', 827 | ['number', 'string'], 828 | [this._pointer, moduleName] 829 | ); 830 | return boolean; 831 | } 832 | 833 | /** 834 | * Sets the current fiber to be aborted, and uses the value in [slot] as the 835 | * runtime error object. 836 | * @param {number} slot the index of the slot. 837 | */ 838 | abortFiber(slot) { 839 | Module.ccall('wrenAbortFiber', 840 | null, 841 | ['number', 'number'], 842 | [this._pointer, slot] 843 | ); 844 | } 845 | 846 | // The following APIs are not implemented. 847 | //getUserData() {} 848 | //setUserData(userData) {} 849 | } 850 | -------------------------------------------------------------------------------- /docs/wren.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | wren.js - Documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 29 | 30 |
31 | 32 |

wren.js

33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
41 |
42 |
/**
 43 |  * @overview
 44 |  * The wren programming language in your browser!
 45 |  * <br>
 46 |  *
 47 |  * @example
 48 |  * import * as Wren from "../out/wren.js";
 49 |  *
 50 |  * let vm = new Wren.VM({
 51 |  *   resolveModuleFn     : function(importer, name) {...},
 52 |  *   loadModuleFn        : function(name) {...},
 53 |  *   bindForeignMethodFn : function(moduleName, className, isStatic, signature) {...},
 54 |  *   bindForeignClassFn  : function(moduleName, className) {...},
 55 |  *   writeFn             : function(toLog) {...},
 56 |  *   errorFn             : function(errorType, moduleName, line, msg) {...}
 57 |  * });
 58 |  *
 59 |  * vm.interpret("main", `
 60 |  *   System.print("Hello from Wren!")
 61 |  * `);
 62 |  */
 63 | 
 64 | /**
 65 |  * wrenjs is an ES6 module.
 66 |  *
 67 |  * @example
 68 |  * import * as Wren from "./path/to/wren.js";
 69 |  *
 70 |  * @module Wren
 71 |  */
 72 | 
 73 | import libwren from './generated/libwren.js';
 74 | 
 75 | /*
 76 | * 'libwren' represents our connection to the Wren C API, through emscripten's ccall function.
 77 | * We attach an empty object to it so that we can store and lookup JS Wren.VMs from C and JS.
 78 | */
 79 | var Module = libwren();
 80 | Module._VMs = {};
 81 | Module._values = [];
 82 | 
 83 | /**
 84 | * Get the current wren version number.
 85 | *
 86 | * Can be used to range checks over versions.
 87 | * @return {number} A monotonically increasing numeric representation of the
 88 | *                  version number.
 89 | */
 90 | export function getVersionNumber() {
 91 |   let result = Module.ccall('wrenGetVersionNumber',
 92 |       'number',
 93 |       [], []
 94 |   );
 95 | 
 96 |   return result;
 97 | }
 98 | 
 99 | 
100 | /**
101 | * The type of error returned by the [VM].
102 | * @property {number} COMPILE A syntax or resolution error detected at compile time.
103 | * @property {number} RUNTIME The error message for a runtime error.
104 | * @property {number} STACK_TRACE One entry of a runtime error's stack trace.
105 | */
106 | export var ErrorType = {
107 |   COMPILE:      0,
108 |   RUNTIME:      1,
109 |   STACK_TRACE:  2
110 | }
111 | 
112 | /**
113 | * The result of a VM interpreting wren source.
114 | * @property {number} SUCCESS the VM interpreted the source without error.
115 | * @property {number} COMPILE_ERROR the VM experienced a compile error.
116 | * @property {number} RUNTIME_ERROR the VM experienced a runtime error.
117 | */
118 | export var Result = {
119 |   SUCCESS:        0,
120 |   COMPILE_ERROR:  1,
121 |   RUNTIME_ERROR:  2
122 | }
123 | 
124 | 
125 | /**
126 | * A single virtual machine for executing Wren code.
127 | */
128 | export class VM {
129 | 
130 |     /**
131 |     * Creates a new Wren virtual machine using the given [configuration].
132 |     * If [configuration] is undefined, uses a default
133 |     * configuration.
134 |     * @param {Object} configuration
135 |     * an object containing any or all of the following properties:
136 |     * resolveModuleFn, loadModuleFn, bindForeignMethodFn, bindForeignClassFn,
137 |     * writeFn, errorFn.
138 |     *
139 |     * let vm = new Wren.VM({
140 |     *   resolveModuleFn     : function(importer, name) {...},
141 |     *   loadModuleFn        : function(name) {...},
142 |     *   bindForeignMethodFn : function(moduleName, className, isStatic, signature) {...},
143 |     *   bindForeignClassFn  : function(moduleName, className) {...},
144 |     *   writeFn             : function(toLog) {...},
145 |     *   errorFn             : function(errorType, moduleName, line, msg) {...}
146 |     * });
147 |     */
148 |     constructor(config) {
149 |         // Replaces wrenInitConfiguration
150 |         let default_config = {
151 |             resolveModuleFn     : VM.defaultResolveModuleFn,
152 |             loadModuleFn        : VM.defaultLoadModuleFn,
153 |             bindForeignMethodFn : VM.defaultBindForeignMethodFn,
154 |             bindForeignClassFn  : VM.defaultBindForeignClassFn,
155 |             writeFn             : VM.defaultWriteFn,
156 |             errorFn             : VM.defaultErrorFn
157 |         }
158 |         this.config = Object.assign(default_config, config);
159 | 
160 |         this._pointer = Module.ccall('shimNewVM',
161 |           'number',
162 |           [],[]
163 |         );
164 | 
165 |         Module._VMs[this._pointer] = this;
166 | 
167 |         this._foreignClasses = {};
168 |     }
169 | 
170 |     // Defaults //
171 |     static defaultResolveModuleFn(importer, name) {
172 |         return name;
173 |     }
174 | 
175 |     static defaultLoadModuleFn(name) {
176 |         return null;
177 |     }
178 | 
179 |     static defaultBindForeignMethodFn(moduleName, className, isStatic, signature) {
180 |         return null;
181 |     }
182 | 
183 |     static defaultBindForeignClassFn(moduleName, className) {
184 |         return null;
185 |     }
186 | 
187 |     static defaultWriteFn(toLog) {
188 |         let str = 'WRENJS: ';
189 |         console.log(str + toLog);
190 |     }
191 | 
192 |     static defaultErrorFn(errorType, moduleName, line, msg) {
193 |         let str = 'WRENJS: ';
194 |         if (errorType == 0) {
195 |           console.warn(
196 |               str + "["+moduleName+" line " +line+ "] [Error] "+msg+"\n"
197 |           );
198 |         }
199 |         if (errorType == 1) {
200 |           console.warn(
201 |               str + "["+moduleName+" line "+line+"] in "+msg+"\n"
202 |           );
203 |         }
204 |         if (errorType == 2) {
205 |           console.warn(
206 |               str + "[Runtime Error] "+msg+"\n"
207 |           );
208 |         }
209 |     }
210 | 
211 |     /*
212 |     * The following methods are called from C, and should not be relied upon in
213 |     * the JS context.
214 |     * --------------------------------------------------------------------------
215 |     */
216 | 
217 |     _resolveModuleFn(importer, name) {
218 |         return this.config.resolveModuleFn(importer, name);
219 |     }
220 | 
221 |     _loadModuleFn(name) {
222 |         return this.config.loadModuleFn(name);
223 |     }
224 | 
225 |     _bindForeignMethod(moduleName, className, isStatic, signature) {
226 |         // This should return a function looking for a Wren.VM as its only arg.
227 |         let method = this.config.bindForeignMethodFn(moduleName, className,
228 |           isStatic, signature
229 |         );
230 | 
231 |         if (method == null) {
232 |           return null;
233 |         }
234 | 
235 |         // The wren C api expects a function looking for a pointer as its arg.
236 |         let vm = this;
237 |         let wrappedMethod = function(pointer) {
238 |           method(vm);
239 |         }
240 |         return wrappedMethod;
241 |     }
242 | 
243 |     _bindForeignClass(moduleName, className) {
244 |         var methods =  this.config.bindForeignClassFn(moduleName, className);
245 | 
246 |         if (methods == null) {
247 |           return null;
248 |         }
249 | 
250 |         // Similar to the bindForeignMethod fn above, C expects to pass these
251 |         // a pointer to the VM, and we need to convert that to a JS Wren.VM
252 |         let vm = this;
253 | 
254 |         return {
255 |             allocate: function() {
256 |                 methods.allocate(vm);
257 |             },
258 |             finalize: function() {
259 |                 methods.finalize(vm);
260 | 
261 |                 let pointer = Module.ccall('wrenGetSlotForeign',
262 |                   'number',
263 |                   ['number', 'number'],
264 |                   [vm._pointer, 0]
265 |                 );
266 | 
267 |                 delete vm._foreignClasses[pointer];
268 |             }
269 |         }
270 |     }
271 | 
272 |     _write(text) {
273 |         this.config.writeFn(text);
274 |     }
275 | 
276 |     _error(errorType, moduleName, line, msg) {
277 |         this.config.errorFn(errorType, moduleName, line, msg);
278 |     }
279 | 
280 |     /*
281 |     * The following methods are implementations of the Wren C API, callable
282 |     * from the JS context.
283 |     * --------------------------------------------------------------------------
284 |     */
285 | 
286 |     /**
287 |     * Disposes of all resources in use by the VM.
288 |     */
289 |     free() {
290 |         Module.ccall('wrenFreeVM',
291 |           null,
292 |           ['number'],
293 |           [this._pointer]
294 |         );
295 |         delete VM[this._pointer]
296 |         this._pointer = undefined;
297 |     }
298 | 
299 |     /**
300 |     * Immediately run the garbage collector to free unused memory.
301 |     */
302 |     collectGarbage() {
303 |         Module.ccall('wrenCollectGarbage',
304 |           null,
305 |           ['number'],
306 |           [this._pointer]
307 |         );
308 |     }
309 | 
310 |     /**
311 |     * Runs [source], a string of Wren source code in a new fiber in [vm] in the
312 |     * context of resolved [moduleName].
313 |     * @return {string} whether the result was a success or an error.
314 |     * @param {string} moduleName the name of the wren module.
315 |     * @param {string} src the wren source code to interpret
316 |     */
317 |     interpret(moduleName, src) {
318 |         let result = Module.ccall('wrenInterpret',
319 |             'number',
320 |             ['number', 'string', 'string'],
321 |             [this._pointer, moduleName, src]);
322 | 
323 |         return result;
324 |     }
325 | 
326 |     /**
327 |     * Creates a handle that can be used to invoke a method with [signature] on
328 |     * using a receiver and arguments that are set up on the stack.
329 |     *
330 |     * This handle can be used repeatedly to directly invoke that method from JS
331 |     * code using [call].
332 |     *
333 |     * When you are done with this handle, it must be released using
334 |     * [releaseHandle].
335 |     * @return {number} a handle for use with [VM.call].
336 |     * @param {string} signature a string depicting the signature of a wren method.
337 |     */
338 |     makeCallHandle(signature) {
339 |         let handle = Module.ccall('wrenMakeCallHandle',
340 |           'number',
341 |           ['number', 'string'],
342 |           [this._pointer, signature]
343 |         );
344 |         return handle;
345 |     }
346 | 
347 |     /**
348 |     * Calls [method], using the receiver and arguments previously set up on the
349 |     * stack.
350 |     *
351 |     * [method] must have been created by a call to [makeCallHandle]. The
352 |     * arguments to the method must be already on the stack. The receiver should be
353 |     * in slot 0 with the remaining arguments following it, in order. It is an
354 |     * error if the number of arguments provided does not match the method's
355 |     * signature.
356 |     *
357 |     * After this returns, you can access the return value from slot 0 on the stack.
358 |     * @return {string} whether the result was a success or error.
359 |     * @param {number} method the handle returned from makeCallHandle.
360 |     */
361 |     call(method) {
362 |         let result = Module.ccall('wrenCall',
363 |           'number',
364 |           ['number', 'number'],
365 |           [this._pointer, method]
366 |         );
367 | 
368 |         return result;
369 |     }
370 | 
371 |     /**
372 |     * Releases the reference stored in [handle]. After calling this, [handle] can
373 |     * no longer be used.
374 |     * @param {number} handle the handle returned from makeCallHandle.
375 |     */
376 |     releaseHandle(handle) {
377 |         Module.ccall('wrenReleaseHandle',
378 |           null,
379 |           ['number', 'number'],
380 |           [this._pointer, 'handle']
381 |         );
382 |     }
383 | 
384 |     /**
385 |     * Returns the number of slots available to the current foreign method.
386 |     * @return {number} the number of slots.
387 |     */
388 |     getSlotCount() {
389 |         let count = Module.ccall('wrenGetSlotCount',
390 |           'number',
391 |           ['number'],
392 |           [this._pointer]
393 |         );
394 |         return count;
395 |     }
396 | 
397 |     /**
398 |     * Ensures that the foreign method stack has at least [numSlots] available for
399 |     * use, growing the stack if needed.
400 |     *
401 |     * Does not shrink the stack if it has more than enough slots.
402 |     *
403 |     * It is an error to call this from a finalizer.
404 |     * @param {number} numSlots the number of slots needed.
405 |     */
406 |     ensureSlots(numSlots) {
407 |         Module.ccall('wrenEnsureSlots',
408 |           null,
409 |           ['number', 'number'],
410 |           [this._pointer, numSlots]
411 |         );
412 |     }
413 | 
414 |     /**
415 |     * Gets the type of the object in [slot].
416 |     * @return {string} the type of the object.
417 |     * @param {number} slot the index of the slot.
418 |     */
419 |     getSlotType(slot) {
420 |         let t = Module.ccall('wrenGetSlotType',
421 |           'number',
422 |           ['number', 'number'],
423 |           [this._pointer, slot]
424 |         );
425 | 
426 |         let types = [
427 |           'WREN_TYPE_BOOL',
428 |           'WREN_TYPE_NUM',
429 |           'WREN_TYPE_FOREIGN',
430 |           'WREN_TYPE_LIST',
431 |           'WREN_TYPE_MAP',
432 |           'WREN_TYPE_NULL',
433 |           'WREN_TYPE_STRING',
434 |           'WREN_TYPE_UNKNOWN'
435 |         ]; // TODO: pull out into an enum.
436 | 
437 |         return types[t];
438 |     }
439 | 
440 |     /**
441 |     * Reads a boolean value from [slot].
442 |     *
443 |     * It is an error to call this if the slot does not contain a boolean value.
444 |     * @return {boolean} the value stored in the slot.
445 |     * @param {number} slot the index of the slot.
446 |     */
447 |     getSlotBool(slot) {
448 |         let boolean = Module.ccall('wrenGetSlotBool',
449 |           'boolean',
450 |           ['number', 'number'],
451 |           [this._pointer, slot]
452 |         );
453 |         return boolean;
454 |     }
455 | 
456 |     /**
457 |     * Reads a byte array from [slot].
458 |     *
459 |     * The memory for the returned string is owned by Wren. You can inspect it
460 |     * while in your foreign method, but cannot keep a pointer to it after the
461 |     * function returns, since the garbage collector may reclaim it.
462 |     *
463 |     * Returns a pointer to the first byte of the array and fill [length] with the
464 |     * number of bytes in the array. TODO: does it?
465 |     *
466 |     * It is an error to call this if the slot does not contain a string.
467 |     * @return {string} the bytes as a string.
468 |     * @param {number} slot the index of the slot.
469 |     * @param {number} length the length of the bytes.
470 |     */
471 |     getSlotBytes(slot, length) {
472 |         let bytes = Module.ccall('wrenGetSlotBytes',
473 |           'string',
474 |           ['number', 'number', 'number'],
475 |           [this._pointer, slot, length]
476 |         );
477 |         return bytes;
478 |     }
479 | 
480 |     /**
481 |     * Reads a number from [slot].
482 |     *
483 |     * It is an error to call this if the slot does not contain a number.
484 |     * @return {number} the value stored in the slot.
485 |     * @param {number} slot the index of the slot.
486 |     */
487 |     getSlotDouble(slot) {
488 |         let double = Module.ccall('wrenGetSlotDouble',
489 |           'number',
490 |           ['number', 'number'],
491 |           [this._pointer, slot]
492 |         );
493 |         return double;
494 |     }
495 | 
496 |     /**
497 |     * Reads a foreign object from [slot] and returns a pointer to the foreign data
498 |     * stored with it.
499 |     *
500 |     * It is an error to call this if the slot does not contain an instance of a
501 |     * foreign class.
502 |     * @return {Object} the JavaScript Object stored in the slot.
503 |     * @param {number} slot the index of the slot.
504 |     */
505 |     getSlotForeign(slot) {
506 |         let pointer = Module.ccall('wrenGetSlotForeign',
507 |           'number',
508 |           ['number', 'number'],
509 |           [this._pointer, slot]
510 |         );
511 | 
512 |         return this._foreignClasses[pointer];
513 |     }
514 | 
515 |     /**
516 |     * Reads a string from [slot].
517 |     *
518 |     * The memory for the returned string is owned by Wren. You can inspect it
519 |     * while in your foreign method, but cannot keep a pointer to it after the
520 |     * function returns, since the garbage collector may reclaim it.
521 |     * TODO: Is it?
522 |     *
523 |     * It is an error to call this if the slot does not contain a string.
524 |     * @return {string} the string stored in the slot.
525 |     * @param {number} slot the index of the slot.
526 |     */
527 |     getSlotString(slot) {
528 |         let string = Module.ccall('wrenGetSlotString',
529 |           'string',
530 |           ['number', 'number'],
531 |           [this._pointer, slot]
532 |         );
533 |         return string;
534 |     }
535 | 
536 |     /**
537 |     * Creates a handle for the value stored in [slot].
538 |     *
539 |     * This will prevent the object that is referred to from being garbage collected
540 |     * until the handle is released by calling [releaseHandle()].
541 |     * @return {number} a handle for use with [VM.call].
542 |     * @param {number} slot the index of the slot.
543 |     */
544 |     getSlotHandle(slot) {
545 |         let handle = Module.ccall('wrenGetSlotHandle',
546 |           'number',
547 |           ['number', 'number'],
548 |           [this._pointer, slot]
549 |         );
550 |         return handle;
551 |     }
552 | 
553 |     /**
554 |     * Stores the boolean [value] in [slot].
555 |     * @param {number} slot the index of the slot.
556 |     * @param {boolean} value the boolean to store.
557 |     */
558 |     setSlotBool(slot, value) {
559 |         Module.ccall('wrenSetSlotBool',
560 |           null,
561 |           ['number', 'number', 'boolean'],
562 |           [this._pointer, slot, value]
563 |         );
564 |     }
565 | 
566 |     /**
567 |     * Stores the array [length] of [bytes] in [slot].
568 |     *
569 |     * The bytes are copied to a new string within Wren's heap, so you can free
570 |     * memory used by them after this is called.
571 |     * @param {number} slot the index of the slot.
572 |     * @param {string} bytes the bytes to store.
573 |     * @param {number} length the length of the bytes.
574 |     */
575 |     setSlotBytes(slot, bytes, length) {
576 |         Module.ccall('wrenSetSlotBytes',
577 |           null,
578 |           ['number', 'number', 'string', 'number'],
579 |           [this._pointer, slot, bytes, length]
580 |         );
581 |     }
582 | 
583 |     /**
584 |     * Stores the numeric [value] in [slot].
585 |     * @param {number} slot the index of the slot.
586 |     * @param {number} value the value to store.
587 |     */
588 |     setSlotDouble(slot, value) {
589 |         Module.ccall('wrenSetSlotDouble',
590 |           null,
591 |           ['number', 'number', 'number'],
592 |           [this._pointer, slot, value]
593 |         );
594 |     }
595 | 
596 |     /**
597 |     * Creates a new instance of the foreign class stored in [classSlot] with [size]
598 |     * bytes of raw storage and places the resulting object in [slot].
599 |     *
600 |     * This does not invoke the foreign class's constructor on the new instance. If
601 |     * you need that to happen, call the constructor from Wren, which will then
602 |     * call the allocator foreign method. In there, call this to create the object
603 |     * and then the constructor will be invoked when the allocator returns.
604 |     *
605 |     * @return {Object} the same foreignObject you passed in.
606 |     * @param {number} slot the index of the slot.
607 |     * @param {number} classSlot the slot containing the foreign class.
608 |     * @param {Object} foreignObject a JavaScript class.
609 |     */
610 |     setSlotNewForeign(slot, classSlot, foreignObject) {
611 |         let pointer = Module.ccall('wrenSetSlotNewForeign',
612 |           'number',
613 |           ['number', 'number', 'number', 'number'],
614 |           [this._pointer, slot, classSlot, 0]
615 |         );
616 | 
617 |         this._foreignClasses[pointer] = foreignObject;
618 | 
619 |         return foreignObject;
620 |     }
621 | 
622 |     /**
623 |     * Stores a new empty list in [slot].
624 |     * @param {number} slot the index of the slot.
625 |     */
626 |     setSlotNewList(slot) {
627 |         Module.ccall('wrenSetSlotNewList',
628 |           null,
629 |           ['number', 'number'],
630 |           [this._pointer, slot]
631 |         );
632 |     }
633 | 
634 |     /**
635 |     * Stores a new empty map in [slot].
636 |     * @param {number} slot the index of the slot.
637 |     */
638 |     setSlotNewMap(slot) {
639 |         Module.ccall('wrenSetSlotNewMap',
640 |           null,
641 |           ['number', 'number'],
642 |           [this._pointer, slot]
643 |         );
644 |     }
645 | 
646 |     /**
647 |     * Stores null in [slot].
648 |     * @param {number} slot the index of the slot.
649 |     */
650 |     setSlotNull(slot) {
651 |         Module.ccall('wrenSetSlotNull',
652 |           null,
653 |           ['number', 'number'],
654 |           [this._pointer, slot]
655 |         );
656 |     }
657 | 
658 |     /**
659 |     * Stores the string [text] in [slot].
660 |     *
661 |     * The [text] is copied to a new string within Wren's heap, so you can free
662 |     * memory used by it after this is called. The length is calculated using
663 |     * [strlen()]. If the string may contain any null bytes in the middle, then you
664 |     * should use [setSlotBytes()] instead.
665 |     * @param {number} slot the index of the slot.
666 |     * @param {string} text the string to store.
667 |     */
668 |     setSlotString(slot, text) {
669 |         Module.ccall('wrenSetSlotString',
670 |           null,
671 |           ['number', 'number', 'string'],
672 |           [this._pointer, slot, text]
673 |         );
674 |     }
675 | 
676 |     /**
677 |     * Stores the value captured in [handle] in [slot].
678 |     *
679 |     * This does not release the handle for the value.
680 |     * @param {number} slot the index of the slot.
681 |     * @param {number} handle a handle returned from makeCallHandle.
682 |     */
683 |     setSlotHandle(slot, handle) {
684 |         Module.ccall('wrenSetSlotHandle',
685 |           null,
686 |           ['number', 'number', 'number'],
687 |           [this._pointer, slot, handle]
688 |         );
689 |     }
690 | 
691 |     /**
692 |     * Returns the number of elements in the list stored in [slot].
693 |     * @return {number} the number of elements in the list.
694 |     * @param {number} slot the index of the slot.
695 |     */
696 |     getListCount(slot) {
697 |         let count = Module.ccall('wrenGetListCount',
698 |           'number',
699 |           ['number', 'number'],
700 |           [this._pointer, slot]
701 |         );
702 |         return count;
703 |     }
704 | 
705 |     /**
706 |     * Reads element [index] from the list in [listSlot] and stores it in
707 |     * [elementSlot].
708 |     * @param {number} listSlot
709 |     * @param {number} index
710 |     * @param {number} elementSlot
711 |     */
712 |     getListElement(listSlot, index, elementSlot) {
713 |         Module.ccall('wrenGetListElement',
714 |           null,
715 |           ['number', 'number', 'number', 'number'],
716 |           [this._pointer, listSlot, index, elementSlot]
717 |         );
718 |     }
719 | 
720 |     /**
721 |     * Sets the value stored at [index] in the list at [listSlot],
722 |     * to the value from [elementSlot].
723 |     * @param {number} listSlot
724 |     * @param {number} index
725 |     * @param {number} elementSlot
726 |     */
727 |     setListElement(listSlot, index, elementSlot) {
728 |         Module.ccall('wrenSetListElement',
729 |           null,
730 |           ['number', 'number', 'number', 'number'],
731 |           [this._pointer, listSlot, index, elementSlot]
732 |         );
733 |     }
734 | 
735 |     /**
736 |     * Takes the value stored at [elementSlot] and inserts it into the list stored
737 |     * at [listSlot] at [index].
738 |     *
739 |     * As in Wren, negative indexes can be used to insert from the end. To append
740 |     * an element, use `-1` for the index.
741 |     * @param {number} listSlot
742 |     * @param {number} index
743 |     * @param {number} elementSlot
744 |     */
745 |     insertInList(listSlot, index, elementSlot) {
746 |         Module.ccall('wrenInsertInList',
747 |           null,
748 |           ['number', 'number', 'number', 'number'],
749 |           [this._pointer, listSlot, index, elementSlot]
750 |         );
751 |     }
752 | 
753 |     /**
754 |     * Returns the number of entries in the map stored in [slot].
755 |     * @return {number} the number of entries in the map.
756 |     * @param {number} slot the index of the slot.
757 |     */
758 |     getMapCount(slot) {
759 |         let count = Module.ccall('wrenGetMapCount',
760 |           'number',
761 |           ['number', 'number'],
762 |           [this._pointer, slot]
763 |         );
764 |         return count;
765 |     }
766 | 
767 |     /**
768 |     * Returns true if the key in [keySlot] is found in the map placed in [mapSlot].
769 |     * @return {boolean} whether the map contains the key.
770 |     * @param {number} mapSlot a slot containing the map.
771 |     * @param {number} keySlot a slot containing the key.
772 |     */
773 |     getMapContainsKey(mapSlot, keySlot) {
774 |         let boolean = Module.ccall('wrenGetMapContainsKey',
775 |           'boolean',
776 |           ['number', 'number', 'number'],
777 |           [this._pointer, mapSlot, keySlot]
778 |         );
779 |         return boolean;
780 |     }
781 | 
782 |     /**
783 |     * Retrieves a value with the key in [keySlot] from the map in [mapSlot] and
784 |     * stores it in [valueSlot].
785 |     * @param {number} mapSlot a slot containing the map.
786 |     * @param {number} keySlot a slot containing the key.
787 |     * @param {number} valueSlot a slot to place the value.
788 |     */
789 |     getMapValue(mapSlot, keySlot, valueSlot) {
790 |         Module.ccall('wrenGetMapValue',
791 |           null,
792 |           ['number', 'number', 'number', 'number'],
793 |           [this._pointer, mapSlot, keySlot, valueSlot]
794 |         );
795 |     }
796 | 
797 |     /**
798 |     * Takes the value stored at [valueSlot] and inserts it into the map stored
799 |     * at [mapSlot] with key [keySlot].
800 |     * @param {number} mapSlot a slot containing the map.
801 |     * @param {number} keySlot a slot containing the key to add.
802 |     * @param {number} valueSlot a slot containing the key's value.
803 |     */
804 |     setMapValue(mapSlot, keySlot, valueSlot) {
805 |         Module.ccall('wrenSetMapValue',
806 |           null,
807 |           ['number', 'number', 'number', 'number'],
808 |           [this._pointer, mapSlot, keySlot, valueSlot]
809 |         );
810 |     }
811 | 
812 |     /**
813 |     * Removes a value from the map in [mapSlot], with the key from [keySlot],
814 |     * and place it in [removedValueSlot]. If not found, [removedValueSlot] is
815 |     * set to null, the same behaviour as the Wren Map API.
816 |     * @param {number} mapSlot a slot containing the map.
817 |     * @param {number} keySlot a slot containing the key to remove.
818 |     * @param {number} removedValueSlot a slot to contain the removed value.
819 |     */
820 |     removeMapValue(mapSlot, keySlot, removedValueSlot) {
821 |         Module.ccall('wrenRemoveMapValue',
822 |           null,
823 |           ['number', 'number', 'number', 'number'],
824 |           [this._pointer, mapSlot, keySlot, removedValueSlot]
825 |         );
826 |     }
827 | 
828 |     /**
829 |     * Looks up the top level variable with [name] in resolved [moduleName] and stores
830 |     * it in [slot].
831 |     * @param {string} moduleName the name of the wren moduleName.
832 |     * @param {string} name the name of the variable.
833 |     * @param {number} slot the index of the slot.
834 |     */
835 |     getVariable(moduleName, name, slot) {
836 |         Module.ccall('wrenGetVariable',
837 |           null,
838 |           ['number', 'string', 'string', 'number'],
839 |           [this._pointer, moduleName, name, slot]
840 |         );
841 |     }
842 | 
843 |     /**
844 |     * Looks up the top level variable with [name] in resolved [moduleName],
845 |     * returns false if not found. The module must be imported at the time,
846 |     * use wrenHasModule to ensure that before calling.
847 |     * @return {boolean} whether the variable exists in module.
848 |     * @param {string} moduleName the name of the wren module.
849 |     * @param {string} name the name of the variable.
850 |     */
851 |     hasVariable(moduleName, name) {
852 |         let boolean = Module.ccall('wrenHasVariable',
853 |           'boolean',
854 |           ['number', 'string', 'string'],
855 |           [this._pointer, moduleName, name]
856 |         );
857 |         return boolean;
858 |     }
859 | 
860 |     /**
861 |     * Returns true if [moduleName] has been imported/resolved before, false if not.
862 |     * @return {boolean} whether the module has been imported/resolved before.
863 |     * @param {string} moduleName the name of the wren module.
864 |     */
865 |     hasModule(moduleName) {
866 |         let boolean = Module.ccall('wrenHasModule',
867 |           'boolean',
868 |           ['number', 'string'],
869 |           [this._pointer, moduleName]
870 |         );
871 |         return boolean;
872 |     }
873 | 
874 |     /**
875 |     * Sets the current fiber to be aborted, and uses the value in [slot] as the
876 |     * runtime error object.
877 |     * @param {number} slot the index of the slot.
878 |     */
879 |     abortFiber(slot) {
880 |         Module.ccall('wrenAbortFiber',
881 |           null,
882 |           ['number', 'number'],
883 |           [this._pointer, slot]
884 |         );
885 |     }
886 | 
887 |     // The following APIs are not implemented.
888 |     //getUserData() {}
889 |     //setUserData(userData) {}
890 | }
891 | 
892 |
893 |
894 | 895 | 896 | 897 | 898 |
899 | 900 |
901 | 902 |
903 | Generated by JSDoc 3.6.7 on Wed Oct 19 2022 18:29:41 GMT+0200 (Central European Summer Time) using the Minami theme. 904 |
905 | 906 | 907 | 908 | 909 | 910 | --------------------------------------------------------------------------------