Browse Source

use better formatting

master
Alison Watson 4 months ago
parent
commit
02632f81d3
39 changed files with 258 additions and 325 deletions
  1. +8
    -0
      rustfmt.toml
  2. +2
    -2
      source/framework/conf.rs
  3. +7
    -7
      source/framework/data/image.rs
  4. +10
    -10
      source/framework/data/model.rs
  5. +1
    -4
      source/framework/data/read.rs
  6. +7
    -7
      source/framework/data/text.rs
  7. +7
    -12
      source/framework/data/vfs.rs
  8. +17
    -23
      source/framework/defl.rs
  9. +2
    -2
      source/framework/hal/evt.rs
  10. +2
    -6
      source/framework/hal/win.rs
  11. +1
    -3
      source/framework/log.rs
  12. +8
    -10
      source/framework/log/color.rs
  13. +7
    -7
      source/framework/log/level.rs
  14. +1
    -4
      source/framework/log/standard.rs
  15. +7
    -17
      source/framework/render/buffer.rs
  16. +1
    -2
      source/framework/render/cmd.rs
  17. +4
    -4
      source/framework/render/conf.rs
  18. +2
    -4
      source/framework/render/descriptorpool.rs
  19. +5
    -10
      source/framework/render/device.rs
  20. +1
    -2
      source/framework/render/fence.rs
  21. +4
    -8
      source/framework/render/framebuffer.rs
  22. +13
    -20
      source/framework/render/image.rs
  23. +2
    -5
      source/framework/render/instance.rs
  24. +2
    -5
      source/framework/render/model.rs
  25. +2
    -4
      source/framework/render/pipeline.rs
  26. +1
    -3
      source/framework/render/properties.rs
  27. +1
    -2
      source/framework/render/queue.rs
  28. +1
    -2
      source/framework/render/renderpass.rs
  29. +1
    -2
      source/framework/render/sampler.rs
  30. +1
    -2
      source/framework/render/semaphore.rs
  31. +1
    -2
      source/framework/render/shader.rs
  32. +1
    -2
      source/framework/render/surface.rs
  33. +2
    -4
      source/framework/render/swapchain.rs
  34. +10
    -11
      source/framework/vire/compiler/function.rs
  35. +10
    -10
      source/framework/vire/compiler/types.rs
  36. +16
    -16
      source/framework/vire/parser.rs
  37. +74
    -75
      source/framework/vire/parser/tok.rs
  38. +14
    -14
      source/main_test/entry.rs
  39. +2
    -2
      source/main_test/main.rs

+ 8
- 0
rustfmt.toml View File

@@ -1,6 +1,14 @@
edition = "2018"
fn_args_layout = "Compressed"
force_explicit_abi = true
hard_tabs = true
match_arm_leading_pipes = "Always"
max_width = 79
merge_derives = true
newline_style = "Unix"
remove_nested_parens = true
reorder_imports = true
reorder_modules = true
tab_spaces = 3
use_field_init_shorthand = true
use_small_heuristics = "Max"

+ 2
- 2
source/framework/conf.rs View File

@@ -18,8 +18,8 @@ pub enum ErrConfLoad {
impl From<std::io::Error> for ErrConfLoad {
fn from(err: std::io::Error) -> Self {
match err.kind() {
std::io::ErrorKind::NotFound => Self::NoFile,
_ => Self::File(err),
| std::io::ErrorKind::NotFound => Self::NoFile,
| _ => Self::File(err),
}
}
}


+ 7
- 7
source/framework/data/image.rs View File

@@ -74,9 +74,9 @@ impl Image {

// make sure the encoding is OK
let alpha = match head[16] {
24 => false,
32 => true,
_ => return Err(ErrImageRead::Encoding),
| 24 => false,
| 32 => true,
| _ => return Err(ErrImageRead::Encoding),
};

let descr = head[17];
@@ -204,8 +204,8 @@ where

fn next(&mut self) -> Option<Self::Item> {
match self {
Self::Not(it) => it.next(),
Self::Rev(it) => it.next_back(),
| Self::Not(it) => it.next(),
| Self::Rev(it) => it.next_back(),
}
}
}
@@ -216,8 +216,8 @@ where
{
fn len(&self) -> usize {
match self {
Self::Not(it) => it.len(),
Self::Rev(it) => it.len(),
| Self::Not(it) => it.len(),
| Self::Rev(it) => it.len(),
}
}
}


+ 10
- 10
source/framework/data/model.rs View File

@@ -93,8 +93,8 @@ impl Iterator for VertexZipper {
self.wgt_v.next(),
self.clr_v.next(),
) {
(None, None, None, None, None, None) => None,
tuple => Some(tuple),
| (None, None, None, None, None, None) => None,
| tuple => Some(tuple),
}
}
}
@@ -187,7 +187,7 @@ impl Model {
rd.seek(SeekFrom::Start(of))?;

match ty {
0 => {
| 0 => {
for pos in read::hunk(rd, 4 * 3 * num_vert)?.chunks(4 * 3) {
let x = read::f32le_32(pos, 0);
let y = read::f32le_32(pos, 4);
@@ -195,14 +195,14 @@ impl Model {
pos_v.push(Vec3A::new(x, y, z));
}
}
1 => {
| 1 => {
for tex in read::hunk(rd, 4 * 2 * num_vert)?.chunks(4 * 2) {
let u = read::f32le_32(tex, 0);
let v = read::f32le_32(tex, 4);
tex_v.push(Vec3A::new(u, v, 0.0));
}
}
2 => {
| 2 => {
for nrm in read::hunk(rd, 4 * 3 * num_vert)?.chunks(4 * 3) {
let x = read::f32le_32(nrm, 0);
let y = read::f32le_32(nrm, 4);
@@ -210,10 +210,10 @@ impl Model {
nrm_v.push(Vec3A::new(x, y, z));
}
}
3 => {
| 3 => {
// ignore tangents for now
}
4 => {
| 4 => {
for idx in read::hunk(rd, 4 * num_vert)?.chunks(4) {
let idx0 = f32::from(idx[0]);
let idx1 = f32::from(idx[1]);
@@ -222,7 +222,7 @@ impl Model {
idx_v.push(Vec4::new(idx0, idx1, idx2, idx3));
}
}
5 => {
| 5 => {
for wgt in read::hunk(rd, 4 * num_vert)?.chunks(4) {
let wgt0 = f32::from(wgt[0]) / 255.0;
let wgt1 = f32::from(wgt[1]) / 255.0;
@@ -231,7 +231,7 @@ impl Model {
wgt_v.push(Vec4::new(wgt0, wgt1, wgt2, wgt3));
}
}
6 => {
| 6 => {
for clr in read::hunk(rd, 4 * num_vert)?.chunks(4) {
let r = f32::from(clr[0]) / 255.0;
let g = f32::from(clr[1]) / 255.0;
@@ -240,7 +240,7 @@ impl Model {
clr_v.push(Vec4::new(r, g, b, a));
}
}
_ => return Err(Err::UnknownType),
| _ => return Err(Err::UnknownType),
}
}



+ 1
- 4
source/framework/data/read.rs View File

@@ -25,10 +25,7 @@ pub fn f32le_32(b: &[u8], p: usize) -> f32 {
}

pub fn array<'a, 'b, T>(
f: impl Fn(&[u8], usize) -> T,
b: &'a [u8],
v: &'b mut [T],
step: usize,
f: impl Fn(&[u8], usize) -> T, b: &'a [u8], v: &'b mut [T], step: usize,
beg: usize,
) -> &'b [T] {
for (i, p) in (beg..beg + v.len() * step).step_by(step).enumerate() {


+ 7
- 7
source/framework/data/text.rs View File

@@ -25,16 +25,16 @@ impl Iterator for PosReader<'_> {

fn next(&mut self) -> Option<Self::Item> {
match self.itr.next() {
Some('\n') => {
| Some('\n') => {
self.pos.line += 1;
self.pos.colu = 0;
Some('\n')
}
Some(c) => {
| Some(c) => {
self.pos.colu += 1;
Some(c)
}
None => None,
| None => None,
}
}
}
@@ -107,10 +107,10 @@ pub fn ellipsize_small_str(inp: &str) -> ([u8; 32], usize) {
pub const fn radix(c: char) -> u8 {
c as u8
- match c {
'a'..='z' => 0x61 - 10,
'A'..='Z' => 0x41 - 10,
'0'..='9' => 0x30,
_ => 0,
| 'a'..='z' => 0x61 - 10,
| 'A'..='Z' => 0x41 - 10,
| '0'..='9' => 0x30,
| _ => 0,
}
}



+ 7
- 12
source/framework/data/vfs.rs View File

@@ -2,8 +2,7 @@ use crate::{data::read, defl};
use smol_str::SmolStr;
use std::{
collections::HashMap,
fmt,
fs,
fmt, fs,
hash::Hasher,
io::{self, Read},
iter::FromIterator,
@@ -60,8 +59,7 @@ fn path_to_local(top_path: &Path, path: &Path) -> SmolStr {
}

fn file_ref(
file_dat: &mut HashMap<u64, File>,
mut data: Vec<u8>,
file_dat: &mut HashMap<u64, File>, mut data: Vec<u8>,
) -> Result<u64, ErrArc> {
// un-gzip
if let Some(data_p) = defl::read_gzip(&data) {
@@ -114,9 +112,7 @@ impl Arc {

pub fn read_dir(path: &Path) -> Result<Pin<Box<Self>>, ErrArc> {
fn recurse(
top_path: &Path,
cur_path: &Path,
file_dat: &mut HashMap<u64, File>,
top_path: &Path, cur_path: &Path, file_dat: &mut HashMap<u64, File>,
name_map: &mut HashMap<SmolStr, u64>,
) -> Result<(), ErrArc> {
for ent in fs::read_dir(cur_path)? {
@@ -177,16 +173,16 @@ impl Arc {
}

match ftyp {
'g' | 'x' | 'A'..='Z' | '5' => {
| 'g' | 'x' | 'A'..='Z' | '5' => {
// skip extensions and directories entirely
}
'0' | '\0' | '7' => {
| '0' | '\0' | '7' => {
// file plus padding
let data = read::hunk(rd, size)?;
rd.read_exact(&mut junk[..512 - size % 512])?;
name_map.insert(name, file_ref(&mut file_dat, data)?);
}
_ => {
| _ => {
// some unsupported type
return Err(ErrArc::FileType(name));
}
@@ -201,8 +197,7 @@ impl Arc {
}

fn finalize(
file_dat: HashMap<u64, File>,
name_map: HashMap<SmolStr, u64>,
file_dat: HashMap<u64, File>, name_map: HashMap<SmolStr, u64>,
) -> Result<Pin<Box<Self>>, ErrArc> {
// create a flat map of names
let mut refs_dat = Vec::with_capacity(name_map.len());


+ 17
- 23
source/framework/defl.rs View File

@@ -110,10 +110,10 @@ pub fn read_defl(b: &[u8], p: &mut usize) -> Result<Vec<u8>, Err> {
*p += 3;

match bstype {
0b10 => st_dynamic(b, p, &mut v)?,
0b01 => st_s_table(b, p, &mut v)?,
0b00 => st_literal(b, p, &mut v)?,
_ => return Err(Err::BlockType),
| 0b10 => st_dynamic(b, p, &mut v)?,
| 0b01 => st_s_table(b, p, &mut v)?,
| 0b00 => st_literal(b, p, &mut v)?,
| _ => return Err(Err::BlockType),
}

if bfinal == 1 {
@@ -171,9 +171,9 @@ fn st_s_table(b: &[u8], p: &mut usize, v: &mut Vec<u8>) -> Result<(), Err> {

for (i, len) in len.iter_mut().enumerate() {
*len = match i {
144..=255 => 9,
256..=279 => 7,
_ => 8,
| 144..=255 => 9,
| 256..=279 => 7,
| _ => 8,
};
}

@@ -208,10 +208,7 @@ fn next_alpha(alpha: &mut [u16], i: &mut usize, n: u16) -> Result<(), Err> {
}

fn read_alphabet(
b: &[u8],
p: &mut usize,
n: usize,
table: &HuffmanTable,
b: &[u8], p: &mut usize, n: usize, table: &HuffmanTable,
) -> Result<Vec<u16>, Err> {
let mut alpha = vec![0; n];
let mut i = 0;
@@ -220,11 +217,11 @@ fn read_alphabet(
let ty = table.decode(b, p)?;

match ty {
0..=15 => {
| 0..=15 => {
// raw code
next_alpha(&mut alpha, &mut i, ty)?;
}
16 => {
| 16 => {
// copy previous code 3-6 times
let lst = *alpha.get(i - 1).ok_or(Err::BitsCode)?;
let len = u8::read_bits_le(b, *p, 2).ok_or(Err::BitsCode)? + 3;
@@ -234,7 +231,7 @@ fn read_alphabet(
next_alpha(&mut alpha, &mut i, lst)?;
}
}
17 => {
| 17 => {
// repeat '0' 3-10 times
let len = u8::read_bits_le(b, *p, 3).ok_or(Err::Bits0)? + 3;
*p += 3;
@@ -243,7 +240,7 @@ fn read_alphabet(
next_alpha(&mut alpha, &mut i, 0)?;
}
}
18 => {
| 18 => {
// repeat '0' 11-138 times
let len = u8::read_bits_le(b, *p, 7).ok_or(Err::Bits0)? + 11;
*p += 7;
@@ -252,7 +249,7 @@ fn read_alphabet(
next_alpha(&mut alpha, &mut i, 0)?;
}
}
_ => {
| _ => {
return Err(Err::Symbol);
}
}
@@ -262,10 +259,7 @@ fn read_alphabet(
}

fn output_tables(
b: &[u8],
p: &mut usize,
v: &mut Vec<u8>,
table_len: &HuffmanTable,
b: &[u8], p: &mut usize, v: &mut Vec<u8>, table_len: &HuffmanTable,
table_dst: &HuffmanTable,
) -> Result<(), Err> {
const LEN_BASE: [usize; 29] = [
@@ -293,15 +287,15 @@ fn output_tables(
let ty = table_len.decode(b, p)?;

match ty.cmp(&256) {
Ordering::Less => {
| Ordering::Less => {
// direct byte
v.push(ty as u8);
}
Ordering::Equal => {
| Ordering::Equal => {
// finished
return Ok(());
}
Ordering::Greater => {
| Ordering::Greater => {
// <len, dst> pair

// decode the length (plus extra bits)


+ 2
- 2
source/framework/hal/evt.rs View File

@@ -23,8 +23,8 @@ impl Iterator for EventIterator {
fn read_in(evt: sdl::SDL_Event) -> Option<Event> {
let typ = unsafe { std::mem::transmute(evt.type_) };
match typ {
sdl::SDL_EventType::SDL_QUIT => Some(Event::Quit),
_ => None,
| sdl::SDL_EventType::SDL_QUIT => Some(Event::Quit),
| _ => None,
}
}



+ 2
- 6
source/framework/hal/win.rs View File

@@ -13,10 +13,7 @@ pub struct Window<'a> {

impl<'a> Window<'a> {
pub fn new(
_hal: &'a ctx::Context,
title: ffi::Nts,
w: i16,
h: i16,
_hal: &'a ctx::Context, title: ffi::Nts, w: i16, h: i16,
) -> Result<Self, Err> {
let handle = unsafe {
sdl::SDL_CreateWindow(
@@ -66,8 +63,7 @@ impl<'a> Window<'a> {
}

pub fn vulkan_create_surface(
&self,
instance: &crate::render::Instance,
&self, instance: &crate::render::Instance,
) -> Result<vk::SurfaceKHR, Err> {
let mut surface = 0;
let res = unsafe {


+ 1
- 3
source/framework/log.rs View File

@@ -117,9 +117,7 @@ impl Log {
}

pub fn write_into(
&self,
args: std::fmt::Arguments,
record: Record,
&self, args: std::fmt::Arguments, record: Record,
out: &mut impl std::io::Write,
) -> std::io::Result<()> {
writeln!(


+ 8
- 10
source/framework/log/color.rs View File

@@ -7,21 +7,19 @@ pub struct Color;

impl Color {
fn write_level(
&self,
level: Level,
out: &mut impl WriteColor,
&self, level: Level, out: &mut impl WriteColor,
) -> std::io::Result<()> {
use termcolor::Color;

let (color, intense) = match level {
Level::Critical => (Color::Red, true),
Level::Error => (Color::Red, false),
Level::Warning => (Color::Yellow, true),
Level::Notice => (Color::Yellow, false),
Level::Info => (Color::Cyan, true),
Level::Debug => (Color::Cyan, false),
| Level::Critical => (Color::Red, true),
| Level::Error => (Color::Red, false),
| Level::Warning => (Color::Yellow, true),
| Level::Notice => (Color::Yellow, false),
| Level::Info => (Color::Cyan, true),
| Level::Debug => (Color::Cyan, false),
#[cfg(debug_assertions)]
Level::Trace => (Color::Magenta, true),
| Level::Trace => (Color::Magenta, true),
};

let mut spec = ColorSpec::new();


+ 7
- 7
source/framework/log/level.rs View File

@@ -33,14 +33,14 @@ impl Default for Level {
impl fmt::Display for Level {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Critical => f.write_str("Critical"),
Self::Error => f.write_str("Error"),
Self::Warning => f.write_str("Warning"),
Self::Notice => f.write_str("Notice"),
Self::Info => f.write_str("Info"),
Self::Debug => f.write_str("Debug"),
| Self::Critical => f.write_str("Critical"),
| Self::Error => f.write_str("Error"),
| Self::Warning => f.write_str("Warning"),
| Self::Notice => f.write_str("Notice"),
| Self::Info => f.write_str("Info"),
| Self::Debug => f.write_str("Debug"),
#[cfg(debug_assertions)]
Self::Trace => f.write_str("Trace"),
| Self::Trace => f.write_str("Trace"),
}
}
}


+ 1
- 4
source/framework/log/standard.rs View File

@@ -5,10 +5,7 @@ pub struct Std;

impl Std {
fn write_into(
&self,
args: std::fmt::Arguments,
record: Record,
log: &Log,
&self, args: std::fmt::Arguments, record: Record, log: &Log,
out: &mut impl Write,
) -> std::io::Result<()> {
write!(out, "[{:^8}]", record.level)?;


+ 7
- 17
source/framework/render/buffer.rs View File

@@ -15,9 +15,7 @@ pub struct Buffer {
}

unsafe fn create_buffer(
device: &Device,
size: vk::DeviceSize,
usage: vk::BufferUsageFlags,
device: &Device, size: vk::DeviceSize, usage: vk::BufferUsageFlags,
memory_flags: vk::MemoryPropertyFlags,
) -> Result<(vk::Buffer, vk::DeviceMemory), ErrAllocMem> {
let create_info = vk::BufferCreateInfo {
@@ -48,8 +46,7 @@ impl GetDevice for Buffer {
impl Buffer {
/// Creates a vertex buffer.
pub fn create_vert(
cmd_pool: &CommandPool,
vertices: &[Vertex],
cmd_pool: &CommandPool, vertices: &[Vertex],
) -> Result<Rc<Self>, ErrAllocMem> {
let device = cmd_pool.get_device().clone();
let size = dev_size_of(vertices);
@@ -73,8 +70,7 @@ impl Buffer {

/// Creates an index buffer.
pub fn create_indx(
cmd_pool: &CommandPool,
indices: &[u32],
cmd_pool: &CommandPool, indices: &[u32],
) -> Result<Rc<Self>, ErrAllocMem> {
let device = cmd_pool.get_device().clone();
let size = dev_size_of(indices);
@@ -98,8 +94,7 @@ impl Buffer {

/// Creates an image buffer.
pub fn create_image(
device: Rc<Device>,
images: &[data::image::Image],
device: Rc<Device>, images: &[data::image::Image],
) -> Result<Rc<Self>, ErrAllocMem> {
let size =
images.iter().fold(0, |acc, img| acc + dev_size_of(img.data()));
@@ -131,8 +126,7 @@ impl Buffer {

/// Creates a uniform buffer.
pub fn create_uniform(
device: Rc<Device>,
size: vk::DeviceSize,
device: Rc<Device>, size: vk::DeviceSize,
) -> Result<Rc<Self>, ErrAllocMem> {
let (handle, memory) = unsafe {
create_buffer(
@@ -149,9 +143,7 @@ impl Buffer {

/// Copies the contents of `src` to `self` using a transient pool.
unsafe fn copy_buffer(
&self,
src: &Self,
cmd_pool: &CommandPool,
&self, src: &Self, cmd_pool: &CommandPool,
) -> Result<(), vk::Result> {
cmd_pool.with_transient_buffer(|cbuf| {
let copy =
@@ -165,9 +157,7 @@ impl Buffer {

/// Transfers `data` from the client to the server.
pub fn xfer_data<T>(
&self,
cmd_pool: &CommandPool,
data: &[T],
&self, cmd_pool: &CommandPool, data: &[T],
) -> Result<(), ErrAllocMem> {
let size = dev_size_of(data);



+ 1
- 2
source/framework/render/cmd.rs View File

@@ -92,8 +92,7 @@ impl CommandPool {

impl CommandBuffers {
pub fn allocate(
pool: Rc<CommandPool>,
amount: usize,
pool: Rc<CommandPool>, amount: usize,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::CommandBufferAllocateInfo {
command_pool: **pool,


+ 4
- 4
source/framework/render/conf.rs View File

@@ -22,10 +22,10 @@ pub struct Conf {
impl From<PresentMode> for vk::PresentModeKHR {
fn from(mode: PresentMode) -> Self {
match mode {
PresentMode::Fifo => Self::FIFO,
PresentMode::FifoRelaxed => Self::FIFO_RELAXED,
PresentMode::Immediate => Self::IMMEDIATE,
PresentMode::Mailbox => Self::MAILBOX,
| PresentMode::Fifo => Self::FIFO,
| PresentMode::FifoRelaxed => Self::FIFO_RELAXED,
| PresentMode::Immediate => Self::IMMEDIATE,
| PresentMode::Mailbox => Self::MAILBOX,
}
}
}


+ 2
- 4
source/framework/render/descriptorpool.rs View File

@@ -22,10 +22,8 @@ impl GetDevice for DescriptorPool {

impl DescriptorPool {
pub fn create(
layout: Rc<DescriptorSetLayout>,
buffers: Vec<(Rc<Buffer>, Rc<Buffer>)>,
image_view: Rc<ImageView>,
sampler: Rc<Sampler>,
layout: Rc<DescriptorSetLayout>, buffers: Vec<(Rc<Buffer>, Rc<Buffer>)>,
image_view: Rc<ImageView>, sampler: Rc<Sampler>,
) -> Result<Rc<Self>, vk::Result> {
let size_info = [
vk::DescriptorPoolSize {


+ 5
- 10
source/framework/render/device.rs View File

@@ -50,8 +50,7 @@ pub trait GetDevice {
}

fn enable_device_extensions(
physical: &PhysicalDevice,
extensions: &[crate::ffi::Nts],
physical: &PhysicalDevice, extensions: &[crate::ffi::Nts],
) -> Result<vk::DeviceCreateInfo, ErrDeviceCreate> {
if !extensions.is_empty() {
let props = unsafe {
@@ -70,8 +69,7 @@ fn enable_device_extensions(

fn get_memory_type(
memory_props: vk::PhysicalDeviceMemoryProperties,
filter_flags: vk::MemoryPropertyFlags,
filter_types: u32,
filter_flags: vk::MemoryPropertyFlags, filter_types: u32,
) -> Result<u32, ErrAllocMem> {
let count = memory_props.memory_type_count as usize;
let iter = memory_props.memory_types.iter().take(count).enumerate();
@@ -90,8 +88,7 @@ fn get_memory_type(

impl Device {
pub fn create(
physical: Rc<PhysicalDevice>,
qf_info: &QueueFamilyInfo,
physical: Rc<PhysicalDevice>, qf_info: &QueueFamilyInfo,
) -> Result<Rc<Self>, ErrDeviceCreate> {
const QUEUE_PRIORITY: [f32; 1] = [1.0];

@@ -134,8 +131,7 @@ impl Device {
}

pub fn alloc_mem(
&self,
memory_reqs: vk::MemoryRequirements,
&self, memory_reqs: vk::MemoryRequirements,
memory_flags: vk::MemoryPropertyFlags,
) -> Result<vk::DeviceMemory, ErrAllocMem> {
unsafe {
@@ -163,8 +159,7 @@ impl Device {

impl PhysicalDevice {
pub fn get(
instance: Rc<Instance>,
conf: &Conf,
instance: Rc<Instance>, conf: &Conf,
) -> Result<Rc<Self>, ErrPhysicalDeviceGet> {
let devs = unsafe { instance.enumerate_physical_devices()? };



+ 1
- 2
source/framework/render/fence.rs View File

@@ -25,8 +25,7 @@ impl Fence {
}

pub fn create_all(
device: Rc<Device>,
num: usize,
device: Rc<Device>, num: usize,
) -> Result<Vec<Rc<Self>>, vk::Result> {
(0..num).map(|_| Self::create(device.clone())).collect()
}


+ 4
- 8
source/framework/render/framebuffer.rs View File

@@ -18,10 +18,8 @@ impl GetDevice for Framebuffer {

impl Framebuffer {
pub fn create(
render_pass: Rc<RenderPass>,
image_view: Rc<ImageView>,
depth_view: Rc<ImageView>,
image_extent: vk::Extent2D,
render_pass: Rc<RenderPass>, image_view: Rc<ImageView>,
depth_view: Rc<ImageView>, image_extent: vk::Extent2D,
) -> Result<Rc<Self>, vk::Result> {
let attachments = [**image_view, **depth_view];

@@ -43,10 +41,8 @@ impl Framebuffer {
}

pub fn create_all(
render_pass: Rc<RenderPass>,
image_views: &[Rc<ImageView>],
depth_view: Rc<ImageView>,
extent: vk::Extent2D,
render_pass: Rc<RenderPass>, image_views: &[Rc<ImageView>],
depth_view: Rc<ImageView>, extent: vk::Extent2D,
) -> Result<Vec<Rc<Self>>, vk::Result> {
image_views
.iter()


+ 13
- 20
source/framework/render/image.rs View File

@@ -59,8 +59,8 @@ impl GetDevice for IndepImage {
impl GetDevice for Image {
fn get_device(&self) -> &Rc<Device> {
match self {
Self::Owned(image) => image.get_device(),
Self::Indep(image) => image.get_device(),
| Self::Owned(image) => image.get_device(),
| Self::Indep(image) => image.get_device(),
}
}
}
@@ -104,8 +104,7 @@ impl ImageInfo {

impl IndepImage {
pub fn create(
cmd_pool: &CommandPool,
mip: &MipImage,
cmd_pool: &CommandPool, mip: &MipImage,
) -> Result<Self, ErrAllocMem> {
let device = cmd_pool.get_device().clone();

@@ -152,9 +151,7 @@ impl IndepImage {
}

pub fn create_depth(
cmd_pool: &CommandPool,
width: u32,
height: u32,
cmd_pool: &CommandPool, width: u32, height: u32,
) -> Result<Self, ErrAllocMem> {
let device = cmd_pool.get_device().clone();

@@ -188,9 +185,7 @@ impl IndepImage {
}

fn layout_barrier(
&self,
cmd_pool: &CommandPool,
layout_stage: LayoutStage,
&self, cmd_pool: &CommandPool, layout_stage: LayoutStage,
) -> Result<(), vk::Result> {
let (
old_layout,
@@ -200,7 +195,7 @@ impl IndepImage {
src_stage,
dst_stage,
) = match layout_stage {
LayoutStage::Xfer => (
| LayoutStage::Xfer => (
vk::ImageLayout::UNDEFINED,
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
vk::AccessFlags::empty(),
@@ -208,7 +203,7 @@ impl IndepImage {
vk::PipelineStageFlags::TOP_OF_PIPE,
vk::PipelineStageFlags::TRANSFER,
),
LayoutStage::Dpth => (
| LayoutStage::Dpth => (
vk::ImageLayout::UNDEFINED,
vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
vk::AccessFlags::empty(),
@@ -217,7 +212,7 @@ impl IndepImage {
vk::PipelineStageFlags::TOP_OF_PIPE,
vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS,
),
LayoutStage::Frag => (
| LayoutStage::Frag => (
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL,
vk::AccessFlags::TRANSFER_WRITE,
@@ -265,9 +260,7 @@ impl IndepImage {
}

fn copy_mips_to_image(
&self,
cmd_pool: &CommandPool,
mip: &MipImage,
&self, cmd_pool: &CommandPool, mip: &MipImage,
) -> Result<(), ErrAllocMem> {
let buffer =
Buffer::create_image(cmd_pool.get_device().clone(), mip.data())?;
@@ -324,8 +317,8 @@ impl Image {

pub const fn info(&self) -> &ImageInfo {
match self {
Self::Owned(image) => &image.info,
Self::Indep(image) => &image.info,
| Self::Owned(image) => &image.info,
| Self::Indep(image) => &image.info,
}
}
}
@@ -357,8 +350,8 @@ impl std::ops::Deref for Image {
type Target = vk::Image;
fn deref(&self) -> &Self::Target {
match self {
Self::Owned(image) => &image.handle,
Self::Indep(image) => &image.handle,
| Self::Owned(image) => &image.handle,
| Self::Indep(image) => &image.handle,
}
}
}


+ 2
- 5
source/framework/render/instance.rs View File

@@ -30,8 +30,7 @@ pub enum ErrInstanceCreate {
}

fn enable_instance_layers(
layers: &[crate::ffi::Nts],
entry: &ash::Entry,
layers: &[crate::ffi::Nts], entry: &ash::Entry,
) -> Result<vk::InstanceCreateInfo, ErrInstanceCreate> {
if !layers.is_empty() {
let props = entry.enumerate_instance_layer_properties()?;
@@ -47,9 +46,7 @@ fn enable_instance_layers(

impl Instance {
pub fn create(
conf: &Conf,
entry: ash::Entry,
window: &hal::win::Window,
conf: &Conf, entry: ash::Entry, window: &hal::win::Window,
) -> Result<Rc<Self>, ErrInstanceCreate> {
let exts = window.vulkan_instance_extensions()?;



+ 2
- 5
source/framework/render/model.rs View File

@@ -26,8 +26,7 @@ impl GetDevice for Model {

impl Model {
pub fn create(
cmd_pool: &CommandPool,
model: data::model::Model,
cmd_pool: &CommandPool, model: data::model::Model,
model_data: data::model::ModelData,
) -> Result<Rc<Self>, ErrAllocMem> {
let vtx_buf = Buffer::create_vert(cmd_pool, &model_data.vtx)?;
@@ -37,9 +36,7 @@ impl Model {
}

pub fn draw(
&self,
buf: vk::CommandBuffer,
mesh: &str,
&self, buf: vk::CommandBuffer, mesh: &str,
) -> Result<(), ErrModelDraw> {
// TODO: don't bother binding if already bound
unsafe {


+ 2
- 4
source/framework/render/pipeline.rs View File

@@ -21,10 +21,8 @@ impl GetDevice for Pipeline {

impl Pipeline {
pub fn create(
layout: Rc<PipelineLayout>,
render_pass: Rc<RenderPass>,
shader_vert: Rc<ShaderModule>,
shader_frag: Rc<ShaderModule>,
layout: Rc<PipelineLayout>, render_pass: Rc<RenderPass>,
shader_vert: Rc<ShaderModule>, shader_frag: Rc<ShaderModule>,
extent: vk::Extent2D,
) -> Result<Rc<Self>, vk::Result> {
let depth_stencil_state = vk::PipelineDepthStencilStateCreateInfo {


+ 1
- 3
source/framework/render/properties.rs View File

@@ -7,9 +7,7 @@ pub enum ErrProperty {
}

pub fn ensure_properties<T, F>(
props: &[T],
names: &[crate::ffi::Nts],
func: F,
props: &[T], names: &[crate::ffi::Nts], func: F,
) -> Result<(), ErrProperty>
where
F: Fn(&T) -> crate::ffi::Nts,


+ 1
- 2
source/framework/render/queue.rs View File

@@ -35,8 +35,7 @@ impl GetDevice for Queue {

impl QueueFamilyInfo {
pub fn collect(
physical: &PhysicalDevice,
surface: &Surface,
physical: &PhysicalDevice, surface: &Surface,
) -> Result<Self, ErrQueueFamilyCollect> {
let mut gfx_index = None;
let mut srf_index = None;


+ 1
- 2
source/framework/render/renderpass.rs View File

@@ -16,8 +16,7 @@ impl GetDevice for RenderPass {

impl RenderPass {
pub fn create(
device: Rc<Device>,
swapchain_format: vk::Format,
device: Rc<Device>, swapchain_format: vk::Format,
depth_format: vk::Format,
) -> Result<Rc<Self>, vk::Result> {
let attachments = [


+ 1
- 2
source/framework/render/sampler.rs View File

@@ -16,8 +16,7 @@ impl GetDevice for Sampler {

impl Sampler {
pub fn create(
device: Rc<Device>,
conf: &Conf,
device: Rc<Device>, conf: &Conf,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::SamplerCreateInfo {
mag_filter: vk::Filter::NEAREST,


+ 1
- 2
source/framework/render/semaphore.rs View File

@@ -22,8 +22,7 @@ impl Semaphore {
}

pub fn create_all(
device: Rc<Device>,
num: usize,
device: Rc<Device>, num: usize,
) -> Result<Vec<Rc<Self>>, vk::Result> {
(0..num).map(|_| Self::create(device.clone())).collect()
}


+ 1
- 2
source/framework/render/shader.rs View File

@@ -16,8 +16,7 @@ impl GetDevice for ShaderModule {

impl ShaderModule {
pub fn create(
device: Rc<Device>,
spir: &Spir,
device: Rc<Device>, spir: &Spir,
) -> Result<Rc<Self>, vk::Result> {
let create_info = vk::ShaderModuleCreateInfo {
code_size: spir.size,


+ 1
- 2
source/framework/render/surface.rs View File

@@ -10,8 +10,7 @@ pub struct Surface {

impl Surface {
pub fn create(
instance: Rc<Instance>,
window: &hal::win::Window,
instance: Rc<Instance>, window: &hal::win::Window,
) -> Result<Rc<Self>, hal::Err> {
let handle = window.vulkan_create_surface(&instance)?;
Ok(Rc::new(Self { handle, instance }))


+ 2
- 4
source/framework/render/swapchain.rs View File

@@ -24,10 +24,8 @@ impl GetDevice for Swapchain {

impl Swapchain {
pub fn create(
queue_graphics: Rc<Queue>,
queue_surface: Rc<Queue>,
surface: Rc<Surface>,
conf: &Conf,
queue_graphics: Rc<Queue>, queue_surface: Rc<Queue>,
surface: Rc<Surface>, conf: &Conf,
) -> Result<Rc<Self>, vk::Result> {
let device = &queue_graphics.device;



+ 10
- 11
source/framework/vire/compiler/function.rs View File

@@ -36,36 +36,36 @@ impl<'a> IncompleteFunction<'a> {

unsafe {
match datum {
Datum::Null => {
| Datum::Null => {
Ok(LLVMGetUndef(self.contx.basic_type(Basic::Void).handle()))
}
Datum::Bool(value) => Ok(LLVMConstInt(
| Datum::Bool(value) => Ok(LLVMConstInt(
self.contx.basic_type(Basic::Bool).handle(),
*value as _,
0,
)),
Datum::Char(character) => Ok(LLVMConstInt(
| Datum::Char(character) => Ok(LLVMConstInt(
self.contx.basic_type(Basic::Q32_0U).handle(),
*character as _,
0,
)),
Datum::Strn(_) => {
| Datum::Strn(_) => {
// TODO
Err(Err::Syntax)
}
Datum::Symb(name) => {
| Datum::Symb(name) => {
// TODO: must support more than global function symbols
let name = CString::new(name.as_bytes()).unwrap().into_raw();
let func = LLVMGetNamedFunction(self.contx.modul, name);
CString::from_raw(name);
Ok(func)
}
Datum::Numb(number) => Ok(LLVMConstInt(
| Datum::Numb(number) => Ok(LLVMConstInt(
self.contx.basic_type(Basic::Q64_0).handle(),
*number as _,
0,
)),
Datum::Cons { cdr, car } => {
| Datum::Cons { cdr, car } => {
// function call
let func = self.compile(car)?;
let mut args = Vec::new();
@@ -89,8 +89,7 @@ impl<'a> IncompleteFunction<'a> {
}

pub fn begin_context(
&mut self,
block: impl FnOnce(&mut Self) -> Result<(), Err>,
&mut self, block: impl FnOnce(&mut Self) -> Result<(), Err>,
) -> Result<(), Err> {
unsafe {
LLVMPositionBuilderAtEnd(self.contx.build, self.block);
@@ -148,8 +147,8 @@ impl<'a> IncompleteFunction<'a> {
Ok(Function::new(self.value))
} else {
match res {
Ok(error_message) => Err(Err::VerifyFunc(error_message)),
Err(err) => Err(Err::VerifyFunc(err.to_string())),
| Ok(error_message) => Err(Err::VerifyFunc(error_message)),
| Err(err) => Err(Err::VerifyFunc(err.to_string())),
}
}
} else {


+ 10
- 10
source/framework/vire/compiler/types.rs View File

@@ -84,16 +84,16 @@ impl BasicType {
pub fn new(btyp: Basic) -> Self {
let handle = unsafe {
match btyp {
Basic::Void => LLVMVoidType(),
Basic::Bool => LLVMInt1Type(),
Basic::Q8_0 | Basic::Q8_0U => LLVMInt8Type(),
Basic::Q16_0 | Basic::Q16_0U | Basic::Q16 | Basic::Q16U => {
| Basic::Void => LLVMVoidType(),
| Basic::Bool => LLVMInt1Type(),
| Basic::Q8_0 | Basic::Q8_0U => LLVMInt8Type(),
| Basic::Q16_0 | Basic::Q16_0U | Basic::Q16 | Basic::Q16U => {
LLVMInt16Type()
}
Basic::Q32_0 | Basic::Q32_0U | Basic::Q24_8 | Basic::Q24_8U => {
| Basic::Q32_0 | Basic::Q32_0U | Basic::Q24_8 | Basic::Q24_8U => {
LLVMInt32Type()
}
Basic::Q64_0 | Basic::Q64_0U => LLVMInt64Type(),
| Basic::Q64_0 | Basic::Q64_0U => LLVMInt64Type(),
}
};
Self { btyp, handle }
@@ -161,10 +161,10 @@ impl TypeHandle for FunctType {
impl TypeHandle for ComplType {
fn handle(&self) -> LLVMTypeRef {
match self {
Self::Basic(t) => t.handle(),
Self::Array(t) => t.handle(),
Self::Struc(t) => t.handle(),
Self::Funct(t) => t.handle(),
| Self::Basic(t) => t.handle(),
| Self::Array(t) => t.handle(),
| Self::Struc(t) => t.handle(),
| Self::Funct(t) => t.handle(),
}
}
}


+ 16
- 16
source/framework/vire/parser.rs View File

@@ -31,27 +31,27 @@ impl Datum {
pub fn parse(tki: &mut TokenIter) -> Result<Self, Err> {
match tki.err_next()? {
// atoms
Token { typ: Bool, dat: Data::Bool(b), .. } => Ok(Self::Bool(b)),
Token { typ: Char, dat: Data::Char(c), .. } => Ok(Self::Char(c)),
Token { typ: Numb, dat: Data::Numb(n), .. } => Ok(Self::Numb(n)),
Token { typ: Strn, dat: Data::Strn(s), .. } => Ok(Self::Strn(s)),
Token { typ: Symb, dat: Data::Strn(s), .. } => Ok(Self::Symb(s)),
| Token { typ: Bool, dat: Data::Bool(b), .. } => Ok(Self::Bool(b)),
| Token { typ: Char, dat: Data::Char(c), .. } => Ok(Self::Char(c)),
| Token { typ: Numb, dat: Data::Numb(n), .. } => Ok(Self::Numb(n)),
| Token { typ: Strn, dat: Data::Strn(s), .. } => Ok(Self::Strn(s)),
| Token { typ: Symb, dat: Data::Strn(s), .. } => Ok(Self::Symb(s)),

// lists
Token { typ: Br1O, .. } => Self::list(tki, Br1C),
Token { typ: Br3O, .. } => Self::list(tki, Br3C),
| Token { typ: Br1O, .. } => Self::list(tki, Br1C),
| Token { typ: Br3O, .. } => Self::list(tki, Br3C),

// abbreviations
Token { typ: QQuo, .. } => Self::abbrev(tki, "quasiquote"),
Token { typ: QSyn, .. } => Self::abbrev(tki, "quasisyntax"),
Token { typ: Quot, .. } => Self::abbrev(tki, "quote"),
Token { typ: Synt, .. } => Self::abbrev(tki, "syntax"),
Token { typ: UnQS, .. } => Self::abbrev(tki, "unquote-splicing"),
Token { typ: UnQu, .. } => Self::abbrev(tki, "unquote"),
Token { typ: UnSS, .. } => Self::abbrev(tki, "unsyntax-splicing"),
Token { typ: UnSy, .. } => Self::abbrev(tki, "unsyntax"),
| Token { typ: QQuo, .. } => Self::abbrev(tki, "quasiquote"),
| Token { typ: QSyn, .. } => Self::abbrev(tki, "quasisyntax"),
| Token { typ: Quot, .. } => Self::abbrev(tki, "quote"),
| Token { typ: Synt, .. } => Self::abbrev(tki, "syntax"),
| Token { typ: UnQS, .. } => Self::abbrev(tki, "unquote-splicing"),
| Token { typ: UnQu, .. } => Self::abbrev(tki, "unquote"),
| Token { typ: UnSS, .. } => Self::abbrev(tki, "unsyntax-splicing"),
| Token { typ: UnSy, .. } => Self::abbrev(tki, "unsyntax"),

Token { typ, pos, .. } => Err(Err::Unexpected(typ, pos)),
| Token { typ, pos, .. } => Err(Err::Unexpected(typ, pos)),
}
}



+ 74
- 75
source/framework/vire/parser/tok.rs View File

@@ -58,24 +58,24 @@ pub enum Data {
impl fmt::Display for Type {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Bool => f.write_str("boolean"),
Self::Br1C => f.write_str("⟨)⟩"),
Self::Br1O => f.write_str("⟨(⟩"),
Self::Br3C => f.write_str("⟨]⟩"),
Self::Br3O => f.write_str("⟨[⟩"),
Self::Char => f.write_str("character"),
Self::Numb => f.write_str("number"),
Self::Peri => f.write_str("⟨.⟩"),
Self::QQuo => f.write_str("⟨`⟩"),
Self::QSyn => f.write_str("⟨#`⟩"),
Self::Quot => f.write_str("⟨'⟩"),
Self::Strn => f.write_str("string"),
Self::Symb => f.write_str("symbol"),
Self::Synt => f.write_str("⟨#'⟩"),
Self::UnQS => f.write_str("⟨,@⟩"),
Self::UnQu => f.write_str("⟨,⟩"),
Self::UnSS => f.write_str("⟨#,@⟩"),
Self::UnSy => f.write_str("⟨#,⟩"),
| Self::Bool => f.write_str("boolean"),
| Self::Br1C => f.write_str("⟨)⟩"),
| Self::Br1O => f.write_str("⟨(⟩"),
| Self::Br3C => f.write_str("⟨]⟩"),
| Self::Br3O => f.write_str("⟨[⟩"),
| Self::Char => f.write_str("character"),
| Self::Numb => f.write_str("number"),
| Self::Peri => f.write_str("⟨.⟩"),
| Self::QQuo => f.write_str("⟨`⟩"),
| Self::QSyn => f.write_str("⟨#`⟩"),
| Self::Quot => f.write_str("⟨'⟩"),
| Self::Strn => f.write_str("string"),
| Self::Symb => f.write_str("symbol"),
| Self::Synt => f.write_str("⟨#'⟩"),
| Self::UnQS => f.write_str("⟨,@⟩"),
| Self::UnQu => f.write_str("⟨,⟩"),
| Self::UnSS => f.write_str("⟨#,@⟩"),
| Self::UnSy => f.write_str("⟨#,⟩"),
}
}
}
@@ -96,9 +96,9 @@ fn delim_end<'a, 'b>(
rd: &'a mut PosReader<'b>,
) -> Result<&'a PosReader<'b>, Err> {
match rd.peek() {
c if is_delim(c) => Ok(rd),
Some(c) => Err(Err::Delim(rd.pos(), c)),
None => unsafe { std::hint::unreachable_unchecked() },
| c if is_delim(c) => Ok(rd),
| Some(c) => Err(Err::Delim(rd.pos(), c)),
| None => unsafe { std::hint::unreachable_unchecked() },
}
}

@@ -121,13 +121,13 @@ fn read_uni_char(rd: &mut PosReader) -> Result<char, Err> {

loop {
match rd.next().ok_or(Err::Eof)? {
'}' => break,
c if c.is_digit(16) => {
| '}' => break,
| c if c.is_digit(16) => {
let cn = text::radix(c).into();
n = n.checked_mul(16).ok_or_else(|| Err::Numb(rd.pos()))?;
n = n.checked_add(cn).ok_or_else(|| Err::Numb(rd.pos()))?;
}
c => return Err(Err::Char(rd.pos(), c)),
| c => return Err(Err::Char(rd.pos(), c)),
}
}

@@ -151,9 +151,9 @@ fn char_txt(rd: &mut PosReader) -> Result<Token, Err> {

fn char_lit(rd: &mut PosReader) -> Result<Token, Err> {
match rd.next().ok_or(Err::Eof)? {
'u' | 'U' => char_pnt(rd),
'\'' => char_txt(rd),
c => Err(Err::Char(rd.pos(), c)),
| 'u' | 'U' => char_pnt(rd),
| '\'' => char_txt(rd),
| c => Err(Err::Char(rd.pos(), c)),
}
}

@@ -162,16 +162,16 @@ fn strn_lit(rd: &mut PosReader) -> Result<Token, Err> {

loop {
s.push(match rd.next().ok_or(Err::Eof)? {
'"' => break,
'\\' => match rd.next().ok_or(Err::Eof)? {
'n' | 'N' => '\n',
'r' | 'R' => '\r',
't' | 'T' => '\t',
'u' | 'U' => read_uni_char(rd)?,
c @ '"' | c @ '\\' => c,
c => return Err(Err::Char(rd.pos(), c)),
| '"' => break,
| '\\' => match rd.next().ok_or(Err::Eof)? {
| 'n' | 'N' => '\n',
| 'r' | 'R' => '\r',
| 't' | 'T' => '\t',
| 'u' | 'U' => read_uni_char(rd)?,
| c @ '"' | c @ '\\' => c,
| c => return Err(Err::Char(rd.pos(), c)),
},
c => c,
| c => c,
});
}

@@ -190,8 +190,8 @@ fn integer_rad(rd: &mut PosReader, rad: u32) -> Result<Token, Err> {

loop {
match rd.peek() {
c if is_delim(c) => break,
Some(c) if c.is_digit(rad) => {
| c if is_delim(c) => break,
| Some(c) if c.is_digit(rad) => {
rd.next();
let c = text::radix(c).into();
let res = n.checked_mul(rad.into());
@@ -199,8 +199,8 @@ fn integer_rad(rd: &mut PosReader, rad: u32) -> Result<Token, Err> {
let res = if sign { n.checked_sub(c) } else { n.checked_add(c) };
n = res.ok_or_else(|| Err::Numb(rd.pos()))?;
}
Some(c) => return Err(Err::Delim(rd.pos(), c)),
None => return Err(Err::Eof),
| Some(c) => return Err(Err::Delim(rd.pos(), c)),
| None => return Err(Err::Eof),
}
}

@@ -231,13 +231,13 @@ fn symbol(rd: &mut PosReader, c: char) -> Result<Token, Err> {

loop {
match rd.peek() {
c if is_delim(c) => break,
Some(c) if is_sym_subs(c) => {
| c if is_delim(c) => break,
| Some(c) if is_sym_subs(c) => {
rd.next();
s.push(c);
}
Some(c) => return Err(Err::Delim(rd.pos(), c)),
None => unsafe { std::hint::unreachable_unchecked() },
| Some(c) => return Err(Err::Delim(rd.pos(), c)),
| None => unsafe { std::hint::unreachable_unchecked() },
}
}

@@ -261,7 +261,7 @@ fn block_comment(rd: &mut PosReader) -> Result<(), Err> {
let fst = rd.next().ok_or(Err::Eof)?;
let snd = rd.peek();
match (fst, snd) {
('|', Some('#')) => {
| ('|', Some('#')) => {
rd.next();

if nesting == 0 {
@@ -270,12 +270,12 @@ fn block_comment(rd: &mut PosReader) -> Result<(), Err> {
nesting -= 1;
}
}
('#', Some('|')) => {
| ('#', Some('|')) => {
rd.next();

nesting += 1;
}
_ => (),
| _ => (),
}
}

@@ -284,70 +284,69 @@ fn block_comment(rd: &mut PosReader) -> Result<(), Err> {

impl Token {
fn read_from_char(
rd: &mut PosReader,
c: char,
rd: &mut PosReader, c: char,
) -> Result<Option<Self>, Err> {
use self::Type::*;

let tk = match c {
// line comments
';' => {
| ';' => {
line_comment(rd)?;
return Ok(None);
}

// basic tokens
'(' => new_tok(rd, Br1O, Data::None),
')' => new_tok(rd, Br1C, Data::None),
'[' => new_tok(rd, Br3O, Data::None),
']' => new_tok(rd, Br3C, Data::None),
| '(' => new_tok(rd, Br1O, Data::None),
| ')' => new_tok(rd, Br1C, Data::None),
| '[' => new_tok(rd, Br3O, Data::None),
| ']' => new_tok(rd, Br3C, Data::None),

'.' => new_tok(delim_end(rd)?, Peri, Data::None),
| '.' => new_tok(delim_end(rd)?, Peri, Data::None),

// quote abbreviations
'\'' => new_tok(rd, Quot, Data::None),
'`' => new_tok(rd, QQuo, Data::None),
',' => unquote(rd, UnQS, UnQu),
| '\'' => new_tok(rd, Quot, Data::None),
| '`' => new_tok(rd, QQuo, Data::None),
| ',' => unquote(rd, UnQS, UnQu),

// tokens preceded by #
'#' => match rd.next().ok_or(Err::Eof)? {
| '#' => match rd.next().ok_or(Err::Eof)? {
// block comments
'|' => {
| '|' => {
block_comment(rd)?;
return Ok(None);
}

// integers
'b' | 'B' => integer_rad(rd, 2)?,
'o' | 'O' => integer_rad(rd, 8)?,
'd' | 'D' => integer_rad(rd, 10)?,
'x' | 'X' => integer_rad(rd, 16)?,
| 'b' | 'B' => integer_rad(rd, 2)?,
| 'o' | 'O' => integer_rad(rd, 8)?,
| 'd' | 'D' => integer_rad(rd, 10)?,
| 'x' | 'X' => integer_rad(rd, 16)?,

// booleans
't' | 'T' => new_tok(delim_end(rd)?, Bool, Data::Bool(true)),
'f' | 'F' => new_tok(delim_end(rd)?, Bool, Data::Bool(false)),
| 't' | 'T' => new_tok(delim_end(rd)?, Bool, Data::Bool(true)),
| 'f' | 'F' => new_tok(delim_end(rd)?, Bool, Data::Bool(false)),

// syntax abbreviations
'\'' => new_tok(rd, Synt, Data::None),
'`' => new_tok(rd, QSyn, Data::None),
',' => unquote(rd, UnSS, UnSy),
| '\'' => new_tok(rd, Synt, Data::None),
| '`' => new_tok(rd, QSyn, Data::None),
| ',' => unquote(rd, UnSS, UnSy),

// character literals
'\\' => char_lit(rd)?,
| '\\' => char_lit(rd)?,

c => return Err(Err::Char(rd.pos(), c)),
| c => return Err(Err::Char(rd.pos(), c)),
},

// strings
'"' => strn_lit(rd)?,
| '"' => strn_lit(rd)?,

// symbols
c if is_sym_init(c) => symbol(rd, c)?,
| c if is_sym_init(c) => symbol(rd, c)?,

// skip whitespace
c if c.is_whitespace() => return Ok(None),
| c if c.is_whitespace() => return Ok(None),

c => return Err(Err::Char(rd.pos(), c)),
| c => return Err(Err::Char(rd.pos(), c)),
};

Ok(Some(tk))


+ 14
- 14
source/main_test/entry.rs View File

@@ -194,7 +194,11 @@ impl<'a> SwapchainData<'a, '_> {
);

// TODO
for which in &["mesh0", "mesh1", "mesh2", "mesh3", "mesh4", "mesh5", "mesh6", "mesh7", "mesh8", "mesh9", "mesh10", "mesh11", "mesh12", "mesh13", "mesh14", "mesh15", "mesh16", "mesh17", "mesh18"] {
for which in &[
"mesh0", "mesh1", "mesh2", "mesh3", "mesh4", "mesh5", "mesh6",
"mesh7", "mesh8", "mesh9", "mesh10", "mesh11", "mesh12",
"mesh13", "mesh14", "mesh15", "mesh16", "mesh17", "mesh18",
] {
sc_info.model.draw(buf, which).unwrap();
}

@@ -215,11 +219,8 @@ impl<'a> SwapchainData<'a, '_> {
}

fn draw_frame<'b>(
sc_data: &mut SwapchainData<'_, 'b>,
image_avail_s: &Semaphore,
render_fini_s: &Semaphore,
frame_f: &'b Fence,
time_ms: u128,
sc_data: &mut SwapchainData<'_, 'b>, image_avail_s: &Semaphore,
render_fini_s: &Semaphore, frame_f: &'b Fence, time_ms: u128,
) -> Result<(), vk::Result> {
let fences = [**frame_f];

@@ -346,14 +347,14 @@ fn seize_device(lg: &log::Log, device: &Device) {
}

pub fn run(
conf: &conf::Conf,
lg: &log::Log,
conf: &conf::Conf, lg: &log::Log,
) -> Result<(), Box<dyn std::error::Error>> {
let start_time = std::time::Instant::now();

let mut vfs = vfs::Vfs::default();
vfs.add_arc(vfs::Arc::read_path("testres".as_ref())?);

/*
let ctx = vire::compiler::Context::new()?;

let datum = vire::parser::Datum::parse_all(
@@ -366,8 +367,8 @@ pub fn run(
ctx.compile_all(datum)?;

ctx.execute()?;
*/

/*
let concur_frames = conf.render.concurrent_frames.into();

let hal = hal::ctx::Context::new()?;
@@ -444,7 +445,7 @@ pub fn run(
#[allow(clippy::never_loop)]
for event in hal::evt::EventIterator {
match event {
hal::evt::Event::Quit => break 'main_loop,
| hal::evt::Event::Quit => break 'main_loop,
}
}

@@ -457,12 +458,12 @@ pub fn run(
);

match frame {
Ok(()) => {}
Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => {
| Ok(()) => {}
| Err(vk::Result::ERROR_OUT_OF_DATE_KHR) => {
seize_device(lg, sc_data.get_device());
sc_data = SwapchainData::create(sc_data.info)?;
}
Err(res) => {
| Err(res) => {
lg!(lg, log::Level::Error, "Error rendering frame: {}", res);
}
}
@@ -471,7 +472,6 @@ pub fn run(
}

seize_device(lg, sc_data.get_device());
*/

Ok(())
}


+ 2
- 2
source/main_test/main.rs View File

@@ -26,8 +26,8 @@ fn main() {

let conf = conf::Conf::read("blonkus.toml").unwrap_or_else(|err| {
let level = match err {
conf::ErrConfLoad::NoFile => log::Level::Notice,
_ => log::Level::Error,
| conf::ErrConfLoad::NoFile => log::Level::Notice,
| _ => log::Level::Error,
};
lg!(&lg, level, "{}", err);
lg!(&lg, log::Level::Notice, "Using default configuration.");


Loading…
Cancel
Save