moved some types to workertypes.ts

This commit is contained in:
Steven Hugg 2018-07-08 09:07:19 -05:00
parent 1e7e7feae5
commit 82f01b3fcd
9 changed files with 116 additions and 101 deletions

View File

@ -248,6 +248,7 @@ function require(modname) {
<script src="src/audio.js"></script>
<script src="gen/util.js"></script>
<script src="src/cpu/disasm6502.js"></script>
<script src="gen/workertypes.js"></script>
<script src="gen/project.js"></script>
<script src="gen/windows.js"></script>
<script src="gen/views.js"></script>

View File

@ -1,84 +1,6 @@
"use strict";
type FileData = string | Uint8Array;
export interface SourceLine {
offset:number;
line:number;
insns?:string;
iscode?:boolean;
}
export interface Dependency {
path:string,
filename:string,
data:FileData // TODO: or binary?
}
export interface WorkerFileUpdate { path:string, data:FileData };
export interface WorkerBuildStep { path:string, platform:string, tool:string, mainfile?:boolean };
export interface WorkerMessage {
updates:WorkerFileUpdate[],
buildsteps:WorkerBuildStep[]
}
export interface WorkerError {
line:number,
msg:string,
path?:string
//TODO
}
export class SourceFile {
lines: SourceLine[];
text: string;
offset2line: {[offset:number]:number};
line2offset: {[line:number]:number};
constructor(lines:SourceLine[], text?:string) {
lines = lines || [];
this.lines = lines;
this.text = text;
this.offset2line = {};
this.line2offset = {};
for (var info of lines) {
if (info.offset >= 0) {
this.offset2line[info.offset] = info.line;
this.line2offset[info.line] = info.offset;
}
}
}
findLineForOffset(PC:number):number {
if (this.offset2line) {
for (var i=0; i<16; i++) {
var line = this.offset2line[PC];
if (line >= 0) {
return line;
}
PC--;
}
}
return null;
}
lineCount():number { return this.lines.length; }
}
interface CodeListing {
lines:SourceLine[],
asmlines:SourceLine[],
text:string,
sourcefile:SourceFile,
assemblyfile:SourceFile
}
type CodeListingMap = {[path:string]:CodeListing};
interface WorkerResult {
output:Uint8Array, //TODO
errors:WorkerError[],
listings:CodeListingMap,
}
import { FileData, Dependency, SourceLine, SourceFile, CodeListing, CodeListingMap, WorkerError, WorkerResult } from "./workertypes";
type BuildResultCallback = (result:WorkerResult) => void;
type BuildStatusCallback = (busy:boolean) => void;

View File

@ -4,7 +4,8 @@
import $ = require("jquery");
import * as bootstrap from "bootstrap";
import { SourceFile, CodeProject } from "./project";
import { CodeProject } from "./project";
import { WorkerResult, SourceFile } from "./workertypes";
import { ProjectWindows } from "./windows";
import { Platform, Preset } from "./baseplatform";
import * as Views from "./views";
@ -43,7 +44,7 @@ var TOOL_TO_SOURCE_STYLE = {
'jsasm': 'z80'
}
function newWorker() {
function newWorker() : Worker {
return new Worker("./src/worker/workermain.js");
}
@ -60,21 +61,21 @@ var store; // persistent store
var lastDebugInfo; // last debug info (CPU text)
var lastDebugState; // last debug state (object)
function inspectVariable(ed, name) {
function inspectVariable(ed, name) { // TODO: ed?
var val;
if (platform.inspect) {
platform.inspect(name);
}
}
function getCurrentPresetTitle() {
function getCurrentPresetTitle() : string {
if (!current_preset_entry)
return "ROM";
else
return current_preset_entry.title || current_preset_entry.name || "ROM";
}
function setLastPreset(id) {
function setLastPreset(id:string) {
if (platform_id != 'base_z80') { // TODO
localStorage.setItem("__lastplatform", platform_id);
localStorage.setItem("__lastid_"+platform_id, id);
@ -125,7 +126,7 @@ function refreshWindowList() {
}
}
function loadEditor(path) {
function loadEditor(path:string) {
var tool = platform.getToolForFilename(path);
var mode = tool && TOOL_TO_SOURCE_STYLE[tool];
return new Views.SourceEditor(path, mode);
@ -170,7 +171,7 @@ function refreshWindowList() {
}
// can pass integer or string id
function loadProject(preset_id) {
function loadProject(preset_id:string) {
var index = parseInt(preset_id+""); // might fail -1
for (var i=0; i<PRESETS.length; i++)
if (PRESETS[i].id == preset_id)
@ -198,13 +199,13 @@ function loadProject(preset_id) {
});
}
function reloadPresetNamed(id) {
function reloadPresetNamed(id:string) {
qs['platform'] = platform_id;
qs['file'] = id;
gotoNewLocation();
}
function getSkeletonFile(fileid, callback) {
function getSkeletonFile(fileid:string, callback) {
var ext = platform.getToolForFilename(fileid);
$.get( "presets/"+platform_id+"/skeleton."+ext, function( text ) {
callback(null, text);
@ -240,7 +241,7 @@ function _uploadNewFile(e) {
$("#uploadFileElem").click();
}
function handleFileUpload(files) {
function handleFileUpload(files: File[]) {
console.log(files);
var index = 0;
function uploadNextFile() {
@ -270,7 +271,7 @@ function handleFileUpload(files) {
if (files) uploadNextFile();
}
function getCurrentFilename() {
function getCurrentFilename() : string {
var toks = main_file_id.split("/");
return toks[toks.length-1];
}
@ -373,7 +374,7 @@ function updateSelector() {
});
}
function setCompileOutput(data) {
function setCompileOutput(data: WorkerResult) {
// errors? mark them in editor
if (data.errors && data.errors.length > 0) {
projectWindows.setErrors(data.errors);
@ -387,7 +388,7 @@ function setCompileOutput(data) {
compparams = data.params;
// load ROM
var rom = data.output;
if (rom) {
if (rom instanceof Uint8Array) {
try {
//console.log("Loading ROM length", rom.length);
platform.loadROM(getCurrentPresetTitle(), rom);
@ -427,7 +428,7 @@ function showMemory(state?) {
}
}
function setDebugButtonState(btnid, btnstate) {
function setDebugButtonState(btnid:string, btnstate:string) {
$("#debug_bar").find("button").removeClass("btn_active").removeClass("btn_stopped");
$("#dbg_"+btnid).addClass("btn_"+btnstate);
}
@ -483,7 +484,7 @@ function singleFrameStep() {
platform.runToVsync();
}
function getEditorPC() {
function getEditorPC() : number {
var wnd = projectWindows.getActive();
return wnd && wnd.getCursorPC && wnd.getCursorPC();
}
@ -545,7 +546,7 @@ function _breakExpression() {
}
}
function getSymbolAtAddress(a) {
function getSymbolAtAddress(a : number) {
if (addr2symbol[a]) return addr2symbol[a];
var i=0;
while (--a >= 0) {
@ -607,7 +608,7 @@ function _recordVideo() {
f();
}
function setFrameRateUI(fps) {
function setFrameRateUI(fps:number) {
platform.setFrameRate(fps);
if (fps > 0.01)
$("#fps_label").text(fps.toFixed(2));
@ -859,7 +860,7 @@ function startPlatform() {
}
}
function loadSharedFile(sharekey) {
function loadSharedFile(sharekey : string) {
var github = new Octokat();
var gist = github.gists(sharekey);
gist.fetch().done(function(val) {
@ -881,7 +882,7 @@ function loadSharedFile(sharekey) {
}
// start
function startUI(loadplatform) {
function startUI(loadplatform : boolean) {
installErrorHandler();
// add default platform?
platform_id = qs['platform'] || localStorage.getItem("__lastplatform");

View File

@ -1,7 +1,8 @@
"use strict";
import $ = require("jquery");
import { SourceFile, WorkerError, CodeProject } from "./project";
import { CodeProject } from "./project";
import { SourceFile, WorkerError } from "./workertypes";
import { Platform } from "./baseplatform";
export interface ProjectView {

View File

@ -1,7 +1,8 @@
"use strict";
import $ = require("jquery");
import { WorkerError, CodeProject } from "./project";
import { CodeProject } from "./project";
import { WorkerError } from "./workertypes";
import { ProjectView } from "./views";
type WindowCreateFunction = (id:string) => ProjectView;

86
src/workertypes.ts Normal file
View File

@ -0,0 +1,86 @@
export type FileData = string | Uint8Array;
export interface SourceLine {
offset:number;
line:number;
insns?:string;
iscode?:boolean;
}
export class SourceFile {
lines: SourceLine[];
text: string;
offset2line: {[offset:number]:number};
line2offset: {[line:number]:number};
constructor(lines:SourceLine[], text?:string) {
lines = lines || [];
this.lines = lines;
this.text = text;
this.offset2line = {};
this.line2offset = {};
for (var info of lines) {
if (info.offset >= 0) {
this.offset2line[info.offset] = info.line;
this.line2offset[info.line] = info.offset;
}
}
}
findLineForOffset(PC:number):number {
if (this.offset2line) {
for (var i=0; i<16; i++) {
var line = this.offset2line[PC];
if (line >= 0) {
return line;
}
PC--;
}
}
return null;
}
lineCount():number { return this.lines.length; }
}
export interface Dependency {
path:string,
filename:string,
data:FileData // TODO: or binary?
}
export interface WorkerFileUpdate { path:string, data:FileData };
export interface WorkerBuildStep { path:string, platform:string, tool:string, mainfile?:boolean };
export interface WorkerMessage {
updates:WorkerFileUpdate[],
buildsteps:WorkerBuildStep[]
}
export interface WorkerError {
line:number,
msg:string,
path?:string
//TODO
}
export interface CodeListing {
lines:SourceLine[],
asmlines:SourceLine[],
text:string,
sourcefile?:SourceFile,
assemblyfile?:SourceFile
}
export type CodeListingMap = {[path:string]:CodeListing};
// TODO
export type WorkerOutput = Uint8Array |
{program_rom_variable:string, program_rom:Uint8Array, code:{}, name:string, ports:any[], signals:any[]};
export interface WorkerResult {
output:WorkerOutput,
errors:WorkerError[],
listings:CodeListingMap,
symbolmap:{[sym:string]:number},
params:{},
}

View File

@ -48,6 +48,7 @@ includeInThisContext("localForage/dist/localforage.js");
includeInThisContext("gen/util.js");
includeInThisContext("src/store.js");
var prj = require("../../gen/project.js");
var prj = require("../../gen/workertypes.js");
var test_platform_id = "_TEST";

View File

@ -36,6 +36,7 @@ function doBuild(msgs, callback, outlen, nlines, nerrors) {
} else {
assert.equal(nerrors||0, 0, "errors");
assert.equal(msg.output.code?msg.output.code.length:msg.output.length, outlen, "output binary");
assert.ok(msg.output.code || msg.output instanceof Uint8Array);
if (nlines) {
if (typeof nlines === 'number')
nlines = [nlines];

View File

@ -9,7 +9,8 @@
"dom"
],
"noImplicitThis": false,
"noImplicitAny": false
"noImplicitAny": false,
"alwaysStrict": true
},
"include": [
"./src/*.ts",