1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-14 15:29:27 +00:00

try to get bbasic listings, fixed highlighting

This commit is contained in:
Steven Hugg 2018-11-21 07:21:07 -05:00
parent eb01bdcea0
commit a7b1fb4f57
5 changed files with 65 additions and 64 deletions

View File

@ -46,7 +46,7 @@ CodeMirror.defineMode('bataribasic', function(_config, parserConfig) {
for (var s of directives_list) for (var s of directives_list)
directives[s] = 'keyword'; directives[s] = 'keyword';
var numbers = /^([$][0-9a-f]+|[%][01]+|[0-9.]+)\b/i; var numbers = /^([$][0-9a-f]+|[%][01]+|[0-9.]+)/i;
return { return {
startState: function() { startState: function() {
@ -68,7 +68,7 @@ CodeMirror.defineMode('bataribasic', function(_config, parserConfig) {
return null; return null;
var w; var w;
if (stream.eatWhile(/\w/)) { if (stream.eatWhile(/[$%A-Z0-9]/i)) {
w = stream.current(); w = stream.current();
var cur = w.toLowerCase(); var cur = w.toLowerCase();
var style = directives[cur]; var style = directives[cur];
@ -79,9 +79,8 @@ CodeMirror.defineMode('bataribasic', function(_config, parserConfig) {
if (style) if (style)
return style; return style;
if (state.context == 4 && numbers.test(w)) { console.log(w, numbers.test(w));
return 'number'; if (numbers.test(w)) {
} else if (stream.match(numbers)) {
return 'number'; return 'number';
} else { } else {
return null; return null;

View File

@ -24,7 +24,7 @@ export class CodeProject {
callbackGetRemote : GetRemoteCallback; callbackGetRemote : GetRemoteCallback;
mainPath : string; mainPath : string;
isCompiling : boolean = false; isCompiling : boolean = false;
constructor(worker, platform_id:string, platform, store) { constructor(worker, platform_id:string, platform, store) {
this.worker = worker; this.worker = worker;
this.platform_id = platform_id; this.platform_id = platform_id;
@ -48,7 +48,7 @@ export class CodeProject {
} }
}; };
} }
preloadWorker(path:string) { preloadWorker(path:string) {
var tool = this.platform.getToolForFilename(path); var tool = this.platform.getToolForFilename(path);
if (tool && !this.tools_preloaded[tool]) { if (tool && !this.tools_preloaded[tool]) {
@ -106,7 +106,7 @@ export class CodeProject {
callback(err, result); callback(err, result);
}); });
} }
okToSend():boolean { okToSend():boolean {
return this.pendingWorkerMessages++ == 0; return this.pendingWorkerMessages++ == 0;
} }
@ -117,7 +117,7 @@ export class CodeProject {
this.store.setItem(path, text); this.store.setItem(path, text);
} }
} }
// TODO: test duplicate files, local paths mixed with presets // TODO: test duplicate files, local paths mixed with presets
buildWorkerMessage(depends:Dependency[]) { buildWorkerMessage(depends:Dependency[]) {
this.preloadWorker(this.mainpath); this.preloadWorker(this.mainpath);
@ -143,8 +143,8 @@ export class CodeProject {
} }
return msg; return msg;
} }
// TODO: get local file as well as presets? // TODO: get local file as well as presets?
loadFiles(paths:string[], callback:LoadFilesCallback) { loadFiles(paths:string[], callback:LoadFilesCallback) {
var result : Dependency[] = []; var result : Dependency[] = [];
function addResult(path, data) { function addResult(path, data) {
@ -207,18 +207,18 @@ export class CodeProject {
} }
loadNext(); // load first file loadNext(); // load first file
} }
getFile(path:string):FileData { getFile(path:string):FileData {
return this.filedata[path]; return this.filedata[path];
} }
// TODO: purge files not included in latest build? // TODO: purge files not included in latest build?
iterateFiles(callback:IterateFilesCallback) { iterateFiles(callback:IterateFilesCallback) {
for (var path in this.filedata) { for (var path in this.filedata) {
callback(path, this.getFile(path)); callback(path, this.getFile(path));
} }
} }
sendBuild() { sendBuild() {
if (!this.mainpath) throw "need to call setMainFile first"; if (!this.mainpath) throw "need to call setMainFile first";
var maindata = this.getFile(this.mainpath); var maindata = this.getFile(this.mainpath);
@ -245,7 +245,7 @@ export class CodeProject {
this.isCompiling = true; this.isCompiling = true;
}); });
} }
updateFile(path:string, text:FileData) { updateFile(path:string, text:FileData) {
this.updateFileInStore(path, text); // TODO: isBinary this.updateFileInStore(path, text); // TODO: isBinary
this.filedata[path] = text; this.filedata[path] = text;
@ -254,13 +254,13 @@ export class CodeProject {
this.sendBuild(); this.sendBuild();
} }
}; };
setMainFile(path:string) { setMainFile(path:string) {
this.mainpath = path; this.mainpath = path;
if (this.callbackBuildStatus) this.callbackBuildStatus(true); if (this.callbackBuildStatus) this.callbackBuildStatus(true);
this.sendBuild(); this.sendBuild();
} }
processBuildResult(data:WorkerResult) { processBuildResult(data:WorkerResult) {
// TODO: link listings with source files // TODO: link listings with source files
if (data.listings) { if (data.listings) {
@ -274,7 +274,7 @@ export class CodeProject {
} }
} }
} }
getListings() : CodeListingMap { getListings() : CodeListingMap {
return this.listings; return this.listings;
} }
@ -290,4 +290,3 @@ export class CodeProject {
} }
} }
} }

View File

@ -105,7 +105,7 @@ function initProject() {
function refreshWindowList() { function refreshWindowList() {
var ul = $("#windowMenuList").empty(); var ul = $("#windowMenuList").empty();
var separate = false; var separate = false;
function addWindowItem(id, name, createfn) { function addWindowItem(id, name, createfn) {
if (separate) { if (separate) {
ul.append(document.createElement("hr")); ul.append(document.createElement("hr"));
@ -129,24 +129,24 @@ function refreshWindowList() {
}); });
} }
} }
function loadEditor(path:string) { function loadEditor(path:string) {
var tool = platform.getToolForFilename(path); var tool = platform.getToolForFilename(path);
var mode = tool && TOOL_TO_SOURCE_STYLE[tool]; var mode = tool && TOOL_TO_SOURCE_STYLE[tool];
return new Views.SourceEditor(path, mode); return new Views.SourceEditor(path, mode);
} }
// add main file editor // add main file editor
var id = main_file_id; var id = main_file_id;
addWindowItem(id, getFilenameForPath(id), loadEditor); addWindowItem(id, getFilenameForPath(id), loadEditor);
// add other source files // add other source files
separate = true; separate = true;
current_project.iterateFiles(function(id, text) { current_project.iterateFiles(function(id, text) {
if (text && id != main_file_id) if (text && id != main_file_id)
addWindowItem(id, getFilenameForPath(id), loadEditor); addWindowItem(id, getFilenameForPath(id), loadEditor);
}); });
// add listings // add listings
// TODO: update listing when recompiling // TODO: update listing when recompiling
var listings = current_project.getListings(); var listings = current_project.getListings();
@ -155,8 +155,8 @@ function refreshWindowList() {
var lst = listings[lstfn]; var lst = listings[lstfn];
// TODO: add assembly listings? (lines, macrolines, sourcefile) // TODO: add assembly listings? (lines, macrolines, sourcefile)
if (lst.assemblyfile) { if (lst.assemblyfile) {
addWindowItem(lstfn, getFilenameForPath(lstfn), function(path) { addWindowItem(lstfn, getFilenameForPath(lstfn), (path) => {
return new Views.ListingView(lstfn); return new Views.ListingView(path);
}); });
} }
} }
@ -258,7 +258,7 @@ function _uploadNewFile(e) {
function handleFileUpload(files: File[]) { function handleFileUpload(files: File[]) {
console.log(files); console.log(files);
var index = 0; var index = 0;
function uploadNextFile() { function uploadNextFile() {
var f = files[index++]; var f = files[index++];
if (!f) { if (!f) {
console.log("Done uploading"); console.log("Done uploading");

View File

@ -57,7 +57,7 @@ export class SourceEditor implements ProjectView {
errormsgs = []; errormsgs = [];
errorwidgets = []; errorwidgets = [];
inspectWidget; inspectWidget;
createDiv(parent:HTMLElement, text:string) { createDiv(parent:HTMLElement, text:string) {
var div = document.createElement('div'); var div = document.createElement('div');
div.setAttribute("class", "editor"); div.setAttribute("class", "editor");
@ -81,7 +81,7 @@ export class SourceEditor implements ProjectView {
: ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"], : ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"],
}); });
} }
setupEditor() { setupEditor() {
var timer; var timer;
this.editor.on('changes', (ed, changeobj) => { this.editor.on('changes', (ed, changeobj) => {
@ -103,7 +103,7 @@ export class SourceEditor implements ProjectView {
//scrollProfileView(editor); //scrollProfileView(editor);
this.editor.setOption("mode", this.mode); this.editor.setOption("mode", this.mode);
} }
inspect(ident : string) : void { inspect(ident : string) : void {
var result; var result;
if (platform.inspect) { if (platform.inspect) {
@ -126,11 +126,11 @@ export class SourceEditor implements ProjectView {
this.editor.setValue(text); // calls setCode() this.editor.setValue(text); // calls setCode()
this.editor.clearHistory(); this.editor.clearHistory();
} }
getValue() : string { getValue() : string {
return this.editor.getValue(); return this.editor.getValue();
} }
getPath() : string { return this.path; } getPath() : string { return this.path; }
addErrorMarker(line:number, msg:string) { addErrorMarker(line:number, msg:string) {
@ -144,21 +144,21 @@ export class SourceEditor implements ProjectView {
this.expandErrors(); this.expandErrors();
}); });
} }
addErrorLine(line:number, msg:string) { addErrorLine(line:number, msg:string) {
var errspan = document.createElement("span"); var errspan = document.createElement("span");
errspan.setAttribute("class", "tooltiperrorline"); errspan.setAttribute("class", "tooltiperrorline");
errspan.appendChild(document.createTextNode(msg)); errspan.appendChild(document.createTextNode(msg));
this.errorwidgets.push(this.editor.addLineWidget(line, errspan)); this.errorwidgets.push(this.editor.addLineWidget(line, errspan));
} }
expandErrors() { expandErrors() {
var e; var e;
while (e = this.errormsgs.shift()) { while (e = this.errormsgs.shift()) {
this.addErrorLine(e.line, e.msg); this.addErrorLine(e.line, e.msg);
} }
} }
markErrors(errors:WorkerError[]) { markErrors(errors:WorkerError[]) {
// TODO: move cursor to error line if offscreen? // TODO: move cursor to error line if offscreen?
this.clearErrors(); this.clearErrors();
@ -173,7 +173,7 @@ export class SourceEditor implements ProjectView {
} }
} }
} }
clearErrors() { clearErrors() {
this.editor.clearGutter("gutter-info"); this.editor.clearGutter("gutter-info");
this.refreshDebugState(false); this.refreshDebugState(false);
@ -183,9 +183,9 @@ export class SourceEditor implements ProjectView {
while (this.errorwidgets.length) while (this.errorwidgets.length)
this.errorwidgets.shift().clear(); this.errorwidgets.shift().clear();
} }
getSourceFile() : SourceFile { return this.sourcefile; } getSourceFile() : SourceFile { return this.sourcefile; }
updateListing() { updateListing() {
// update editor annotations // update editor annotations
this.editor.clearGutter("gutter-info"); this.editor.clearGutter("gutter-info");
@ -212,7 +212,7 @@ export class SourceEditor implements ProjectView {
} }
} }
} }
setGutter(type:string, line:number, text:string) { setGutter(type:string, line:number, text:string) {
var lineinfo = this.editor.lineInfo(line); var lineinfo = this.editor.lineInfo(line);
if (lineinfo && lineinfo.gutterMarkers && lineinfo.gutterMarkers[type]) { if (lineinfo && lineinfo.gutterMarkers && lineinfo.gutterMarkers[type]) {
@ -222,11 +222,11 @@ export class SourceEditor implements ProjectView {
this.editor.setGutterMarker(line, type, textel); this.editor.setGutterMarker(line, type, textel);
} }
} }
setGutterBytes(line:number, s:string) { setGutterBytes(line:number, s:string) {
this.setGutter("gutter-bytes", line-1, s); this.setGutter("gutter-bytes", line-1, s);
} }
setTimingResult(result:CodeAnalyzer) : void { setTimingResult(result:CodeAnalyzer) : void {
this.editor.clearGutter("gutter-bytes"); this.editor.clearGutter("gutter-bytes");
// show the lines // show the lines
@ -246,7 +246,7 @@ export class SourceEditor implements ProjectView {
} }
} }
} }
setCurrentLine(line:number, moveCursor:boolean) { setCurrentLine(line:number, moveCursor:boolean) {
var addCurrentMarker = (line:number) => { var addCurrentMarker = (line:number) => {
@ -272,7 +272,7 @@ export class SourceEditor implements ProjectView {
this.currentDebugLine = 0; this.currentDebugLine = 0;
} }
} }
getActiveLine() { getActiveLine() {
var state = lastDebugState; var state = lastDebugState;
if (state && state.c && this.sourcefile) { if (state && state.c && this.sourcefile) {
@ -282,7 +282,7 @@ export class SourceEditor implements ProjectView {
} else } else
return -1; return -1;
} }
refreshDebugState(moveCursor:boolean) { refreshDebugState(moveCursor:boolean) {
var line = this.getActiveLine(); var line = this.getActiveLine();
if (line >= 0) { if (line >= 0) {
@ -291,7 +291,7 @@ export class SourceEditor implements ProjectView {
// TODO: switch to disasm? // TODO: switch to disasm?
} }
} }
refreshListing() { refreshListing() {
// lookup corresponding sourcefile for this file, using listing // lookup corresponding sourcefile for this file, using listing
var lst = current_project.getListingForFile(this.path); var lst = current_project.getListingForFile(this.path);
@ -308,15 +308,15 @@ export class SourceEditor implements ProjectView {
this.refreshListing(); this.refreshListing();
this.refreshDebugState(moveCursor); this.refreshDebugState(moveCursor);
} }
getLine(line : number) { getLine(line : number) {
return this.editor.getLine(line-1); return this.editor.getLine(line-1);
} }
getCurrentLine() : number { getCurrentLine() : number {
return this.editor.getCursor().line+1; return this.editor.getCursor().line+1;
} }
getCursorPC() : number { getCursorPC() : number {
var line = this.getCurrentLine(); var line = this.getCurrentLine();
while (this.sourcefile && line >= 0) { while (this.sourcefile && line >= 0) {
@ -331,7 +331,7 @@ export class SourceEditor implements ProjectView {
openBitmapEditorWithParams(fmt, bytestr, palfmt, palstr) { openBitmapEditorWithParams(fmt, bytestr, palfmt, palstr) {
var handleWindowMessage = (e) => { var handleWindowMessage = (e) => {
//console.log("window message", e.data); //console.log("window message", e.data);
if (e.data.bytes) { if (e.data.bytes) {
this.editor.replaceSelection(e.data.bytestr); this.editor.replaceSelection(e.data.bytestr);
@ -405,9 +405,9 @@ export class SourceEditor implements ProjectView {
export class DisassemblerView implements ProjectView { export class DisassemblerView implements ProjectView {
disasmview; disasmview;
getDisasmView() { return this.disasmview; } getDisasmView() { return this.disasmview; }
createDiv(parent : HTMLElement) { createDiv(parent : HTMLElement) {
var div = document.createElement('div'); var div = document.createElement('div');
div.setAttribute("class", "editor"); div.setAttribute("class", "editor");
@ -415,7 +415,7 @@ export class DisassemblerView implements ProjectView {
this.newEditor(div); this.newEditor(div);
return div; return div;
} }
newEditor(parent : HTMLElement) { newEditor(parent : HTMLElement) {
this.disasmview = CodeMirror(parent, { this.disasmview = CodeMirror(parent, {
mode: 'z80', // TODO: pick correct one mode: 'z80', // TODO: pick correct one
@ -598,12 +598,12 @@ export class MemoryView implements ProjectView {
if (compparams && this.dumplines) if (compparams && this.dumplines)
this.memorylist.scrollToItem(this.findMemoryWindowLine(compparams.data_start)); this.memorylist.scrollToItem(this.findMemoryWindowLine(compparams.data_start));
} }
refresh() { refresh() {
this.dumplines = null; this.dumplines = null;
this.tick(); this.tick();
} }
tick() { tick() {
if (this.memorylist) { if (this.memorylist) {
$(this.maindiv).find('[data-index]').each( (i,e) => { $(this.maindiv).find('[data-index]').each( (i,e) => {
@ -660,7 +660,7 @@ export class MemoryView implements ProjectView {
this.dumplines = []; this.dumplines = [];
var ofs = 0; var ofs = 0;
var sym; var sym;
for (const _nextofs of Object.keys(addr2sym)) { for (const _nextofs of Object.keys(addr2sym)) {
var nextofs = parseInt(_nextofs); // convert from string (stupid JS) var nextofs = parseInt(_nextofs); // convert from string (stupid JS)
var nextsym = addr2sym[nextofs]; var nextsym = addr2sym[nextofs];
if (sym) { if (sym) {
@ -702,4 +702,3 @@ export class MemoryView implements ProjectView {
return i; return i;
} }
} }

View File

@ -693,6 +693,13 @@ function assembleDASM(step:BuildStep) {
symbolmap[toks[0]] = parseInt(toks[1], 16); symbolmap[toks[0]] = parseInt(toks[1], 16);
} }
} }
// for bataribasic (TODO)
if (step['bblines']) {
let lst = listings[lstpath];
lst.asmlines = lst.lines;
lst.text = alst;
lst.lines = [];
}
return { return {
output:aout.slice(2), output:aout.slice(2),
listings:listings, listings:listings,
@ -1587,7 +1594,8 @@ function compileBatariBasic(step:BuildStep) {
nexttool:"dasm", nexttool:"dasm",
path:destpath, path:destpath,
args:[destpath], args:[destpath],
files:[destpath, "2600basic.h", "2600basic_variable_redefs.h"] files:[destpath, "2600basic.h", "2600basic_variable_redefs.h"],
bblines:true,
}; };
} }
@ -1689,13 +1697,9 @@ function executeBuildSteps() {
} }
// process with another tool? // process with another tool?
if (step.result.nexttool) { if (step.result.nexttool) {
var asmstep = { var asmstep = step.result;
tool:step.result.nexttool, asmstep.tool = step.result.nexttool;
platform:platform, asmstep.platform = platform;
files:step.result.files,
path:step.result.path,
args:step.result.args
};
buildsteps.push(asmstep); // TODO: unshift changes order buildsteps.push(asmstep); // TODO: unshift changes order
step.generated = asmstep.files; step.generated = asmstep.files;
} }