From 11500fefed7e790d461ac186f484ae3c45141600 Mon Sep 17 00:00:00 2001 From: Laborratte5 Date: Sat, 20 Jul 2024 18:30:21 +0200 Subject: [PATCH] Encode bytecode version in first byte of binary --- app/Assembler.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Assembler.hs b/app/Assembler.hs index da159f3..fe4aa1c 100644 --- a/app/Assembler.hs +++ b/app/Assembler.hs @@ -18,6 +18,9 @@ import Compiler type Bytecode = BL.ByteString +version1 :: Bu.Builder +version1 = P.execPut $ B.putWord8 1 + toBinary :: Command -> P.Put toBinary (Const i) = do P.putWord8 0x0001 @@ -28,4 +31,4 @@ toBinary Mult = P.putWord8 0x0006 toBinary Div = P.putWord8 0x0007 assemble :: [Command] -> Bytecode -assemble cmds = Bu.toLazyByteString $ mconcat (map (P.execPut . toBinary) cmds) +assemble cmds = Bu.toLazyByteString $ mconcat $ version1:map (P.execPut . toBinary) cmds