Skip to content

Commit 30e431c

Browse files
committed
Use ui::error instead of asserts
1 parent d39111a commit 30e431c

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ set_property(TEST frozen_bridge_segfault.frank PROPERTY WILL_FAIL true)
9090
set_property(TEST unresolved_field.frank PROPERTY WILL_FAIL true)
9191
set_property(TEST unresolved_global.frank PROPERTY WILL_FAIL true)
9292
set_property(TEST unresolved_name.frank PROPERTY WILL_FAIL true)
93+
set_property(TEST func_no_return.frank PROPERTY WILL_FAIL true)

src/lang/interpreter.cc

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ namespace verona::interpreter
242242

243243
if (node == StoreFrame)
244244
{
245-
assert(frame()->get_stack_size() >= 1 && "the stack is too small");
245+
if (frame()->get_stack_size() < 1)
246+
{
247+
rt::ui::error("Interpreter: The stack is too small");
248+
}
246249
auto v = frame()->stack_pop("value to store");
247250
std::string field{node->location().view()};
248251
auto v2 = rt::set(frame()->object(), field, v);
@@ -252,7 +255,10 @@ namespace verona::interpreter
252255

253256
if (node == SwapFrame)
254257
{
255-
assert(frame()->get_stack_size() >= 1 && "the stack is too small");
258+
if (frame()->get_stack_size() < 1)
259+
{
260+
rt::ui::error("Interpreter: The stack is too small");
261+
}
256262
auto new_var = frame()->stack_pop("swap value");
257263
std::string field{node->location().view()};
258264

@@ -265,7 +271,10 @@ namespace verona::interpreter
265271

266272
if (node == LoadField)
267273
{
268-
assert(frame()->get_stack_size() >= 2 && "the stack is too small");
274+
if (frame()->get_stack_size() < 2)
275+
{
276+
rt::ui::error("Interpreter: The stack is too small");
277+
}
269278
auto k = frame()->stack_pop("lookup-key");
270279
auto v = frame()->stack_pop("lookup-value");
271280

@@ -293,7 +302,10 @@ namespace verona::interpreter
293302

294303
if (node == StoreField)
295304
{
296-
assert(frame()->get_stack_size() >= 3 && "the stack is too small");
305+
if (frame()->get_stack_size() < 3)
306+
{
307+
rt::ui::error("Interpreter: The stack is too small");
308+
}
297309
auto v = frame()->stack_pop("value to store");
298310
auto k = frame()->stack_pop("lookup-key");
299311
auto v2 = frame()->stack_pop("lookup-value");
@@ -307,7 +319,10 @@ namespace verona::interpreter
307319

308320
if (node == SwapField)
309321
{
310-
assert(frame()->get_stack_size() >= 3 && "the stack is too small");
322+
if (frame()->get_stack_size() < 3)
323+
{
324+
rt::ui::error("Interpreter: The stack is too small");
325+
}
311326
auto new_var = frame()->stack_pop("swap value");
312327
auto key = frame()->stack_pop("lookup-key");
313328
auto obj = frame()->stack_pop("lookup-value");
@@ -432,9 +447,11 @@ namespace verona::interpreter
432447
// solution would require more effort and would be messier
433448
auto dup_idx = std::stoul(std::string(node->location().view()));
434449
auto stack_size = frame()->get_stack_size();
435-
assert(
436-
dup_idx < stack_size &&
437-
"the stack is too small for this duplication");
450+
if (dup_idx > stack_size)
451+
{
452+
rt::ui::error(
453+
"Interpreter: the stack is too small for this duplication");
454+
}
438455

439456
auto var = frame()->stack_get(stack_size - dup_idx - 1);
440457
frame()->stack_push(var, "duplicated value");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def new(proto):
2+
fresh_obj = {}
3+
fresh_obj.__proto__ = proto
4+
5+
Obj = {} # Modelling the class as a prototype object
6+
7+
x = new(Obj)
8+
y = new(Obj)

0 commit comments

Comments
 (0)