From 54ff11f13c479754fc9cbdca671209d571101654 Mon Sep 17 00:00:00 2001
From: Reid 'arrdem' McKenzie <me@arrdem.com>
Date: Wed, 15 Jun 2022 21:56:52 -0600
Subject: [PATCH] Wire up define_type

---
 .../shoggoth/src/python/ichor/bootstrap.py    | 26 ++++++++-----------
 projects/shoggoth/src/python/ichor/state.py   | 11 +++++---
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/projects/shoggoth/src/python/ichor/bootstrap.py b/projects/shoggoth/src/python/ichor/bootstrap.py
index dbeed0b..90ad4f8 100644
--- a/projects/shoggoth/src/python/ichor/bootstrap.py
+++ b/projects/shoggoth/src/python/ichor/bootstrap.py
@@ -10,8 +10,12 @@ from ichor.state import Module
 
 BOOTSTRAP = Module()
 
+BOOL = BOOTSTRAP.define_type(
+    ";bool;true(),false()",
+)
+
 NOT1 = BOOTSTRAP.define_function(
-    ";not;bool;bool",
+    f";not;{BOOL};{BOOL}",
     [
         Opcode.IF(target=3),
         Opcode.FALSE(),
@@ -22,7 +26,7 @@ NOT1 = BOOTSTRAP.define_function(
 )
 
 OR2 = BOOTSTRAP.define_function(
-    ";or;bool,bool;bool",
+    f";or;{BOOL},{BOOL};{BOOL}",
     [
         Opcode.IF(target=3),
         Opcode.TRUE(),
@@ -36,7 +40,7 @@ OR2 = BOOTSTRAP.define_function(
 )
 
 OR3 = BOOTSTRAP.define_function(
-    ";or;bool,bool,bool;bool",
+    f";or;{BOOL},{BOOL},{BOOL};{BOOL}",
     [
         # A B C
         Opcode.IDENTIFIERC(OR2),
@@ -54,7 +58,7 @@ OR3 = BOOTSTRAP.define_function(
 )
 
 AND2 = BOOTSTRAP.define_function(
-    ";and;bool,bool;bool",
+    f";and;{BOOL},{BOOL};{BOOL}",
     [
         Opcode.IF(target=3),
         Opcode.IF(target=3),
@@ -67,7 +71,7 @@ AND2 = BOOTSTRAP.define_function(
 )
 
 AND3 = BOOTSTRAP.define_function(
-    ";and;bool,bool,bool;bool",
+    f";and;{BOOL},{BOOL},{BOOL};{BOOL}",
     [
         # A B C
         Opcode.IDENTIFIERC(AND2),
@@ -84,7 +88,7 @@ AND3 = BOOTSTRAP.define_function(
 )
 
 XOR2 = BOOTSTRAP.define_function(
-    ";xor;bool,bool;bool",
+    f";xor;{BOOL},{BOOL};{BOOL}",
     [
         Opcode.IDENTIFIERC(AND2),
         Opcode.FUNREF(),
@@ -119,7 +123,7 @@ XOR2 = BOOTSTRAP.define_function(
 )
 
 XOR3 = BOOTSTRAP.define_function(
-    ";xor;bool,bool,bool;bool",
+    f";xor;{BOOL},{BOOL},{BOOL};{BOOL}",
     [
         Opcode.IDENTIFIERC(XOR2),
         Opcode.FUNREF(),
@@ -145,11 +149,3 @@ XOR3 = BOOTSTRAP.define_function(
         Opcode.RETURN(1),
     ]
 )
-
-BOOL = BOOTSTRAP.define_type(
-    ";bool",
-    {
-        ";true;": [],
-        ";false;": [],
-    },
-)
diff --git a/projects/shoggoth/src/python/ichor/state.py b/projects/shoggoth/src/python/ichor/state.py
index 5b50218..3dcc58b 100644
--- a/projects/shoggoth/src/python/ichor/state.py
+++ b/projects/shoggoth/src/python/ichor/state.py
@@ -137,6 +137,10 @@ class Type(t.NamedTuple):
         # They both probably live in the same list
         return cls(name, arms, typeconstraints=constraints)
 
+    @property
+    def signature(self):
+        return self.name
+
 
 class Closure(t.NamedTuple):
     # 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))
         return func.signature
 
-    def define_type(self, name, signature):
-        self.types[name] = signature
-        return name
+    def define_type(self, name):
+        type = Type.build(name)
+        self.types[type.signature] = type
+        return type.signature
 
     def __str__(self):
         b = []