Skip to content

Commit

Permalink
interpreter: Add some GC pointers where we hold temporaries
Browse files Browse the repository at this point in the history
There are a number of places where we hold a temporary value, and the garbage
collector is triggered for each evaluation. Replace these with GC pointers.

Signed-off-by: Christophe de Dinechin <[email protected]>
  • Loading branch information
c3d committed Jul 1, 2021
1 parent e382f22 commit 1e2a64d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ Tree *Bindings::Do(Prefix *what)
}
if (Infix *typecast = binding->AsInfix())
{
Tree *want = EvaluateType(typecast->right);
Tree_p want = EvaluateType(typecast->right);
Infix *vartype = IsTypeAnnotation(rewrite->left);
Tree *have = EvaluateType(vartype->right);
Tree_p have = EvaluateType(vartype->right);
Name *name = vartype->left->AsName();
if (!Tree::Equal(want, have))
{
Expand Down Expand Up @@ -292,10 +292,10 @@ Tree *Bindings::Do(Prefix *what)

// Check prefix left first, which may set 'defined' to name
test = pfx->left;
if (Tree *left = what->left->Do(this))
if (Tree_p left = what->left->Do(this))
{
test = pfx->right;
if (Tree *right = what->right->Do(this))
if (Tree_p right = what->right->Do(this))
{
if (left != pfx->left || right != pfx->right)
pfx = new Prefix(pfx, left, right);
Expand Down Expand Up @@ -331,10 +331,10 @@ Tree *Bindings::Do(Postfix *what)
{
// Check postfix right first, which maye set 'defined' to name
test = pfx->right;
if (Tree *right = what->right->Do(this))
if (Tree_p right = what->right->Do(this))
{
test = pfx->left;
if (Tree *left = what->left->Do(this))
if (Tree_p left = what->left->Do(this))
{
if (left != pfx->left || right != pfx->right)
pfx = new Postfix(pfx, left, right);
Expand Down Expand Up @@ -367,8 +367,8 @@ Tree *Bindings::Do(Infix *what)
if (Infix *cast = IsTypeCast(test))
{
test = cast->left;
Tree *wtype = EvaluateType(what->right);
Tree *ttype = EvaluateType(cast->right);
Tree_p wtype = EvaluateType(what->right);
Tree_p ttype = EvaluateType(cast->right);
if (wtype != ttype || HadErrors())
{
Ooops("Type $2 of $1", cast->right, cast);
Expand All @@ -378,7 +378,7 @@ Tree *Bindings::Do(Infix *what)

// Process the lambda name
defined = what;
if (Tree *result = declared->Do(this))
if (Tree_p result = declared->Do(this))
return result;
}

Expand All @@ -388,7 +388,7 @@ Tree *Bindings::Do(Infix *what)
}

// Need to evaluate the type on the right
Tree *want = EvaluateType(what->right);
Tree_p want = EvaluateType(what->right);
if (!want || HadErrors() || IsError(want))
return nullptr;

Expand All @@ -399,7 +399,7 @@ Tree *Bindings::Do(Infix *what)
}
else
{
Tree *checked = TypeCheck(EvaluationScope(), want, test);
Tree_p checked = TypeCheck(EvaluationScope(), want, test);
if (!checked)
{
Ooops("Value $1 does not belong to type $2", test, want);
Expand Down Expand Up @@ -427,7 +427,7 @@ Tree *Bindings::Do(Infix *what)
return nullptr;

// Here, we need to evaluate in the local context, not eval one
Tree *check = EvaluateGuard(what->right);
Tree_p check = EvaluateGuard(what->right);
if (check == xl_true)
return left;
else if (check != xl_false)
Expand Down Expand Up @@ -455,10 +455,10 @@ Tree *Bindings::Do(Infix *what)
}

test = ifx->left;
if (Tree *left = what->left->Do(this))
if (Tree_p left = what->left->Do(this))
{
test = ifx->right;
if (Tree *right = what->right->Do(this))
if (Tree_p right = what->right->Do(this))
{
if (left != ifx->left || right != ifx->right)
ifx = new Infix(ifx, left, right);
Expand All @@ -478,7 +478,7 @@ bool Bindings::MustEvaluate()
// Evaluate 'test', ensuring that each bound arg is evaluated at most once
// ----------------------------------------------------------------------------
{
Tree *evaluated = Evaluate(EvaluationScope(), test);
Tree_p evaluated = Evaluate(EvaluationScope(), test);

// For matching purpose, we need the value inside closures
while (Scope *scope = Context::IsClosure(evaluated))
Expand Down Expand Up @@ -556,7 +556,7 @@ Tree *Bindings::TypeCheck(Scope *scope, Tree *type, Tree *value)
}
return nullptr;
}
Tree *cast = cache.CachedTypeCheck(type, value);
Tree_p cast = cache.CachedTypeCheck(type, value);
if (!cast)
{
cast = Interpreter::DoTypeCheck(scope, type, value, cache);
Expand Down Expand Up @@ -607,7 +607,7 @@ Tree *Bindings::Bind(Name *name, Tree *value)
record(bindings, "Binding %t = %t", name, value);
if (!cache.Cached(value))
value = evalContext.Enclose(value);
Rewrite *rewrite = argContext.Define(name, value);
Rewrite_p rewrite = argContext.Define(name, value);
bindings.push_back(rewrite);
cache.Cache(name, value);
return value;
Expand All @@ -619,7 +619,7 @@ Tree *Bindings::Argument(unsigned n, bool unwrap)
// Unwrap all arguments before calling a builtin or native function
// ----------------------------------------------------------------------------
{
Tree *value = Binding(n)->right;
Tree_p value = Binding(n)->right;
while (Scope *scope = Context::IsClosure(value))
{
Prefix *closure = (Prefix *) (Tree *) value;
Expand All @@ -640,7 +640,7 @@ Tree *Bindings::NamedTree(unsigned n)
// Evaluate the given argument without evaluting bodies
// ----------------------------------------------------------------------------
{
Tree *value = Binding(n)->right;
Tree_p value = Binding(n)->right;
while (Scope *scope = Context::IsClosure(value))
{
Prefix *closure = (Prefix *) (Tree *) value;
Expand Down

0 comments on commit 1e2a64d

Please sign in to comment.