Skip to content

Commit

Permalink
feat(stdlib): Add shifting methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yhara committed Nov 18, 2019
1 parent 92a3a23 commit c463dfc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser/definition_parser.rs
Expand Up @@ -118,6 +118,8 @@ impl<'a> Parser<'a> {
Token::And => { name_str = "&" },
Token::Or => { name_str = "|" },
Token::Xor => { name_str = "^" },
Token::LShift => { name_str = "<<" },
Token::RShift => { name_str = ">>" },
Token::LessThan => { name_str = "<" },
Token::LessEq => { name_str = "<=" },
Token::GraterThan => { name_str = ">" },
Expand Down
16 changes: 16 additions & 0 deletions src/stdlib/int.rs
Expand Up @@ -52,6 +52,22 @@ pub fn create_methods() -> Vec<SkMethod> {
Ok(())
}),

create_method("Int", "<<(other: Int) -> Int", |code_gen, function| {
let val1 = function.get_params()[0].into_int_value();
let val2 = function.get_params()[1].into_int_value();
let result = code_gen.builder.build_left_shift(val1, val2, "lshift");
code_gen.builder.build_return(Some(&result));
Ok(())
}),

create_method("Int", ">>(other: Int) -> Int", |code_gen, function| {
let val1 = function.get_params()[0].into_int_value();
let val2 = function.get_params()[1].into_int_value();
let result = code_gen.builder.build_right_shift(val1, val2, true, "rshift");
code_gen.builder.build_return(Some(&result));
Ok(())
}),

create_method("Int", "to_f() -> Float", |code_gen, function| {
let int = function.get_params()[0].into_int_value();
let float = code_gen.builder.build_signed_int_to_float(int, code_gen.f64_type, "float");
Expand Down

0 comments on commit c463dfc

Please sign in to comment.