Rely on the new mbed repository rather than hardcode a lot of C++ in
TouchDevelop.
This commit is contained in:
Jonathan Protzenko 2015-04-15 10:29:05 -07:00
Родитель 6443a6ea63
Коммит 3d1d754d50
2 изменённых файлов: 10 добавлений и 20 удалений

Просмотреть файл

@ -83,23 +83,6 @@ module TDev {
});
}
var cppPrelude =
'#include "mbed.h"\n'+
'#include <string>\n'+
'DigitalOut led2(LED2), led1(LED1);\n'+
'Serial pc(USBTX, USBRX);\n'+
'typedef void (*callback)();\n'+
'void microbit_register(const string& event, callback f) {\n'+
' if (event == "start")\n'+
' f();\n'+
'}\n'+
'void microbit_set_led(int led, int val) {\n'+
' if (led == 2)\n'+
' led2 = val;\n'+
' else if (led == 1)\n'+
' led1 = val;\n'+
'}\n';
export class Channel {
constructor(
private editor: ExternalEditor,
@ -234,7 +217,7 @@ module TDev {
}
cpp.then((cpp: string) => {
console.log(cpp);
cpp = cppPrelude + cpp;
cpp = "#include \"prelude.h\"\n" + cpp;
Cloud.postUserInstalledCompileAsync(this.guid, cpp).then(json => {
// Success.
console.log(json);

Просмотреть файл

@ -32,7 +32,7 @@ module TDev {
var knownMicrobitCalls: { [index: string]: string } = {
"on": "microbit_register",
"wait": "wait",
"wait": "wait_ms",
"set led": "microbit_set_led",
};
@ -53,6 +53,13 @@ module TDev {
}
public visitLocalRef(env: EmitterEnv, name: string, id: string) {
// In our translation, referring to a TouchDevelop identifier never
// requires adding a reference operator (&). Things passed by reference
// are either:
// - function pointers (a.k.a. "handlers" in TouchDevelop lingo), for
// which C and C++ accept both "f" and "&f" (we hence use the former)
// - arrays, strings, user-defined objects, which are in fact of type
// "shared_ptr<T>", no "&" operator here.
return H.mangle(name, id);
}
@ -95,7 +102,7 @@ module TDev {
throw "Unknown microbit call: "+name;
return mkCall(knownMicrobitCalls[name]);
} else if (name == ":=") {
return this.visit(env, receiver) + " = " + this.visit(env, args[0]);
return this.visit(env, receiver) + " = " + argsCode[0];
} else {
throw "Unknown call "+name;
}