source/projects/shoggoth/src/python/ichor/bootstrap.py

87 lines
1.6 KiB
Python
Raw Normal View History

"""Shogoth bootstrap code.
Some utterly trivial functions and types that allow me to begin testing the VM.
Hopefully no "real" interpreter ever uses this code, since it's obviously replaceable.
"""
2022-07-16 01:33:32 +00:00
from ichor import isa
2022-06-28 04:35:21 +00:00
from ichor.state import Module, Variant
2022-05-31 15:41:10 +00:00
BOOTSTRAP = Module()
2022-06-16 03:56:52 +00:00
BOOL = BOOTSTRAP.define_type(
";bool;true(),false()",
)
2022-07-16 01:37:34 +00:00
TRUE = Variant(BOOL, "true", ())
FALSE = Variant(BOOL, "false", ())
2022-06-28 04:35:21 +00:00
2022-06-01 05:08:29 +00:00
NOT1 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";not;{BOOL};{BOOL}",
[
2022-06-28 04:35:21 +00:00
# a: Bool
2022-07-16 01:33:32 +00:00
isa.IDENTIFIERC("bool"),
isa.TYPEREF(), # <typeref bool> a
isa.DUP(),
isa.IDENTIFIERC("true"),
2022-08-09 15:39:33 +00:00
isa.ARMREF(), # <variantref true:bool> <typeref bool> a
2022-07-16 01:33:32 +00:00
isa.DUP(),
isa.SLOT(0),
isa.ROT(2),
2022-08-09 15:39:33 +00:00
isa.ATEST(11),
2022-06-28 04:35:21 +00:00
2022-08-09 15:39:33 +00:00
isa.ARM(0),
isa.RETURN(),
2022-06-28 04:35:21 +00:00
2022-07-16 01:33:32 +00:00
isa.DROP(1),
isa.IDENTIFIERC("false"),
2022-08-09 15:39:33 +00:00
isa.ARMREF(),
isa.ARM(0),
isa.RETURN(),
],
)
2022-06-01 05:08:29 +00:00
OR2 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";or;{BOOL},{BOOL};{BOOL}",
[
2022-07-16 01:33:32 +00:00
isa.BREAK(),
],
)
2022-06-01 05:08:29 +00:00
OR3 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";or;{BOOL},{BOOL},{BOOL};{BOOL}",
2022-06-01 05:08:29 +00:00
[
2022-07-16 01:33:32 +00:00
isa.BREAK(),
2022-06-01 05:08:29 +00:00
]
)
AND2 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";and;{BOOL},{BOOL};{BOOL}",
[
2022-07-16 01:33:32 +00:00
isa.BREAK(),
],
)
2022-06-01 05:08:29 +00:00
AND3 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";and;{BOOL},{BOOL},{BOOL};{BOOL}",
2022-06-01 05:08:29 +00:00
[
2022-07-16 01:33:32 +00:00
isa.BREAK(),
2022-06-01 05:08:29 +00:00
],
)
XOR2 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";xor;{BOOL},{BOOL};{BOOL}",
[
2022-07-16 01:33:32 +00:00
isa.BREAK(),
],
)
2022-06-01 05:08:29 +00:00
XOR3 = BOOTSTRAP.define_function(
2022-06-16 03:56:52 +00:00
f";xor;{BOOL},{BOOL},{BOOL};{BOOL}",
2022-06-01 05:08:29 +00:00
[
2022-06-28 04:35:21 +00:00
# A^B|B^C
2022-07-16 01:33:32 +00:00
isa.BREAK(),
2022-06-01 05:08:29 +00:00
]
)