初始化提交
This commit is contained in:
1512
boards/default_src/python_skulpt_car/converters/data.js
Normal file
1512
boards/default_src/python_skulpt_car/converters/data.js
Normal file
File diff suppressed because it is too large
Load Diff
74
boards/default_src/python_skulpt_car/converters/inout.js
Normal file
74
boards/default_src/python_skulpt_car/converters/inout.js
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
|
||||
pbc.globalFunctionD['input'] = function(py2block, func, args, keywords, starargs, kwargs, node){
|
||||
if (args.length !== 1 && args.length !== 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
if (args.length == 1){
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return block("inout_type_input", func.lineno, {
|
||||
"DIR":"str"
|
||||
}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
});}
|
||||
if (args.length == 0){
|
||||
|
||||
return block("inout_type_input", func.lineno, {
|
||||
"DIR":"str"
|
||||
}, {
|
||||
//'VAR':argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
});}
|
||||
}
|
||||
|
||||
|
||||
//int(input('prompt'))在math.js中实现
|
||||
//float(input('prompt'))在lists.js中实现
|
||||
|
||||
pbc.globalFunctionD['print'] = function(py2block, func, args, keywords, starargs, kwargs, node){
|
||||
if (args.length === 1 && keywords.length === 1
|
||||
&& py2block.identifier(keywords[0].arg) === "end"
|
||||
&& keywords[0].value._astname === "Str"
|
||||
//&& py2block.Str_value(keywords[0].value) === ""
|
||||
) { if(py2block.Str_value(keywords[0].value) === ""){//print('Hello',end ="")
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print_inline", func.lineno, {}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "false"
|
||||
})];
|
||||
}
|
||||
else{
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print_end", func.lineno, {
|
||||
}, {
|
||||
'VAR':argblock,
|
||||
'END':py2block.convert(keywords[0].value)
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
}else if (args.length === 1 && keywords.length === 0) { //print('Hello')
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print", func.lineno, {}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "false"
|
||||
})];
|
||||
}else if (args.length != 1 && keywords.length === 0) { //print()
|
||||
var d = py2block.convertElements("ADD", args);
|
||||
|
||||
return [block("inout_print_many", node.lineno, {
|
||||
}, d, {
|
||||
"inline": "true",
|
||||
}, {
|
||||
"@items":args.length
|
||||
})];
|
||||
|
||||
}else{
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
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();
|
||||
|
||||
45
boards/default_src/python_skulpt_car/converters/system.js
Normal file
45
boards/default_src/python_skulpt_car/converters/system.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
pbc.globalFunctionD['exit'] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return [block("controls_end_program", func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
|
||||
|
||||
pbc.moduleFunctionD.get('time')['time'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return block("controls_millis", func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('time')['localtime'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return block("time_localtime", func.lineno, {
|
||||
"op":'all'
|
||||
}, {}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('time')['sleep'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 1) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("time_sleep", func.lineno, {}, {
|
||||
|
||||
"DELAY_TIME":argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
1127
boards/default_src/python_skulpt_car/converters/turtle.js
Normal file
1127
boards/default_src/python_skulpt_car/converters/turtle.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user