History

Create specific exception when index is out of range. Update thread class to print out exception details. Throw exception when an invalid op-code is detected. Enforce mspawn instruction cannot start from a built-in module.

arr committed 10 years ago

Commit 266fad61 parent 9af409310 files · +63 −40Browse files

Showing the changes to src/include (3 of 10 files). Show all

Unified · Split

3 files
  1. src/include/builtin_module.h +12 −3
  2. src/include/exceptions.h +9 −12
  3. src/include/runtime.h +1 −1
src/include/builtin_module.h+12−3
@@ -66,9 +66,18 @@ namespace disvm · 65 unmodified lines
6666 // Includes registers on base frame plus the implied return register
6767 static const auto default_register_count = (sizeof(vm_frame_base_alloc_t) / register_size_in_bytes) + 1;
6868
69− // See VM frame definition
70− static const auto fixed_point_register_1_frame_offset = default_register_count * register_size_in_bytes;
71− static const auto fixed_point_register_2_frame_offset = fixed_point_register_1_frame_offset + (2 * register_size_in_bytes);
69+ // [SPEC] The fixed point registers are defined by their usage in the
70+ // Inferno implementation. They rely on the 'temp' registers defined below.
71+ // See fixed point op-codes in Inferno (libinterp/xec.c).
72+ static const auto fixed_point_register_1_offset = default_register_count * register_size_in_bytes;
73+ static const auto fixed_point_register_2_offset = fixed_point_register_1_offset + (2 * register_size_in_bytes);
74+
75+ // [SPEC] The official Limbo compiler allocates additional 'temp' registers on all call frames.
76+ // See 'STemp', 'RTemp', and 'DTemp' in Inferno (limbo/limbo.h)
77+ static const auto limbo_temp_register_count = 3;
78+
79+ // Define the first argument offset in a Limbo compiler generated call frame.
80+ static const auto limbo_first_arg_register_offset = (default_register_count + limbo_temp_register_count) * register_size_in_bytes;
7281 };
7382
7483 //
src/include/exceptions.h+9−12
@@ -60,7 +60,7 @@ namespace disvm · 59 unmodified lines
6060 { }
6161 };
6262
63− class invalid_utf8 : public vm_user_exception
63+ class invalid_utf8 final : public vm_user_exception
6464 {
6565 public:
6666 explicit invalid_utf8()
@@ -84,7 +84,7 @@ namespace disvm · 17 unmodified lines
8484 const char *operation;
8585 };
8686
87− class type_violation : public vm_user_exception
87+ class type_violation final : public vm_user_exception
8888 {
8989 public:
9090 explicit type_violation()
@@ -92,26 +92,23 @@ namespace disvm · 1 unmodified line
9292 { }
9393 };
9494
95− class out_of_range_memory final : public vm_user_exception
95+ class out_of_range_memory : public vm_user_exception
9696 {
9797 public:
9898 explicit out_of_range_memory()
9999 : vm_user_exception("Out of range access")
100− , invalid_value{ 0 }
101− , range_defined{ false }
102− , valid_max{ 0 }
103− , valid_min{ 0 }
104100 { }
101+ };
105102
106− explicit out_of_range_memory(word_t valid_min, word_t valid_max, word_t invalid_valid)
107− : vm_user_exception("Out of range access")
108− , invalid_value{ invalid_valid }
109− , range_defined{ true }
103+ class index_out_of_range_memory final : public out_of_range_memory
104+ {
105+ public:
106+ explicit index_out_of_range_memory(word_t valid_min, word_t valid_max, word_t invalid_value)
107+ : invalid_value{ invalid_value }
110108 , valid_max{ valid_max }
111109 , valid_min{ valid_min }
112110 { }
113111
114− const bool range_defined;
115112 const word_t valid_min;
116113 const word_t valid_max;
117114 const word_t invalid_value;
src/include/runtime.h+1−1
@@ -759,7 +759,7 @@ namespace disvm · 758 unmodified lines
759759
760760 ~vm_thread_t();
761761
762− vm_thread_state_t execute(vm_t &virtual_machine, uint32_t quanta);
762+ vm_thread_state_t execute(vm_t &virtual_machine, const uint32_t quanta);
763763
764764 vm_thread_state_t get_state() const;
765765