2020-05-11 22:02:48 -07:00
|
|
|
const std = @import("std");
|
|
|
|
const Type = @import("type.zig").Type;
|
|
|
|
const Value = @import("value.zig").Value;
|
|
|
|
const Allocator = std.mem.Allocator;
|
|
|
|
const TypedValue = @This();
|
|
|
|
|
|
|
|
ty: Type,
|
|
|
|
val: Value,
|
|
|
|
|
|
|
|
/// Memory management for TypedValue. The main purpose of this type
|
|
|
|
/// is to be small and have a deinit() function to free associated resources.
|
|
|
|
pub const Managed = struct {
|
|
|
|
/// If the tag value is less than Tag.no_payload_count, then no pointer
|
|
|
|
/// dereference is needed.
|
|
|
|
typed_value: TypedValue,
|
|
|
|
/// If this is `null` then there is no memory management needed.
|
|
|
|
arena: ?*std.heap.ArenaAllocator.State = null,
|
|
|
|
|
2020-05-13 17:06:01 -07:00
|
|
|
pub fn deinit(self: *Managed, allocator: *Allocator) void {
|
2020-05-11 22:02:48 -07:00
|
|
|
if (self.arena) |a| a.promote(allocator).deinit();
|
|
|
|
self.* = undefined;
|
|
|
|
}
|
|
|
|
};
|