Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Bugfix release
Browse files Browse the repository at this point in the history
  • Loading branch information
fetch-bot committed Oct 8, 2018
1 parent ef14a4a commit 312df72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
15 changes: 9 additions & 6 deletions libs/vm/include/vm/defs.hpp
Expand Up @@ -34,7 +34,7 @@ struct Object
{}
Object(TypeId const &type_id__, VM *vm__)
{
count = 10; // TODO(private issue 213): Ref counter 1 segfaults
count = 1;
type_id = type_id__;
vm = vm__;
}
Expand Down Expand Up @@ -219,32 +219,33 @@ struct Value
type_id = other.type_id;
variant = other.variant;
other.type_id = TypeId::Unknown;
other.variant.Zero();
}

Value &operator=(Value &&other)
{
const bool is_object = IsObject();
const bool other_is_object = other.IsObject();

if (is_object && other_is_object)
{
if (variant.object != other.variant.object)
{
Release();
variant.object = other.variant.object;
type_id = other.type_id;
other.type_id = TypeId::Unknown;
type_id = other.type_id;
variant = other.variant;
other.type_id = TypeId::Unknown;
other.variant.Zero();
}
return *this;
}

if (is_object)
{
Release();
}
type_id = other.type_id;
variant = other.variant;
other.type_id = TypeId::Unknown;
other.variant.Zero();
return *this;
}

Expand All @@ -265,11 +266,13 @@ struct Value
Release();
}
type_id = TypeId::Unknown;
variant.Zero();
}

void PrimitiveReset()
{
type_id = TypeId::Unknown;
variant.Zero();
}

void AddRef()
Expand Down
42 changes: 21 additions & 21 deletions libs/vm/include/vm/vm.hpp
Expand Up @@ -34,16 +34,11 @@ struct String : public Object
bool is_literal;
String()
{}
String(VM *vm, std::string const &str__, const bool is_literal__)
String(VM *vm, std::string str__, const bool is_literal__)
: Object(TypeId::String, vm)
, str(std::move(str__))
, is_literal(is_literal__)
{}
String(VM *vm, std::string &&str__, const bool is_literal__)
: Object(TypeId::String, vm)
, str(str__)
, is_literal(is_literal__)
{}
virtual ~String()
{}
};
Expand Down Expand Up @@ -164,7 +159,7 @@ class VM
friend struct details::StorerClass;
/// }

static const int FRAME_STACK_SIZE = 40;
static const int FRAME_STACK_SIZE = 50;
static const int STACK_SIZE = 5000;
static const int MAX_LIVE_OBJECTS = 200;
static const int MAX_RANGE_LOOPS = 50;
Expand Down Expand Up @@ -226,24 +221,28 @@ class VM
break;
}
Value &variable = GetVariable(info.variable_index);
variable.Release();
variable.Reset();
--live_object_sp_;
}
}

void InvokeUserFunction(const Index index)
{
// check num frames, num variables, num objects?
// Note: the parameters are already on the stack
Frame frame;
frame.function = function_;
frame.bsp = bsp_;
frame.pc = pc_;
frame.function = function_;
frame.bsp = bsp_;
frame.pc = pc_;
if (frame_sp_ >= FRAME_STACK_SIZE - 1)
{
RuntimeError("frame stack overflow");
return;
}
frame_stack_[++frame_sp_] = frame;
bsp_ += function_->num_variables;
function_ = &(script_->functions[index]);
pc_ = 0;
// Note: the parameters are already on the stack
const int num_locals = function_->num_variables - function_->num_parameters;
function_ = &(script_->functions[index]);
bsp_ = sp_ - function_->num_parameters + 1; // first parameter
pc_ = 0;
const int num_locals = function_->num_variables - function_->num_parameters;
sp_ += num_locals;
}

Expand Down Expand Up @@ -920,7 +919,8 @@ class VM
rhsv.variant.Get(rhs);
Move(*ptr, rhs);
arrayv.Reset();
rhsv.PrimitiveReset();
rhsv.type_id = TypeId::Unknown;
rhsv.variant.Zero();
}

//
Expand Down Expand Up @@ -1183,7 +1183,7 @@ class VM
Value & rhsv = stack_[sp_--];
ElementType rhs;
rhsv.variant.Get(rhs);
Op::Apply(this, *ptr, rhs); // TODO(private issue 214): what if fails?
Op::Apply(this, *ptr, rhs);
matrixv.Reset();
rhsv.Reset();
}
Expand All @@ -1200,7 +1200,7 @@ class VM
Value & rhsv = stack_[sp_--];
ElementType rhs;
rhsv.variant.Get(rhs);
Op::Apply(this, *ptr, rhs); // TODO(private issue 214): what if fails?
Op::Apply(this, *ptr, rhs);
arrayv.Reset();
rhsv.Reset();
}
Expand All @@ -1218,7 +1218,7 @@ class VM
RHSVariantType xx;
rhsv.variant.Get(xx);
RHSElementType rhs = static_cast<RHSElementType>(xx);
Op::Apply(this, *ptr, rhs); // TODO(private issue 214): what if fails?
Op::Apply(this, *ptr, rhs);
arrayv.Reset();
rhsv.Reset();
}
Expand Down
7 changes: 6 additions & 1 deletion libs/vm/src/vm.cpp
Expand Up @@ -36,7 +36,7 @@ void VM::RuntimeError(const std::string &message)
std::stringstream stream;
stream << "runtime error: " << message;
error_ = stream.str();
error_line_ = std::size_t(this->instruction_->line);
error_line_ = std::size_t(instruction_->line);
stop_ = true;
}

Expand Down Expand Up @@ -501,6 +501,11 @@ bool VM::Execute(const Script &script, const std::string &name)
else
{
// We've finished executing
if (sp_ == 0)
{
// Reset the return value, if there was one, of the executed function
stack_[sp_--].Reset();
}
stop_ = true;
}
break;
Expand Down

0 comments on commit 312df72

Please sign in to comment.