From 9496b357c54ed826767e09650207b6a5c111bd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=BE=E6=B5=A6=20=E7=9F=A5=E4=B9=9F=20Matsuura=20Tomoy?= =?UTF-8?q?a?= Date: Mon, 23 Sep 2024 01:06:09 +0900 Subject: [PATCH] [obsidian] vault backup: 2024-09-23 01:06:09[ --- content/mimiumの配列のGC.md | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 content/mimiumの配列のGC.md diff --git a/content/mimiumの配列のGC.md b/content/mimiumの配列のGC.md new file mode 100644 index 00000000..80decba6 --- /dev/null +++ b/content/mimiumの配列のGC.md @@ -0,0 +1,65 @@ +--- +date: 2024-09-22 21:15 +--- + +Reference Countにする場合、Dropをどう実装するか + +drop_array()、drop_closure()をプリミティブ命令として用意する? + +プリミティブな値の配列ならそのまま開放してよし、オブジェクトを含む(配列の配列とか、クロージャの配列)なら再帰的にdropする必要あり + +drop命令をどのタイミングで挿入するか +mirgenでletの生存期間を調べるしかない +bindsでArgumentの区別はされてるから、環境参照してArgument以外を全部dropする、みたいな感じでええのか + +```rust + +enum UpvalueKind{ + Open{base_ptr:u64,offset:u64}, + Closed(ObjectIdx) +} +struct Upvalue{ + data:UpvalueKind, + ty: ObjType, +} + +type SharedUpValue = Rc> +struct Closure{ + pub fnproto_i: u64, + pub base_ptr: u64, //base pointer to current closure, to calculate open upvalue + pub is_closed: bool, + pub upvalues: Vec, + pub state_storage:StateStorage, +} +struct Array{ + pub d_size:TypeSize, + pub raw_data: Vec, +} +union HeapObject{ + clousre: Closure, + array: Array, + primitive: Vec, +} +struct RcObject{ + refcount:u64, + data: HeapObject +} +type = ObjectStorage=SlotMap; +type = ObjectIdx = DefaultKey; + +impl Machine{ +... + fn drop_closure(&mut self, objectid:ObjectIdx){ + let obj = self.get_object_mut(objectid); + obj.refcount-=1; + if obj.refcount==0{ + let cls = unsafe{ &obj.data.closure }; + cls.upvalue.iter().for_each(|upv|{ + upv + }) + self.object_storage.remove(objectid) + } + } +} + +``` \ No newline at end of file