From 696c86fef082ff3001a36caca8da2189ac190816 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 14 Aug 2018 16:22:50 -0700 Subject: [PATCH] Run GC after every code execution. --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index befe8e1..68b2449 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,6 +60,7 @@ class abacus_ref { abacus_ref(void* data, void (*free_func)(void*)); abacus_ref(const abacus_ref& other); abacus_ref& operator=(const abacus_ref& other); + abacus_ref& operator=(std::nullptr_t); operator libab_ref*() { return &ref; } @@ -83,6 +84,12 @@ abacus_ref& abacus_ref::operator=(const abacus_ref& other) { return *this; } +abacus_ref& abacus_ref::operator=(std::nullptr_t t) { + libab_ref_free(&ref); + libab_ref_null(&ref); + return *this; +} + abacus_ref::~abacus_ref() { libab_ref_free(&ref); } @@ -180,10 +187,12 @@ void abacus::add_function(const std::string& name, libab_function_ptr ptr, const abacus_ref abacus::run(const std::string& code) { abacus_ref value; libab_run_scoped(&ab, code.c_str(), scope, value); + libab_gc_run(&ab.containers); return value; } abacus::~abacus() { + scope = nullptr; libab_free(&ab); } @@ -195,5 +204,5 @@ int main() { ab.add_function("minus", function_minus, "(num, num)->num"); ab.add_function("times", function_times, "(num, num)->num"); ab.add_function("divide", function_divide, "(num, num)->num"); - ab.run("print(to_string(plus(1, times(3, 3))))"); + ab.run("fun test(): unit {}; print(to_string(plus(1, times(3, 3))))"); }