diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 135d947..1815c0d 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,21 +7,15 @@
-
-
+
-
-
-
-
+
+
-
-
-
@@ -69,32 +63,32 @@
- {
+ "keyToString": {
+ "Cargo.Run whython-8.executor": "Run",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.rust.reset.selective.auto.import": "true",
+ "Shell Script.Test Asm.executor": "Run",
+ "git-widget-placeholder": "master",
+ "ignore.virus.scanning.warn.message": "true",
+ "last_opened_file_path": "/home/robertlucas/RustroverProjects/whython-8/src/root/builtin/types/int",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
+ "org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",
+ "org.rust.first.attach.projects": "true",
+ "settings.editor.selected.configurable": "preferences.keymap",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
-
+
@@ -213,7 +207,9 @@
-
+
+
+
@@ -479,7 +475,15 @@
1718803787262
-
+
+
+ 1718805301324
+
+
+
+ 1718805301324
+
+
@@ -520,7 +524,8 @@
-
+
+
diff --git a/build/out.asm b/build/out.asm
index 894a3de..dd7d088 100644
--- a/build/out.asm
+++ b/build/out.asm
@@ -5,26 +5,17 @@ section .text
main:
push rbp
mov rbp, rsp
+ mov qword [rbp-9], 2
+ mov qword [rbp-17], 3
+ mov rax, qword [rbp-17]
+ cmp rax, qword [rbp-9]
+ jg __5_0
mov byte [rbp-1], 0
- mov rax, rbp
- add rax, -1
- mov qword [rbp-9], rax
+ jmp __5_1
+ __5_0:
+ mov byte [rbp-1], 1
+ __5_1:
mov al, byte [rbp-1]
- mov byte [rbp-11], al
- mov al, byte [rbp-11]
- cmp al, 0
- jz __7_0
- mov byte [rbp-10], 0
- jmp __7_1
- __7_0:
- mov byte [rbp-10], 1
- __7_1:
- mov rdx, qword [rbp-9]
- mov al, byte [rbp-10]
- mov byte [rdx], al
- mov al, byte [rbp-1]
- mov byte [rbp-12], al
- mov al, byte [rbp-12]
cmp al, 0
jz __7_2
mov rdi, __7_t_fstr
@@ -34,12 +25,12 @@ main:
__7_3:
mov rsi, 0
mov al, 0
- sub rsp, 12
+ sub rsp, 17
extern printf
call printf
- add rsp, 12
- mov qword [rbp-20], 2
- mov rax, qword [rbp-20]
+ add rsp, 17
+ mov qword [rbp-25], 2
+ mov rax, qword [rbp-25]
leave
ret
diff --git a/build/out.o b/build/out.o
index f52d4df..5044bbf 100644
Binary files a/build/out.o and b/build/out.o differ
diff --git a/build/out.out b/build/out.out
index bd489dc..fc092e4 100755
Binary files a/build/out.out and b/build/out.out differ
diff --git a/main.why b/main.why
index 3708e59..28a3af5 100644
--- a/main.why
+++ b/main.why
@@ -1,8 +1,5 @@
fn main() -> int {
- let a: bool = true;
- &a = !a;
-
- printb(a);
+ printb(2 < 3);
return 2;
}
diff --git a/src/root/builtin/types/int/comparators.rs b/src/root/builtin/types/int/comparators.rs
new file mode 100644
index 0000000..a92e26d
--- /dev/null
+++ b/src/root/builtin/types/int/comparators.rs
@@ -0,0 +1,267 @@
+use unique_type_id::UniqueTypeId;
+use crate::root::builtin::{BuiltinInlineFunction, InlineFunctionGenerator, f_id};
+use crate::root::builtin::types::bool::BoolType;
+use crate::root::builtin::types::int::IntType;
+use crate::root::name_resolver::resolve_function_signatures::FunctionSignature;
+
+use crate::root::shared::common::{FunctionID, LocalAddress, TypeID};
+
+#[derive(UniqueTypeId)]
+#[UniqueTypeIdType = "u16"]
+pub struct IntEq;
+
+impl IntEq {
+ pub const fn id() -> FunctionID {
+ f_id(IntEq::unique_type_id().0)
+ }
+}
+
+impl BuiltinInlineFunction for IntEq {
+ fn id(&self) -> FunctionID {
+ IntEq::id()
+ }
+
+ fn name(&self) -> &'static str {
+ "eq"
+ }
+
+ fn signature(&self) -> FunctionSignature {
+ FunctionSignature::new_inline_builtin(
+ true,
+ &[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())],
+ Some(BoolType::id().immediate())
+ )
+ }
+
+ fn inline(&self) -> InlineFunctionGenerator {
+ |args: &[LocalAddress], return_into: Option, gt, _| -> String {
+ let lhs = args[0];
+ let rhs = args[1];
+ let return_into = return_into.unwrap();
+ let jmp_true = gt.get_unique_tag(IntEq::id());
+ let jmp_end = gt.get_unique_tag(IntEq::id());
+
+ format!(
+ " mov rax, qword {lhs}
+ cmp rax, qword {rhs}
+ jz {jmp_true}
+ mov byte {return_into}, 0
+ jmp {jmp_end}
+ {jmp_true}:
+ mov byte {return_into}, 1
+ {jmp_end}:\n")
+ }
+ }
+
+ fn parent_type(&self) -> Option {
+ Some(IntType::id())
+ }
+}
+
+#[derive(UniqueTypeId)]
+#[UniqueTypeIdType = "u16"]
+pub struct IntGT;
+
+impl IntGT {
+ pub const fn id() -> FunctionID {
+ f_id(IntGT::unique_type_id().0)
+ }
+}
+
+impl BuiltinInlineFunction for IntGT {
+ fn id(&self) -> FunctionID {
+ IntGT::id()
+ }
+
+ fn name(&self) -> &'static str {
+ "gt"
+ }
+
+ fn signature(&self) -> FunctionSignature {
+ FunctionSignature::new_inline_builtin(
+ true,
+ &[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())],
+ Some(BoolType::id().immediate())
+ )
+ }
+
+ fn inline(&self) -> InlineFunctionGenerator {
+ |args: &[LocalAddress], return_into: Option, gt, _| -> String {
+ let lhs = args[0];
+ let rhs = args[1];
+ let return_into = return_into.unwrap();
+ let jmp_true = gt.get_unique_tag(IntEq::id());
+ let jmp_end = gt.get_unique_tag(IntEq::id());
+
+ format!(
+" mov rax, qword {lhs}
+ cmp rax, qword {rhs}
+ jg {jmp_true}
+ mov byte {return_into}, 0
+ jmp {jmp_end}
+ {jmp_true}:
+ mov byte {return_into}, 1
+ {jmp_end}:\n")
+ }
+ }
+
+ fn parent_type(&self) -> Option {
+ Some(IntType::id())
+ }
+}
+
+#[derive(UniqueTypeId)]
+#[UniqueTypeIdType = "u16"]
+pub struct IntLT;
+
+impl IntLT {
+ pub const fn id() -> FunctionID {
+ f_id(IntLT::unique_type_id().0)
+ }
+}
+
+impl BuiltinInlineFunction for IntLT {
+ fn id(&self) -> FunctionID {
+ IntLT::id()
+ }
+
+ fn name(&self) -> &'static str {
+ "lt"
+ }
+
+ fn signature(&self) -> FunctionSignature {
+ FunctionSignature::new_inline_builtin(
+ true,
+ &[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())],
+ Some(BoolType::id().immediate())
+ )
+ }
+
+ fn inline(&self) -> InlineFunctionGenerator {
+ |args: &[LocalAddress], return_into: Option, gt, _| -> String {
+ let lhs = args[0];
+ let rhs = args[1];
+ let return_into = return_into.unwrap();
+ let jmp_true = gt.get_unique_tag(IntEq::id());
+ let jmp_end = gt.get_unique_tag(IntEq::id());
+
+ format!(
+ " mov rax, qword {rhs}
+ cmp rax, qword {lhs}
+ jg {jmp_true}
+ mov byte {return_into}, 0
+ jmp {jmp_end}
+ {jmp_true}:
+ mov byte {return_into}, 1
+ {jmp_end}:\n")
+ }
+ }
+
+ fn parent_type(&self) -> Option {
+ Some(IntType::id())
+ }
+}
+
+#[derive(UniqueTypeId)]
+#[UniqueTypeIdType = "u16"]
+pub struct IntGE;
+
+impl IntGE {
+ pub const fn id() -> FunctionID {
+ f_id(IntGE::unique_type_id().0)
+ }
+}
+
+impl BuiltinInlineFunction for IntGE {
+ fn id(&self) -> FunctionID {
+ IntGE::id()
+ }
+
+ fn name(&self) -> &'static str {
+ "ge"
+ }
+
+ fn signature(&self) -> FunctionSignature {
+ FunctionSignature::new_inline_builtin(
+ true,
+ &[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())],
+ Some(BoolType::id().immediate())
+ )
+ }
+
+ fn inline(&self) -> InlineFunctionGenerator {
+ |args: &[LocalAddress], return_into: Option, gt, _| -> String {
+ let lhs = args[0];
+ let rhs = args[1];
+ let return_into = return_into.unwrap();
+ let jmp_true = gt.get_unique_tag(IntEq::id());
+ let jmp_end = gt.get_unique_tag(IntEq::id());
+
+ format!(
+ " mov rax, qword {lhs}
+ cmp rax, qword {rhs}
+ jge {jmp_true}
+ mov byte {return_into}, 0
+ jmp {jmp_end}
+ {jmp_true}:
+ mov byte {return_into}, 1
+ {jmp_end}:\n")
+ }
+ }
+
+ fn parent_type(&self) -> Option {
+ Some(IntType::id())
+ }
+}
+
+#[derive(UniqueTypeId)]
+#[UniqueTypeIdType = "u16"]
+pub struct IntLE;
+
+impl IntLE {
+ pub const fn id() -> FunctionID {
+ f_id(IntLE::unique_type_id().0)
+ }
+}
+
+impl BuiltinInlineFunction for IntLE {
+ fn id(&self) -> FunctionID {
+ IntLE::id()
+ }
+
+ fn name(&self) -> &'static str {
+ "le"
+ }
+
+ fn signature(&self) -> FunctionSignature {
+ FunctionSignature::new_inline_builtin(
+ true,
+ &[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())],
+ Some(BoolType::id().immediate())
+ )
+ }
+
+ fn inline(&self) -> InlineFunctionGenerator {
+ |args: &[LocalAddress], return_into: Option, gt, _| -> String {
+ let lhs = args[0];
+ let rhs = args[1];
+ let return_into = return_into.unwrap();
+ let jmp_true = gt.get_unique_tag(IntEq::id());
+ let jmp_end = gt.get_unique_tag(IntEq::id());
+
+ format!(
+ " mov rax, qword {rhs}
+ cmp rax, qword {lhs}
+ jge {jmp_true}
+ mov byte {return_into}, 0
+ jmp {jmp_end}
+ {jmp_true}:
+ mov byte {return_into}, 1
+ {jmp_end}:\n")
+ }
+ }
+
+ fn parent_type(&self) -> Option {
+ Some(IntType::id())
+ }
+}
diff --git a/src/root/builtin/types/int/eq.rs b/src/root/builtin/types/int/eq.rs
deleted file mode 100644
index d9d835e..0000000
--- a/src/root/builtin/types/int/eq.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-use unique_type_id::UniqueTypeId;
-use crate::root::builtin::{BuiltinInlineFunction, InlineFunctionGenerator, f_id};
-use crate::root::builtin::types::bool::BoolType;
-use crate::root::builtin::types::int::IntType;
-use crate::root::name_resolver::resolve_function_signatures::FunctionSignature;
-
-use crate::root::shared::common::{FunctionID, LocalAddress, TypeID};
-
-#[derive(UniqueTypeId)]
-#[UniqueTypeIdType = "u16"]
-pub struct IntEq;
-
-impl IntEq {
- pub const fn id() -> FunctionID {
- f_id(IntEq::unique_type_id().0)
- }
-}
-
-impl BuiltinInlineFunction for IntEq {
- fn id(&self) -> FunctionID {
- IntEq::id()
- }
-
- fn name(&self) -> &'static str {
- "eq"
- }
-
- fn signature(&self) -> FunctionSignature {
- FunctionSignature::new_inline_builtin(
- true,
- &[("lhs", IntType::id().immediate()), ("rhs", IntType::id().immediate())],
- Some(BoolType::id().immediate())
- )
- }
-
- fn inline(&self) -> InlineFunctionGenerator {
- |args: &[LocalAddress], return_into: Option, gt, _| -> String {
- let lhs = args[0];
- let rhs = args[1];
- let return_into = return_into.unwrap();
- let j = gt.get_unique_tag(IntEq::id());
- let j2 = gt.get_unique_tag(IntEq::id());
-
- format!(
-" mov rax, qword {lhs}
- cmp rax, qword {rhs}
- jz {j}
- mov byte {return_into}, 0
- jmp {j2}
- {j}:
- mov byte {return_into}, 1
- {j2}:\n")
- }
- }
-
- fn parent_type(&self) -> Option {
- Some(IntType::id())
- }
-}
diff --git a/src/root/builtin/types/int/mod.rs b/src/root/builtin/types/int/mod.rs
index 67fae54..100c5b6 100644
--- a/src/root/builtin/types/int/mod.rs
+++ b/src/root/builtin/types/int/mod.rs
@@ -3,8 +3,8 @@ use unique_type_id::UniqueTypeId;
use crate::root::builtin::{BuiltinInlineFunction, f_id, InlineFunctionGenerator, t_id};
use crate::root::builtin::types::int::add::{IntAdd, IntAsAdd};
+use crate::root::builtin::types::int::comparators::{IntEq, IntGE, IntGT, IntLE, IntLT};
use crate::root::builtin::types::int::div::{IntAsDiv, IntDiv};
-use crate::root::builtin::types::int::eq::IntEq;
use crate::root::builtin::types::int::modulo::{IntAsMod, IntMod};
use crate::root::builtin::types::int::mul::{IntAsMul, IntMul};
use crate::root::builtin::types::int::p_add::IntPAdd;
@@ -22,11 +22,11 @@ mod add;
mod sub;
mod p_sub;
mod printi;
-mod eq;
mod p_add;
mod mul;
mod div;
mod modulo;
+mod comparators;
pub fn register_int(global_table: &mut GlobalDefinitionTable) {
global_table.register_builtin_type(b!(IntType));
@@ -43,6 +43,10 @@ pub fn register_int(global_table: &mut GlobalDefinitionTable) {
global_table.register_inline_function(&IntMod);
global_table.register_inline_function(&IntAsMod);
global_table.register_inline_function(&IntEq);
+ global_table.register_inline_function(&IntGT);
+ global_table.register_inline_function(&IntLT);
+ global_table.register_inline_function(&IntGE);
+ global_table.register_inline_function(&IntLE);
global_table.register_inline_function(&PrintI);
global_table.register_inline_function(&IntAssign);
}
diff --git a/src/root/parser/parse_function/parse_operator.rs b/src/root/parser/parse_function/parse_operator.rs
index 738f66b..434836c 100644
--- a/src/root/parser/parse_function/parse_operator.rs
+++ b/src/root/parser/parse_function/parse_operator.rs
@@ -19,7 +19,7 @@ pub enum PrefixOrInfixEx {
Infix
}
-const OPERATOR_MAPS: [(&str, OperatorTokens, PrefixOrInfix, &str); 18] = [
+const OPERATOR_MAPS: [(&str, OperatorTokens, PrefixOrInfix, &str); 22] = [
("+=", OperatorTokens::AsAdd, PrefixOrInfix::Infix, "as_add"),
("-=", OperatorTokens::AsSub, PrefixOrInfix::Infix, "as_sub"),
("*=", OperatorTokens::AsMul, PrefixOrInfix::Infix, "as_mul"),
@@ -30,6 +30,10 @@ const OPERATOR_MAPS: [(&str, OperatorTokens, PrefixOrInfix, &str); 18] = [
("&", OperatorTokens::Reference, PrefixOrInfix::Prefix, "ref"),
("||", OperatorTokens::Or, PrefixOrInfix::Infix, "or"),
("|=", OperatorTokens::AsOr, PrefixOrInfix::Infix, "as_or"),
+ (">=", OperatorTokens::GreaterEqual, PrefixOrInfix::Infix, "ge"),
+ ("<=", OperatorTokens::LessEqual, PrefixOrInfix::Infix, "le"),
+ (">", OperatorTokens::GreaterThan, PrefixOrInfix::Infix, "gt"),
+ ("<", OperatorTokens::LessThan, PrefixOrInfix::Infix, "lt"),
("+", OperatorTokens::Add, PrefixOrInfix::Both, "add"),
("-", OperatorTokens::Subtract, PrefixOrInfix::Both, "sub"),
("*", OperatorTokens::Multiply, PrefixOrInfix::Both, "mul"),
@@ -67,6 +71,10 @@ pub enum OperatorTokens {
Equals,
And,
Or,
+ GreaterEqual,
+ LessEqual,
+ GreaterThan,
+ LessThan,
AsAdd,
AsSub,
AsMul,
diff --git a/types.toml b/types.toml
deleted file mode 100644
index beb85dd..0000000
--- a/types.toml
+++ /dev/null
@@ -1,70 +0,0 @@
-IntAdd=0
-IntSub=1
-IntPSub=2
-PrintI=3
-IntEq=4
-IntType=5
-PrintB=6
-BoolType=7
-ExitFunction=8
-IntasAdd=9
-IntaAdd=10
-IntAAdd=11
-IntASAdd=12
-IntAsAdd=13
-IntAss=14
-IntAsss=15
-IntAsssi=16
-IntAsssig=17
-IntAsssign=18
-IntAssign=19
-IntPA=20
-IntPAd=21
-IntPAdd=22
-I=23
-In=24
-Int=25
-IntA=26
-IntAs=27
-IntAsS=28
-IntAsSu=29
-IntAsSub=30
-IntM=31
-IntMu=32
-IntMul=33
-IntAsMul=34
-IntAsDiv=35
-IntDiv=36
-i=37
-int=38
-intM=39
-intMo=40
-intMod=41
-ntMod=42
-IntMod=43
-IntAsM=44
-IntAsMo=45
-IntAsMod=46
-B=47
-Bo=48
-Boo=49
-Bool=50
-BoolA=51
-BoolAn=52
-BoolAnd=53
-BoolAs=54
-BoolAsA=55
-BoolAsAnb=56
-BoolAsAnbd=57
-BoolAsAn=58
-BoolAsAnd=59
-BoolOr=60
-BoolAsO=61
-BoolAsOr=62
-BoolN=63
-BoolNo=64
-BoolNot=65
-BoolAss=66
-BoolAssi=67
-BoolAssig=68
-BoolAssign=69