2022-04-12 07:49:12 +00:00
|
|
|
"""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-07-02 06:35:03 +00:00
|
|
|
from ichor.assembler import FuncBuilder
|
2022-04-12 07:49:12 +00:00
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
|
2022-04-12 07:49:12 +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-04-12 07:49:12 +00:00
|
|
|
[
|
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"),
|
|
|
|
isa.VARIANTREF(), # <variantref true:bool> <typeref bool> a
|
|
|
|
isa.DUP(),
|
|
|
|
isa.SLOT(0),
|
|
|
|
isa.ROT(2),
|
|
|
|
isa.VTEST(11),
|
2022-06-28 04:35:21 +00:00
|
|
|
|
2022-07-16 01:33:32 +00:00
|
|
|
isa.VARIANT(0),
|
|
|
|
isa.RETURN(1),
|
2022-06-28 04:35:21 +00:00
|
|
|
|
2022-07-16 01:33:32 +00:00
|
|
|
isa.DROP(1),
|
|
|
|
isa.IDENTIFIERC("false"),
|
|
|
|
isa.VARIANTREF(),
|
|
|
|
isa.VARIANT(0),
|
|
|
|
isa.RETURN(1),
|
2022-04-12 07:49:12 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
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-04-12 07:49:12 +00:00
|
|
|
[
|
2022-07-16 01:33:32 +00:00
|
|
|
isa.BREAK(),
|
2022-04-12 07:49:12 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
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-04-12 07:49:12 +00:00
|
|
|
[
|
2022-07-16 01:33:32 +00:00
|
|
|
isa.BREAK(),
|
2022-04-12 07:49:12 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
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-04-12 07:49:12 +00:00
|
|
|
[
|
2022-07-16 01:33:32 +00:00
|
|
|
isa.BREAK(),
|
2022-04-12 07:49:12 +00:00
|
|
|
],
|
|
|
|
)
|
2022-04-21 06:17:59 +00:00
|
|
|
|
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
|
|
|
]
|
|
|
|
)
|