diff --git a/stdlib/runtime/bigint.gr b/stdlib/runtime/bigint.gr index 458e69f35..726843bc8 100644 --- a/stdlib/runtime/bigint.gr +++ b/stdlib/runtime/bigint.gr @@ -25,7 +25,6 @@ from "runtime/unsafe/wasmf32" include WasmF32 from "runtime/unsafe/wasmf64" include WasmF64 from "runtime/exception" include Exception from "runtime/dataStructures" include DataStructures as DS -from "runtime/utils/printing" include Printing as RPrint // things we need which are missing due to --no-pervasives: primitive (!) = "@not" @@ -131,34 +130,6 @@ let init = (limbs: WasmI32) => { ptr } -// For debugging -@unsafe -provide let debugDumpNumber = (num: WasmI32) => { - use WasmI32.{ (*), (+), (-), (&), (>>>), (<) } - //let num = WasmI32.fromGrain(num) - RPrint.printString("-=-=-=-== debug dump ==-=-=-=-") - RPrint.printString("Ref Count:") - RPrint.printNumber(WasmI64.extendI32U(WasmI32.load(num - 8n, 0n))) - RPrint.printString("Heap Tag:") - RPrint.printNumber(WasmI64.extendI32U(WasmI32.load(num, 0n))) - RPrint.printString("Boxed Num Tag:") - RPrint.printNumber(WasmI64.extendI32U(WasmI32.load(num, 4n))) - RPrint.printString("Num Limbs:") - let limbs = WasmI32.load(num, 8n) - RPrint.printNumber(WasmI64.extendI32U(limbs)) - RPrint.printString("Flags:") - RPrint.printNumber(WasmI64.extendI32U(0xffffn & WasmI32.load(num, 12n))) - RPrint.printString(":") - RPrint.printNumber( - WasmI64.extendI32U((0xffff0000n & WasmI32.load(num, 12n)) >>> 16n) - ) - RPrint.printString("Limbs:") - for (let mut i = 0n; i < limbs; i += 1n) { - // if a nonzero limb is found, then we're at the min - RPrint.printNumber(WasmI64.load(num, (i + 2n) * 8n)) - } -} - @unsafe provide let getSize = ptr => { WasmI32.load(ptr, 8n) diff --git a/stdlib/runtime/bigint.md b/stdlib/runtime/bigint.md index e5f72b93d..333e4cefc 100644 --- a/stdlib/runtime/bigint.md +++ b/stdlib/runtime/bigint.md @@ -6,12 +6,6 @@ title: Bigint Functions and constants included in the Bigint module. -### Bigint.**debugDumpNumber** - -```grain -debugDumpNumber : (num: WasmI32) => Void -``` - ### Bigint.**getSize** ```grain diff --git a/stdlib/runtime/debugPrint.gr b/stdlib/runtime/debugPrint.gr index 194a7d1af..4f258b84a 100644 --- a/stdlib/runtime/debugPrint.gr +++ b/stdlib/runtime/debugPrint.gr @@ -1,3 +1,4 @@ +@noPervasives module DebugPrint from "runtime/numberUtils" include NumberUtils as Utils @@ -9,6 +10,8 @@ from "runtime/unsafe/memory" include Memory foreign wasm fd_write: (WasmI32, WasmI32, WasmI32, WasmI32) => WasmI32 from "wasi_snapshot_preview1" +primitive ignore = "@ignore" + @unsafe provide let print = (s: String) => { let ptr = WasmI32.fromGrain(s) @@ -26,7 +29,7 @@ provide let print = (s: String) => { WasmI32.store(iov, 1n, 12n) fd_write(1n, iov, 2n, written) Memory.free(buf) - void + ignore(s) } @unsafe diff --git a/stdlib/runtime/utils/printing.gr b/stdlib/runtime/utils/printing.gr deleted file mode 100644 index 96b267a9c..000000000 --- a/stdlib/runtime/utils/printing.gr +++ /dev/null @@ -1,60 +0,0 @@ -@noPervasives -module Printing - -// Printing utilities for runtime code (primarily for debugging) -from "runtime/unsafe/wasmi32" include WasmI32 -from "runtime/unsafe/memory" include Memory -from "runtime/numberUtils" include NumberUtils - -foreign wasm fd_write: - (WasmI32, WasmI32, WasmI32, WasmI32) => WasmI32 from "wasi_snapshot_preview1" - -@unsafe -provide let numberToString = (n: WasmI64) => { - NumberUtils.itoa64(n, 10n) -} - -@unsafe -provide let printNumber = (n: WasmI64) => { - // like print(), but `s` should be a Grain string - use WasmI32.{ (+) } - let s = numberToString(n) - let ptr = WasmI32.fromGrain(s) - // iov: [ ] (32 bytes) - // buf: - // fd_write(STDOUT (1), iov, len(iov), written) - let buf = Memory.malloc(37n) - let iov = buf - let written = buf + 32n - let lf = buf + 36n - WasmI32.store(iov, ptr + 8n, 0n) - WasmI32.store(iov, WasmI32.load(ptr, 4n), 4n) - WasmI32.store8(lf, 10n, 0n) - WasmI32.store(iov, lf, 8n) - WasmI32.store(iov, 1n, 12n) - fd_write(1n, iov, 2n, written) - Memory.free(buf) - void -} - -@unsafe -provide let printString = (s: String) => { - // like print(), but `s` should be a Grain string - use WasmI32.{ (+) } - let ptr = WasmI32.fromGrain(s) - // iov: [ ] (32 bytes) - // buf: - // fd_write(STDOUT (1), iov, len(iov), written) - let buf = Memory.malloc(37n) - let iov = buf - let written = buf + 32n - let lf = buf + 36n - WasmI32.store(iov, ptr + 8n, 0n) - WasmI32.store(iov, WasmI32.load(ptr, 4n), 4n) - WasmI32.store8(lf, 10n, 0n) - WasmI32.store(iov, lf, 8n) - WasmI32.store(iov, 1n, 12n) - fd_write(1n, iov, 2n, written) - Memory.free(buf) - void -} diff --git a/stdlib/runtime/utils/printing.md b/stdlib/runtime/utils/printing.md deleted file mode 100644 index 07480e41e..000000000 --- a/stdlib/runtime/utils/printing.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: Printing ---- - -## Values - -Functions and constants included in the Printing module. - -### Printing.**numberToString** - -```grain -numberToString : (n: WasmI64) => String -``` - -### Printing.**printNumber** - -```grain -printNumber : (n: WasmI64) => Void -``` - -### Printing.**printString** - -```grain -printString : (s: String) => Void -``` -