mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-11 23:30:04 +00:00
try to get bbasic listings, fixed highlighting
This commit is contained in:
parent
eb01bdcea0
commit
a7b1fb4f57
@ -46,7 +46,7 @@ CodeMirror.defineMode('bataribasic', function(_config, parserConfig) {
|
||||
for (var s of directives_list)
|
||||
directives[s] = 'keyword';
|
||||
|
||||
var numbers = /^([$][0-9a-f]+|[%][01]+|[0-9.]+)\b/i;
|
||||
var numbers = /^([$][0-9a-f]+|[%][01]+|[0-9.]+)/i;
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
@ -68,7 +68,7 @@ CodeMirror.defineMode('bataribasic', function(_config, parserConfig) {
|
||||
return null;
|
||||
|
||||
var w;
|
||||
if (stream.eatWhile(/\w/)) {
|
||||
if (stream.eatWhile(/[$%A-Z0-9]/i)) {
|
||||
w = stream.current();
|
||||
var cur = w.toLowerCase();
|
||||
var style = directives[cur];
|
||||
@ -79,9 +79,8 @@ CodeMirror.defineMode('bataribasic', function(_config, parserConfig) {
|
||||
if (style)
|
||||
return style;
|
||||
|
||||
if (state.context == 4 && numbers.test(w)) {
|
||||
return 'number';
|
||||
} else if (stream.match(numbers)) {
|
||||
console.log(w, numbers.test(w));
|
||||
if (numbers.test(w)) {
|
||||
return 'number';
|
||||
} else {
|
||||
return null;
|
||||
|
@ -24,7 +24,7 @@ export class CodeProject {
|
||||
callbackGetRemote : GetRemoteCallback;
|
||||
mainPath : string;
|
||||
isCompiling : boolean = false;
|
||||
|
||||
|
||||
constructor(worker, platform_id:string, platform, store) {
|
||||
this.worker = worker;
|
||||
this.platform_id = platform_id;
|
||||
@ -48,7 +48,7 @@ export class CodeProject {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
preloadWorker(path:string) {
|
||||
var tool = this.platform.getToolForFilename(path);
|
||||
if (tool && !this.tools_preloaded[tool]) {
|
||||
@ -106,7 +106,7 @@ export class CodeProject {
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
okToSend():boolean {
|
||||
return this.pendingWorkerMessages++ == 0;
|
||||
}
|
||||
@ -117,7 +117,7 @@ export class CodeProject {
|
||||
this.store.setItem(path, text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: test duplicate files, local paths mixed with presets
|
||||
buildWorkerMessage(depends:Dependency[]) {
|
||||
this.preloadWorker(this.mainpath);
|
||||
@ -143,8 +143,8 @@ export class CodeProject {
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
// TODO: get local file as well as presets?
|
||||
|
||||
// TODO: get local file as well as presets?
|
||||
loadFiles(paths:string[], callback:LoadFilesCallback) {
|
||||
var result : Dependency[] = [];
|
||||
function addResult(path, data) {
|
||||
@ -207,18 +207,18 @@ export class CodeProject {
|
||||
}
|
||||
loadNext(); // load first file
|
||||
}
|
||||
|
||||
|
||||
getFile(path:string):FileData {
|
||||
return this.filedata[path];
|
||||
}
|
||||
|
||||
|
||||
// TODO: purge files not included in latest build?
|
||||
iterateFiles(callback:IterateFilesCallback) {
|
||||
for (var path in this.filedata) {
|
||||
callback(path, this.getFile(path));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sendBuild() {
|
||||
if (!this.mainpath) throw "need to call setMainFile first";
|
||||
var maindata = this.getFile(this.mainpath);
|
||||
@ -245,7 +245,7 @@ export class CodeProject {
|
||||
this.isCompiling = true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
updateFile(path:string, text:FileData) {
|
||||
this.updateFileInStore(path, text); // TODO: isBinary
|
||||
this.filedata[path] = text;
|
||||
@ -254,13 +254,13 @@ export class CodeProject {
|
||||
this.sendBuild();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
setMainFile(path:string) {
|
||||
this.mainpath = path;
|
||||
if (this.callbackBuildStatus) this.callbackBuildStatus(true);
|
||||
this.sendBuild();
|
||||
}
|
||||
|
||||
|
||||
processBuildResult(data:WorkerResult) {
|
||||
// TODO: link listings with source files
|
||||
if (data.listings) {
|
||||
@ -274,7 +274,7 @@ export class CodeProject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getListings() : CodeListingMap {
|
||||
return this.listings;
|
||||
}
|
||||
@ -290,4 +290,3 @@ export class CodeProject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
16
src/ui.ts
16
src/ui.ts
@ -105,7 +105,7 @@ function initProject() {
|
||||
function refreshWindowList() {
|
||||
var ul = $("#windowMenuList").empty();
|
||||
var separate = false;
|
||||
|
||||
|
||||
function addWindowItem(id, name, createfn) {
|
||||
if (separate) {
|
||||
ul.append(document.createElement("hr"));
|
||||
@ -129,24 +129,24 @@ function refreshWindowList() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function loadEditor(path:string) {
|
||||
var tool = platform.getToolForFilename(path);
|
||||
var mode = tool && TOOL_TO_SOURCE_STYLE[tool];
|
||||
return new Views.SourceEditor(path, mode);
|
||||
}
|
||||
|
||||
|
||||
// add main file editor
|
||||
var id = main_file_id;
|
||||
addWindowItem(id, getFilenameForPath(id), loadEditor);
|
||||
|
||||
|
||||
// add other source files
|
||||
separate = true;
|
||||
current_project.iterateFiles(function(id, text) {
|
||||
if (text && id != main_file_id)
|
||||
addWindowItem(id, getFilenameForPath(id), loadEditor);
|
||||
});
|
||||
|
||||
|
||||
// add listings
|
||||
// TODO: update listing when recompiling
|
||||
var listings = current_project.getListings();
|
||||
@ -155,8 +155,8 @@ function refreshWindowList() {
|
||||
var lst = listings[lstfn];
|
||||
// TODO: add assembly listings? (lines, macrolines, sourcefile)
|
||||
if (lst.assemblyfile) {
|
||||
addWindowItem(lstfn, getFilenameForPath(lstfn), function(path) {
|
||||
return new Views.ListingView(lstfn);
|
||||
addWindowItem(lstfn, getFilenameForPath(lstfn), (path) => {
|
||||
return new Views.ListingView(path);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -258,7 +258,7 @@ function _uploadNewFile(e) {
|
||||
function handleFileUpload(files: File[]) {
|
||||
console.log(files);
|
||||
var index = 0;
|
||||
function uploadNextFile() {
|
||||
function uploadNextFile() {
|
||||
var f = files[index++];
|
||||
if (!f) {
|
||||
console.log("Done uploading");
|
||||
|
57
src/views.ts
57
src/views.ts
@ -57,7 +57,7 @@ export class SourceEditor implements ProjectView {
|
||||
errormsgs = [];
|
||||
errorwidgets = [];
|
||||
inspectWidget;
|
||||
|
||||
|
||||
createDiv(parent:HTMLElement, text:string) {
|
||||
var div = document.createElement('div');
|
||||
div.setAttribute("class", "editor");
|
||||
@ -81,7 +81,7 @@ export class SourceEditor implements ProjectView {
|
||||
: ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
setupEditor() {
|
||||
var timer;
|
||||
this.editor.on('changes', (ed, changeobj) => {
|
||||
@ -103,7 +103,7 @@ export class SourceEditor implements ProjectView {
|
||||
//scrollProfileView(editor);
|
||||
this.editor.setOption("mode", this.mode);
|
||||
}
|
||||
|
||||
|
||||
inspect(ident : string) : void {
|
||||
var result;
|
||||
if (platform.inspect) {
|
||||
@ -126,11 +126,11 @@ export class SourceEditor implements ProjectView {
|
||||
this.editor.setValue(text); // calls setCode()
|
||||
this.editor.clearHistory();
|
||||
}
|
||||
|
||||
|
||||
getValue() : string {
|
||||
return this.editor.getValue();
|
||||
}
|
||||
|
||||
|
||||
getPath() : string { return this.path; }
|
||||
|
||||
addErrorMarker(line:number, msg:string) {
|
||||
@ -144,21 +144,21 @@ export class SourceEditor implements ProjectView {
|
||||
this.expandErrors();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
addErrorLine(line:number, msg:string) {
|
||||
var errspan = document.createElement("span");
|
||||
errspan.setAttribute("class", "tooltiperrorline");
|
||||
errspan.appendChild(document.createTextNode(msg));
|
||||
this.errorwidgets.push(this.editor.addLineWidget(line, errspan));
|
||||
}
|
||||
|
||||
|
||||
expandErrors() {
|
||||
var e;
|
||||
while (e = this.errormsgs.shift()) {
|
||||
this.addErrorLine(e.line, e.msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
markErrors(errors:WorkerError[]) {
|
||||
// TODO: move cursor to error line if offscreen?
|
||||
this.clearErrors();
|
||||
@ -173,7 +173,7 @@ export class SourceEditor implements ProjectView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
clearErrors() {
|
||||
this.editor.clearGutter("gutter-info");
|
||||
this.refreshDebugState(false);
|
||||
@ -183,9 +183,9 @@ export class SourceEditor implements ProjectView {
|
||||
while (this.errorwidgets.length)
|
||||
this.errorwidgets.shift().clear();
|
||||
}
|
||||
|
||||
|
||||
getSourceFile() : SourceFile { return this.sourcefile; }
|
||||
|
||||
|
||||
updateListing() {
|
||||
// update editor annotations
|
||||
this.editor.clearGutter("gutter-info");
|
||||
@ -212,7 +212,7 @@ export class SourceEditor implements ProjectView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setGutter(type:string, line:number, text:string) {
|
||||
var lineinfo = this.editor.lineInfo(line);
|
||||
if (lineinfo && lineinfo.gutterMarkers && lineinfo.gutterMarkers[type]) {
|
||||
@ -222,11 +222,11 @@ export class SourceEditor implements ProjectView {
|
||||
this.editor.setGutterMarker(line, type, textel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setGutterBytes(line:number, s:string) {
|
||||
this.setGutter("gutter-bytes", line-1, s);
|
||||
}
|
||||
|
||||
|
||||
setTimingResult(result:CodeAnalyzer) : void {
|
||||
this.editor.clearGutter("gutter-bytes");
|
||||
// show the lines
|
||||
@ -246,7 +246,7 @@ export class SourceEditor implements ProjectView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setCurrentLine(line:number, moveCursor:boolean) {
|
||||
|
||||
var addCurrentMarker = (line:number) => {
|
||||
@ -272,7 +272,7 @@ export class SourceEditor implements ProjectView {
|
||||
this.currentDebugLine = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getActiveLine() {
|
||||
var state = lastDebugState;
|
||||
if (state && state.c && this.sourcefile) {
|
||||
@ -282,7 +282,7 @@ export class SourceEditor implements ProjectView {
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
refreshDebugState(moveCursor:boolean) {
|
||||
var line = this.getActiveLine();
|
||||
if (line >= 0) {
|
||||
@ -291,7 +291,7 @@ export class SourceEditor implements ProjectView {
|
||||
// TODO: switch to disasm?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
refreshListing() {
|
||||
// lookup corresponding sourcefile for this file, using listing
|
||||
var lst = current_project.getListingForFile(this.path);
|
||||
@ -308,15 +308,15 @@ export class SourceEditor implements ProjectView {
|
||||
this.refreshListing();
|
||||
this.refreshDebugState(moveCursor);
|
||||
}
|
||||
|
||||
|
||||
getLine(line : number) {
|
||||
return this.editor.getLine(line-1);
|
||||
}
|
||||
|
||||
|
||||
getCurrentLine() : number {
|
||||
return this.editor.getCursor().line+1;
|
||||
}
|
||||
|
||||
|
||||
getCursorPC() : number {
|
||||
var line = this.getCurrentLine();
|
||||
while (this.sourcefile && line >= 0) {
|
||||
@ -331,7 +331,7 @@ export class SourceEditor implements ProjectView {
|
||||
|
||||
openBitmapEditorWithParams(fmt, bytestr, palfmt, palstr) {
|
||||
|
||||
var handleWindowMessage = (e) => {
|
||||
var handleWindowMessage = (e) => {
|
||||
//console.log("window message", e.data);
|
||||
if (e.data.bytes) {
|
||||
this.editor.replaceSelection(e.data.bytestr);
|
||||
@ -405,9 +405,9 @@ export class SourceEditor implements ProjectView {
|
||||
|
||||
export class DisassemblerView implements ProjectView {
|
||||
disasmview;
|
||||
|
||||
|
||||
getDisasmView() { return this.disasmview; }
|
||||
|
||||
|
||||
createDiv(parent : HTMLElement) {
|
||||
var div = document.createElement('div');
|
||||
div.setAttribute("class", "editor");
|
||||
@ -415,7 +415,7 @@ export class DisassemblerView implements ProjectView {
|
||||
this.newEditor(div);
|
||||
return div;
|
||||
}
|
||||
|
||||
|
||||
newEditor(parent : HTMLElement) {
|
||||
this.disasmview = CodeMirror(parent, {
|
||||
mode: 'z80', // TODO: pick correct one
|
||||
@ -598,12 +598,12 @@ export class MemoryView implements ProjectView {
|
||||
if (compparams && this.dumplines)
|
||||
this.memorylist.scrollToItem(this.findMemoryWindowLine(compparams.data_start));
|
||||
}
|
||||
|
||||
|
||||
refresh() {
|
||||
this.dumplines = null;
|
||||
this.tick();
|
||||
}
|
||||
|
||||
|
||||
tick() {
|
||||
if (this.memorylist) {
|
||||
$(this.maindiv).find('[data-index]').each( (i,e) => {
|
||||
@ -660,7 +660,7 @@ export class MemoryView implements ProjectView {
|
||||
this.dumplines = [];
|
||||
var ofs = 0;
|
||||
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 nextsym = addr2sym[nextofs];
|
||||
if (sym) {
|
||||
@ -702,4 +702,3 @@ export class MemoryView implements ProjectView {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -693,6 +693,13 @@ function assembleDASM(step:BuildStep) {
|
||||
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 {
|
||||
output:aout.slice(2),
|
||||
listings:listings,
|
||||
@ -1587,7 +1594,8 @@ function compileBatariBasic(step:BuildStep) {
|
||||
nexttool:"dasm",
|
||||
path: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?
|
||||
if (step.result.nexttool) {
|
||||
var asmstep = {
|
||||
tool:step.result.nexttool,
|
||||
platform:platform,
|
||||
files:step.result.files,
|
||||
path:step.result.path,
|
||||
args:step.result.args
|
||||
};
|
||||
var asmstep = step.result;
|
||||
asmstep.tool = step.result.nexttool;
|
||||
asmstep.platform = platform;
|
||||
buildsteps.push(asmstep); // TODO: unshift changes order
|
||||
step.generated = asmstep.files;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user