This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function unitTest (description:string, testFunction:Function):void { | |
const testLog:Array<string> = [`Test: ${description}:`]; | |
const expectQueue:Array<Function> = []; | |
class Expectation { | |
actualValue; | |
constructor(anyValue: any) { | |
this.actualValue = anyValue; | |
return this; | |
} | |
toBe(expectedValue: any) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object storage with publisher/subscriber model for updates. | |
type State = null|object; | |
export class DataStore { | |
state:State; | |
oldState:State; | |
subscribers:Map<number|string, Set<Function>>; | |
constructor(state: State = null) { | |
this.state = {}; | |
this.oldState = {}; | |
this.subscribers = new Map(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Return string representation of every value in the given list. | |
/// Traverses sub-lists to provide every reachable value. | |
/proc/list2string(root) | |
var/str = "Travsersal Tree for `[root]`:\n" | |
var/list/seen_lists = list("\ref[root]") | |
var/list/runqueue = list() | |
var/list/waitqueue = list() | |
waitqueue[root] = list("root", " ") | |
while(length(waitqueue)) | |
runqueue = waitqueue.Copy() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MemManager(constructor, free, min, max, args = null) { | |
this.pool = []; | |
this.free = poolObj => { | |
if (!poolObj[MemManager.allocSym]) return; | |
poolObj[MemManager.allocSym] = false; | |
free(poolObj); | |
this.pool.push(poolObj); | |
}; | |
this.objConstructor = constructor; | |
this.args = args; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"quote":"It's time to kick ass and chew bubble gum. And I'm all out of gum.", | |
"author":"Duke Nukem" | |
}, | |
{ | |
"quote":"Damn, those alien bastards are gonna pay for shooting up my ride.", | |
"author":"Duke Nukem" | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Hz = require("hertzscript-vm"); | |
const performance = require("perf_hooks").performance; | |
// Lazy Caterer's Sequence | |
const src1 = ` | |
var total = 1; | |
const numbers = [1]; | |
while (total < 200) { | |
numbers.push(numbers[numbers.length - 1] + total); | |
total++; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (const foo of bar) { | |
// Source | |
} | |
// Transform to equivalent of: | |
const hzIterator = bar(); | |
while(true) { | |
const hzIteratorState = hzIterator.next(); | |
if (hzIteratorState.done) break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== Voluntary Preemption === | |
Voluntary Preemption is most simply described as a hybrid combination of both cooperative multitasking and preemptive multitasking. | |
Voluntary Preemption is implemented via a source code compilation technique whereby a source-to-source compiler implements an analogue to preemption via the automatic insertion of cooperative yields; such a compiler produces newly re-entrant programs which effectively replicate the behavior of preemption.<ref>{{cite journal |author-first1=Abha |author-last1=Moitra |title=Voluntary Preemption: A Tool In The Design Of Hard Real-Time Systems |journal=International Symposium on Formal Techniques in Real-Time and Fault-Tolerant Systems, Second International Symposium Nijmegen, The Netherlands, January 8–10, 1992 Proceedings |pages=87–106}}</ref> | |
To implement Preemptive Multitasking via Voluntary Preemption, a compiler analyzes source code using a process calculus algorithm which predicts the amount of time a process will control the processor; location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Channel(limit = 0) { | |
this.limit = limit; | |
this.buffer = []; | |
this.readers = []; | |
this.wakeRead = null; | |
this.wakeWrite = null; | |
this.readPromise = null; | |
this.writePromise = null; | |
} | |
Channel.prototype.waitForRead = function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns true if obj1 differs in any way from obj2 | |
function testDiff(obj1, obj2) { | |
if (obj1 === null) return obj1 !== obj2; | |
const stack = [{ obj1: obj1, obj2: obj2 }]; | |
const seen = new Map(); | |
seen.set(obj1, stack[0]); | |
_objects: while (stack.length !== 0) { | |
const objects = stack.pop(); | |
if (Array.isArray(objects.obj1) !== Array.isArray(objects.obj2)) return true; | |
const props1 = Object.keys(objects.obj1); |
NewerOlder