From 4f1e82e70a7b6e4a21efd0d37486a26122bd9fb3 Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Wed, 12 Apr 2023 15:32:43 -0400 Subject: [PATCH] simplified object enum, added xml conversion --- kernel/src/interp/host_functions.rs | 9 ++------- kernel/src/interp/objects.rs | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/kernel/src/interp/host_functions.rs b/kernel/src/interp/host_functions.rs index f55ea7ed..86607d35 100644 --- a/kernel/src/interp/host_functions.rs +++ b/kernel/src/interp/host_functions.rs @@ -34,7 +34,7 @@ pub fn host_register_idt_handler( 0 } -use crate::interp::{Handle, objects::{Object, ObjectHeader, ObjectSpecial}}; +use crate::interp::{objects::Object, Handle}; pub fn host_make_object( mut caller: Caller<'_, HostState>, @@ -59,12 +59,7 @@ pub fn host_make_object( let hand = Handle::new(olock.len()); let obj = xml::XMLElement::new(name); - olock.push(Some(Object{ - header: ObjectHeader{ - - }, - special: ObjectSpecial::Xml(obj) - })); + olock.push(Some(Object::Raw(obj))); caller.data_mut().handles.push(hand); // hand.into() hand.as_u64().try_into().unwrap() diff --git a/kernel/src/interp/objects.rs b/kernel/src/interp/objects.rs index 3d9c24ec..50d845b6 100644 --- a/kernel/src/interp/objects.rs +++ b/kernel/src/interp/objects.rs @@ -2,15 +2,29 @@ use alloc::{vec, vec::Vec}; use spin::{Lazy, Mutex}; -pub struct Object { - pub header: ObjectHeader, - pub special: ObjectSpecial, +pub enum Object{ + Raw(xml::XMLElement) } -pub struct ObjectHeader {} +pub fn dump(o: Object) -> xml::XMLElement{ + match o{ + Object::Raw(x) => { + let mut e = xml::XMLElement::new("akern-internal-raw"); + e.children.push(x); + return e; + } + } +} -pub enum ObjectSpecial { - Xml(xml::XMLElement), +pub fn rest(x: xml::XMLElement) -> Option{ + let s: &str = &x.name; + match s{ + "akern-internal-raw" => { + let f = x.children.get(0)?; + return Some(Object::Raw(f.clone())) + } + _ => None + } } pub type HostObjects = Vec>;