-
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.
- Loading branch information
Robert-M-Lucas
committed
Jun 18, 2024
1 parent
a671c3e
commit 7fb49e0
Showing
23 changed files
with
409 additions
and
179 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
if PathBuf::from("types.toml").is_file() { | ||
fs::remove_file(PathBuf::from("types.toml")).unwrap(); | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.
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,12 +1,15 @@ | ||
fn fib(a: int, b: int) { | ||
printi(a); | ||
let d: int = a + b; | ||
let c: int = b; | ||
exit(12); | ||
fib(c, d); | ||
} | ||
|
||
fn main() -> int { | ||
fib(0, 1); | ||
return 255; | ||
let i: int = 3; | ||
let j: int = 4; | ||
let x: bool = true; | ||
printb(x); | ||
|
||
if (x) { | ||
printi(i); | ||
return 13; | ||
} | ||
else { | ||
printi(j); | ||
return 12; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
pub struct AssemblyBuilder { | ||
inner: String | ||
} | ||
|
||
impl AssemblyBuilder { | ||
pub fn new() -> AssemblyBuilder { | ||
AssemblyBuilder { inner: String::new() } | ||
} | ||
|
||
pub fn line(&mut self, line: &str) { | ||
self.inner += " "; | ||
self.inner += line; | ||
self.inner.push('\n'); | ||
} | ||
|
||
pub fn toplevel(&mut self, line: &str) { | ||
self.inner += line; | ||
self.inner.push('\n'); | ||
} | ||
|
||
pub fn other(&mut self, other: &str) { | ||
self.inner += other; | ||
} | ||
|
||
pub fn finish(self) -> String { | ||
self.inner | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod assembly_builder; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
mod printb; | ||
|
||
use b_box::b; | ||
use unique_type_id::UniqueTypeId; | ||
use crate::root::builtin::t_id; | ||
use crate::root::builtin::types::bool::printb::PrintB; | ||
use crate::root::errors::WErr; | ||
use crate::root::name_resolver::name_resolvers::GlobalDefinitionTable; | ||
use crate::root::parser::parse_function::parse_literal::{LiteralToken, LiteralTokens}; | ||
use crate::root::shared::common::{ByteSize, LocalAddress, TypeID}; | ||
use crate::root::shared::types::Type; | ||
|
||
pub fn register_bool(global_table: &mut GlobalDefinitionTable) { | ||
global_table.register_builtin_type(b!(BoolType)); | ||
global_table.register_inline_function(&PrintB); | ||
} | ||
|
||
#[derive(UniqueTypeId)] | ||
#[UniqueTypeIdType = "u16"] | ||
pub struct BoolType; | ||
|
||
impl BoolType { | ||
pub const fn id() -> TypeID { | ||
t_id(BoolType::unique_type_id().0) | ||
} | ||
} | ||
|
||
impl Type for BoolType { | ||
fn id(&self) -> TypeID { Self::id() } | ||
|
||
fn size(&self) -> ByteSize { | ||
ByteSize(1) | ||
} | ||
|
||
fn name(&self) -> &str { | ||
"bool" | ||
} | ||
|
||
fn instantiate_from_literal(&self, location: &LocalAddress, literal: &LiteralToken) -> Result<String, WErr> { | ||
Ok(match literal.literal() { | ||
LiteralTokens::Bool(value) => { | ||
if *value { | ||
format!(" mov byte {location}, 1\n") | ||
} | ||
else { | ||
format!(" mov byte {location}, 0\n") | ||
} | ||
} | ||
LiteralTokens::Int(value) => { | ||
if *value == 0 { | ||
format!(" mov byte {location}, 0\n") | ||
} | ||
else { | ||
format!(" mov byte {location}, 1\n") | ||
} | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.