-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
builtin functions now work and i made builtin functions a type of typ…
…e and data
- Loading branch information
Showing
8 changed files
with
85 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
let hi = "so"; | ||
let b = "no"; | ||
hi.b = "cardi"; | ||
fn hi() { | ||
"ok"; | ||
} | ||
print(hi()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
use crate::data::Data; | ||
use crate::errors::ParseErrKind; | ||
use crate::memory::Memory; | ||
use crate::types::Type; | ||
|
||
pub mod print; | ||
|
||
const BUILTIN_FUNCTIONS: [(&'static str, Type, Data); 1] = [ | ||
("print", Type::BuiltinFn(BuiltinFn::Print), Data::BuiltinFn(BuiltinFn::Print)), | ||
]; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum BuiltinFunc { | ||
pub enum BuiltinFn { | ||
Print, | ||
} | ||
|
||
impl BuiltinFunc { | ||
pub fn from_name(name: &String) -> Option<BuiltinFunc> { | ||
match &name[..] { | ||
"print" => Some(BuiltinFunc::Print), | ||
_ => None | ||
impl BuiltinFn { | ||
pub fn populate_memory(memory: &mut Memory<Data>) { | ||
for (name, _, builtin_fn_data) in BUILTIN_FUNCTIONS { | ||
memory.insert(String::from(name), builtin_fn_data); | ||
} | ||
} | ||
|
||
pub fn populate_sim_memory(memory: &mut Memory<Type>) { | ||
for (name, builtin_fn_type, _) in BUILTIN_FUNCTIONS { | ||
memory.insert(String::from(name), builtin_fn_type); | ||
} | ||
} | ||
|
||
pub fn type_check(&self, args: Vec<Type>) -> Result<Type, ParseErrKind>{ | ||
match self { | ||
BuiltinFunc::Print => print::type_check(args) | ||
BuiltinFn::Print => print::type_check(args) | ||
} | ||
} | ||
|
||
pub fn eval(&self, args: Vec<Data>) -> Data { | ||
match self { | ||
BuiltinFunc::Print => print::eval(args) | ||
BuiltinFn::Print => print::eval(args) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters