Moved Mars language to a separate repository. Partially refactored for the simple render pipeline. Incomplete refactor, does not build.

This commit is contained in:
paladin 2026-08-19 23:43:47 +01:00
parent 35cf269781
commit 1dcbcb3073
6 changed files with 20 additions and 172 deletions

View file

@ -5,7 +5,6 @@ use glam::camera::lh::proj::directx::perspective;
use wgpu::util::DeviceExt;
use glam::prelude::*;
struct Controller {
buttons: HashMap<MouseButton,bool>,
keys: HashMap<KeyCode,bool>,
@ -150,9 +149,20 @@ struct SimpleMaterial {
specular: Option<TexturePlan>,
}
struct SimpleModel {
affine: Affine3A,
material: mars::gc::Gc<SimpleMaterial>,
}
struct SimpleRenderPlan {
pipeline: wgpu::RenderPipeline,
clients: Kt<SimpleMesh,Kt<SimpleMaterial,Affine3A>>
// todo: clients: Kt<SimpleMesh,Kt<SimpleMaterial,Vec<Affine3A>>>
clients: Vec<SimpleModel>
}
struct FluidRigidBody {
}
pub struct State {

View file

@ -1,108 +0,0 @@
use std::alloc::{alloc, dealloc, Layout};
use std::any::Any;
use std::cell::{Ref, RefCell, RefMut};
use std::fmt::Debug;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
#[derive(Debug)]
pub struct Gc<T: ?Sized + Traverse> {
it: *mut RefCell<Header<T>>
}
impl<T: ?Sized + Traverse> Clone for Gc<T> {
fn clone(&self) -> Self {
Gc { it: self.it }
}
}
impl<T: ?Sized + Traverse> Traverse for Gc<T> {
fn traverse(&self) {
self.borrow().traverse()
}
}
impl<T: ?Sized + Traverse> PartialEq for Gc<T> {
fn eq(&self, other: &Gc<T>) -> bool {
self.it == other.it
}
}
impl<T: ?Sized + Traverse> Gc<T> {
pub(crate) fn borrow(&self) -> impl Deref<Target=T> {
Ref::map(unsafe { // ???
(*self.it).borrow()
},|it| &it.data)
}
pub(crate) fn borrow_mut(&self) -> impl DerefMut<Target=T> {
RefMut::map(unsafe {
(*self.it).borrow_mut()
},|it| &mut it.data)
}
}
#[derive(Clone, Debug, Copy)]
enum Color {
White,
Black,
}
#[repr(C)] // Trying to access everything but `item: T` while not knowing what T is...
struct Header<T: ?Sized + Traverse> {
layout: Layout,
color: Color, // NOT for incremental tri-color right now; white == mark-free, black == mark-keep
data: T
}
pub struct Allocator {
objects: Vec<Option<*mut RefCell<Header<dyn Traverse>>>>,
}
impl Allocator {
pub fn new() -> Allocator {
Allocator {
objects: Vec::new(),
}
}
pub fn alloc<T: Traverse + 'static>(&mut self, it: T) -> Gc<T> {
let layout = Layout::new::<RefCell<Header<T>>>();
let pointer = unsafe { alloc(layout) as *mut RefCell<Header<T>> };
let mut header = unsafe { pointer.as_mut() }.unwrap().borrow_mut();
header.layout = layout;
header.color = Color::Black;
header.data = it;
self.objects.push(Some(pointer as *mut RefCell<Header<dyn Traverse>>));
Gc {
it: pointer,
}
}
fn mark_white(&mut self) {
for i in 0..self.objects.len() {
if let Some(object) = self.objects[i] {
unsafe { (*object).borrow_mut().color = Color::White };
}
}
}
fn collect(&mut self) {
self.objects.retain(|object| {
if let Some(object) = object {
let header = unsafe { (**object).borrow_mut() };
match header.color {
Color::White => {
unsafe { dealloc(*object as *mut u8,header.layout); }
true
}
Color::Black => false
}
} else {
false
}
});
}
}
pub trait Traverse: Any + Debug {
fn traverse(&self) { // mark or grey
()
}
}

View file

@ -1,48 +0,0 @@
use std::alloc::{alloc, Layout};
use std::collections::HashMap;
use std::ptr::null_mut;
use crate::gc::{Gc, Traverse};
use crate::Value;
#[derive(Debug, Clone)]
pub struct Table {
table: (*mut [(Value, Value)],usize,usize),
array: (*mut [Value],usize,usize),
meta: Option<Gc<Table>>
}
impl Traverse for Table {
fn traverse(&self) {
unsafe {
if let Some(table) = self.table.0.as_ref() {
for (index,item) in table.iter() {
if !matches!(index,Value::Nil) {
index.traverse();
item.traverse();
}
}
}
if let Some(array) = self.array.0.as_ref() {
for item in array.iter() {
item.traverse();
}
}
}
}
}
impl Table {
pub fn set(index: Value, item: Value) {
}
pub fn get(index: Value) {
}
pub fn new() -> Self {
Table {
table: (null_mut::<[(Value,Value)]>().into(),0,0),
array: (null_mut().into(),0,0),
meta: None
}
}
}

View file

@ -1,12 +0,0 @@
local two
do
local one
if something then
local three
print(something)
end
local four
if something2 then
end
end