diff options
author | JJ | 2024-05-10 01:00:01 +0000 |
---|---|---|
committer | JJ | 2024-05-10 02:41:52 +0000 |
commit | 073c902a31936c2b53d89245662fb272c9670169 (patch) | |
tree | a8789ed4561dc4c3dde84489a600272cbd5f806b /std/prelude/debug.pk | |
parent | 51c8b349a77a8d8b1b34ce8e03518dad6e3cba00 (diff) |
std: sweeping changes.
- replace interfaces with classes
- replace : with then and do
- solidify memory management as rust-style ownership
- replace unsafe blocks with safe/unsafe attributes
- add magic and copy attributes
- switch Coerce impl from from to to
Diffstat (limited to 'std/prelude/debug.pk')
-rw-r--r-- | std/prelude/debug.pk | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/std/prelude/debug.pk b/std/prelude/debug.pk index 3af1def..92d31dd 100644 --- a/std/prelude/debug.pk +++ b/std/prelude/debug.pk @@ -1,27 +1,22 @@ ## std.debug: Useful functions for debugging. ## This module is imported by default. -## The special ... syntax is used to mark unimplemented parts of code. -## Such code will compile, but panic upon being called at runtime. -## It is usable almost anywhere, including in type declarations, thanks to compiler magic. -pub func ...: never - ## The `assert` macro checks that a provided assertation is true, ## and panics and dumps information if it is not. -## Asserts remain in release builds. If not desired, see `debug_assert` +## Asserts remain in release builds. If not desired, see `dbg_assert` pub macro assert(cond: bool) = - quote: - if not `cond`: + quote + if not `cond` then panic "assertation failed!\n {}".fmt(dbg(`cond`)) -## The `debug_assert` function provides an assert that is compiled out in release builds. +## The `dbg_assert` function provides an assert that is compiled out in release builds. ## This is useful for debugging performance-critical code. -pub macro debug_assert(cond: bool) - quote: - when debug: # fixme: where is this coming from? +pub macro dbg_assert(cond: bool) = + quote + when debug then # fixme: where is this constant coming from? assert `cond` -## The `discard` function consumes any type. +## The `discard` function consumes an object of any type. ## Useful for throwing away the result of a computation. pub func discard[T](self: T) = return @@ -30,3 +25,10 @@ pub func discard[T](self: T) = pub func panic(message: str): never = stderr.write(message, "\n") std.os.exit(1) + +## The special ... syntax is used to mark unimplemented parts of code. +## Such code will compile, but panic upon being called at runtime. +## It is usable almost anywhere, including in type declarations, thanks to compiler magic. +@[magic] +pub func ...: never = + panic("unimplemented") |