Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbrown committed Mar 8, 2024
1 parent 91fc669 commit b4d1ac2
Show file tree
Hide file tree
Showing 33 changed files with 431 additions and 293 deletions.
6 changes: 1 addition & 5 deletions pax-chassis-common/src/core_graphics_c_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

extern crate core;


use std::ffi::c_void;

use std::mem::{transmute, ManuallyDrop};


use core_graphics::context::CGContext;
use pax_runtime::api::math::Point2;
use piet_coregraphics::CoreGraphicsContext;
Expand Down Expand Up @@ -37,14 +35,12 @@ pub struct PaxEngineContainer {
pub extern "C" fn pax_init() -> *mut PaxEngineContainer {
env_logger::init();

let mut definition_to_instance_traverser =
pax_cartridge::DefinitionToInstanceTraverser::new();
let mut definition_to_instance_traverser = pax_cartridge::DefinitionToInstanceTraverser::new();
let main_component_instance = definition_to_instance_traverser.get_main_component();
let expression_table = ExpressionTable {
table: pax_cartridge::instantiate_expression_table(),
};


//Initialize a ManuallyDrop-contained PaxEngine, so that a pointer to that
//engine can be passed back to Swift via the C (FFI) bridge
//This could presumably be cleaned up -- see `pax_dealloc_engine`
Expand Down
5 changes: 3 additions & 2 deletions pax-chassis-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use js_sys::Uint8Array;
use log::Level;
use pax_message::ImageLoadInterruptArgs;
use pax_runtime::api::math::Point2;
use pax_runtime::api::ButtonClick;
use pax_runtime::api::CheckboxChange;
use pax_runtime::api::RenderContext;
use pax_runtime::api::math::Point2;
use pax_runtime::api::TextboxChange;
use pax_runtime::api::TextboxInput;
use pax_runtime::ExpressionTable;
Expand All @@ -24,7 +24,8 @@ use pax_runtime::{PaxEngine, Renderer};
use pax_message::NativeInterrupt;
use pax_runtime::api::{
Clap, Click, ContextMenu, DoubleClick, KeyDown, KeyPress, KeyUp, KeyboardEventArgs,
ModifierKey, MouseButton, MouseDown, MouseEventArgs, MouseMove, MouseOut, MouseOver, MouseUp, Touch, TouchEnd, TouchMove, TouchStart, Wheel,
ModifierKey, MouseButton, MouseDown, MouseEventArgs, MouseMove, MouseOut, MouseOver, MouseUp,
Touch, TouchEnd, TouchMove, TouchStart, Wheel,
};
use serde_json;

Expand Down
56 changes: 31 additions & 25 deletions pax-compiler/src/expressions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pax_manifest::{
escape_identifier, ComponentDefinition, ComponentTemplate,
ControlFlowRepeatPredicateDefinition, ExpressionSpec, ExpressionSpecInvocation, HostCrateInfo,
PaxManifest, PropertyDefinition, PropertyDefinitionFlags, SettingElement, TemplateNodeId, Token, TypeDefinition, TypeId, TypeTable,
ValueDefinition,
PaxManifest, PropertyDefinition, PropertyDefinitionFlags, SettingElement, TemplateNodeId,
Token, TypeDefinition, TypeId, TypeTable, ValueDefinition,
};
use std::any::Any;
use std::collections::HashMap;
Expand All @@ -14,7 +14,7 @@ use crate::errors::PaxTemplateError;
use color_eyre::eyre;
use color_eyre::eyre::Report;
use lazy_static::lazy_static;
use pax_manifest::constants::{COMMON_PROPERTIES_TYPE};
use pax_manifest::constants::COMMON_PROPERTIES_TYPE;

pub fn compile_all_expressions<'a>(
manifest: &'a mut PaxManifest,
Expand Down Expand Up @@ -67,25 +67,31 @@ pub fn compile_all_expressions<'a>(
Ok(())
}


fn get_output_type_by_property_identifier(_ctx: &ExpressionCompilationContext, prop_defs: &Vec<PropertyDefinition>, property_identifier: &str) -> String {

let output_type = if let Some(common_match) = COMMON_PROPERTIES_TYPE.iter().find(|cpt|{
cpt.0 == property_identifier
}) {
fn get_output_type_by_property_identifier(
_ctx: &ExpressionCompilationContext,
prop_defs: &Vec<PropertyDefinition>,
property_identifier: &str,
) -> String {
let output_type = if let Some(common_match) = COMMON_PROPERTIES_TYPE
.iter()
.find(|cpt| cpt.0 == property_identifier)
{
(*common_match).1.to_string()
} else if let Some(local_match) = prop_defs
.iter()
.find(|property_def| property_def.name == property_identifier) {
.find(|property_def| property_def.name == property_identifier)
{
local_match.type_id.to_string()
} else {
panic!("Failed to resolve symbol bound to expression: {}", property_identifier);
panic!(
"Failed to resolve symbol bound to expression: {}",
property_identifier
);
};

output_type
}


fn recurse_compile_literal_block<'a>(
settings_pairs: &mut IterMut<SettingElement>,
ctx: &mut ExpressionCompilationContext,
Expand All @@ -95,9 +101,6 @@ fn recurse_compile_literal_block<'a>(
) -> Result<(), eyre::Report> {
settings_pairs.try_for_each(|e| {
if let SettingElement::Setting(token, value) = e {



match value {
// LiteralValue: no need to compile literal values
// EventBindingTarget: event bindings are handled on a separate compiler pass; no-op here
Expand Down Expand Up @@ -126,7 +129,11 @@ fn recurse_compile_literal_block<'a>(
ValueDefinition::Expression(input, manifest_id) => {
// e.g. the `self.num_clicks + 5` in `<SomeNode some_property={self.num_clicks + 5} />`

let output_type = get_output_type_by_property_identifier(ctx,&current_property_definitions,&token.token_value);
let output_type = get_output_type_by_property_identifier(
ctx,
&current_property_definitions,
&token.token_value,
);

let id = ctx.vtable_uid_gen.next().unwrap();
let (output_statement, invocations) =
Expand Down Expand Up @@ -166,14 +173,14 @@ fn recurse_compile_literal_block<'a>(
let type_def = (current_property_definitions
.iter()
.find(|property_def| property_def.name == token.token_value))
.ok_or::<eyre::Report>(PaxTemplateError::new(
Some(format!(
"Property `{}` not found on `{}`",
&token.token_value, type_id
)),
token.clone(),
))?
.get_type_definition(ctx.type_table);
.ok_or::<eyre::Report>(PaxTemplateError::new(
Some(format!(
"Property `{}` not found on `{}`",
&token.token_value, type_id
)),
token.clone(),
))?
.get_type_definition(ctx.type_table);
let output_type = type_def.type_id.clone();

//Write this id back to the manifest, for downstream use by RIL component tree generator
Expand Down Expand Up @@ -453,7 +460,6 @@ fn recurse_compile_expressions<'a>(
let input_statement =
source_map.generate_mapped_string(whitespace_removed_input, source_map_id);


ctx.expression_specs.insert(
id,
ExpressionSpec {
Expand Down
4 changes: 3 additions & 1 deletion pax-compiler/src/formatting/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ fn get_formatting_rules(pest_rule: Rule) -> Vec<Box<dyn FormattingRule>> {
Box::new(IdentifierCallDefaultRule),
],
Rule::event_id => vec![Box::new(EventIdDefaultRule)],
Rule::literal_enum_args_list | Rule::xo_enum_or_function_args_list | Rule::literal_color => vec![
Rule::literal_enum_args_list
| Rule::xo_enum_or_function_args_list
| Rule::literal_color => vec![
Box::new(ArgsListMultiLineRule),
Box::new(ArgsListDefaultRule),
],
Expand Down
3 changes: 0 additions & 3 deletions pax-compiler/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use pest::iterators::{Pair, Pairs};
use pest::{Parser, Span};
use pest_derive::Parser;


use pest::pratt_parser::{Assoc, Op, PrattParser};

#[derive(Parser)]
Expand Down Expand Up @@ -1558,8 +1557,6 @@ impl Reflectable for pax_runtime::api::Rotation {
"Rotation".to_string()
}
fn get_type_id() -> TypeId {


let type_id = TypeId::build_singleton(
&Self::get_import_path(),
Some(&Self::get_self_pascal_identifier()),
Expand Down
2 changes: 1 addition & 1 deletion pax-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pub use pax_macro::*;

pub use log;
pub use pax_runtime::api;
pub use pax_runtime::api::math;
pub use pax_runtime::engine::node_interface::*;
pub use pax_runtime::layout;
pub use pax_runtime::api::math;
pub use pax_runtime::rendering;

pub use pax_runtime::api::serde;
Expand Down
2 changes: 1 addition & 1 deletion pax-manifest/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use pax_runtime_api::constants::*;
pub use pax_runtime_api::constants::*;
66 changes: 32 additions & 34 deletions pax-manifest/src/deserializer/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde::{
forward_to_deserialize_any,
};


use pax_runtime_api::constants::{COLOR_CHANNEL, INTEGER, PERCENT};

use crate::constants::{NUMERIC, STRING_BOX};
Expand All @@ -14,7 +13,6 @@ use super::{
Deserializer, PaxParser, Rule,
};


pub struct PaxColor {
pub color_func: String,
pub args: Vec<ColorFuncArg>,
Expand All @@ -31,10 +29,12 @@ impl<'de> EnumAccess<'de> for crate::deserializer::helpers::PaxColor {
type Variant = Self;

fn variant_seed<V>(self, seed: V) -> Result<(V::Value, Self::Variant)>
where
V: DeserializeSeed<'de>,
where
V: DeserializeSeed<'de>,
{
let val = seed.deserialize(crate::deserializer::helpers::PrimitiveDeserializer::new(self.color_func.as_str()))?;
let val = seed.deserialize(crate::deserializer::helpers::PrimitiveDeserializer::new(
self.color_func.as_str(),
))?;
Ok((val, self))
}
}
Expand All @@ -49,43 +49,47 @@ impl<'de> VariantAccess<'de> for crate::deserializer::helpers::PaxColor {

// Handle seq args like Color::rgb(255,0,0) or Color::rgb(100%, 0%, 0%)
fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
where
V: Visitor<'de>,
{
let seq = self.args.iter().map(|cc|{
match cc {
let seq = self
.args
.iter()
.map(|cc| match cc {
ColorFuncArg::Rotation(val) => PaxSeqArg::String(val.to_string()),
ColorFuncArg::Percent(val) => PaxSeqArg::Enum(PaxEnum {
identifier: Some(COLOR_CHANNEL.to_string()),
variant: PERCENT.to_string(),
args: Some(val.to_string()),
}),
ColorFuncArg::Integer(val) => {

PaxSeqArg::Enum(

PaxEnum {
identifier: Some(COLOR_CHANNEL.to_string()),
variant: INTEGER.to_string(),
args: Some(val.to_string())
}
)},
}
}).collect();
ColorFuncArg::Integer(val) => PaxSeqArg::Enum(PaxEnum {
identifier: Some(COLOR_CHANNEL.to_string()),
variant: INTEGER.to_string(),
args: Some(val.to_string()),
}),
})
.collect();

visitor.visit_seq(PaxSeq::new(seq))
}

// Color::rgb(only_one_arg)
fn newtype_variant_seed<T>(self, _seed: T) -> Result<T::Value>
where
T: DeserializeSeed<'de>,
where
T: DeserializeSeed<'de>,
{
unreachable!(); //Incorrect color syntax
}

// Color::rgb { r: ... } (not supported)
fn struct_variant<V>(self, _fields: &'static [&'static str], _visitor: V) -> std::result::Result<V::Value, Self::Error> where V: Visitor<'de> {
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
_visitor: V,
) -> std::result::Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
unreachable!(); //Incorrect color syntax
}
}
Expand All @@ -108,14 +112,13 @@ impl<'de> de::Deserializer<'de> for PaxEnum {
}

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
where
V: Visitor<'de>,
{
visitor.visit_enum(self.clone())
}
}


impl PaxEnum {
pub fn new(identifier: Option<String>, variant: String, args: Option<String>) -> Self {
PaxEnum {
Expand Down Expand Up @@ -187,7 +190,7 @@ impl<'de> VariantAccess<'de> for PaxEnum {
where
T: DeserializeSeed<'de>,
{
if let Some(i) = self.identifier{
if let Some(i) = self.identifier {
if i == NUMERIC {
return seed.deserialize(PrimitiveDeserializer::new(&self.args.unwrap()));
}
Expand Down Expand Up @@ -224,7 +227,6 @@ impl<'de> VariantAccess<'de> for PaxEnum {
}
}


struct PrimitiveDeserializer {
input: String,
}
Expand Down Expand Up @@ -291,7 +293,6 @@ impl PaxSeq {
}
}


impl<'de> SeqAccess<'de> for PaxSeq {
type Error = Error;

Expand All @@ -300,13 +301,10 @@ impl<'de> SeqAccess<'de> for PaxSeq {
T: DeserializeSeed<'de>,
{
if self.index < self.elements.len() {

let elem = &self.elements[self.index];

let val = match elem {
PaxSeqArg::Enum(pax_enum) => {
seed.deserialize(pax_enum.clone())?
},
PaxSeqArg::Enum(pax_enum) => seed.deserialize(pax_enum.clone())?,
PaxSeqArg::String(str) => {
seed.deserialize(Deserializer::from_string(str.to_string()))?
}
Expand Down
Loading

0 comments on commit b4d1ac2

Please sign in to comment.