Encode bytecode version in first byte of binary

This commit is contained in:
Laborratte 5 2024-07-20 18:30:21 +02:00
parent 29e5f97dae
commit 11500fefed
Signed by: Laborratte5
GPG key ID: 3A30072E35202C02

View file

@ -18,6 +18,9 @@ import Compiler
type Bytecode = BL.ByteString type Bytecode = BL.ByteString
version1 :: Bu.Builder
version1 = P.execPut $ B.putWord8 1
toBinary :: Command -> P.Put toBinary :: Command -> P.Put
toBinary (Const i) = do toBinary (Const i) = do
P.putWord8 0x0001 P.putWord8 0x0001
@ -28,4 +31,4 @@ toBinary Mult = P.putWord8 0x0006
toBinary Div = P.putWord8 0x0007 toBinary Div = P.putWord8 0x0007
assemble :: [Command] -> Bytecode assemble :: [Command] -> Bytecode
assemble cmds = Bu.toLazyByteString $ mconcat (map (P.execPut . toBinary) cmds) assemble cmds = Bu.toLazyByteString $ mconcat $ version1:map (P.execPut . toBinary) cmds