Skip to content

Commit

Permalink
Fix most typescript errors - other than Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav-ag committed Apr 9, 2024
1 parent 7f4ce3f commit 40b37ae
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function testProgram(
debug.disable(); // Disable debug logs initially
debug.enable('ooga:tests');
// debug.enable('ooga:typechecker');
log(`Running program:\n\`\`\`${program}\`\`\`\nExpected value: ${expectedValue}`);
log(
`Running program:\n\`\`\`${program}\`\`\`\nExpected value: ${expectedValue}\nExpected output: ${expectedOutput}`
);

let value;
let capturedOutput = '';
Expand All @@ -38,7 +40,6 @@ export function testProgram(
};
value = run(numWords);
console.log = originalLog;
log('Got output: ', capturedOutput);
} catch (e) {
if (e.message === expectedValue) {
logTest('Test passed');
Expand All @@ -58,7 +59,7 @@ export function testProgram(
if (value !== expectedValue) {
logTest('--------------------------------------------', true);
logTest('Test failed', true);
logTest(`Expected ${expectedValue} but got ${value}`, true);
logTest(`Expected result: ${expectedValue} but got ${value}`, true);
logTest('--------------------------------------------', true);
throw new Error(`Test failed: Expected ${expectedValue} but got ${value}`);
} else if (capturedOutput.trim() !== expectedOutput?.trim()) {
Expand Down
13 changes: 5 additions & 8 deletions src/vm/oogavm-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ function compileTimeEnvironmentPosition(env: CompileTimeEnvironment, x: string |
function valueIndex(frame: CompileTimeFrame, x: string | Method) {
log('Finding value index of ' + unparse(x));
for (let i = 0; i < frame.length; i++) {
const name = frame[i].name;
log(
'Comparing ' + unparse(frame[i].name) + ' with ' + unparse(x),
'Comparing ' + unparse(name) + ' with ' + unparse(x),
typeof x === 'string',
frame[i].name === x
name === x
);
if (typeof x === 'string' && frame[i].name === x) {
if (typeof x === 'string' && name === x) {
return i;
} else if (
x instanceof Method &&
frame[i].name instanceof Method &&
x.equals(frame[i].name)
) {
} else if (x instanceof Method && name instanceof Method && x.equals(name)) {
return i;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/vm/oogavm-heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export let Undefined;

let emptyString;

let literals = [];
let literals: number[] = [];

let updateRoots;

Expand Down Expand Up @@ -476,7 +476,7 @@ const StringValueOffset = 3;
function allocateString(s: string): number {
log('Inside allocateString for ' + s);
if (StringPool.has(s)) {
return StringPool.get(s);
return StringPool.get(s)!;
}

const size = Math.ceil(s.length / 8);
Expand Down
6 changes: 3 additions & 3 deletions src/vm/oogavm-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function deleteThread() {
function runThread() {
[currentThreadId, TimeQuanta] = scheduler.runThread();
// TODO: Load thread state
let thread = threads.get(currentThreadId);
let thread = threads.get(currentThreadId)!;
OS = thread._OS;
PC = thread._PC;
RTS = thread._RTS;
Expand Down Expand Up @@ -555,7 +555,7 @@ const microcode = {
let fieldValue;
[OS[0], fieldValue] = popStack(OS[0]); // Next, the value to be set for the field
log('Field value is ' + addressToTSValue(fieldValue));
let structAddress = [];
let structAddress: number[] = [];
[OS[0], structAddress[0]] = popStack(OS[0]); // Assuming struct is on top of OS
log('Struct address is ' + structAddress);
log('Field index is ' + instr.fieldIndex);
Expand Down Expand Up @@ -583,7 +583,7 @@ const microcode = {
let fieldIndex;
[OS[0], fieldIndex] = popStack(OS[0]);
fieldIndex = addressToTSValue(fieldIndex);
let structAddress = [];
let structAddress: number[] = [];
[OS[0], structAddress[0]] = popStack(OS[0]);
let fieldValue;
[OS[0], fieldValue] = popStack(OS[0]);
Expand Down
1 change: 1 addition & 0 deletions src/vm/oogavm-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class RoundRobinScheduler implements Scheduler {
}

runThread(): [ThreadId, number] | null {
// Arnav: When will this be 0?
if (this._idleThreads.length === 0) {
return null;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/vm/oogavm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function parseOptions(): CliOptions | null {
const ret: CliOptions = {
compileTo: 'json',
inputFilename: '',
outputFilename: null,
logAst: false
outputFilename: '',
logAst: false,
};

let endOfOptions = false;
Expand Down

0 comments on commit 40b37ae

Please sign in to comment.