Wire up define_type

This commit is contained in:
Reid 'arrdem' McKenzie 2022-06-15 21:56:52 -06:00
parent 0564031502
commit 56e12252f5
2 changed files with 19 additions and 18 deletions

View file

@ -10,8 +10,12 @@ from ichor.state import Module
BOOTSTRAP = Module() BOOTSTRAP = Module()
BOOL = BOOTSTRAP.define_type(
";bool;true(),false()",
)
NOT1 = BOOTSTRAP.define_function( NOT1 = BOOTSTRAP.define_function(
";not;bool;bool", f";not;{BOOL};{BOOL}",
[ [
Opcode.IF(target=3), Opcode.IF(target=3),
Opcode.FALSE(), Opcode.FALSE(),
@ -22,7 +26,7 @@ NOT1 = BOOTSTRAP.define_function(
) )
OR2 = BOOTSTRAP.define_function( OR2 = BOOTSTRAP.define_function(
";or;bool,bool;bool", f";or;{BOOL},{BOOL};{BOOL}",
[ [
Opcode.IF(target=3), Opcode.IF(target=3),
Opcode.TRUE(), Opcode.TRUE(),
@ -36,7 +40,7 @@ OR2 = BOOTSTRAP.define_function(
) )
OR3 = BOOTSTRAP.define_function( OR3 = BOOTSTRAP.define_function(
";or;bool,bool,bool;bool", f";or;{BOOL},{BOOL},{BOOL};{BOOL}",
[ [
# A B C # A B C
Opcode.IDENTIFIERC(OR2), Opcode.IDENTIFIERC(OR2),
@ -54,7 +58,7 @@ OR3 = BOOTSTRAP.define_function(
) )
AND2 = BOOTSTRAP.define_function( AND2 = BOOTSTRAP.define_function(
";and;bool,bool;bool", f";and;{BOOL},{BOOL};{BOOL}",
[ [
Opcode.IF(target=3), Opcode.IF(target=3),
Opcode.IF(target=3), Opcode.IF(target=3),
@ -67,7 +71,7 @@ AND2 = BOOTSTRAP.define_function(
) )
AND3 = BOOTSTRAP.define_function( AND3 = BOOTSTRAP.define_function(
";and;bool,bool,bool;bool", f";and;{BOOL},{BOOL},{BOOL};{BOOL}",
[ [
# A B C # A B C
Opcode.IDENTIFIERC(AND2), Opcode.IDENTIFIERC(AND2),
@ -84,7 +88,7 @@ AND3 = BOOTSTRAP.define_function(
) )
XOR2 = BOOTSTRAP.define_function( XOR2 = BOOTSTRAP.define_function(
";xor;bool,bool;bool", f";xor;{BOOL},{BOOL};{BOOL}",
[ [
Opcode.IDENTIFIERC(AND2), Opcode.IDENTIFIERC(AND2),
Opcode.FUNREF(), Opcode.FUNREF(),
@ -119,7 +123,7 @@ XOR2 = BOOTSTRAP.define_function(
) )
XOR3 = BOOTSTRAP.define_function( XOR3 = BOOTSTRAP.define_function(
";xor;bool,bool,bool;bool", f";xor;{BOOL},{BOOL},{BOOL};{BOOL}",
[ [
Opcode.IDENTIFIERC(XOR2), Opcode.IDENTIFIERC(XOR2),
Opcode.FUNREF(), Opcode.FUNREF(),
@ -145,11 +149,3 @@ XOR3 = BOOTSTRAP.define_function(
Opcode.RETURN(1), Opcode.RETURN(1),
] ]
) )
BOOL = BOOTSTRAP.define_type(
";bool",
{
";true;": [],
";false;": [],
},
)

View file

@ -137,6 +137,10 @@ class Type(t.NamedTuple):
# They both probably live in the same list # They both probably live in the same list
return cls(name, arms, typeconstraints=constraints) return cls(name, arms, typeconstraints=constraints)
@property
def signature(self):
return self.name
class Closure(t.NamedTuple): class Closure(t.NamedTuple):
# Note that a closure over a closure is equivalent to a single closure which extends the captured stack fragment, so # Note that a closure over a closure is equivalent to a single closure which extends the captured stack fragment, so
@ -197,9 +201,10 @@ class Module(t.NamedTuple):
self.codepage.append(self.translate(start, start + len(opcodes), op)) self.codepage.append(self.translate(start, start + len(opcodes), op))
return func.signature return func.signature
def define_type(self, name, signature): def define_type(self, name):
self.types[name] = signature type = Type.build(name)
return name self.types[type.signature] = type
return type.signature
def __str__(self): def __str__(self):
b = [] b = []