Skip to content

Commit

Permalink
refact(rivetc.codegen): use runtime_error to attempt to access a `n…
Browse files Browse the repository at this point in the history
…one` value
  • Loading branch information
StunxFS committed Nov 30, 2023
1 parent d236496 commit 5361b0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
16 changes: 4 additions & 12 deletions lib/core/src/lib.ri
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,27 @@ func runtime_error(s: string, args: ...Stringable) -> never {
#[inline]
func internal_alloc(size: uint) -> rawptr {
return mem_alloc(size) catch {
runtime_error(
"internal error: cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif
)
runtime_error("cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif)
};
}

#[inline]
func internal_zeroed(size: uint) -> rawptr {
return mem_zeroed(size) catch {
runtime_error(
"internal error: cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif
)
runtime_error("cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif)
};
}

#[inline]
func internal_dup(src: rawptr, sz: uint) -> rawptr {
return mem_dup(src, sz) catch {
runtime_error(
"internal error: cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif
)
runtime_error("cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif)
};
}

#[inline]
func internal_resize(ptr: ?rawptr, sz: uint) -> rawptr {
return mem_resize(ptr, sz) catch {
runtime_error(
"internal error: cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif
)
runtime_error("cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif)
};
}
10 changes: 1 addition & 9 deletions rivetc/src/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ def gen_expr(self, expr, custom_tmp = None):
)
value = ir.Selector(ir_typ, left, ir.Name("value"))
self.cur_fn.add_label(panic_l)
self.panic(f"attempt to use none value (`{expr.left}`)")
self.runtime_error(f"attempt to use none value (`{expr.left}`)")
self.cur_fn.add_label(exit_l)
return value
elif isinstance(left, ir.StringLit):
Expand Down Expand Up @@ -2628,14 +2628,6 @@ def runtime_error(self, msg):
]
)

def panic(self, msg):
self.cur_fn.add_call(
"_R4core13process_panicF", [
self.gen_string_literal(utils.smart_quote(msg, False)),
self.empty_vec(self.comp.universe["[]core.Stringable"])
]
)

def variadic_args(self, vargs, var_arg_typ_):
if len(vargs) == 0:
return self.empty_vec(var_arg_typ_.typ.symbol())
Expand Down

0 comments on commit 5361b0e

Please sign in to comment.