protected Executable Compile(string code, MachineInfo mi, params int[] expectedErrors) { var fullCode = "void start() { __cinit(); main(); } " + code; var printer = new TestPrinter(expectedErrors); var i = CLanguageService.CreateInterpreter(fullCode, mi ?? new TestMachineInfo(), printer: printer); printer.CheckForErrors(); return(i.Executable); }
protected CInterpreter Run(string code, MachineInfo mi, params int[] expectedErrors) { var fullCode = "void start() { __cinit(); main(); } " + code; var printer = new TestPrinter(expectedErrors); var i = CLanguageService.CreateInterpreter(fullCode, mi ?? new TestMachineInfo(), printer: printer); printer.CheckForErrors(); i.Reset("start"); i.Step(); return(i); }
Executable CompileWithErrors(string code, params int[] errorCodes) { var printer = new TestPrinter(errorCodes); var c = new Compiler(MachineInfo.Arduino, new Report(printer)); c.AddCode(code); var exe = c.Compile(); printer.CheckForErrors(); return(exe); }
public void Sizes() { var printer = new TestPrinter(); var mi = new TestMachineInfo(); var ec = new ExecutableContext(new Executable(mi), new Report(printer)); Interpreter.CompiledVariable ParseVariable(string code) { var exe = Compile(code, mi, printer); return(exe.Globals.Skip(1).First()); } var charV = ParseVariable("char v;"); Assert.AreEqual(1, charV.VariableType.GetByteSize(ec)); var intV = ParseVariable("int v;"); Assert.AreEqual(2, intV.VariableType.GetByteSize(ec)); var shortIntV = ParseVariable("short int v;"); Assert.AreEqual(2, shortIntV.VariableType.GetByteSize(ec)); var unsignedLongV = ParseVariable("unsigned long v;"); Assert.AreEqual(4, unsignedLongV.VariableType.GetByteSize(ec)); var unsignedLongLongV = ParseVariable("unsigned long long v;"); Assert.AreEqual(8, unsignedLongLongV.VariableType.GetByteSize(ec)); var intPV = ParseVariable("int *v;"); Assert.AreEqual(2, intPV.VariableType.GetByteSize(ec)); var longPV = ParseVariable("long *v;"); Assert.AreEqual(2, longPV.VariableType.GetByteSize(ec)); }
Executable CompileWithErrors(string code, params int[] errorCodes) { var printer = new TestPrinter(errorCodes); return(CLanguageService.Compile(code, new ArduinoTestMachineInfo(), printer)); }