Files
mixly3/boards/default_src/python_mixpy/converters/py2block_config.js
2024-07-19 10:16:00 +08:00

83 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function defDict(type) {
var dict = {};
return {
get: function (key) {
if (!dict[key]) {
dict[key] = type.constructor();
}
return dict[key];
},
dict: dict
};
}
function Py2blockConfig (){
this.initIgnoreS();
this.initModuleAttrD();
this.initKnownModuleS();
this.initObjectTypeD();
}
var pbc = Py2blockConfig.prototype;
pbc.MIXPY = "MIXPY";
pbc.board = pbc.MIXPY;
pbc.objectFunctionD = defDict({});
pbc.moduleFunctionD = defDict({});
pbc.moduleAttrD = defDict({});
pbc.objectAttrD = defDict({});
pbc.globalFunctionD = {};
pbc.assignD = defDict({});
pbc.ifStatementD= defDict({});
pbc.whileStatementD= defDict({});
pbc.forStatementD= defDict({});
pbc.reservedNameD= {};
pbc.knownModuleS = new Set();
pbc.objectTypeD = {}; //key变量名value变量类型如{'a':'List'}
pbc.ignoreS = new Set();
pbc.pinType = null;
pbc.inScope = null;
pbc.formatModuleKeyL = [];
pbc.formatModuleL = [];
//忽略某些方法、类、赋值
pbc.initIgnoreS = function(){
var pythonIgnoreL = [
];
var boardIgnoreL = [];
var ignoreL = pythonIgnoreL.concat(boardIgnoreL);
for (var i = 0; i < ignoreL.length; i++) {
this.ignoreS.add(ignoreL[i]);
}
}
pbc.initModuleAttrD = function(){
}
pbc.initKnownModuleS = function(){
var pythonModuleL = [
'math', 'random'
];
var boardModuleL = [];
var moduleL = pythonModuleL.concat(boardModuleL);
for (var i = 0; i < moduleL.length; i++) {
this.knownModuleS.add(moduleL[i]);
}
}
pbc.initObjectTypeD = function () {
this.objectTypeD = {
'tina': 'turtle.Turtle',
'f': 'open'
}
}
pbc.reset = function(){
this.initObjectTypeD();
}
var py2block_config = new Py2blockConfig();