Skip to content

Commit

Permalink
builtin contract creation on ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
g-r-a-n-t committed Apr 25, 2022
1 parent 182d189 commit b402593
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/analyzer/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub enum ValueMethod {
Clone,
ToMem,
AbiEncode,
Create,
}

#[derive(
Expand Down
6 changes: 6 additions & 0 deletions crates/analyzer/src/traversal/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ fn expr_call_method(
target,
method,
field,
generic_args,
args,
);
}
Expand Down Expand Up @@ -1468,6 +1469,7 @@ fn expr_call_builtin_value_method(
value: &Node<fe::Expr>,
method: ValueMethod,
method_name: &Node<SmolStr>,
generic_args: &Option<Node<Vec<fe::GenericArg>>>,
args: &Node<Vec<Node<fe::CallArg>>>,
) -> Result<(ExpressionAttributes, CallType), FatalError> {
// for now all of these functions expect 0 arguments
Expand Down Expand Up @@ -1603,6 +1605,10 @@ fn expr_call_builtin_value_method(
],
))),
},
ValueMethod::Create => {
// temp
Ok((value_attrs.into_cloned(), calltype))
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/test-files/fixtures/features/create_contract.fe
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ contract Foo:

contract FooFactory:
pub fn create_foo(ctx: Context) -> address:
let foo: Foo = Foo.create(ctx, 0)
let foo: Foo = ctx.create<Foo>((), 0)
return address(foo)
15 changes: 9 additions & 6 deletions crates/yulgen/src/mappers/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::operations::{
math as math_operations, structs as struct_operations,
};
use crate::types::{AsAbiType, EvmSized};
use fe_analyzer::builtins::{self, ContractTypeMethod, GlobalFunction};
use fe_analyzer::builtins::{self, ContractTypeMethod, GlobalFunction, ValueMethod};
use fe_analyzer::context::{CallType, Location};
use fe_analyzer::namespace::items::Class;
use fe_analyzer::namespace::types::{Base, FixedSize, Type};
Expand Down Expand Up @@ -126,6 +126,13 @@ fn expr_call(context: &mut FnContext, exp: &Node<fe::Expr>) -> yul::Expression {
),
_ => panic!("invalid attributes"),
},
builtins::ValueMethod::Create => {
contract_operations::create2(
&contract_name,
yul_args[1].clone(),
yul_args[2].clone(),
)
}
}
}
CallType::TypeConstructor(Type::Struct(val)) => {
Expand All @@ -149,11 +156,7 @@ fn expr_call(context: &mut FnContext, exp: &Node<fe::Expr>) -> yul::Expression {
CallType::BuiltinAssociatedFunction { contract, function } => {
let contract_name = contract.name(context.adb);
match function {
ContractTypeMethod::Create2 => contract_operations::create2(
&contract_name,
yul_args[1].clone(),
yul_args[2].clone(),
),
ContractTypeMethod::Create2 => ,
ContractTypeMethod::Create => {
contract_operations::create(&contract_name, yul_args[0].clone())
}
Expand Down

0 comments on commit b402593

Please sign in to comment.