Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time.Sleep() #19

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ x;
`,
5,
'',
300
400
);

// Testing mark and sweep, with exactly one variable that should be freed
Expand All @@ -497,7 +497,7 @@ x;
`,
5,
'',
220
400
);

// Testing structs (no methods for now)
Expand Down Expand Up @@ -1044,7 +1044,7 @@ go googa(x, y);
`,
true,
'15',
206
400
);

// Test various array expressions
Expand Down
9 changes: 5 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,7 @@ export function run(numWords = 1000000) {
log('Program value is ' + returnValue);
log('After STD initialization: ');
printHeapUsage();
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{};