Skip to content

Commit

Permalink
chore: cleanup + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Jan 11, 2023
1 parent f2a30fe commit 7abb2de
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# dojo-beta

Dojo is a toolchain for developing onchain games on Starknet. It implements an Entity Component System and

## Getting Started
### Prerequisites
- Install [Rust](https://www.rust-lang.org/tools/install)
- Setup Rust:
```
rustup override set stable && rustup update && cargo test
```

15 changes: 15 additions & 0 deletions crates/cairo-lang-dojo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cairo-lang-dojo

Cairo language plugin for compiling the Dojo Entity Component System to Starknet contracts.

## Testing

Expected test outputs are defined in `crates/cairo-lang-dojo/src/plugin_test_data/component`.

To run the tests, run:

```
cargo test --package cairo-lang-dojo --lib -- plugin::test::expand_contract::component --exact --nocapture
```

To regenerate, set `CAIRO_FIX_TESTS=1`.
12 changes: 6 additions & 6 deletions crates/cairo-lang-dojo/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,12 @@ pub struct DojoPlugin {}

impl MacroPlugin for DojoPlugin {
fn generate_code(&self, db: &dyn SyntaxGroup, item_ast: ast::Item) -> PluginResult {
println!("{}\n---", item_ast.as_syntax_node().get_text(db));
match item_ast {
ast::Item::Struct(struct_ast) => handle_struct(db, struct_ast),
// ast::Item::Module(module_ast) => handle_mod(db, module_ast),
ast::Item::Impl(impl_ast) => handle_impl(db, impl_ast),
// ast::Item::Trait(trait_ast) => handle_trait(db, trait_ast),
// Nothing to do for other items.
_ => PluginResult {
remove_original_item: false,
..PluginResult::default()
}
_ => PluginResult::default(),
}
}
}
Expand Down Expand Up @@ -184,3 +180,7 @@ fn handle_component(db: &dyn SyntaxGroup, struct_ast: ast::ItemStruct) -> Plugin
remove_original_item: false,
}
}

fn handle_impl(_db: &dyn SyntaxGroup, _impl_ast: ast::ItemImpl) -> PluginResult {
PluginResult { remove_original_item: true, ..PluginResult::default() }
}
8 changes: 5 additions & 3 deletions crates/cairo-lang-dojo/src/plugin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ pub fn test_expand_contract(
format_diagnostics(db, &diag.message, location)
}));

if !remove_original_item {
generated_items.push(item.as_syntax_node().get_text(db));
}

let content = match code {
Some(PluginGeneratedFile { content, .. }) => content,
None => continue,
};
if !remove_original_item {
generated_items.push(item.as_syntax_node().get_text(db));
}

generated_items.push(content);
}

Expand Down
9 changes: 2 additions & 7 deletions crates/cairo-lang-dojo/src/plugin_test_data/component
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
//! > Test expansion of the hello_starknet contract.
//! > Test expansion of the component contract.

//! > test_function_name
test_expand_contract

//! > cairo_code
#[abi]
trait IPosition {
fn is_zero(entity_id: felt) -> bool;
}

#[derive(Component)]
struct Position { x: felt, y: felt }

impl IPosition of Position {
#[external]
#[view]
fn is_zero(entity_id: felt) -> bool {
return bool::True(());
}
Expand Down

0 comments on commit 7abb2de

Please sign in to comment.