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

88 lines
1.7 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-06-14 02:23:43 +00:00
from ichor.isa import Opcode
2022-06-28 04:35:21 +00:00
from ichor.state import Module, Variant
2022-07-02 06:35:03 +00:00
from ichor.assembler import FuncBuilder
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-06-28 04:35:21 +00:00
TRUE = Variant(BOOL, 'true', ())
FALSE = Variant(BOOL, 'false', ())
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
Opcode.IDENTIFIERC("bool"),
Opcode.TYPEREF(), # <typeref bool> a
Opcode.DUP(),
Opcode.IDENTIFIERC("true"),
Opcode.VARIANTREF(), # <variantref true:bool> <typeref bool> a
Opcode.DUP(),
Opcode.SLOT(0),
Opcode.ROT(2),
Opcode.VTEST(11),
Opcode.VARIANT(0),
Opcode.RETURN(1),
2022-06-28 04:35:21 +00:00
Opcode.DROP(1),
Opcode.IDENTIFIERC("false"),
Opcode.VARIANTREF(),
Opcode.VARIANT(0),
Opcode.RETURN(1),
],
)
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-06-28 04:35:21 +00:00
Opcode.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-06-28 04:35:21 +00:00
Opcode.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-06-28 04:35:21 +00:00
Opcode.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-06-28 04:35:21 +00:00
Opcode.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-06-28 04:35:21 +00:00
Opcode.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
Opcode.BREAK(),
2022-06-01 05:08:29 +00:00
]
)