Skip to content

Commit

Permalink
Add time.Sleep()
Browse files Browse the repository at this point in the history
  • Loading branch information
JothamWong committed Apr 16, 2024
1 parent 2492269 commit de2ec1f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/vm/oogavm-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ export const builtinMappings = {
isAtomicSection = false;
return True;
},
// "make": () => {
// // TODO: Support channels as priority number 1
// }
getTime: () => {
// Get unix time in millis
return TSValueToAddress(Date.now());
}
};

class Builtin {
Expand Down Expand Up @@ -1245,7 +1246,6 @@ function runInstruction() {
// printStringPoolMapping();
}

// TODO: Switch to low level memory representation
export function run(numWords = 1000000) {
initialize(numWords);
while (running) {
Expand All @@ -1267,6 +1267,8 @@ export function run(numWords = 1000000) {
log('Program value is ' + returnValue);
log('After STD initialization: ');
printHeapUsage();
console.log("Return value is " + returnValue);
debugHeap();
log('Return value: ' + returnValue);
return returnValue;
}
Expand Down
1 change: 1 addition & 0 deletions src/vm/oogavm-typechecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const global_type_frame = {
blockThread: new FunctionType([], new NullType()),
getThreadID: new FunctionType([], new IntegerType()),
oogaError: new FunctionType([], new NullType()),
getTime: new FunctionType([], new IntegerType()),
};

const empty_type_environment = null;
Expand Down
16 changes: 16 additions & 0 deletions std/ooga-std.ooga
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,19 @@ func (m *Mutex) Unlock() {
}

var fmt format = format{}


type Time struct {
}

// Duration to sleep for in milliseconds
func (t *Time) Sleep(duration int) {
startTime := getTime();
for {
if getTime() - startTime >= duration {
break;
}
}
}

var time Time = Time{};

0 comments on commit de2ec1f

Please sign in to comment.