Skip to content

Commit

Permalink
Compile the division instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed May 25, 2024
1 parent ab7995d commit cf40b9e
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 675 deletions.
15 changes: 9 additions & 6 deletions packages/valkyrie-esoteric/source/statement/match-case.valkyrie
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ match literal {
case nil:
case true | false:
case
| none # variable = none
| none # variable = none
then
print("none variable")
case
| None # variant = Option::None
| Option⸬None # variant = Option::None
| Boolean⸬True
| Boolean⸬Fals
| None # variant = Option::None
| Option⸬None # variant = Option::None
| Boolean⸬True
| Boolean⸬Fals
then
print("none type")
case None = 0: # variable = None
Expand All @@ -19,7 +19,10 @@ match literal {
case "":
case '':
}

match value {
case Boolean⸬Fals: 0
case Boolean⸬True: 1
}
match tuple {
case ():
case (a):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Point3D⟨T⟩ {
x: T,
y: T,
z: T,
constructor(x: T, y: T, z: T) {
@bind_fields(x, y, z)
}
}

class Complex⟨T⟩ {
re: T,
im: T,
constructor(real: T, imaginary: T) {
this.re = real;
this.im = imaginary;
}
}

13 changes: 5 additions & 8 deletions packages/valkyrie-experiment/source/text/Unicode.vk
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ namespace package.native;

#native(4byte)
#derive(Copy, Clone, Display)
class Unicode {
#range(1, 0x10FFFF)
codepoint: u32,
}


#native
extends char {
imply char {
as_ascii(self) -> Ascii {

}
is_ascii(self) -> bool {
???

}
is_whitespace(self) -> bool {
@matches(self, true)
Expand All @@ -30,10 +27,10 @@ extends char {

#native
extends bool: Negative {
micro negative(mut self) {
negative(mut self) {
self = self.opposite()
}
micro opposite(self) -> bool {
opposite(self) -> bool {
self.is_false()
}
}
5 changes: 0 additions & 5 deletions packages/valkyrie-experiment/source/text/_.vk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@ trait Text {
}


trait MutableText: Text {

}


This file was deleted.

10 changes: 0 additions & 10 deletions packages/valkyrie-standard/source/primitive/Boolean.valkyrie
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,3 @@ enums Boolean = i32 {
Fals = 0
True = 1
}

class Complex⟨T⟩ {
re: T,
im: T,
constructor(real: T, imaginary: T) {
this.re = real;
this.im = imaginary;
}
}

28 changes: 0 additions & 28 deletions packages/valkyrie-standard/source/primitive/f32.valkyrie
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,3 @@ namespace package.primitive;

↯primitive(f32)
class f32 {}

↯derive(Converters)
imply f32 {
↯specialized(0)
explicit from(self) -> i8 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
↯specialized(-100)
implicit into(self) -> u64 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
}
28 changes: 0 additions & 28 deletions packages/valkyrie-standard/source/primitive/f64.valkyrie
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,3 @@ namespace package.primitive;

↯primitive(f64)
class f64 {}

↯derive(Converters)
imply u32 {
↯specialized(0)
explicit into(self) -> i32 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
↯specialized(-100)
implicit into(self) -> u64 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
}
126 changes: 2 additions & 124 deletions packages/valkyrie-standard/source/primitive/i16.valkyrie
Original file line number Diff line number Diff line change
@@ -1,126 +1,4 @@
namespace package.primitive;

↯primitive(u32)
class u32 {}

↯derive(Operators)
imply u32 {
# ↯specialized(0)
# infix `+`(self, rhs: u32) {
#
# }
# ↯specialized(-100)
# infix `+`(self, rhs: i32) {
#
# }
↯unchecked
↯instruction(i32.div_u)
add_unchecked(self, rhs: u32) -> u32 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
# ↯specialized(0)
# infix `-`(self, rhs: u32) {
#
# }
# ↯specialized(-100)
# infix `-`(self, rhs: i32) {
#
# }
# infix `/=`(mut self, rhs: u32) {
# self = self / rhs
# }
# infix `/`(self, rhs: u32)-> u32 {
# if rhs == 0 {
# raise DivideByZero(rhs)
# }
# else {
# self.div_unchecked(rhs)
# }
# }
↯unchecked
↯instruction(i32.div_u)
div_unchecked(self, rhs: u32) -> u32 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
}

↯derive(Converters)
imply u32 {
↯specialized(0)
explicit into(self) -> i32 {
"""
(param $self)
(param $rhs)
(result i32)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
↯specialized(-100)
implicit into(self) -> u64 {
"""
(param $self)
(result i64)
(i32.div_s
local.get $self
local.get $rhs
)
"""
}
}

↯derive(From, Into)
imply bool {
↯asm
explicit from(value: u16) {
"""
(param $value i32)
(result i32)
local.get $self
i32.eqz
"""
}
↯asm
explicit into(self) -> u16 {
"""
(param $self i32)
(result i32)
local.get $self
"""
}
↯asm
explicit from(value: i16) {
"""
(param $value i32)
(result i32)
local.get $self
i32.eqz
"""
}
↯asm
explicit into(self) -> i16 {
"""
(param $self i32)
(result i32)
local.get $self
"""
}
}
↯primitive(i32)
class i16 {}
Loading

0 comments on commit cf40b9e

Please sign in to comment.