Update README.md

This commit is contained in:
Tim Mickel 2016-09-14 17:00:17 -04:00 committed by GitHub
parent 1ebee14eb0
commit 9b4433069e

View file

@ -22,7 +22,7 @@ npm install
## Development Server ## Development Server
This requires Node.js to be installed. This requires Node.js to be installed.
For convenience, we've included a development server with the VM. This is useful because the VM can take advantage of executing in a WebWorker, which is not permitted in a local file. For convenience, we've included a development server with the VM. This is sometimes useful when running in an environment that's loading remote resources (e.g., SVGs from the Scratch server).
## Running the Development Server ## Running the Development Server
Open a Command Prompt or Terminal in the repository and run: Open a Command Prompt or Terminal in the repository and run:
@ -61,48 +61,44 @@ var vm = new VirtualMachine();
// Block events // Block events
workspace.addChangeListener(vm.blockListener); workspace.addChangeListener(vm.blockListener);
var flyoutWorkspace = workspace.toolbox_.flyout_.workspace_;
flyoutWorkspace.addChangeListener(vm.flyoutBlockListener);
// Run threads // Run threads
vm.runtime.start(); vm.start();
``` ```
## Abstract Syntax Tree ## Abstract Syntax Tree
#### Overview #### Overview
The Virtual Machine constructs and maintains the state of an [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST) by listening to events emitted by the [scratch-blocks](https://github.com/LLK/scratch-blocks) workspace via the `blockListener`. At any time, the current state of the AST can be viewed by inspecting the `vm.runtime.blocks` object. The Virtual Machine constructs and maintains the state of an [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (AST) by listening to events emitted by the [scratch-blocks](https://github.com/LLK/scratch-blocks) workspace via the `blockListener`. Each target (code-running object, for example, a sprite) keeps an AST for its blocks. At any time, the current state of an AST can be viewed by inspecting the `vm.runtime.targets[...].blocks` object.
#### Anatomy of a Block #### Anatomy of a Block
The VM's block representation contains all the important information for execution and storage. Here's an example representing the "when key pressed" script on a workspace:
```json ```json
{ {
"7AJZR#NA;m*b}R]pdq63": { "_blocks": {
"id": "7AJZR#NA;m*b}R]pdq63", "Q]PK~yJ@BTV8Y~FfISeo": {
"opcode": "control_wait", "id": "Q]PK~yJ@BTV8Y~FfISeo",
"opcode": "event_whenkeypressed",
"inputs": { "inputs": {
"DURATION": {
"name": "DURATION",
"block": ",xA8/S!Z6+kR,9dph.rO"
}
}, },
"fields": {},
"next": null,
"topLevel": true
},
",xA8/S!Z6+kR,9dph.rO": {
"id": ",xA8/S!Z6+kR,9dph.rO",
"opcode": "math_number",
"inputs": {},
"fields": { "fields": {
"NUM": { "KEY_OPTION": {
"name": "NUM", "name": "KEY_OPTION",
"value": "1" "value": "space"
} }
}, },
"next": null, "next": null,
"topLevel": false "topLevel": true,
"parent": null,
"shadow": false,
"x": -69.333333333333,
"y": 174
} }
} },
"_scripts": [
"Q]PK~yJ@BTV8Y~FfISeo"
]
}
``` ```
## Testing ## Testing