Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Blockly/framework/List-test.agc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Unit tests for the List functions.

# TEST: SET

CA NUM4 # list[0] -> 4
TCR PUSH
CA NUM0
TCR PUSH
TCR LS-SET
CA NUM2 # list[1] -> 2
TCR PUSH
CA NUM1
TCR PUSH
TCR LS-SET

CA NUM4 # Test that list[0] == 4
TCR PUSH
CA LIST
TCR PUSH
TCR TS-EQUAL

CA NUM2 # Test that list[1] == 2
TCR PUSH
CA NUM1
COM
INDEX A
CA LIST
TCR PUSH
TCR TS-EQUAL

# Blockly will normally define list.
# But for tests, it otherwise wouldn't be defined.
LIST = 3777
18 changes: 18 additions & 0 deletions Blockly/framework/List.agc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# List functions.

# Set.
# Stack arguments:
# Value.
# Index.
# Uses L register.
LS-SET EXTEND
QXCH QPOP
TCR POP # Pop the index.
COM
TS L
TCR POP # Pop the value.
INDEX L
TS LIST
EXTEND
QXCH QPOP
RETURN
1 change: 1 addition & 0 deletions Blockly/framework/Main.agc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ END CA A

# Code modules.
$Boolean.agc
$List.agc
$Math.agc
$Print.agc
$Random.agc
Expand Down
1 change: 1 addition & 0 deletions Blockly/framework/Tests.agc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Execute the tests.
$Boolean-test.agc
$List-test.agc
$Math-test.agc
$Random-test.agc
$Print-test.agc
Expand Down
46 changes: 46 additions & 0 deletions Blockly/html/agc/blocks/lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @fileoverview List blocks for Blockly.
*/
'use strict';

Blockly.defineBlocksWithJsonArray([
// Block for list item setter.
{
"type": "list_set",
"message0": "set list at %1 to %2",
"args0": [
{
'type': 'input_value',
'name': 'INDEX',
'check': 'Number',
},
{
'type': 'input_value',
'name': 'VALUE',
'check': 'Number',
},
],
"previousStatement": null,
"nextStatement": null,
"inputsInline": true,
"style": "list_blocks",
"helpUrl": null,
"tooltip": "Set the value in the list at the specified location.",
},
// Block for list item getter.
{
"type": "list_get",
"message0": "get list at %1",
"args0": [
{
'type': 'input_value',
'name': 'INDEX',
'check': 'Number',
},
],
"output": null,
"style": "list_blocks",
"helpUrl": null,
"tooltip": "Get the value in the list at the specified location.",
},
]);
20 changes: 11 additions & 9 deletions Blockly/html/agc/generator/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ AgcGenerator.init = function(workspace) {
}

// Declare all of the variables.
if (defvars.length) {
// Octal 4000 is just beyond the end of AGC's erasable memory.
// Declare variables starting from the end of memory and working downwards.
let memoryAddress = 0o4000;
this.definitions_['variables'] = '';
for (const varName of defvars) {
memoryAddress--;
this.definitions_['variables'] += varName + '\t=\t' + memoryAddress.toString(8) + '\n';
}
// Octal 4000 is just beyond the end of AGC's erasable memory.
// Declare variables starting from the end of memory and working downwards.
let memoryAddress = 0o4000;
this.definitions_['variables'] = '';
for (const varName of defvars) {
memoryAddress--;
this.definitions_['variables'] += varName + '\t=\t' + memoryAddress.toString(8) + '\n';
}
// Final variable is the list.
memoryAddress--;
this.definitions_['variables'] += 'LIST\t=\t' + memoryAddress.toString(8) + '\n';

this.isInitialized = true;
};

Expand Down
33 changes: 33 additions & 0 deletions Blockly/html/agc/generator/lists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @fileoverview Generating AGC assembly for list blocks.
*/
'use strict';

AgcGenerator['list_get'] = function(block) {
// List item getter.
const argument0 = AgcGenerator.valueToCode(block, 'INDEX') ||
AgcGenerator.default0;
const code = `
${argument0}
\tCOM
\tINDEX\tA
\tCA\tLIST
`;
return code;
};

AgcGenerator['list_set'] = function(block) {
// List item setter.
const argument0 = AgcGenerator.valueToCode(block, 'INDEX') ||
AgcGenerator.default0;
const argument1 = AgcGenerator.valueToCode(block, 'VALUE') ||
AgcGenerator.default0;
const code = `
${argument1}
\tTCR\tPUSH
${argument0}
\tTCR\tPUSH
\tTCR\tLS-SET
`;
return code;
};
51 changes: 37 additions & 14 deletions Blockly/html/agc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
-->
<script src="storage.js"></script>
<script src="blocks/agc.js"></script>
<script src="blocks/lists.js"></script>
<script src="blocks/logic.js"></script>
<script src="blocks/loops.js"></script>
<script src="blocks/math.js"></script>
<script src="blocks/procedures.js"></script>
<script src="blocks/variables.js"></script>
<script src="generator/generator.js"></script>
<script src="generator/agc.js"></script>
<script src="generator/lists.js"></script>
<script src="generator/logic.js"></script>
<script src="generator/loops.js"></script>
<script src="generator/math.js"></script>
Expand Down Expand Up @@ -71,6 +73,33 @@ <h1>Blockly AGC</h1>
<textarea id="content_xml" class="content" wrap="off"></textarea>

<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox" style="display: none">
<category name="AGC" colour="%{BKY_COLOUR_HUE}">
<block type="agc_print_digit">
<value name="DIGIT">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="COL">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="ROW">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
</block>
<block type="agc_key_press"></block>
<block type="agc_sleep">
<value name="TIME">
<shadow type="math_number">
<field name="NUM">100</field>
</shadow>
</value>
</block>
</category>
<category name="Logic" colour="%{BKY_LOGIC_HUE}">
<block type="logic_if"></block>
<block type="logic_ifelse"></block>
Expand Down Expand Up @@ -119,34 +148,28 @@ <h1>Blockly AGC</h1>
</value>
</block>
</category>
<category name="AGC" colour="%{BKY_COLOUR_HUE}">
<block type="agc_print_digit">
<value name="DIGIT">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="COL">
<sep></sep>
<category name="List" colour="%{BKY_LISTS_HUE}">
<block type="list_set">
<value name="INDEX">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
<value name="ROW">
<value name="VALUE">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
</block>
<block type="agc_key_press"></block>
<block type="agc_sleep">
<value name="TIME">
<block type="list_get">
<value name="INDEX">
<shadow type="math_number">
<field name="NUM">100</field>
<field name="NUM">0</field>
</shadow>
</value>
</block>
</category>
<sep></sep>
<category name="Variables" colour="%{BKY_VARIABLES_HUE}" custom="VARIABLE"></category>
<category name="Functions" colour="%{BKY_PROCEDURES_HUE}" custom="PROCEDURE"></category>
</xml>
Expand Down