Skip to content

Commit

Permalink
feat(stdlib): Convert runtime printing utils to @unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Mar 6, 2022
1 parent 5a44e93 commit 33952ba
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 223 deletions.
16 changes: 0 additions & 16 deletions stdlib/runtime/dataStructures.gr
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,6 @@ export let allocateString = size => {
str
}

/**
* Creates a new Grain string containing the given character
*
* @param {WasmI32} c The character for which to allocate a string
* @returns {WasmI32} The pointer to the string
*/
export let singleByteString = c => {
let str = Memory.malloc(9n)

WasmI32.store(str, Tags._GRAIN_STRING_HEAP_TAG, 0n)
WasmI32.store(str, 1n, 4n)
WasmI32.store8(str, c, 8n)

str
}

/**
* Allocates a new Grain char.
*
Expand Down
14 changes: 12 additions & 2 deletions stdlib/runtime/gc.gr
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ primitive unbox: Box<a> -> a = "@unbox"

exception DecRefError

export let decimalCount32 = box((n: WasmI32) => 0n)
export let utoa32Buffered = box((a: WasmI32, b: WasmI32, c: WasmI32) => void)
let decimalCount32Dummy = (n: WasmI32) => 0n
let utoa32BufferedDummy = (a: WasmI32, b: WasmI32, c: WasmI32) => void

// When these boxes are backpatched, the reference count of each function will
// fall to zero which would cause them to be freed. We can't free anything that
// got allocated in runtime mode (since that memory space is not managed by the
// GC, so here we prevent that by manually setting a higher refcount.
WasmI32.store(WasmI32.fromGrain(decimalCount32Dummy) - 8n, 2n, 0n)
WasmI32.store(WasmI32.fromGrain(utoa32BufferedDummy) - 8n, 2n, 0n)

export let decimalCount32 = box(decimalCount32Dummy)
export let utoa32Buffered = box(utoa32BufferedDummy)

let mut _DEBUG = false

Expand Down
Loading

0 comments on commit 33952ba

Please sign in to comment.