diff --git a/benchmark/benchmark.ml b/benchmark/benchmark.ml index b1d4c27..29af793 100644 --- a/benchmark/benchmark.ml +++ b/benchmark/benchmark.ml @@ -243,7 +243,8 @@ end = struct | Compile -> fun _ -> ignore @@ Sys.opaque_identity (Pinc_lang.Compiler.compile ast) | Deserialize -> fun _ -> ignore @@ Sys.opaque_identity (Pinc_lang.Bytecode.deserialize bytecode) - | Vm _root -> fun _ -> ignore @@ Sys.opaque_identity (Pinc_lang.Vm.eval bytecode) + | Vm root -> + fun _ -> ignore @@ Sys.opaque_identity (Pinc_lang.Vm.eval ~root bytecode) in let name = string_of_action action in let b = Benchmark.make ~name ~f:benchmarkFn () in diff --git a/bin/print_vm.ml b/bin/print_vm.ml index 147cf98..d171716 100644 --- a/bin/print_vm.ml +++ b/bin/print_vm.ml @@ -28,10 +28,8 @@ let main = try sources |> Parser.get_ast ~include_stdlib:false - |> StringMap.find root - |> StringMap.singleton root |> Compiler.compile - |> Vm.eval + |> Vm.eval ~root |> print_endline with Diagnostics.Pinc_error _ -> exit 1 ;; diff --git a/lib/pinc_bytecode/bytecode.ml b/lib/pinc_bytecode/bytecode.ml index 605a1cf..7e1f950 100644 --- a/lib/pinc_bytecode/bytecode.ml +++ b/lib/pinc_bytecode/bytecode.ml @@ -1,9 +1,11 @@ -type t = { +type t = declaration StringMap.t + +and declaration = { instructions : Instruction.t Array.t; constants : Value.t Dynarray.t; } -let make ~instructions ~constants = { instructions; constants } +let make_declaration ~instructions ~constants = { instructions; constants } let pp_instructions fmt = let offset = ref 0 in @@ -48,26 +50,50 @@ let pp_constants fmt constants = constants ;; -let pp fmt t = +let pp_declaration fmt declaration = let () = - match Dynarray.is_empty t.constants with + match Dynarray.is_empty declaration.constants with | true -> () | false -> - Format.fprintf Format.std_formatter "[CONSTANTS]@."; - pp_constants fmt t.constants; - Format.fprintf Format.std_formatter "@." + Format.fprintf Format.std_formatter "[CONSTANTS]@;"; + pp_constants fmt declaration.constants; + Format.fprintf Format.std_formatter "@;" in let () = - match t.instructions with + match declaration.instructions with | [||] -> () | instructions -> - Format.fprintf Format.std_formatter "[INSTRUCTIONS]@."; + Format.fprintf Format.std_formatter "[INSTRUCTIONS]@;"; Format.fprintf fmt "@[%a@]" pp_instructions instructions in () ;; -let serialize t = +let pp fmt t = + StringMap.iter + (fun identifier declaration -> + Format.fprintf fmt "" identifier; + Format.fprintf fmt " [@;@[ %a@]@.]" pp_declaration declaration; + Format.fprintf fmt "@."; + Format.fprintf fmt "@.") + t +;; + +let rec serialize (t : t) = + let buf = Buffer.create 65565 in + let () = + StringMap.iter + (fun identifier declaration -> + Buffer.add_int16_be buf (String.length identifier); + Buffer.add_string buf identifier; + let serialized_declaration = serialize_declaration declaration in + Buffer.add_int32_be buf (Int32.of_int @@ String.length serialized_declaration); + Buffer.add_string buf serialized_declaration) + t + in + Buffer.contents buf + +and serialize_declaration t = let buf = Buffer.create 65565 in let constants = t.constants in let num_constants = Dynarray.length constants in @@ -84,13 +110,32 @@ let serialize t = Buffer.contents buf ;; -let deserialize ?(function_count = ref 0) str = +let rec deserialize str = let bytes = Bytes.of_string str in + let bytes_length = Bytes.length bytes in let offset = ref 0 in + let declarations = Dynarray.create () in + while !offset < bytes_length do + let identifier_length = Bytes.get_int16_be bytes !offset in + offset := !offset + 2; + let identifier = Bytes.sub_string bytes !offset identifier_length in + offset := !offset + identifier_length; + let declaration_length = Int32.to_int @@ Bytes.get_int32_be bytes !offset in + offset := !offset + 4; + let declaration = Bytes.sub_string bytes !offset declaration_length in + offset := !offset + declaration_length; + let deserialized_declaration = deserialize_declaration declaration in + Dynarray.add_last declarations (identifier, deserialized_declaration) + done; + StringMap.of_seq @@ Dynarray.to_seq declarations + +and deserialize_declaration str = + let offset = ref 0 in + let bytes = Bytes.of_string str in let num_constants = Int32.to_int @@ Bytes.get_int32_be bytes !offset in offset := !offset + 4; let constants = - Dynarray.init num_constants @@ fun _ -> Value.deserialize ~function_count bytes offset + Dynarray.init num_constants @@ fun _ -> Value.deserialize bytes offset in let instructions_length = Int32.to_int @@ Bytes.get_int32_be bytes !offset in offset := !offset + 4; @@ -101,5 +146,5 @@ let deserialize ?(function_count = ref 0) str = res) in assert (!offset = Bytes.length bytes); - make ~instructions ~constants + make_declaration ~instructions ~constants ;; diff --git a/lib/pinc_bytecode/value.ml b/lib/pinc_bytecode/value.ml index 319e176..68f9ce7 100644 --- a/lib/pinc_bytecode/value.ml +++ b/lib/pinc_bytecode/value.ml @@ -292,7 +292,7 @@ and serialize_fragment_template_node buf children = () ;; -let deserialize ~function_count bytes offset = +let deserialize bytes offset = let rec deserialize_value bytes offset = let tag = Bytes.get_int8 bytes !offset in offset := !offset + 1; @@ -356,8 +356,7 @@ let deserialize ~function_count bytes offset = offset := new_offset; res) in - let fn_addr = !function_count in - let () = incr function_count in + let fn_addr = -1 in { num_locals; num_parameters; instructions; fn_addr } and deserialize_builtin_function bytes offset = let num_parameters = Int32.to_int @@ Bytes.get_int32_be bytes !offset in diff --git a/lib/pinc_compiler/compiler.ml b/lib/pinc_compiler/compiler.ml index 5a9d6f5..6c19c29 100644 --- a/lib/pinc_compiler/compiler.ml +++ b/lib/pinc_compiler/compiler.ml @@ -22,6 +22,25 @@ type t = { let empty_instruction = { offset = 0; instruction = I_Null } +let make () = + let frames = + [ + { + instructions = Dynarray.create (); + previous_instruction = empty_instruction; + last_instruction = empty_instruction; + loop_level = 0; + break_instructions = []; + continue_instructions = []; + }; + ] + in + let constants = Dynarray.create () in + let () = Dynarray.ensure_capacity constants 2048 in + let symbol_table = SymbolTable.make () in + { constants; symbol_table; frames } +;; + let current_frame t = match t.frames with | [] -> assert false @@ -197,9 +216,9 @@ let emit_constant t constant = emit t constant ;; -let define_symbol t name ~is_mutable = +let define_symbol t name ~is_mutable ~is_heap_allocated = let symbol_table, address = - SymbolTable.define_symbol t.symbol_table ~name ~is_mutable + SymbolTable.define_symbol t.symbol_table ~name ~is_mutable ~is_heap_allocated in ({ t with symbol_table }, address) ;; @@ -368,7 +387,7 @@ and compile_function t ~identifier ~parameters ~body = let t = List.fold_left (fun t (Pinc_Types.Ast.Lowercase_Id (name, _)) -> - fst @@ define_symbol t name ~is_mutable:false) + fst @@ define_symbol t name ~is_mutable:false ~is_heap_allocated:false) t parameters in @@ -557,8 +576,12 @@ and compile_loop_expression t ~index ~iterator ~reverse:_ ~iterable ~body = let (Lowercase_Id (iterator, _)) = iterator in let t = add_scope t in let t = enter_loop t in - let t, iterator_symbol = define_symbol t iterator ~is_mutable:false in - let t, length_symbol = define_symbol t ".length" ~is_mutable:false in + let t, iterator_symbol = + define_symbol t iterator ~is_mutable:false ~is_heap_allocated:false + in + let t, length_symbol = + define_symbol t ".length" ~is_mutable:false ~is_heap_allocated:false + in (* Index *) let index_identifier = match index with @@ -566,15 +589,21 @@ and compile_loop_expression t ~index ~iterator ~reverse:_ ~iterable ~body = | None -> ".index" in let t = emit_constant t @@ Pinc_Bytecode.Value.Int 0 in - let t, index_symbol = define_symbol t index_identifier ~is_mutable:false in + let t, index_symbol = + define_symbol t index_identifier ~is_mutable:false ~is_heap_allocated:false + in let t = emit_set_symbol t index_symbol in (* Iterations *) let t = emit_constant t @@ Pinc_Bytecode.Value.Int 0 in - let t, n_iterations_symbol = define_symbol t ".n_iterations" ~is_mutable:false in + let t, n_iterations_symbol = + define_symbol t ".n_iterations" ~is_mutable:false ~is_heap_allocated:false + in let t = emit_set_symbol t n_iterations_symbol in (* Iterable *) let t = compile_expr t iterable in - let t, iterable_symbol = define_symbol t ".iterable" ~is_mutable:false in + let t, iterable_symbol = + define_symbol t ".iterable" ~is_mutable:false ~is_heap_allocated:false + in let t = emit_set_symbol t iterable_symbol in let t = emit_get_symbol t iterable_symbol in let t = emit t @@ Pinc_Bytecode.Instruction.I_Length in @@ -646,7 +675,7 @@ and compile_let_stmt ~predefined t definition = let t = compile_expr t body in let t, symbol = match List.assoc_opt name predefined with - | None -> define_symbol t name ~is_mutable + | None -> define_symbol t name ~is_mutable ~is_heap_allocated:is_mutable | Some symbol -> (t, symbol) in let t = emit_set_symbol t symbol in @@ -682,7 +711,7 @@ and compile_let_group_stmt t definitions = let ~is_optional:_, ~is_mutable, Pinc_Types.Ast.Lowercase_Id (name, _), _ = definition in - let t, symbol = define_symbol t name ~is_mutable in + let t, symbol = define_symbol t name ~is_mutable ~is_heap_allocated:true in (t, (name, symbol) :: symbols)) (t, []) definitions @@ -733,31 +762,81 @@ and compile_template_node_children t children = t ;; -let compile_declaration (decl : Pinc_Types.Ast.declaration) t = - compile_expr t decl.declaration_body +let compile_template_declaration t identifier declaration = + let t, _declaration_symbol = + let symbol_table, symbol = + SymbolTable.define_symbol + t.symbol_table + ~name:identifier + ~is_mutable:false + ~is_heap_allocated:true + in + ({ t with symbol_table }, symbol) + in + let t = add_frame t in + (* TODO: Count tag symbols in body and define them as parameters to the declaration *) + (* + let t = + List.fold_left + (fun t (Pinc_Types.Ast.Lowercase_Id (name, _)) -> + fst @@ define_symbol t name ~is_mutable:false) + t + parameters + in *) + let t = + let body = declaration.Pinc_Types.Ast.declaration_body in + match body.Pinc_Types.Ast.expression_desc with + | Pinc_Types.Ast.BlockExpression stmts -> List.fold_left compile_stmt t stmts + | _ -> + let t = compile_expr t body in + emit t @@ Pinc_Bytecode.Instruction.I_Return + in + let t = + if match_last_instruction t I_Pop then ( + let t = remove_last_instruction t in + emit t @@ Pinc_Bytecode.Instruction.I_Return) + else + t + in + let t = + if not @@ match_last_instruction t I_Return then ( + let t = emit t @@ Pinc_Bytecode.Instruction.I_Null in + emit t @@ Pinc_Bytecode.Instruction.I_Return) + else + t + in + let free_variables = SymbolTable.free_variables t.symbol_table in + let num_locals = SymbolTable.length t.symbol_table in + let t, frame = pop_frame t in + let t = List.fold_left emit_get_symbol t free_variables in + + let num_free_variables = List.length free_variables in + (* TODO: set num_parameters *) + let num_parameters = 0 in + let instructions = Dynarray.to_array @@ frame.instructions in + let fn_addr, t = + add_constant t + @@ Pinc_Bytecode.Value.Function + { fn_addr = -1; num_locals; num_parameters; instructions } + in + let t = emit t @@ Pinc_Bytecode.Instruction.I_Closure (fn_addr, num_free_variables) in + t ;; -let compile (ast : Pinc_Types.Ast.t) = - let frames = - [ - { - instructions = Dynarray.create (); - previous_instruction = empty_instruction; - last_instruction = empty_instruction; - loop_level = 0; - break_instructions = []; - continue_instructions = []; - }; - ] +let compile_declaration identifier (declaration : Pinc_Types.Ast.declaration) = + let t = make () in + let t = + match declaration.declaration_kind with + | Declaration_Component -> compile_template_declaration t identifier declaration + | Declaration_Page -> compile_template_declaration t identifier declaration + | Declaration_Library -> raise TODO + | Declaration_Store -> raise TODO in - let constants = Dynarray.create () in - let () = Dynarray.ensure_capacity constants 2048 in - let symbol_table = SymbolTable.make () in - let t = { constants; symbol_table; frames } in - let t = StringMap.fold (fun _ -> compile_declaration) ast t in + let instructions = Dynarray.to_array @@ current_instructions t in + let constants = t.constants in + Pinc_Bytecode.Bytecode.make_declaration ~instructions ~constants +;; - Pinc_Bytecode.Bytecode.serialize - @@ Pinc_Bytecode.Bytecode.make - ~instructions:(Dynarray.to_array @@ current_instructions t) - ~constants:t.constants +let compile (ast : Pinc_Types.Ast.t) = + Pinc_Bytecode.Bytecode.serialize @@ StringMap.mapi compile_declaration ast ;; diff --git a/lib/pinc_core/SymbolTable.ml b/lib/pinc_core/SymbolTable.ml index 8ced64a..dce6041 100644 --- a/lib/pinc_core/SymbolTable.ml +++ b/lib/pinc_core/SymbolTable.ml @@ -65,11 +65,12 @@ let pop_frame t = | Some t -> t ;; -let define_symbol t ~name ~is_mutable = +let define_symbol t ~name ~is_mutable ~is_heap_allocated = let kind = - match t.outer with - | None -> Kind.Global - | Some _ -> Kind.Local + match (is_heap_allocated, t.outer) with + | true, _ -> Kind.Global + | false, None -> Kind.Global + | false, Some _ -> Kind.Local in let symbol = Symbol.make ~name ~kind ~address:t.num_bindings ~level:t.scope ~is_mutable diff --git a/lib/pinc_vm/vm.ml b/lib/pinc_vm/vm.ml index bc6d7ea..270a8a0 100644 --- a/lib/pinc_vm/vm.ml +++ b/lib/pinc_vm/vm.ml @@ -80,7 +80,7 @@ let make ~constants ~resolved_functions ~instructions = constants; resolved_functions; stack = Stack.make ~size:stack_size; - globals = Array.make 131_072 Value.Null; + globals = Array.make (2 lsl 16) Value.Null; past_frames = []; current_frame = main_frame; } @@ -996,7 +996,6 @@ let resolve_instructions instructions = ;; let resolve_constant_functions ~function_count constants = - (* We add one to the function count to reserve the first space for the main function *) let resolved_functions = Array.make function_count [||] in let rec resolve_from_value value = match value with @@ -1014,9 +1013,11 @@ let resolve_constant_functions ~function_count constants = | Value.FragmentTemplateNode children -> Array.iter resolve_from_value children | Value.Function fn -> let instructions = resolve_instructions fn.instructions in + assert (fn.fn_addr < function_count); Array.set resolved_functions fn.fn_addr instructions | Value.Closure closure -> let instructions = resolve_instructions closure.fn.instructions in + assert (closure.fn.fn_addr < function_count); Array.set resolved_functions closure.fn.fn_addr instructions | Value.BuiltinFunction _ -> () in @@ -1024,16 +1025,129 @@ let resolve_constant_functions ~function_count constants = resolved_functions ;; -let eval bytecode = - let function_count = ref 0 in - let code = bytecode |> Pinc_Bytecode.Bytecode.deserialize ~function_count in - let instructions = - Array.append (resolve_instructions code.instructions) [| execute_halt |] +let update_instructions_space ~constants_offset ~globals_offset ~num_globals instructions + = + Array.map + (fun instruction -> + match instruction with + | Instruction.I_Constant addr -> Instruction.I_Constant (addr + !constants_offset) + | Instruction.I_Set_Global addr -> + incr num_globals; + Instruction.I_Set_Global (addr + !globals_offset) + | Instruction.I_Get_Global addr -> Instruction.I_Get_Global (addr + !globals_offset) + | Instruction.I_Closure (fn_addr, num_free_variables) -> + Instruction.I_Closure (fn_addr + !constants_offset, num_free_variables) + | instruction -> instruction) + instructions +;; + +let update_constants_space + ~constants_offset + ~globals_offset + ~num_globals + ~function_index + (constants : Value.t Dynarray.t) = + let rec update_value = function + | Value.Null -> Value.Null + | Value.Int i -> Value.Int i + | Value.Float f -> Value.Float f + | Value.Bool b -> Value.Bool b + | Value.Char c -> Value.Char c + | Value.String s -> Value.String s + | Value.Array a -> Value.Array (Array.map update_value a) + | Value.Record r -> Value.Record (StringMap.map update_value r) + | Value.HtmlTemplateNode { tag; attributes; children } -> + let tag = tag in + let attributes = StringMap.map update_value attributes in + let children = Array.map update_value children in + Value.HtmlTemplateNode { tag; attributes; children } + | Value.FragmentTemplateNode children -> + Value.FragmentTemplateNode (Array.map update_value children) + | Value.BuiltinFunction f -> Value.BuiltinFunction f + | Value.Function fn -> + incr function_index; + let instructions = + update_instructions_space + ~constants_offset + ~globals_offset + ~num_globals + fn.instructions + in + Value.Function { fn with fn_addr = !function_index; instructions } + | Value.Closure closure -> + incr function_index; + let instructions = + update_instructions_space + ~constants_offset + ~globals_offset + ~num_globals + closure.fn.instructions + in + let fn = { closure.fn with fn_addr = !function_index; instructions } in + Value.Closure { closure with fn } in - let constants = Dynarray.to_array @@ code.constants in - let resolved_functions = - resolve_constant_functions ~function_count:!function_count constants + Dynarray.map update_value constants +;; + +let deserialize_and_merge_address_space bytecode = + let constants_offset = ref 0 in + let globals_offset = ref 0 in + let function_index = ref (-1) in + let code = + bytecode + |> Pinc_Bytecode.Bytecode.deserialize + |> StringMap.map (fun (code : Pinc_Bytecode.Bytecode.declaration) -> + let num_globals = ref 0 in + let constants = + update_constants_space + ~constants_offset + ~globals_offset + ~num_globals + ~function_index + code.constants + in + let instructions = + update_instructions_space + ~constants_offset + ~globals_offset + ~num_globals + code.instructions + in + constants_offset := !constants_offset + Dynarray.length constants; + globals_offset := !globals_offset + !num_globals; + Pinc_Bytecode.Bytecode.{ instructions; constants }) + in + (code, !function_index + 1) +;; + +let eval ~root bytecode = + let deserialized, function_count = deserialize_and_merge_address_space bytecode in + + let constants, instructions = + StringMap.fold + (fun identifier + (code : Pinc_Bytecode.Bytecode.declaration) + (constants, instructions) + -> + let constants' = Dynarray.to_array @@ code.constants in + let instructions' = + if String.equal identifier root then + code.instructions + else + instructions + in + (Array.append constants constants', instructions')) + deserialized + ([||], [||]) + in + + let instructions = + Array.append + (resolve_instructions instructions) + [| execute_function_call 0; execute_halt |] in + + let resolved_functions = resolve_constant_functions ~function_count constants in let t = make ~resolved_functions ~instructions ~constants in let result = call_current_instruction t in result.stack |> Stack.top |> Value.to_string diff --git a/test/vm/array/array_instructions.t b/test/vm/array/array_instructions.t index 63fbc6b..889eca3 100644 --- a/test/vm/array/array_instructions.t +++ b/test/vm/array/array_instructions.t @@ -1,112 +1,154 @@ $ NO_COLOR="1" print_instructions . EmptyArray - [CONSTANTS] - 0x00000000 (00000000) : 0 + [ + [CONSTANTS] + 0x00000000 (00000000) : 0 + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Array + 0006 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Array $ NO_COLOR="1" print_instructions . Array - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 5 + 0x00000006 (00000006) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Array + 0031 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000006 (00000006) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Array $ NO_COLOR="1" print_instructions . ExpressionArray - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 6 - 0x00000006 (00000006) : 7 - 0x00000007 (00000007) : 8 - 0x00000008 (00000008) : 4 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 6 + 0x00000006 (00000006) : 7 + 0x00000007 (00000007) : 8 + 0x00000008 (00000008) : 4 + 0x00000009 (00000009) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Add + 0011 I_Constant 0x00000002 (00000002) + 0016 I_Constant 0x00000003 (00000003) + 0021 I_Sub + 0022 I_Constant 0x00000004 (00000004) + 0027 I_Constant 0x00000005 (00000005) + 0032 I_Mul + 0033 I_Constant 0x00000006 (00000006) + 0038 I_Constant 0x00000007 (00000007) + 0043 I_Div + 0044 I_Constant 0x00000008 (00000008) + 0049 I_Array + 0050 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000009 (00000009) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Add - 0011 I_Constant 0x00000002 (00000002) - 0016 I_Constant 0x00000003 (00000003) - 0021 I_Sub - 0022 I_Constant 0x00000004 (00000004) - 0027 I_Constant 0x00000005 (00000005) - 0032 I_Mul - 0033 I_Constant 0x00000006 (00000006) - 0038 I_Constant 0x00000007 (00000007) - 0043 I_Div - 0044 I_Constant 0x00000008 (00000008) - 0049 I_Array $ NO_COLOR="1" print_instructions . ArrayAccess - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 6 - 0x00000006 (00000006) : 7 - 0x00000007 (00000007) : 8 - 0x00000008 (00000008) : 4 - 0x00000009 (00000009) : 3 - 0x0000000A (00000010) : 2 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 6 + 0x00000006 (00000006) : 7 + 0x00000007 (00000007) : 8 + 0x00000008 (00000008) : 4 + 0x00000009 (00000009) : 3 + 0x0000000A (00000010) : 2 + 0x0000000B (00000011) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Add + 0011 I_Constant 0x00000002 (00000002) + 0016 I_Constant 0x00000003 (00000003) + 0021 I_Sub + 0022 I_Constant 0x00000004 (00000004) + 0027 I_Constant 0x00000005 (00000005) + 0032 I_Mul + 0033 I_Constant 0x00000006 (00000006) + 0038 I_Constant 0x00000007 (00000007) + 0043 I_Div + 0044 I_Constant 0x00000008 (00000008) + 0049 I_Array + 0050 I_Constant 0x00000009 (00000009) + 0055 I_Constant 0x0000000A (00000010) + 0060 I_Sub + 0061 I_Index + 0062 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000B (00000011) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Add - 0011 I_Constant 0x00000002 (00000002) - 0016 I_Constant 0x00000003 (00000003) - 0021 I_Sub - 0022 I_Constant 0x00000004 (00000004) - 0027 I_Constant 0x00000005 (00000005) - 0032 I_Mul - 0033 I_Constant 0x00000006 (00000006) - 0038 I_Constant 0x00000007 (00000007) - 0043 I_Div - 0044 I_Constant 0x00000008 (00000008) - 0049 I_Array - 0050 I_Constant 0x00000009 (00000009) - 0055 I_Constant 0x0000000A (00000010) - 0060 I_Sub - 0061 I_Index $ NO_COLOR="1" print_instructions . ArrayRange - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 10 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 10 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Range + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Range $ NO_COLOR="1" print_instructions . ArrayRangeInclusive - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 10 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 10 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Range_Inclusive + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Range_Inclusive diff --git a/test/vm/bindings/bindings.pi b/test/vm/bindings/bindings.pi index 411dcaa..a986b57 100644 --- a/test/vm/bindings/bindings.pi +++ b/test/vm/bindings/bindings.pi @@ -4,11 +4,6 @@ component Let { two } -component UnboundIdentifier { - let two = one; - two -} - component Shadowing { let a = 1; let a = a + 1; @@ -41,20 +36,3 @@ component MutableBindings { [a, get_b(), get_c()] } - -component WrongMutation { - let a = ""; - if (true) { - a := "error!"; - }; - a -} - -component ScopeError { - let a = { - let local_x = 1; - let local_y = 2; - local_x + local_y - }; - local_x -} diff --git a/test/vm/bindings/bindings_instructions.t b/test/vm/bindings/bindings_instructions.t index e6a53a8..1a44536 100644 --- a/test/vm/bindings/bindings_instructions.t +++ b/test/vm/bindings/bindings_instructions.t @@ -1,159 +1,149 @@ $ NO_COLOR="1" print_instructions . Let - [CONSTANTS] - 0x00000000 (00000000) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Set_Local 0x00000001 (00000001) + 0022 I_Null + 0023 I_Pop + 0024 I_Get_Local 0x00000001 (00000001) + 0029 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000000 (00000000) - 0017 I_Set_Global 0x00000001 (00000001) - 0022 I_Null - 0023 I_Pop - 0024 I_Get_Global 0x00000001 (00000001) $ NO_COLOR="1" print_instructions . Shadowing - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 1 - - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000000 (00000000) - 0017 I_Constant 0x00000001 (00000001) - 0022 I_Add - 0023 I_Set_Global 0x00000001 (00000001) - 0028 I_Null - 0029 I_Pop - 0030 I_Get_Global 0x00000001 (00000001) - - - $ NO_COLOR="1" print_instructions . UnboundIdentifier - - ERROR in file ./bindings.pi:8:13-16 - - 7 │ component UnboundIdentifier { - 8 │ let two = one; - │ ^^^ - 9 │ two + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 1 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Constant 0x00000001 (00000001) + 0022 I_Add + 0023 I_Set_Local 0x00000001 (00000001) + 0028 I_Null + 0029 I_Pop + 0030 I_Get_Local 0x00000001 (00000001) + 0035 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - Unbound identifier `one` - [1] - $ NO_COLOR="1" print_instructions . LocalBindings - [CONSTANTS] - 0x00000000 (00000000) : 21 - 0x00000001 (00000001) : [ - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Local 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Local 0x00000000 (00000000) - 0017 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : 21 + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Return + ] + 0x00000002 (00000002) : [ + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + 0009 I_Set_Local 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Call 0 + 0026 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) ] - [INSTRUCTIONS] - 0000 I_Closure 0x00000001 (00000001) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Get_Global 0x00000000 (00000000) - 0021 I_Call 0 $ NO_COLOR="1" print_instructions . MutableBindings - [CONSTANTS] - 0x00000000 (00000000) : "wrong" - 0x00000001 (00000001) : "correct" - 0x00000002 (00000002) : "wrong" - 0x00000003 (00000003) : [ - 0000 I_Get_Global 0x00000001 (00000001) - 0005 I_Return - ] - 0x00000004 (00000004) : "correct" - 0x00000005 (00000005) : "correct" - 0x00000006 (00000006) : [ - 0000 I_Get_Global 0x00000003 (00000003) - 0005 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : "wrong" + 0x00000001 (00000001) : "correct" + 0x00000002 (00000002) : "wrong" + 0x00000003 (00000003) : [ + 0000 I_Get_Global 0x00000001 (00000001) + 0005 I_Return + ] + 0x00000004 (00000004) : "correct" + 0x00000005 (00000005) : "correct" + 0x00000006 (00000006) : [ + 0000 I_Get_Global 0x00000003 (00000003) + 0005 I_Return + ] + 0x00000007 (00000007) : "wrong" + 0x00000008 (00000008) : "wrong" + 0x00000009 (00000009) : 3 + 0x0000000A (00000010) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Global 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_True + 0013 I_Jump_If_False 0x0000000A (00000010) + 0018 I_Constant 0x00000001 (00000001) + 0023 I_Set_Global 0x00000000 (00000000) + 0028 I_Null + 0029 I_Jump 0x0000000B (00000011) + 0034 I_Null + 0035 I_Pop + 0036 I_Constant 0x00000002 (00000002) + 0041 I_Set_Global 0x00000001 (00000001) + 0046 I_Null + 0047 I_Pop + 0048 I_Closure 0x00000003 (00000003) (free variables: 0) + 0057 I_Set_Local 0x00000002 (00000002) + 0062 I_Null + 0063 I_Pop + 0064 I_Constant 0x00000004 (00000004) + 0069 I_Set_Global 0x00000001 (00000001) + 0074 I_Null + 0075 I_Pop + 0076 I_Constant 0x00000005 (00000005) + 0081 I_Set_Global 0x00000003 (00000003) + 0086 I_Null + 0087 I_Pop + 0088 I_Closure 0x00000006 (00000006) (free variables: 0) + 0097 I_Set_Local 0x00000004 (00000004) + 0102 I_Null + 0103 I_Pop + 0104 I_Constant 0x00000007 (00000007) + 0109 I_Set_Global 0x00000005 (00000005) + 0114 I_Null + 0115 I_Pop + 0116 I_Constant 0x00000008 (00000008) + 0121 I_Set_Global 0x00000005 (00000005) + 0126 I_Null + 0127 I_Pop + 0128 I_Get_Global 0x00000000 (00000000) + 0133 I_Get_Local 0x00000002 (00000002) + 0138 I_Call 0 + 0143 I_Get_Local 0x00000004 (00000004) + 0148 I_Call 0 + 0153 I_Constant 0x00000009 (00000009) + 0158 I_Array + 0159 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000A (00000010) (free variables: 0) ] - 0x00000007 (00000007) : "wrong" - 0x00000008 (00000008) : "wrong" - 0x00000009 (00000009) : 3 - - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_True - 0013 I_Jump_If_False 0x0000000A (00000010) - 0018 I_Constant 0x00000001 (00000001) - 0023 I_Set_Global 0x00000000 (00000000) - 0028 I_Null - 0029 I_Jump 0x0000000B (00000011) - 0034 I_Null - 0035 I_Pop - 0036 I_Constant 0x00000002 (00000002) - 0041 I_Set_Global 0x00000001 (00000001) - 0046 I_Null - 0047 I_Pop - 0048 I_Closure 0x00000003 (00000003) (free variables: 0) - 0057 I_Set_Global 0x00000002 (00000002) - 0062 I_Null - 0063 I_Pop - 0064 I_Constant 0x00000004 (00000004) - 0069 I_Set_Global 0x00000001 (00000001) - 0074 I_Null - 0075 I_Pop - 0076 I_Constant 0x00000005 (00000005) - 0081 I_Set_Global 0x00000003 (00000003) - 0086 I_Null - 0087 I_Pop - 0088 I_Closure 0x00000006 (00000006) (free variables: 0) - 0097 I_Set_Global 0x00000004 (00000004) - 0102 I_Null - 0103 I_Pop - 0104 I_Constant 0x00000007 (00000007) - 0109 I_Set_Global 0x00000005 (00000005) - 0114 I_Null - 0115 I_Pop - 0116 I_Constant 0x00000008 (00000008) - 0121 I_Set_Global 0x00000005 (00000005) - 0126 I_Null - 0127 I_Pop - 0128 I_Get_Global 0x00000000 (00000000) - 0133 I_Get_Global 0x00000002 (00000002) - 0138 I_Call 0 - 0143 I_Get_Global 0x00000004 (00000004) - 0148 I_Call 0 - 0153 I_Constant 0x00000009 (00000009) - 0158 I_Array - - $ NO_COLOR="1" print_instructions . WrongMutation - - ERROR in file ./bindings.pi:48:5-6 - - 47 │ if (true) { - 48 │ a := "error!"; - │ ^ - 49 │ }; - - Trying to update a non mutable variable `a`. - [1] - - $ NO_COLOR="1" print_instructions . ScopeError - - ERROR in file ./bindings.pi:59:3-10 - - 58 │ }; - 59 │ local_x - │ ^^^^^^^ - 60 │ } - Unbound identifier `local_x` - [1] diff --git a/test/vm/bool/bool_instructions.t b/test/vm/bool/bool_instructions.t index ae211ec..ef95888 100644 --- a/test/vm/bool/bool_instructions.t +++ b/test/vm/bool/bool_instructions.t @@ -1,94 +1,181 @@ $ NO_COLOR="1" print_instructions . True - [INSTRUCTIONS] - 0000 I_True + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_True + 0001 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . False - [INSTRUCTIONS] - 0000 I_False + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_False + 0001 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . And - [INSTRUCTIONS] - 0000 I_False - 0001 I_True - 0002 I_And + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_False + 0001 I_True + 0002 I_And + 0003 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . Or - [INSTRUCTIONS] - 0000 I_False - 0001 I_True - 0002 I_Or + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_False + 0001 I_True + 0002 I_Or + 0003 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . Equal - [CONSTANTS] - 0x00000000 (00000000) : 3 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Equal + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Equal $ NO_COLOR="1" print_instructions . NotEqual - [CONSTANTS] - 0x00000000 (00000000) : 3 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Not_Equal + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Not_Equal $ NO_COLOR="1" print_instructions . Greater - [CONSTANTS] - 0x00000000 (00000000) : 3 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Greater + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Greater $ NO_COLOR="1" print_instructions . GreaterEqual - [CONSTANTS] - 0x00000000 (00000000) : 3 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Greater_Equal + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Greater_Equal $ NO_COLOR="1" print_instructions . Less - [CONSTANTS] - 0x00000000 (00000000) : 3 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Less + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Less $ NO_COLOR="1" print_instructions . LessEqual - [CONSTANTS] - 0x00000000 (00000000) : 3 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Less_Equal + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Less_Equal $ NO_COLOR="1" print_instructions . Not - [INSTRUCTIONS] - 0000 I_True - 0001 I_Not + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_True + 0001 I_Not + 0002 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + diff --git a/test/vm/builtin_functions/builtin_functions.pi b/test/vm/builtin_functions/builtin_functions.pi index 0bf8253..d8fb486 100644 --- a/test/vm/builtin_functions/builtin_functions.pi +++ b/test/vm/builtin_functions/builtin_functions.pi @@ -1,9 +1,3 @@ -component BuiltinFunctionWrongParameters { - let length = fn (a, b) -> %%pinc_array_length%%; - - length([1, 2, 3, 4]) -} - component BuiltinFunctionArrayLength { let length = fn (array) -> %%pinc_array_length%%; diff --git a/test/vm/builtin_functions/builtin_functions.t b/test/vm/builtin_functions/builtin_functions.t index 5597343..4fc20e3 100644 --- a/test/vm/builtin_functions/builtin_functions.t +++ b/test/vm/builtin_functions/builtin_functions.t @@ -1,15 +1,3 @@ - $ NO_COLOR="1" print_vm . BuiltinFunctionWrongParameters - - ERROR in file ./builtin_functions.pi:2:16-50 - - 1 │ component BuiltinFunctionWrongParameters { - 2 │ let length = fn (a, b) -> %%pinc_array_length%%; - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 3 │ - - External function %%pinc_array_length%% expected 1 parameters, but got 2 - [1] - $ NO_COLOR="1" print_vm . BuiltinFunctionArrayLength 4 diff --git a/test/vm/builtin_functions/builtin_functions_instructions.t b/test/vm/builtin_functions/builtin_functions_instructions.t index 70a3803..149bbcd 100644 --- a/test/vm/builtin_functions/builtin_functions_instructions.t +++ b/test/vm/builtin_functions/builtin_functions_instructions.t @@ -1,63 +1,72 @@ - $ NO_COLOR="1" print_instructions . BuiltinFunctionWrongParameters - - ERROR in file ./builtin_functions.pi:2:16-50 - - 1 │ component BuiltinFunctionWrongParameters { - 2 │ let length = fn (a, b) -> %%pinc_array_length%%; - │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 3 │ - - External function %%pinc_array_length%% expected 1 parameters, but got 2 - [1] - $ NO_COLOR="1" print_instructions . BuiltinFunctionArrayLength - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 4 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 4 + 0x00000005 (00000005) : [ + 0000 I_Get_Builtin 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Constant 0x00000000 (00000000) + 0022 I_Constant 0x00000001 (00000001) + 0027 I_Constant 0x00000002 (00000002) + 0032 I_Constant 0x00000003 (00000003) + 0037 I_Constant 0x00000004 (00000004) + 0042 I_Array + 0043 I_Call 1 + 0048 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000005 (00000005) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Get_Builtin 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000000 (00000000) - 0017 I_Constant 0x00000000 (00000000) - 0022 I_Constant 0x00000001 (00000001) - 0027 I_Constant 0x00000002 (00000002) - 0032 I_Constant 0x00000003 (00000003) - 0037 I_Constant 0x00000004 (00000004) - 0042 I_Array - 0043 I_Call 1 $ NO_COLOR="1" print_instructions . BuiltinFunctionStringLength - [CONSTANTS] - 0x00000000 (00000000) : "Hello, World!" + [ + [CONSTANTS] + 0x00000000 (00000000) : "Hello, World!" + 0x00000001 (00000001) : [ + 0000 I_Get_Builtin 0x00000002 (00000002) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Constant 0x00000000 (00000000) + 0022 I_Call 1 + 0027 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Get_Builtin 0x00000002 (00000002) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000000 (00000000) - 0017 I_Constant 0x00000000 (00000000) - 0022 I_Call 1 $ NO_COLOR="1" print_instructions . BuiltinFunctionStringSub - [CONSTANTS] - 0x00000000 (00000000) : "Hello, World!" - 0x00000001 (00000001) : 7 - 0x00000002 (00000002) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : "Hello, World!" + 0x00000001 (00000001) : 7 + 0x00000002 (00000002) : 5 + 0x00000003 (00000003) : [ + 0000 I_Get_Builtin 0x00000003 (00000003) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Constant 0x00000000 (00000000) + 0022 I_Constant 0x00000001 (00000001) + 0027 I_Constant 0x00000002 (00000002) + 0032 I_Call 3 + 0037 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000003 (00000003) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Get_Builtin 0x00000003 (00000003) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000000 (00000000) - 0017 I_Constant 0x00000000 (00000000) - 0022 I_Constant 0x00000001 (00000001) - 0027 I_Constant 0x00000002 (00000002) - 0032 I_Call 3 diff --git a/test/vm/char/char_instructions.t b/test/vm/char/char_instructions.t index b1540f4..ad680b1 100644 --- a/test/vm/char/char_instructions.t +++ b/test/vm/char/char_instructions.t @@ -1,9 +1,16 @@ $ NO_COLOR="1" print_instructions . Char - [CONSTANTS] - 0x00000000 (00000000) : 'c' - 0x00000001 (00000001) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 'c' + 0x00000001 (00000001) : 1 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Add + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Add diff --git a/test/vm/compiler_errors/bindings/data.pi b/test/vm/compiler_errors/bindings/data.pi new file mode 100644 index 0000000..ce1f89f --- /dev/null +++ b/test/vm/compiler_errors/bindings/data.pi @@ -0,0 +1,21 @@ +component WrongMutation { + let a = ""; + if (true) { + a := "error!"; + }; + a +} + +component ScopeError { + let a = { + let local_x = 1; + let local_y = 2; + local_x + local_y + }; + local_x +} + +component UnboundIdentifier { + let two = one; + two +} diff --git a/test/vm/compiler_errors/bindings/dune b/test/vm/compiler_errors/bindings/dune new file mode 100644 index 0000000..232e0bb --- /dev/null +++ b/test/vm/compiler_errors/bindings/dune @@ -0,0 +1,5 @@ +(cram + (deps + %{bin:print_vm} + %{bin:print_instructions} + (source_tree .))) diff --git a/test/vm/compiler_errors/bindings/instructions.t b/test/vm/compiler_errors/bindings/instructions.t new file mode 100644 index 0000000..a520763 --- /dev/null +++ b/test/vm/compiler_errors/bindings/instructions.t @@ -0,0 +1,35 @@ + $ NO_COLOR="1" print_instructions . UnboundIdentifier + + ERROR in file ./data.pi:19:13-16 + + 18 │ component UnboundIdentifier { + 19 │ let two = one; + │ ^^^ + 20 │ two + + Unbound identifier `one` + [1] + + $ NO_COLOR="1" print_instructions . WrongMutation + + ERROR in file ./data.pi:4:5-6 + + 3 │ if (true) { + 4 │ a := "error!"; + │ ^ + 5 │ }; + + Trying to update a non mutable variable `a`. + [1] + + $ NO_COLOR="1" print_instructions . ScopeError + + ERROR in file ./data.pi:15:3-10 + + 14 │ }; + 15 │ local_x + │ ^^^^^^^ + 16 │ } + + Unbound identifier `local_x` + [1] diff --git a/test/vm/compiler_errors/builtin_functions_wrong_parameters/data.pi b/test/vm/compiler_errors/builtin_functions_wrong_parameters/data.pi new file mode 100644 index 0000000..79a3fab --- /dev/null +++ b/test/vm/compiler_errors/builtin_functions_wrong_parameters/data.pi @@ -0,0 +1,5 @@ +component BuiltinFunctionWrongParameters { + let length = fn (a, b) -> %%pinc_array_length%%; + + length([1, 2, 3, 4]) +} diff --git a/test/vm/compiler_errors/builtin_functions_wrong_parameters/dune b/test/vm/compiler_errors/builtin_functions_wrong_parameters/dune new file mode 100644 index 0000000..232e0bb --- /dev/null +++ b/test/vm/compiler_errors/builtin_functions_wrong_parameters/dune @@ -0,0 +1,5 @@ +(cram + (deps + %{bin:print_vm} + %{bin:print_instructions} + (source_tree .))) diff --git a/test/vm/compiler_errors/builtin_functions_wrong_parameters/instructions.t b/test/vm/compiler_errors/builtin_functions_wrong_parameters/instructions.t new file mode 100644 index 0000000..2100ad9 --- /dev/null +++ b/test/vm/compiler_errors/builtin_functions_wrong_parameters/instructions.t @@ -0,0 +1,11 @@ + $ NO_COLOR="1" print_instructions . BuiltinFunctionWrongParameters + + ERROR in file ./data.pi:2:16-50 + + 1 │ component BuiltinFunctionWrongParameters { + 2 │ let length = fn (a, b) -> %%pinc_array_length%%; + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 3 │ + + External function %%pinc_array_length%% expected 1 parameters, but got 2 + [1] diff --git a/test/vm/conditionals/conditionals_instructions.t b/test/vm/conditionals/conditionals_instructions.t index f108b1b..b1d9bb8 100644 --- a/test/vm/conditionals/conditionals_instructions.t +++ b/test/vm/conditionals/conditionals_instructions.t @@ -1,34 +1,70 @@ $ NO_COLOR="1" print_instructions . IfTrue - [INSTRUCTIONS] - 0000 I_True - 0001 I_Jump_If_False 0x00000004 (00000004) - 0006 I_True - 0007 I_Jump 0x00000005 (00000005) - 0012 I_Null + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_True + 0001 I_Jump_If_False 0x00000004 (00000004) + 0006 I_True + 0007 I_Jump 0x00000005 (00000005) + 0012 I_Null + 0013 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . IfTrueElse - [INSTRUCTIONS] - 0000 I_True - 0001 I_Jump_If_False 0x00000004 (00000004) - 0006 I_True - 0007 I_Jump 0x00000005 (00000005) - 0012 I_False + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_True + 0001 I_Jump_If_False 0x00000004 (00000004) + 0006 I_True + 0007 I_Jump 0x00000005 (00000005) + 0012 I_False + 0013 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . IfFalse - [INSTRUCTIONS] - 0000 I_False - 0001 I_Jump_If_False 0x00000004 (00000004) - 0006 I_True - 0007 I_Jump 0x00000005 (00000005) - 0012 I_Null + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_False + 0001 I_Jump_If_False 0x00000004 (00000004) + 0006 I_True + 0007 I_Jump 0x00000005 (00000005) + 0012 I_Null + 0013 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . IfFalseElse - [INSTRUCTIONS] - 0000 I_False - 0001 I_Jump_If_False 0x00000004 (00000004) - 0006 I_True - 0007 I_Jump 0x00000005 (00000005) - 0012 I_False + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_False + 0001 I_Jump_If_False 0x00000004 (00000004) + 0006 I_True + 0007 I_Jump 0x00000005 (00000005) + 0012 I_False + 0013 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + diff --git a/test/vm/functions/functions_instructions.t b/test/vm/functions/functions_instructions.t index 11dea24..e2dc710 100644 --- a/test/vm/functions/functions_instructions.t +++ b/test/vm/functions/functions_instructions.t @@ -1,358 +1,421 @@ $ NO_COLOR="1" print_instructions . FunctionEmpty - [CONSTANTS] - 0x00000000 (00000000) : [ - 0000 I_Null - 0001 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_Null + 0001 I_Return + ] + 0x00000001 (00000001) : [ + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + 0009 I_Set_Local 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Call 0 + 0026 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) ] - [INSTRUCTIONS] - 0000 I_Closure 0x00000000 (00000000) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Get_Global 0x00000000 (00000000) - 0021 I_Call 0 $ NO_COLOR="1" print_instructions . Function - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : [ - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Local 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Constant 0x00000001 (00000001) - 0017 I_Set_Local 0x00000001 (00000001) - 0022 I_Null - 0023 I_Pop - 0024 I_Get_Local 0x00000000 (00000000) - 0029 I_Get_Local 0x00000001 (00000001) - 0034 I_Add - 0035 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Constant 0x00000001 (00000001) + 0017 I_Set_Local 0x00000001 (00000001) + 0022 I_Null + 0023 I_Pop + 0024 I_Get_Local 0x00000000 (00000000) + 0029 I_Get_Local 0x00000001 (00000001) + 0034 I_Add + 0035 I_Return + ] + 0x00000003 (00000003) : [ + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + 0009 I_Set_Local 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Call 0 + 0026 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000003 (00000003) (free variables: 0) ] - [INSTRUCTIONS] - 0000 I_Closure 0x00000002 (00000002) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Get_Global 0x00000000 (00000000) - 0021 I_Call 0 $ NO_COLOR="1" print_instructions . FunctionCurried - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : [ - 0000 I_True - 0001 I_Jump_If_False 0x00000004 (00000004) - 0006 I_Constant 0x00000000 (00000000) - 0011 I_Jump 0x00000005 (00000005) - 0016 I_Constant 0x00000001 (00000001) - 0021 I_Return - ] - 0x00000003 (00000003) : [ - 0000 I_Get_Global 0x00000000 (00000000) - 0005 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : [ + 0000 I_True + 0001 I_Jump_If_False 0x00000004 (00000004) + 0006 I_Constant 0x00000000 (00000000) + 0011 I_Jump 0x00000005 (00000005) + 0016 I_Constant 0x00000001 (00000001) + 0021 I_Return + ] + 0x00000003 (00000003) : [ + 0000 I_Get_Free 0x00000000 (00000000) + 0005 I_Return + ] + 0x00000004 (00000004) : [ + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + 0009 I_Set_Local 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Closure 0x00000003 (00000003) (free variables: 1) + 0030 I_Set_Local 0x00000001 (00000001) + 0035 I_Null + 0036 I_Pop + 0037 I_Get_Local 0x00000001 (00000001) + 0042 I_Call 0 + 0047 I_Call 0 + 0052 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000004 (00000004) (free variables: 0) ] - [INSTRUCTIONS] - 0000 I_Closure 0x00000002 (00000002) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Closure 0x00000003 (00000003) (free variables: 0) - 0025 I_Set_Global 0x00000001 (00000001) - 0030 I_Null - 0031 I_Pop - 0032 I_Get_Global 0x00000001 (00000001) - 0037 I_Call 0 - 0042 I_Call 0 $ NO_COLOR="1" print_instructions . FunctionScope - [CONSTANTS] - 0x00000000 (00000000) : "123" - 0x00000001 (00000001) : 50 - 0x00000002 (00000002) : 1 - 0x00000003 (00000003) : [ - 0000 I_Constant 0x00000002 (00000002) - 0005 I_Set_Local 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000001 (00000001) - 0017 I_Get_Local 0x00000000 (00000000) - 0022 I_Sub - 0023 I_Return - ] - 0x00000004 (00000004) : 2 - 0x00000005 (00000005) : [ - 0000 I_Constant 0x00000004 (00000004) - 0005 I_Set_Local 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000001 (00000001) - 0017 I_Get_Local 0x00000000 (00000000) - 0022 I_Sub - 0023 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : "123" + 0x00000001 (00000001) : 50 + 0x00000002 (00000002) : 1 + 0x00000003 (00000003) : [ + 0000 I_Constant 0x00000002 (00000002) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Free 0x00000000 (00000000) + 0017 I_Get_Local 0x00000000 (00000000) + 0022 I_Sub + 0023 I_Return + ] + 0x00000004 (00000004) : 2 + 0x00000005 (00000005) : [ + 0000 I_Constant 0x00000004 (00000004) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Free 0x00000000 (00000000) + 0017 I_Get_Local 0x00000000 (00000000) + 0022 I_Sub + 0023 I_Return + ] + 0x00000006 (00000006) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Constant 0x00000001 (00000001) + 0017 I_Set_Local 0x00000001 (00000001) + 0022 I_Null + 0023 I_Pop + 0024 I_Get_Local 0x00000001 (00000001) + 0029 I_Closure 0x00000003 (00000003) (free variables: 1) + 0038 I_Set_Local 0x00000002 (00000002) + 0043 I_Null + 0044 I_Pop + 0045 I_Get_Local 0x00000001 (00000001) + 0050 I_Closure 0x00000005 (00000005) (free variables: 1) + 0059 I_Set_Local 0x00000003 (00000003) + 0064 I_Null + 0065 I_Pop + 0066 I_Get_Local 0x00000002 (00000002) + 0071 I_Call 0 + 0076 I_Get_Local 0x00000003 (00000003) + 0081 I_Call 0 + 0086 I_Add + 0087 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000006 (00000006) (free variables: 0) ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Constant 0x00000001 (00000001) - 0017 I_Set_Global 0x00000001 (00000001) - 0022 I_Null - 0023 I_Pop - 0024 I_Closure 0x00000003 (00000003) (free variables: 0) - 0033 I_Set_Global 0x00000002 (00000002) - 0038 I_Null - 0039 I_Pop - 0040 I_Closure 0x00000005 (00000005) (free variables: 0) - 0049 I_Set_Global 0x00000003 (00000003) - 0054 I_Null - 0055 I_Pop - 0056 I_Get_Global 0x00000002 (00000002) - 0061 I_Call 0 - 0066 I_Get_Global 0x00000003 (00000003) - 0071 I_Call 0 - 0076 I_Add $ NO_COLOR="1" print_instructions . FunctionArguments - [CONSTANTS] - 0x00000000 (00000000) : [ - 0000 I_Get_Local 0x00000000 (00000000) - 0005 I_Get_Local 0x00000001 (00000001) - 0010 I_Add - 0011 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_Get_Local 0x00000000 (00000000) + 0005 I_Get_Local 0x00000001 (00000001) + 0010 I_Add + 0011 I_Return + ] + 0x00000001 (00000001) : 1 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000001 (00000001) + 0005 I_Set_Local 0x00000001 (00000001) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Free 0x00000000 (00000000) + 0017 I_Get_Local 0x00000000 (00000000) + 0022 I_Get_Local 0x00000001 (00000001) + 0027 I_Call 2 + 0032 I_Return + ] + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 9 + 0x00000005 (00000005) : [ + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + 0009 I_Set_Local 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Closure 0x00000002 (00000002) (free variables: 1) + 0030 I_Set_Local 0x00000001 (00000001) + 0035 I_Null + 0036 I_Pop + 0037 I_Get_Local 0x00000001 (00000001) + 0042 I_Constant 0x00000003 (00000003) + 0047 I_Call 1 + 0052 I_Get_Local 0x00000001 (00000001) + 0057 I_Constant 0x00000004 (00000004) + 0062 I_Call 1 + 0067 I_Add + 0068 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000005 (00000005) (free variables: 0) ] - 0x00000001 (00000001) : 1 - 0x00000002 (00000002) : [ - 0000 I_Constant 0x00000001 (00000001) - 0005 I_Set_Local 0x00000001 (00000001) - 0010 I_Null - 0011 I_Pop - 0012 I_Get_Global 0x00000000 (00000000) - 0017 I_Get_Local 0x00000000 (00000000) - 0022 I_Get_Local 0x00000001 (00000001) - 0027 I_Call 2 - 0032 I_Return - ] - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 9 - [INSTRUCTIONS] - 0000 I_Closure 0x00000000 (00000000) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Closure 0x00000002 (00000002) (free variables: 0) - 0025 I_Set_Global 0x00000001 (00000001) - 0030 I_Null - 0031 I_Pop - 0032 I_Get_Global 0x00000001 (00000001) - 0037 I_Constant 0x00000003 (00000003) - 0042 I_Call 1 - 0047 I_Get_Global 0x00000001 (00000001) - 0052 I_Constant 0x00000004 (00000004) - 0057 I_Call 1 - 0062 I_Add $ NO_COLOR="1" print_instructions . FunctionClosure - [CONSTANTS] - 0x00000000 (00000000) : 221 - 0x00000001 (00000001) : [ - 0000 I_Get_Free 0x00000000 (00000000) - 0005 I_Return - ] - 0x00000002 (00000002) : [ - 0000 I_Get_Free 0x00000000 (00000000) - 0005 I_Call 0 - 0010 I_Get_Free 0x00000001 (00000001) - 0015 I_Add - 0016 I_Get_Local 0x00000000 (00000000) - 0021 I_Add - 0022 I_Get_Global 0x00000000 (00000000) - 0027 I_Get_Local 0x00000001 (00000001) - 0032 I_Mul - 0033 I_Add - 0034 I_Return - ] - 0x00000003 (00000003) : [ - 0000 I_Get_Free 0x00000000 (00000000) - 0005 I_Get_Local 0x00000000 (00000000) - 0010 I_Add - 0011 I_Set_Local 0x00000001 (00000001) - 0016 I_Null - 0017 I_Pop - 0018 I_Get_Free 0x00000001 (00000001) - 0023 I_Get_Local 0x00000001 (00000001) - 0028 I_Closure 0x00000002 (00000002) (free variables: 2) - 0037 I_Set_Local 0x00000002 (00000002) - 0042 I_Null - 0043 I_Pop - 0044 I_Get_Local 0x00000002 (00000002) - 0049 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : 221 + 0x00000001 (00000001) : [ + 0000 I_Get_Free 0x00000000 (00000000) + 0005 I_Return + ] + 0x00000002 (00000002) : [ + 0000 I_Get_Free 0x00000000 (00000000) + 0005 I_Call 0 + 0010 I_Get_Free 0x00000001 (00000001) + 0015 I_Add + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Add + 0022 I_Get_Free 0x00000002 (00000002) + 0027 I_Get_Local 0x00000001 (00000001) + 0032 I_Mul + 0033 I_Add + 0034 I_Return + ] + 0x00000003 (00000003) : [ + 0000 I_Get_Free 0x00000000 (00000000) + 0005 I_Get_Local 0x00000000 (00000000) + 0010 I_Add + 0011 I_Set_Local 0x00000001 (00000001) + 0016 I_Null + 0017 I_Pop + 0018 I_Get_Free 0x00000001 (00000001) + 0023 I_Get_Local 0x00000001 (00000001) + 0028 I_Get_Free 0x00000002 (00000002) + 0033 I_Closure 0x00000002 (00000002) (free variables: 3) + 0042 I_Set_Local 0x00000002 (00000002) + 0047 I_Null + 0048 I_Pop + 0049 I_Get_Local 0x00000002 (00000002) + 0054 I_Return + ] + 0x00000004 (00000004) : [ + 0000 I_Get_Local 0x00000000 (00000000) + 0005 I_Closure 0x00000001 (00000001) (free variables: 1) + 0014 I_Set_Local 0x00000001 (00000001) + 0019 I_Null + 0020 I_Pop + 0021 I_Get_Local 0x00000000 (00000000) + 0026 I_Get_Local 0x00000001 (00000001) + 0031 I_Get_Free 0x00000000 (00000000) + 0036 I_Closure 0x00000003 (00000003) (free variables: 3) + 0045 I_Return + ] + 0x00000005 (00000005) : 3 + 0x00000006 (00000006) : 7 + 0x00000007 (00000007) : 9 + 0x00000008 (00000008) : 2 + 0x00000009 (00000009) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Get_Local 0x00000000 (00000000) + 0017 I_Closure 0x00000004 (00000004) (free variables: 1) + 0026 I_Set_Local 0x00000001 (00000001) + 0031 I_Null + 0032 I_Pop + 0033 I_Get_Local 0x00000001 (00000001) + 0038 I_Constant 0x00000005 (00000005) + 0043 I_Call 1 + 0048 I_Constant 0x00000006 (00000006) + 0053 I_Call 1 + 0058 I_Constant 0x00000007 (00000007) + 0063 I_Constant 0x00000008 (00000008) + 0068 I_Call 2 + 0073 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000009 (00000009) (free variables: 0) ] - 0x00000004 (00000004) : [ - 0000 I_Get_Local 0x00000000 (00000000) - 0005 I_Closure 0x00000001 (00000001) (free variables: 1) - 0014 I_Set_Local 0x00000001 (00000001) - 0019 I_Null - 0020 I_Pop - 0021 I_Get_Local 0x00000000 (00000000) - 0026 I_Get_Local 0x00000001 (00000001) - 0031 I_Closure 0x00000003 (00000003) (free variables: 2) - 0040 I_Return - ] - 0x00000005 (00000005) : 3 - 0x00000006 (00000006) : 7 - 0x00000007 (00000007) : 9 - 0x00000008 (00000008) : 2 - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Closure 0x00000004 (00000004) (free variables: 0) - 0021 I_Set_Global 0x00000001 (00000001) - 0026 I_Null - 0027 I_Pop - 0028 I_Get_Global 0x00000001 (00000001) - 0033 I_Constant 0x00000005 (00000005) - 0038 I_Call 1 - 0043 I_Constant 0x00000006 (00000006) - 0048 I_Call 1 - 0053 I_Constant 0x00000007 (00000007) - 0058 I_Constant 0x00000008 (00000008) - 0063 I_Call 2 $ NO_COLOR="1" print_instructions . RecursiveFunction - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 1 - 0x00000002 (00000002) : 2 - 0x00000003 (00000003) : [ - 0000 I_Get_Local 0x00000000 (00000000) - 0005 I_Constant 0x00000000 (00000000) - 0010 I_Less_Equal - 0011 I_Jump_If_False 0x00000006 (00000006) - 0016 I_Get_Local 0x00000000 (00000000) - 0021 I_Jump 0x00000011 (00000017) - 0026 I_Current_Closure - 0027 I_Get_Local 0x00000000 (00000000) - 0032 I_Constant 0x00000001 (00000001) - 0037 I_Sub - 0038 I_Call 1 - 0043 I_Current_Closure - 0044 I_Get_Local 0x00000000 (00000000) - 0049 I_Constant 0x00000002 (00000002) - 0054 I_Sub - 0055 I_Call 1 - 0060 I_Add - 0061 I_Return - ] - 0x00000004 (00000004) : 1 - 0x00000005 (00000005) : 1 - 0x00000006 (00000006) : 1 - 0x00000007 (00000007) : [ - 0000 I_Get_Local 0x00000000 (00000000) - 0005 I_Constant 0x00000004 (00000004) - 0010 I_Less_Equal - 0011 I_Jump_If_False 0x00000006 (00000006) - 0016 I_Constant 0x00000005 (00000005) - 0021 I_Jump 0x0000000D (00000013) - 0026 I_Get_Local 0x00000000 (00000000) - 0031 I_Current_Closure - 0032 I_Get_Local 0x00000000 (00000000) - 0037 I_Constant 0x00000006 (00000006) - 0042 I_Sub - 0043 I_Call 1 - 0048 I_Mul - 0049 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 1 + 0x00000002 (00000002) : 2 + 0x00000003 (00000003) : [ + 0000 I_Get_Local 0x00000000 (00000000) + 0005 I_Constant 0x00000000 (00000000) + 0010 I_Less_Equal + 0011 I_Jump_If_False 0x00000006 (00000006) + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Jump 0x00000011 (00000017) + 0026 I_Current_Closure + 0027 I_Get_Local 0x00000000 (00000000) + 0032 I_Constant 0x00000001 (00000001) + 0037 I_Sub + 0038 I_Call 1 + 0043 I_Current_Closure + 0044 I_Get_Local 0x00000000 (00000000) + 0049 I_Constant 0x00000002 (00000002) + 0054 I_Sub + 0055 I_Call 1 + 0060 I_Add + 0061 I_Return + ] + 0x00000004 (00000004) : 1 + 0x00000005 (00000005) : 1 + 0x00000006 (00000006) : 1 + 0x00000007 (00000007) : [ + 0000 I_Get_Local 0x00000000 (00000000) + 0005 I_Constant 0x00000004 (00000004) + 0010 I_Less_Equal + 0011 I_Jump_If_False 0x00000006 (00000006) + 0016 I_Constant 0x00000005 (00000005) + 0021 I_Jump 0x0000000D (00000013) + 0026 I_Get_Local 0x00000000 (00000000) + 0031 I_Current_Closure + 0032 I_Get_Local 0x00000000 (00000000) + 0037 I_Constant 0x00000006 (00000006) + 0042 I_Sub + 0043 I_Call 1 + 0048 I_Mul + 0049 I_Return + ] + 0x00000008 (00000008) : [ + 0000 I_Closure 0x00000003 (00000003) (free variables: 0) + 0009 I_Set_Local 0x00000002 (00000002) + 0014 I_Null + 0015 I_Pop + 0016 I_Closure 0x00000007 (00000007) (free variables: 0) + 0025 I_Set_Local 0x00000003 (00000003) + 0030 I_Null + 0031 I_Pop + 0032 I_Get_Local 0x00000003 (00000003) + 0037 I_Get_Local 0x00000000 (00000000) + 0042 I_Call 1 + 0047 I_Get_Local 0x00000002 (00000002) + 0052 I_Get_Local 0x00000001 (00000001) + 0057 I_Call 1 + 0062 I_Add + 0063 I_Return + ] + 0x00000009 (00000009) : 5 + 0x0000000A (00000010) : 9 + 0x0000000B (00000011) : [ + 0000 I_Closure 0x00000008 (00000008) (free variables: 0) + 0009 I_Set_Local 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Get_Local 0x00000000 (00000000) + 0021 I_Constant 0x00000009 (00000009) + 0026 I_Constant 0x0000000A (00000010) + 0031 I_Call 2 + 0036 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000B (00000011) (free variables: 0) ] - 0x00000008 (00000008) : [ - 0000 I_Closure 0x00000003 (00000003) (free variables: 0) - 0009 I_Set_Local 0x00000002 (00000002) - 0014 I_Null - 0015 I_Pop - 0016 I_Closure 0x00000007 (00000007) (free variables: 0) - 0025 I_Set_Local 0x00000003 (00000003) - 0030 I_Null - 0031 I_Pop - 0032 I_Get_Local 0x00000003 (00000003) - 0037 I_Get_Local 0x00000000 (00000000) - 0042 I_Call 1 - 0047 I_Get_Local 0x00000002 (00000002) - 0052 I_Get_Local 0x00000001 (00000001) - 0057 I_Call 1 - 0062 I_Add - 0063 I_Return - ] - 0x00000009 (00000009) : 5 - 0x0000000A (00000010) : 9 - [INSTRUCTIONS] - 0000 I_Closure 0x00000008 (00000008) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Get_Global 0x00000000 (00000000) - 0021 I_Constant 0x00000009 (00000009) - 0026 I_Constant 0x0000000A (00000010) - 0031 I_Call 2 $ NO_COLOR="1" print_instructions . MutuallyRecursiveFunction - [CONSTANTS] - 0x00000000 (00000000) : 0 - 0x00000001 (00000001) : 1 - 0x00000002 (00000002) : [ - 0000 I_Get_Local 0x00000000 (00000000) - 0005 I_Constant 0x00000000 (00000000) - 0010 I_Equal - 0011 I_Jump_If_False 0x00000006 (00000006) - 0016 I_True - 0017 I_Jump 0x0000000B (00000011) - 0022 I_Get_Global 0x00000001 (00000001) - 0027 I_Get_Local 0x00000000 (00000000) - 0032 I_Constant 0x00000001 (00000001) - 0037 I_Sub - 0038 I_Call 1 - 0043 I_Return - ] - 0x00000003 (00000003) : 0 - 0x00000004 (00000004) : 1 - 0x00000005 (00000005) : [ - 0000 I_Get_Local 0x00000000 (00000000) - 0005 I_Constant 0x00000003 (00000003) - 0010 I_Equal - 0011 I_Jump_If_False 0x00000006 (00000006) - 0016 I_False - 0017 I_Jump 0x0000000B (00000011) - 0022 I_Get_Global 0x00000000 (00000000) - 0027 I_Get_Local 0x00000000 (00000000) - 0032 I_Constant 0x00000004 (00000004) - 0037 I_Sub - 0038 I_Call 1 - 0043 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : 0 + 0x00000001 (00000001) : 1 + 0x00000002 (00000002) : [ + 0000 I_Get_Local 0x00000000 (00000000) + 0005 I_Constant 0x00000000 (00000000) + 0010 I_Equal + 0011 I_Jump_If_False 0x00000006 (00000006) + 0016 I_True + 0017 I_Jump 0x0000000B (00000011) + 0022 I_Get_Global 0x00000001 (00000001) + 0027 I_Get_Local 0x00000000 (00000000) + 0032 I_Constant 0x00000001 (00000001) + 0037 I_Sub + 0038 I_Call 1 + 0043 I_Return + ] + 0x00000003 (00000003) : 0 + 0x00000004 (00000004) : 1 + 0x00000005 (00000005) : [ + 0000 I_Get_Local 0x00000000 (00000000) + 0005 I_Constant 0x00000003 (00000003) + 0010 I_Equal + 0011 I_Jump_If_False 0x00000006 (00000006) + 0016 I_False + 0017 I_Jump 0x0000000B (00000011) + 0022 I_Get_Global 0x00000000 (00000000) + 0027 I_Get_Local 0x00000000 (00000000) + 0032 I_Constant 0x00000004 (00000004) + 0037 I_Sub + 0038 I_Call 1 + 0043 I_Return + ] + 0x00000006 (00000006) : 2 + 0x00000007 (00000007) : [ + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + 0009 I_Set_Global 0x00000000 (00000000) + 0014 I_Null + 0015 I_Pop + 0016 I_Closure 0x00000005 (00000005) (free variables: 0) + 0025 I_Set_Global 0x00000001 (00000001) + 0030 I_Null + 0031 I_Pop + 0032 I_Get_Global 0x00000000 (00000000) + 0037 I_Constant 0x00000006 (00000006) + 0042 I_Call 1 + 0047 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000007 (00000007) (free variables: 0) ] - 0x00000006 (00000006) : 2 - [INSTRUCTIONS] - 0000 I_Closure 0x00000002 (00000002) (free variables: 0) - 0009 I_Set_Global 0x00000000 (00000000) - 0014 I_Null - 0015 I_Pop - 0016 I_Closure 0x00000005 (00000005) (free variables: 0) - 0025 I_Set_Global 0x00000001 (00000001) - 0030 I_Null - 0031 I_Pop - 0032 I_Get_Global 0x00000000 (00000000) - 0037 I_Constant 0x00000006 (00000006) - 0042 I_Call 1 diff --git a/test/vm/html/html_instructions.t b/test/vm/html/html_instructions.t index c0f4979..c5310f7 100644 --- a/test/vm/html/html_instructions.t +++ b/test/vm/html/html_instructions.t @@ -1,207 +1,249 @@ $ NO_COLOR="1" print_instructions . HtmlElement - [CONSTANTS] - 0x00000000 (00000000) : "div" - 0x00000001 (00000001) : 0 + [ + [CONSTANTS] + 0x00000000 (00000000) : "div" + 0x00000001 (00000001) : 0 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Record 0 + 0010 I_Constant 0x00000001 (00000001) + 0015 I_Array + 0016 I_Html_Template + 0017 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Record 0 - 0010 I_Constant 0x00000001 (00000001) - 0015 I_Array - 0016 I_Html_Template $ NO_COLOR="1" print_instructions . HtmlElementAttributes - [CONSTANTS] - 0x00000000 (00000000) : "div" - 0x00000001 (00000001) : "class" - 0x00000002 (00000002) : "test" - 0x00000003 (00000003) : 0 + [ + [CONSTANTS] + 0x00000000 (00000000) : "div" + 0x00000001 (00000001) : "class" + 0x00000002 (00000002) : "test" + 0x00000003 (00000003) : 0 + 0x00000004 (00000004) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Record 1 + 0020 I_Constant 0x00000003 (00000003) + 0025 I_Array + 0026 I_Html_Template + 0027 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000004 (00000004) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Record 1 - 0020 I_Constant 0x00000003 (00000003) - 0025 I_Array - 0026 I_Html_Template $ NO_COLOR="1" print_instructions . HtmlElementSelfClosingVoid - [CONSTANTS] - 0x00000000 (00000000) : "link" - 0x00000001 (00000001) : "href" - 0x00000002 (00000002) : "rel" - 0x00000003 (00000003) : "main.css" - 0x00000004 (00000004) : "stylesheet" - 0x00000005 (00000005) : 0 + [ + [CONSTANTS] + 0x00000000 (00000000) : "link" + 0x00000001 (00000001) : "href" + 0x00000002 (00000002) : "rel" + 0x00000003 (00000003) : "main.css" + 0x00000004 (00000004) : "stylesheet" + 0x00000005 (00000005) : 0 + 0x00000006 (00000006) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Record 2 + 0030 I_Constant 0x00000005 (00000005) + 0035 I_Array + 0036 I_Html_Template + 0037 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000006 (00000006) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Record 2 - 0030 I_Constant 0x00000005 (00000005) - 0035 I_Array - 0036 I_Html_Template $ NO_COLOR="1" print_instructions . HtmlElementChildren - [CONSTANTS] - 0x00000000 (00000000) : "div" - 0x00000001 (00000001) : "class" - 0x00000002 (00000002) : "test" - 0x00000003 (00000003) : "\n" - 0x00000004 (00000004) : "p" - 0x00000005 (00000005) : "Enim commodo velit excepteur aute amet ut ad dolore." - 0x00000006 (00000006) : 1 - 0x00000007 (00000007) : "\n" - 0x00000008 (00000008) : "p" - 0x00000009 (00000009) : "Non et commodo anim eiusmod incididunt sint labore aliqua Lorem ea excepteur mollit sit." - 0x0000000A (00000010) : 1 - 0x0000000B (00000011) : "\n" - 0x0000000C (00000012) : "p" - 0x0000000D (00000013) : "Tempor ex aute minim ut minim excepteur enim aute." - 0x0000000E (00000014) : 1 - 0x0000000F (00000015) : "\n" - 0x00000010 (00000016) : 7 + [ + [CONSTANTS] + 0x00000000 (00000000) : "div" + 0x00000001 (00000001) : "class" + 0x00000002 (00000002) : "test" + 0x00000003 (00000003) : "\n" + 0x00000004 (00000004) : "p" + 0x00000005 (00000005) : "Enim commodo velit excepteur aute amet ut ad dolore." + 0x00000006 (00000006) : 1 + 0x00000007 (00000007) : "\n" + 0x00000008 (00000008) : "p" + 0x00000009 (00000009) : "Non et commodo anim eiusmod incididunt sint labore aliqua Lorem ea excepteur mollit sit." + 0x0000000A (00000010) : 1 + 0x0000000B (00000011) : "\n" + 0x0000000C (00000012) : "p" + 0x0000000D (00000013) : "Tempor ex aute minim ut minim excepteur enim aute." + 0x0000000E (00000014) : 1 + 0x0000000F (00000015) : "\n" + 0x00000010 (00000016) : 7 + 0x00000011 (00000017) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Record 1 + 0020 I_Constant 0x00000003 (00000003) + 0025 I_Constant 0x00000004 (00000004) + 0030 I_Record 0 + 0035 I_Constant 0x00000005 (00000005) + 0040 I_Constant 0x00000006 (00000006) + 0045 I_Array + 0046 I_Html_Template + 0047 I_Constant 0x00000007 (00000007) + 0052 I_Constant 0x00000008 (00000008) + 0057 I_Record 0 + 0062 I_Constant 0x00000009 (00000009) + 0067 I_Constant 0x0000000A (00000010) + 0072 I_Array + 0073 I_Html_Template + 0074 I_Constant 0x0000000B (00000011) + 0079 I_Constant 0x0000000C (00000012) + 0084 I_Record 0 + 0089 I_Constant 0x0000000D (00000013) + 0094 I_Constant 0x0000000E (00000014) + 0099 I_Array + 0100 I_Html_Template + 0101 I_Constant 0x0000000F (00000015) + 0106 I_Constant 0x00000010 (00000016) + 0111 I_Array + 0112 I_Html_Template + 0113 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000011 (00000017) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Record 1 - 0020 I_Constant 0x00000003 (00000003) - 0025 I_Constant 0x00000004 (00000004) - 0030 I_Record 0 - 0035 I_Constant 0x00000005 (00000005) - 0040 I_Constant 0x00000006 (00000006) - 0045 I_Array - 0046 I_Html_Template - 0047 I_Constant 0x00000007 (00000007) - 0052 I_Constant 0x00000008 (00000008) - 0057 I_Record 0 - 0062 I_Constant 0x00000009 (00000009) - 0067 I_Constant 0x0000000A (00000010) - 0072 I_Array - 0073 I_Html_Template - 0074 I_Constant 0x0000000B (00000011) - 0079 I_Constant 0x0000000C (00000012) - 0084 I_Record 0 - 0089 I_Constant 0x0000000D (00000013) - 0094 I_Constant 0x0000000E (00000014) - 0099 I_Array - 0100 I_Html_Template - 0101 I_Constant 0x0000000F (00000015) - 0106 I_Constant 0x00000010 (00000016) - 0111 I_Array - 0112 I_Html_Template $ NO_COLOR="1" print_instructions . HtmlElementExpressions - [CONSTANTS] - 0x00000000 (00000000) : "let-binding" - 0x00000001 (00000001) : "aside" - 0x00000002 (00000002) : "class" - 0x00000003 (00000003) : "child" - 0x00000004 (00000004) : 0 - 0x00000005 (00000005) : [ - 0000 I_Constant 0x00000001 (00000001) - 0005 I_Constant 0x00000002 (00000002) - 0010 I_Constant 0x00000003 (00000003) - 0015 I_Record 1 - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Array - 0026 I_Html_Template - 0027 I_Return + [ + [CONSTANTS] + 0x00000000 (00000000) : "let-binding" + 0x00000001 (00000001) : "aside" + 0x00000002 (00000002) : "class" + 0x00000003 (00000003) : "child" + 0x00000004 (00000004) : 0 + 0x00000005 (00000005) : [ + 0000 I_Constant 0x00000001 (00000001) + 0005 I_Constant 0x00000002 (00000002) + 0010 I_Constant 0x00000003 (00000003) + 0015 I_Record 1 + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Array + 0026 I_Html_Template + 0027 I_Return + ] + 0x00000006 (00000006) : "div" + 0x00000007 (00000007) : "class" + 0x00000008 (00000008) : "\n" + 0x00000009 (00000009) : "p" + 0x0000000A (00000010) : "true" + 0x0000000B (00000011) : 1 + 0x0000000C (00000012) : "br" + 0x0000000D (00000013) : 0 + 0x0000000E (00000014) : "\n" + 0x0000000F (00000015) : "\n" + 0x00000010 (00000016) : 5 + 0x00000011 (00000017) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Closure 0x00000005 (00000005) (free variables: 0) + 0021 I_Set_Local 0x00000001 (00000001) + 0026 I_Null + 0027 I_Pop + 0028 I_Constant 0x00000006 (00000006) + 0033 I_Constant 0x00000007 (00000007) + 0038 I_Get_Local 0x00000000 (00000000) + 0043 I_Record 1 + 0048 I_Constant 0x00000008 (00000008) + 0053 I_True + 0054 I_Jump_If_False 0x00000016 (00000022) + 0059 I_Constant 0x00000009 (00000009) + 0064 I_Record 0 + 0069 I_Constant 0x0000000A (00000010) + 0074 I_Constant 0x0000000B (00000011) + 0079 I_Array + 0080 I_Html_Template + 0081 I_Jump 0x0000001B (00000027) + 0086 I_Constant 0x0000000C (00000012) + 0091 I_Record 0 + 0096 I_Constant 0x0000000D (00000013) + 0101 I_Array + 0102 I_Html_Template + 0103 I_Constant 0x0000000E (00000014) + 0108 I_Get_Local 0x00000001 (00000001) + 0113 I_Call 0 + 0118 I_Constant 0x0000000F (00000015) + 0123 I_Constant 0x00000010 (00000016) + 0128 I_Array + 0129 I_Html_Template + 0130 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000011 (00000017) (free variables: 0) ] - 0x00000006 (00000006) : "div" - 0x00000007 (00000007) : "class" - 0x00000008 (00000008) : "\n" - 0x00000009 (00000009) : "p" - 0x0000000A (00000010) : "true" - 0x0000000B (00000011) : 1 - 0x0000000C (00000012) : "br" - 0x0000000D (00000013) : 0 - 0x0000000E (00000014) : "\n" - 0x0000000F (00000015) : "\n" - 0x00000010 (00000016) : 5 - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Closure 0x00000005 (00000005) (free variables: 0) - 0021 I_Set_Global 0x00000001 (00000001) - 0026 I_Null - 0027 I_Pop - 0028 I_Constant 0x00000006 (00000006) - 0033 I_Constant 0x00000007 (00000007) - 0038 I_Get_Global 0x00000000 (00000000) - 0043 I_Record 1 - 0048 I_Constant 0x00000008 (00000008) - 0053 I_True - 0054 I_Jump_If_False 0x00000016 (00000022) - 0059 I_Constant 0x00000009 (00000009) - 0064 I_Record 0 - 0069 I_Constant 0x0000000A (00000010) - 0074 I_Constant 0x0000000B (00000011) - 0079 I_Array - 0080 I_Html_Template - 0081 I_Jump 0x0000001B (00000027) - 0086 I_Constant 0x0000000C (00000012) - 0091 I_Record 0 - 0096 I_Constant 0x0000000D (00000013) - 0101 I_Array - 0102 I_Html_Template - 0103 I_Constant 0x0000000E (00000014) - 0108 I_Get_Global 0x00000001 (00000001) - 0113 I_Call 0 - 0118 I_Constant 0x0000000F (00000015) - 0123 I_Constant 0x00000010 (00000016) - 0128 I_Array - 0129 I_Html_Template $ NO_COLOR="1" print_instructions . HtmlFragment - [CONSTANTS] - 0x00000000 (00000000) : "\n" - 0x00000001 (00000001) : "p" - 0x00000002 (00000002) : "Enim commodo velit excepteur aute amet ut ad dolore." - 0x00000003 (00000003) : 1 - 0x00000004 (00000004) : "\n" - 0x00000005 (00000005) : "p" - 0x00000006 (00000006) : "Non et commodo anim eiusmod incididunt sint labore aliqua Lorem ea excepteur mollit sit." - 0x00000007 (00000007) : 1 - 0x00000008 (00000008) : "\n" - 0x00000009 (00000009) : "p" - 0x0000000A (00000010) : "Tempor ex aute minim ut minim excepteur enim aute." - 0x0000000B (00000011) : 1 - 0x0000000C (00000012) : "\n" - 0x0000000D (00000013) : 7 + [ + [CONSTANTS] + 0x00000000 (00000000) : "\n" + 0x00000001 (00000001) : "p" + 0x00000002 (00000002) : "Enim commodo velit excepteur aute amet ut ad dolore." + 0x00000003 (00000003) : 1 + 0x00000004 (00000004) : "\n" + 0x00000005 (00000005) : "p" + 0x00000006 (00000006) : "Non et commodo anim eiusmod incididunt sint labore aliqua Lorem ea excepteur mollit sit." + 0x00000007 (00000007) : 1 + 0x00000008 (00000008) : "\n" + 0x00000009 (00000009) : "p" + 0x0000000A (00000010) : "Tempor ex aute minim ut minim excepteur enim aute." + 0x0000000B (00000011) : 1 + 0x0000000C (00000012) : "\n" + 0x0000000D (00000013) : 7 + 0x0000000E (00000014) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Record 0 + 0015 I_Constant 0x00000002 (00000002) + 0020 I_Constant 0x00000003 (00000003) + 0025 I_Array + 0026 I_Html_Template + 0027 I_Constant 0x00000004 (00000004) + 0032 I_Constant 0x00000005 (00000005) + 0037 I_Record 0 + 0042 I_Constant 0x00000006 (00000006) + 0047 I_Constant 0x00000007 (00000007) + 0052 I_Array + 0053 I_Html_Template + 0054 I_Constant 0x00000008 (00000008) + 0059 I_Constant 0x00000009 (00000009) + 0064 I_Record 0 + 0069 I_Constant 0x0000000A (00000010) + 0074 I_Constant 0x0000000B (00000011) + 0079 I_Array + 0080 I_Html_Template + 0081 I_Constant 0x0000000C (00000012) + 0086 I_Constant 0x0000000D (00000013) + 0091 I_Array + 0092 I_Fragment_Template + 0093 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000E (00000014) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Record 0 - 0015 I_Constant 0x00000002 (00000002) - 0020 I_Constant 0x00000003 (00000003) - 0025 I_Array - 0026 I_Html_Template - 0027 I_Constant 0x00000004 (00000004) - 0032 I_Constant 0x00000005 (00000005) - 0037 I_Record 0 - 0042 I_Constant 0x00000006 (00000006) - 0047 I_Constant 0x00000007 (00000007) - 0052 I_Array - 0053 I_Html_Template - 0054 I_Constant 0x00000008 (00000008) - 0059 I_Constant 0x00000009 (00000009) - 0064 I_Record 0 - 0069 I_Constant 0x0000000A (00000010) - 0074 I_Constant 0x0000000B (00000011) - 0079 I_Array - 0080 I_Html_Template - 0081 I_Constant 0x0000000C (00000012) - 0086 I_Constant 0x0000000D (00000013) - 0091 I_Array - 0092 I_Fragment_Template diff --git a/test/vm/loop/loop_instructions.t b/test/vm/loop/loop_instructions.t index 6d6aee9..0b3a52e 100644 --- a/test/vm/loop/loop_instructions.t +++ b/test/vm/loop/loop_instructions.t @@ -1,409 +1,444 @@ $ NO_COLOR="1" print_instructions . Loop - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 5 - 0x00000006 (00000006) : 0 - 0x00000007 (00000007) : 0 - 0x00000008 (00000008) : 1 - 0x00000009 (00000009) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 5 + 0x00000006 (00000006) : 0 + 0x00000007 (00000007) : 0 + 0x00000008 (00000008) : 1 + 0x00000009 (00000009) : 1 + 0x0000000A (00000010) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Array + 0031 I_Set_Local 0x00000000 (00000000) + 0036 I_Null + 0037 I_Pop + 0038 I_Constant 0x00000006 (00000006) + 0043 I_Set_Local 0x00000003 (00000003) + 0048 I_Constant 0x00000007 (00000007) + 0053 I_Set_Local 0x00000004 (00000004) + 0058 I_Get_Local 0x00000000 (00000000) + 0063 I_Set_Local 0x00000005 (00000005) + 0068 I_Get_Local 0x00000005 (00000005) + 0073 I_Length + 0074 I_Set_Local 0x00000002 (00000002) + 0079 I_Get_Local 0x00000005 (00000005) + 0084 I_Get_Local 0x00000003 (00000003) + 0089 I_Index + 0090 I_Set_Local 0x00000001 (00000001) + 0095 I_Get_Local 0x00000001 (00000001) + 0100 I_Get_Local 0x00000003 (00000003) + 0105 I_Mul + 0106 I_Constant 0x00000008 (00000008) + 0111 I_Get_Local 0x00000004 (00000004) + 0116 I_Add + 0117 I_Set_Local 0x00000004 (00000004) + 0122 I_Constant 0x00000009 (00000009) + 0127 I_Get_Local 0x00000003 (00000003) + 0132 I_Add + 0133 I_Set_Local 0x00000003 (00000003) + 0138 I_Get_Local 0x00000003 (00000003) + 0143 I_Get_Local 0x00000002 (00000002) + 0148 I_Greater_Equal + 0149 I_Jump_If_False 0x00000013 (00000019) + 0154 I_Get_Local 0x00000004 (00000004) + 0159 I_Array + 0160 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000A (00000010) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Array - 0031 I_Set_Global 0x00000000 (00000000) - 0036 I_Null - 0037 I_Pop - 0038 I_Constant 0x00000006 (00000006) - 0043 I_Set_Global 0x00000003 (00000003) - 0048 I_Constant 0x00000007 (00000007) - 0053 I_Set_Global 0x00000004 (00000004) - 0058 I_Get_Global 0x00000000 (00000000) - 0063 I_Set_Global 0x00000005 (00000005) - 0068 I_Get_Global 0x00000005 (00000005) - 0073 I_Length - 0074 I_Set_Global 0x00000002 (00000002) - 0079 I_Get_Global 0x00000005 (00000005) - 0084 I_Get_Global 0x00000003 (00000003) - 0089 I_Index - 0090 I_Set_Global 0x00000001 (00000001) - 0095 I_Get_Global 0x00000001 (00000001) - 0100 I_Get_Global 0x00000003 (00000003) - 0105 I_Mul - 0106 I_Constant 0x00000008 (00000008) - 0111 I_Get_Global 0x00000004 (00000004) - 0116 I_Add - 0117 I_Set_Global 0x00000004 (00000004) - 0122 I_Constant 0x00000009 (00000009) - 0127 I_Get_Global 0x00000003 (00000003) - 0132 I_Add - 0133 I_Set_Global 0x00000003 (00000003) - 0138 I_Get_Global 0x00000003 (00000003) - 0143 I_Get_Global 0x00000002 (00000002) - 0148 I_Greater_Equal - 0149 I_Jump_If_False 0x00000013 (00000019) - 0154 I_Get_Global 0x00000004 (00000004) - 0159 I_Array $ NO_COLOR="1" print_instructions . LoopNested - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 2 - 0x00000003 (00000003) : 3 - 0x00000004 (00000004) : 4 - 0x00000005 (00000005) : 2 - 0x00000006 (00000006) : 5 - 0x00000007 (00000007) : 6 - 0x00000008 (00000008) : 2 - 0x00000009 (00000009) : 3 - 0x0000000A (00000010) : 0 - 0x0000000B (00000011) : 0 - 0x0000000C (00000012) : 0 - 0x0000000D (00000013) : 0 - 0x0000000E (00000014) : 1 - 0x0000000F (00000015) : 1 - 0x00000010 (00000016) : 1 - 0x00000011 (00000017) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 2 + 0x00000003 (00000003) : 3 + 0x00000004 (00000004) : 4 + 0x00000005 (00000005) : 2 + 0x00000006 (00000006) : 5 + 0x00000007 (00000007) : 6 + 0x00000008 (00000008) : 2 + 0x00000009 (00000009) : 3 + 0x0000000A (00000010) : 0 + 0x0000000B (00000011) : 0 + 0x0000000C (00000012) : 0 + 0x0000000D (00000013) : 0 + 0x0000000E (00000014) : 1 + 0x0000000F (00000015) : 1 + 0x00000010 (00000016) : 1 + 0x00000011 (00000017) : 1 + 0x00000012 (00000018) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Array + 0016 I_Constant 0x00000003 (00000003) + 0021 I_Constant 0x00000004 (00000004) + 0026 I_Constant 0x00000005 (00000005) + 0031 I_Array + 0032 I_Constant 0x00000006 (00000006) + 0037 I_Constant 0x00000007 (00000007) + 0042 I_Constant 0x00000008 (00000008) + 0047 I_Array + 0048 I_Constant 0x00000009 (00000009) + 0053 I_Array + 0054 I_Set_Local 0x00000000 (00000000) + 0059 I_Null + 0060 I_Pop + 0061 I_Constant 0x0000000A (00000010) + 0066 I_Set_Local 0x00000003 (00000003) + 0071 I_Constant 0x0000000B (00000011) + 0076 I_Set_Local 0x00000004 (00000004) + 0081 I_Get_Local 0x00000000 (00000000) + 0086 I_Set_Local 0x00000005 (00000005) + 0091 I_Get_Local 0x00000005 (00000005) + 0096 I_Length + 0097 I_Set_Local 0x00000002 (00000002) + 0102 I_Get_Local 0x00000005 (00000005) + 0107 I_Get_Local 0x00000003 (00000003) + 0112 I_Index + 0113 I_Set_Local 0x00000001 (00000001) + 0118 I_Constant 0x0000000C (00000012) + 0123 I_Set_Local 0x00000008 (00000008) + 0128 I_Constant 0x0000000D (00000013) + 0133 I_Set_Local 0x00000009 (00000009) + 0138 I_Get_Local 0x00000001 (00000001) + 0143 I_Set_Local 0x0000000A (00000010) + 0148 I_Get_Local 0x0000000A (00000010) + 0153 I_Length + 0154 I_Set_Local 0x00000007 (00000007) + 0159 I_Get_Local 0x0000000A (00000010) + 0164 I_Get_Local 0x00000008 (00000008) + 0169 I_Index + 0170 I_Set_Local 0x00000006 (00000006) + 0175 I_Get_Local 0x00000003 (00000003) + 0180 I_Get_Local 0x00000008 (00000008) + 0185 I_Add + 0186 I_Get_Local 0x00000006 (00000006) + 0191 I_Add + 0192 I_Constant 0x0000000E (00000014) + 0197 I_Get_Local 0x00000009 (00000009) + 0202 I_Add + 0203 I_Set_Local 0x00000009 (00000009) + 0208 I_Constant 0x0000000F (00000015) + 0213 I_Get_Local 0x00000008 (00000008) + 0218 I_Add + 0219 I_Set_Local 0x00000008 (00000008) + 0224 I_Get_Local 0x00000008 (00000008) + 0229 I_Get_Local 0x00000007 (00000007) + 0234 I_Greater_Equal + 0235 I_Jump_If_False 0x00000027 (00000039) + 0240 I_Get_Local 0x00000009 (00000009) + 0245 I_Array + 0246 I_Constant 0x00000010 (00000016) + 0251 I_Get_Local 0x00000004 (00000004) + 0256 I_Add + 0257 I_Set_Local 0x00000004 (00000004) + 0262 I_Constant 0x00000011 (00000017) + 0267 I_Get_Local 0x00000003 (00000003) + 0272 I_Add + 0273 I_Set_Local 0x00000003 (00000003) + 0278 I_Get_Local 0x00000003 (00000003) + 0283 I_Get_Local 0x00000002 (00000002) + 0288 I_Greater_Equal + 0289 I_Jump_If_False 0x0000001A (00000026) + 0294 I_Get_Local 0x00000004 (00000004) + 0299 I_Array + 0300 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000012 (00000018) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Array - 0016 I_Constant 0x00000003 (00000003) - 0021 I_Constant 0x00000004 (00000004) - 0026 I_Constant 0x00000005 (00000005) - 0031 I_Array - 0032 I_Constant 0x00000006 (00000006) - 0037 I_Constant 0x00000007 (00000007) - 0042 I_Constant 0x00000008 (00000008) - 0047 I_Array - 0048 I_Constant 0x00000009 (00000009) - 0053 I_Array - 0054 I_Set_Global 0x00000000 (00000000) - 0059 I_Null - 0060 I_Pop - 0061 I_Constant 0x0000000A (00000010) - 0066 I_Set_Global 0x00000003 (00000003) - 0071 I_Constant 0x0000000B (00000011) - 0076 I_Set_Global 0x00000004 (00000004) - 0081 I_Get_Global 0x00000000 (00000000) - 0086 I_Set_Global 0x00000005 (00000005) - 0091 I_Get_Global 0x00000005 (00000005) - 0096 I_Length - 0097 I_Set_Global 0x00000002 (00000002) - 0102 I_Get_Global 0x00000005 (00000005) - 0107 I_Get_Global 0x00000003 (00000003) - 0112 I_Index - 0113 I_Set_Global 0x00000001 (00000001) - 0118 I_Constant 0x0000000C (00000012) - 0123 I_Set_Global 0x00000008 (00000008) - 0128 I_Constant 0x0000000D (00000013) - 0133 I_Set_Global 0x00000009 (00000009) - 0138 I_Get_Global 0x00000001 (00000001) - 0143 I_Set_Global 0x0000000A (00000010) - 0148 I_Get_Global 0x0000000A (00000010) - 0153 I_Length - 0154 I_Set_Global 0x00000007 (00000007) - 0159 I_Get_Global 0x0000000A (00000010) - 0164 I_Get_Global 0x00000008 (00000008) - 0169 I_Index - 0170 I_Set_Global 0x00000006 (00000006) - 0175 I_Get_Global 0x00000003 (00000003) - 0180 I_Get_Global 0x00000008 (00000008) - 0185 I_Add - 0186 I_Get_Global 0x00000006 (00000006) - 0191 I_Add - 0192 I_Constant 0x0000000E (00000014) - 0197 I_Get_Global 0x00000009 (00000009) - 0202 I_Add - 0203 I_Set_Global 0x00000009 (00000009) - 0208 I_Constant 0x0000000F (00000015) - 0213 I_Get_Global 0x00000008 (00000008) - 0218 I_Add - 0219 I_Set_Global 0x00000008 (00000008) - 0224 I_Get_Global 0x00000008 (00000008) - 0229 I_Get_Global 0x00000007 (00000007) - 0234 I_Greater_Equal - 0235 I_Jump_If_False 0x00000027 (00000039) - 0240 I_Get_Global 0x00000009 (00000009) - 0245 I_Array - 0246 I_Constant 0x00000010 (00000016) - 0251 I_Get_Global 0x00000004 (00000004) - 0256 I_Add - 0257 I_Set_Global 0x00000004 (00000004) - 0262 I_Constant 0x00000011 (00000017) - 0267 I_Get_Global 0x00000003 (00000003) - 0272 I_Add - 0273 I_Set_Global 0x00000003 (00000003) - 0278 I_Get_Global 0x00000003 (00000003) - 0283 I_Get_Global 0x00000002 (00000002) - 0288 I_Greater_Equal - 0289 I_Jump_If_False 0x0000001A (00000026) - 0294 I_Get_Global 0x00000004 (00000004) - 0299 I_Array $ NO_COLOR="1" print_instructions . LoopContinue - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 6 - 0x00000006 (00000006) : 7 - 0x00000007 (00000007) : 8 - 0x00000008 (00000008) : 8 - 0x00000009 (00000009) : 0 - 0x0000000A (00000010) : 0 - 0x0000000B (00000011) : 2 - 0x0000000C (00000012) : 0 - 0x0000000D (00000013) : 1 - 0x0000000E (00000014) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 6 + 0x00000006 (00000006) : 7 + 0x00000007 (00000007) : 8 + 0x00000008 (00000008) : 8 + 0x00000009 (00000009) : 0 + 0x0000000A (00000010) : 0 + 0x0000000B (00000011) : 2 + 0x0000000C (00000012) : 0 + 0x0000000D (00000013) : 1 + 0x0000000E (00000014) : 1 + 0x0000000F (00000015) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Constant 0x00000006 (00000006) + 0035 I_Constant 0x00000007 (00000007) + 0040 I_Constant 0x00000008 (00000008) + 0045 I_Array + 0046 I_Set_Local 0x00000000 (00000000) + 0051 I_Null + 0052 I_Pop + 0053 I_Constant 0x00000009 (00000009) + 0058 I_Set_Local 0x00000003 (00000003) + 0063 I_Constant 0x0000000A (00000010) + 0068 I_Set_Local 0x00000004 (00000004) + 0073 I_Get_Local 0x00000000 (00000000) + 0078 I_Set_Local 0x00000005 (00000005) + 0083 I_Get_Local 0x00000005 (00000005) + 0088 I_Length + 0089 I_Set_Local 0x00000002 (00000002) + 0094 I_Get_Local 0x00000005 (00000005) + 0099 I_Get_Local 0x00000003 (00000003) + 0104 I_Index + 0105 I_Set_Local 0x00000001 (00000001) + 0110 I_Get_Local 0x00000001 (00000001) + 0115 I_Constant 0x0000000B (00000011) + 0120 I_Mod + 0121 I_Constant 0x0000000C (00000012) + 0126 I_Not_Equal + 0127 I_Jump_If_False 0x00000022 (00000034) + 0132 I_Jump 0x00000029 (00000041) + 0137 I_Jump 0x00000023 (00000035) + 0142 I_Null + 0143 I_Pop + 0144 I_Get_Local 0x00000001 (00000001) + 0149 I_Constant 0x0000000D (00000013) + 0154 I_Get_Local 0x00000004 (00000004) + 0159 I_Add + 0160 I_Set_Local 0x00000004 (00000004) + 0165 I_Constant 0x0000000E (00000014) + 0170 I_Get_Local 0x00000003 (00000003) + 0175 I_Add + 0176 I_Set_Local 0x00000003 (00000003) + 0181 I_Get_Local 0x00000003 (00000003) + 0186 I_Get_Local 0x00000002 (00000002) + 0191 I_Greater_Equal + 0192 I_Jump_If_False 0x00000016 (00000022) + 0197 I_Get_Local 0x00000004 (00000004) + 0202 I_Array + 0203 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000F (00000015) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Constant 0x00000006 (00000006) - 0035 I_Constant 0x00000007 (00000007) - 0040 I_Constant 0x00000008 (00000008) - 0045 I_Array - 0046 I_Set_Global 0x00000000 (00000000) - 0051 I_Null - 0052 I_Pop - 0053 I_Constant 0x00000009 (00000009) - 0058 I_Set_Global 0x00000003 (00000003) - 0063 I_Constant 0x0000000A (00000010) - 0068 I_Set_Global 0x00000004 (00000004) - 0073 I_Get_Global 0x00000000 (00000000) - 0078 I_Set_Global 0x00000005 (00000005) - 0083 I_Get_Global 0x00000005 (00000005) - 0088 I_Length - 0089 I_Set_Global 0x00000002 (00000002) - 0094 I_Get_Global 0x00000005 (00000005) - 0099 I_Get_Global 0x00000003 (00000003) - 0104 I_Index - 0105 I_Set_Global 0x00000001 (00000001) - 0110 I_Get_Global 0x00000001 (00000001) - 0115 I_Constant 0x0000000B (00000011) - 0120 I_Mod - 0121 I_Constant 0x0000000C (00000012) - 0126 I_Not_Equal - 0127 I_Jump_If_False 0x00000022 (00000034) - 0132 I_Jump 0x00000029 (00000041) - 0137 I_Jump 0x00000023 (00000035) - 0142 I_Null - 0143 I_Pop - 0144 I_Get_Global 0x00000001 (00000001) - 0149 I_Constant 0x0000000D (00000013) - 0154 I_Get_Global 0x00000004 (00000004) - 0159 I_Add - 0160 I_Set_Global 0x00000004 (00000004) - 0165 I_Constant 0x0000000E (00000014) - 0170 I_Get_Global 0x00000003 (00000003) - 0175 I_Add - 0176 I_Set_Global 0x00000003 (00000003) - 0181 I_Get_Global 0x00000003 (00000003) - 0186 I_Get_Global 0x00000002 (00000002) - 0191 I_Greater_Equal - 0192 I_Jump_If_False 0x00000016 (00000022) - 0197 I_Get_Global 0x00000004 (00000004) - 0202 I_Array $ NO_COLOR="1" print_instructions . LoopBreak - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 6 - 0x00000006 (00000006) : 7 - 0x00000007 (00000007) : 8 - 0x00000008 (00000008) : 8 - 0x00000009 (00000009) : 0 - 0x0000000A (00000010) : 0 - 0x0000000B (00000011) : 3 - 0x0000000C (00000012) : 1 - 0x0000000D (00000013) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 6 + 0x00000006 (00000006) : 7 + 0x00000007 (00000007) : 8 + 0x00000008 (00000008) : 8 + 0x00000009 (00000009) : 0 + 0x0000000A (00000010) : 0 + 0x0000000B (00000011) : 3 + 0x0000000C (00000012) : 1 + 0x0000000D (00000013) : 1 + 0x0000000E (00000014) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Constant 0x00000006 (00000006) + 0035 I_Constant 0x00000007 (00000007) + 0040 I_Constant 0x00000008 (00000008) + 0045 I_Array + 0046 I_Set_Local 0x00000000 (00000000) + 0051 I_Null + 0052 I_Pop + 0053 I_Constant 0x00000009 (00000009) + 0058 I_Set_Local 0x00000003 (00000003) + 0063 I_Constant 0x0000000A (00000010) + 0068 I_Set_Local 0x00000004 (00000004) + 0073 I_Get_Local 0x00000000 (00000000) + 0078 I_Set_Local 0x00000005 (00000005) + 0083 I_Get_Local 0x00000005 (00000005) + 0088 I_Length + 0089 I_Set_Local 0x00000002 (00000002) + 0094 I_Get_Local 0x00000005 (00000005) + 0099 I_Get_Local 0x00000003 (00000003) + 0104 I_Index + 0105 I_Set_Local 0x00000001 (00000001) + 0110 I_Get_Local 0x00000003 (00000003) + 0115 I_Constant 0x0000000B (00000011) + 0120 I_Equal + 0121 I_Jump_If_False 0x00000020 (00000032) + 0126 I_Jump 0x0000002F (00000047) + 0131 I_Jump 0x00000021 (00000033) + 0136 I_Null + 0137 I_Pop + 0138 I_Get_Local 0x00000001 (00000001) + 0143 I_Constant 0x0000000C (00000012) + 0148 I_Get_Local 0x00000004 (00000004) + 0153 I_Add + 0154 I_Set_Local 0x00000004 (00000004) + 0159 I_Constant 0x0000000D (00000013) + 0164 I_Get_Local 0x00000003 (00000003) + 0169 I_Add + 0170 I_Set_Local 0x00000003 (00000003) + 0175 I_Get_Local 0x00000003 (00000003) + 0180 I_Get_Local 0x00000002 (00000002) + 0185 I_Greater_Equal + 0186 I_Jump_If_False 0x00000016 (00000022) + 0191 I_Get_Local 0x00000004 (00000004) + 0196 I_Array + 0197 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x0000000E (00000014) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Constant 0x00000006 (00000006) - 0035 I_Constant 0x00000007 (00000007) - 0040 I_Constant 0x00000008 (00000008) - 0045 I_Array - 0046 I_Set_Global 0x00000000 (00000000) - 0051 I_Null - 0052 I_Pop - 0053 I_Constant 0x00000009 (00000009) - 0058 I_Set_Global 0x00000003 (00000003) - 0063 I_Constant 0x0000000A (00000010) - 0068 I_Set_Global 0x00000004 (00000004) - 0073 I_Get_Global 0x00000000 (00000000) - 0078 I_Set_Global 0x00000005 (00000005) - 0083 I_Get_Global 0x00000005 (00000005) - 0088 I_Length - 0089 I_Set_Global 0x00000002 (00000002) - 0094 I_Get_Global 0x00000005 (00000005) - 0099 I_Get_Global 0x00000003 (00000003) - 0104 I_Index - 0105 I_Set_Global 0x00000001 (00000001) - 0110 I_Get_Global 0x00000003 (00000003) - 0115 I_Constant 0x0000000B (00000011) - 0120 I_Equal - 0121 I_Jump_If_False 0x00000020 (00000032) - 0126 I_Jump 0x0000002F (00000047) - 0131 I_Jump 0x00000021 (00000033) - 0136 I_Null - 0137 I_Pop - 0138 I_Get_Global 0x00000001 (00000001) - 0143 I_Constant 0x0000000C (00000012) - 0148 I_Get_Global 0x00000004 (00000004) - 0153 I_Add - 0154 I_Set_Global 0x00000004 (00000004) - 0159 I_Constant 0x0000000D (00000013) - 0164 I_Get_Global 0x00000003 (00000003) - 0169 I_Add - 0170 I_Set_Global 0x00000003 (00000003) - 0175 I_Get_Global 0x00000003 (00000003) - 0180 I_Get_Global 0x00000002 (00000002) - 0185 I_Greater_Equal - 0186 I_Jump_If_False 0x00000016 (00000022) - 0191 I_Get_Global 0x00000004 (00000004) - 0196 I_Array $ NO_COLOR="1" print_instructions . LoopBreakNested - [CONSTANTS] - 0x00000000 (00000000) : 1 - 0x00000001 (00000001) : 2 - 0x00000002 (00000002) : 3 - 0x00000003 (00000003) : 4 - 0x00000004 (00000004) : 5 - 0x00000005 (00000005) : 6 - 0x00000006 (00000006) : 7 - 0x00000007 (00000007) : 8 - 0x00000008 (00000008) : 8 - 0x00000009 (00000009) : 0 - 0x0000000A (00000010) : 0 - 0x0000000B (00000011) : 1 - 0x0000000C (00000012) : 3 - 0x0000000D (00000013) : 2 - 0x0000000E (00000014) : 0 - 0x0000000F (00000015) : 0 - 0x00000010 (00000016) : 2 - 0x00000011 (00000017) : 4 - 0x00000012 (00000018) : 1 - 0x00000013 (00000019) : 1 - 0x00000014 (00000020) : 1 - 0x00000015 (00000021) : 1 + [ + [CONSTANTS] + 0x00000000 (00000000) : 1 + 0x00000001 (00000001) : 2 + 0x00000002 (00000002) : 3 + 0x00000003 (00000003) : 4 + 0x00000004 (00000004) : 5 + 0x00000005 (00000005) : 6 + 0x00000006 (00000006) : 7 + 0x00000007 (00000007) : 8 + 0x00000008 (00000008) : 8 + 0x00000009 (00000009) : 0 + 0x0000000A (00000010) : 0 + 0x0000000B (00000011) : 1 + 0x0000000C (00000012) : 3 + 0x0000000D (00000013) : 2 + 0x0000000E (00000014) : 0 + 0x0000000F (00000015) : 0 + 0x00000010 (00000016) : 2 + 0x00000011 (00000017) : 4 + 0x00000012 (00000018) : 1 + 0x00000013 (00000019) : 1 + 0x00000014 (00000020) : 1 + 0x00000015 (00000021) : 1 + 0x00000016 (00000022) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Constant 0x00000006 (00000006) + 0035 I_Constant 0x00000007 (00000007) + 0040 I_Constant 0x00000008 (00000008) + 0045 I_Array + 0046 I_Set_Local 0x00000000 (00000000) + 0051 I_Null + 0052 I_Pop + 0053 I_Constant 0x00000009 (00000009) + 0058 I_Set_Local 0x00000003 (00000003) + 0063 I_Constant 0x0000000A (00000010) + 0068 I_Set_Local 0x00000004 (00000004) + 0073 I_Constant 0x0000000B (00000011) + 0078 I_Constant 0x0000000C (00000012) + 0083 I_Range_Inclusive + 0084 I_Set_Local 0x00000005 (00000005) + 0089 I_Get_Local 0x00000005 (00000005) + 0094 I_Length + 0095 I_Set_Local 0x00000002 (00000002) + 0100 I_Get_Local 0x00000005 (00000005) + 0105 I_Get_Local 0x00000003 (00000003) + 0110 I_Index + 0111 I_Set_Local 0x00000001 (00000001) + 0116 I_Get_Local 0x00000001 (00000001) + 0121 I_Constant 0x0000000D (00000013) + 0126 I_Greater + 0127 I_Jump_If_False 0x00000022 (00000034) + 0132 I_Jump 0x00000058 (00000088) + 0137 I_Jump 0x00000023 (00000035) + 0142 I_Null + 0143 I_Pop + 0144 I_Constant 0x0000000E (00000014) + 0149 I_Set_Local 0x00000008 (00000008) + 0154 I_Constant 0x0000000F (00000015) + 0159 I_Set_Local 0x00000009 (00000009) + 0164 I_Get_Local 0x00000000 (00000000) + 0169 I_Set_Local 0x0000000A (00000010) + 0174 I_Get_Local 0x0000000A (00000010) + 0179 I_Length + 0180 I_Set_Local 0x00000007 (00000007) + 0185 I_Get_Local 0x0000000A (00000010) + 0190 I_Get_Local 0x00000008 (00000008) + 0195 I_Index + 0196 I_Set_Local 0x00000006 (00000006) + 0201 I_Get_Local 0x00000001 (00000001) + 0206 I_Constant 0x00000010 (00000016) + 0211 I_Equal + 0212 I_Get_Local 0x00000006 (00000006) + 0217 I_Constant 0x00000011 (00000017) + 0222 I_Equal + 0223 I_And + 0224 I_Jump_If_False 0x0000003B (00000059) + 0229 I_Jump 0x0000004A (00000074) + 0234 I_Jump 0x0000003C (00000060) + 0239 I_Null + 0240 I_Pop + 0241 I_Get_Local 0x00000006 (00000006) + 0246 I_Constant 0x00000012 (00000018) + 0251 I_Get_Local 0x00000009 (00000009) + 0256 I_Add + 0257 I_Set_Local 0x00000009 (00000009) + 0262 I_Constant 0x00000013 (00000019) + 0267 I_Get_Local 0x00000008 (00000008) + 0272 I_Add + 0273 I_Set_Local 0x00000008 (00000008) + 0278 I_Get_Local 0x00000008 (00000008) + 0283 I_Get_Local 0x00000007 (00000007) + 0288 I_Greater_Equal + 0289 I_Jump_If_False 0x0000002D (00000045) + 0294 I_Get_Local 0x00000009 (00000009) + 0299 I_Array + 0300 I_Constant 0x00000014 (00000020) + 0305 I_Get_Local 0x00000004 (00000004) + 0310 I_Add + 0311 I_Set_Local 0x00000004 (00000004) + 0316 I_Constant 0x00000015 (00000021) + 0321 I_Get_Local 0x00000003 (00000003) + 0326 I_Add + 0327 I_Set_Local 0x00000003 (00000003) + 0332 I_Get_Local 0x00000003 (00000003) + 0337 I_Get_Local 0x00000002 (00000002) + 0342 I_Greater_Equal + 0343 I_Jump_If_False 0x00000018 (00000024) + 0348 I_Get_Local 0x00000004 (00000004) + 0353 I_Array + 0354 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000016 (00000022) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Constant 0x00000006 (00000006) - 0035 I_Constant 0x00000007 (00000007) - 0040 I_Constant 0x00000008 (00000008) - 0045 I_Array - 0046 I_Set_Global 0x00000000 (00000000) - 0051 I_Null - 0052 I_Pop - 0053 I_Constant 0x00000009 (00000009) - 0058 I_Set_Global 0x00000003 (00000003) - 0063 I_Constant 0x0000000A (00000010) - 0068 I_Set_Global 0x00000004 (00000004) - 0073 I_Constant 0x0000000B (00000011) - 0078 I_Constant 0x0000000C (00000012) - 0083 I_Range_Inclusive - 0084 I_Set_Global 0x00000005 (00000005) - 0089 I_Get_Global 0x00000005 (00000005) - 0094 I_Length - 0095 I_Set_Global 0x00000002 (00000002) - 0100 I_Get_Global 0x00000005 (00000005) - 0105 I_Get_Global 0x00000003 (00000003) - 0110 I_Index - 0111 I_Set_Global 0x00000001 (00000001) - 0116 I_Get_Global 0x00000001 (00000001) - 0121 I_Constant 0x0000000D (00000013) - 0126 I_Greater - 0127 I_Jump_If_False 0x00000022 (00000034) - 0132 I_Jump 0x00000058 (00000088) - 0137 I_Jump 0x00000023 (00000035) - 0142 I_Null - 0143 I_Pop - 0144 I_Constant 0x0000000E (00000014) - 0149 I_Set_Global 0x00000008 (00000008) - 0154 I_Constant 0x0000000F (00000015) - 0159 I_Set_Global 0x00000009 (00000009) - 0164 I_Get_Global 0x00000000 (00000000) - 0169 I_Set_Global 0x0000000A (00000010) - 0174 I_Get_Global 0x0000000A (00000010) - 0179 I_Length - 0180 I_Set_Global 0x00000007 (00000007) - 0185 I_Get_Global 0x0000000A (00000010) - 0190 I_Get_Global 0x00000008 (00000008) - 0195 I_Index - 0196 I_Set_Global 0x00000006 (00000006) - 0201 I_Get_Global 0x00000001 (00000001) - 0206 I_Constant 0x00000010 (00000016) - 0211 I_Equal - 0212 I_Get_Global 0x00000006 (00000006) - 0217 I_Constant 0x00000011 (00000017) - 0222 I_Equal - 0223 I_And - 0224 I_Jump_If_False 0x0000003B (00000059) - 0229 I_Jump 0x0000004A (00000074) - 0234 I_Jump 0x0000003C (00000060) - 0239 I_Null - 0240 I_Pop - 0241 I_Get_Global 0x00000006 (00000006) - 0246 I_Constant 0x00000012 (00000018) - 0251 I_Get_Global 0x00000009 (00000009) - 0256 I_Add - 0257 I_Set_Global 0x00000009 (00000009) - 0262 I_Constant 0x00000013 (00000019) - 0267 I_Get_Global 0x00000008 (00000008) - 0272 I_Add - 0273 I_Set_Global 0x00000008 (00000008) - 0278 I_Get_Global 0x00000008 (00000008) - 0283 I_Get_Global 0x00000007 (00000007) - 0288 I_Greater_Equal - 0289 I_Jump_If_False 0x0000002D (00000045) - 0294 I_Get_Global 0x00000009 (00000009) - 0299 I_Array - 0300 I_Constant 0x00000014 (00000020) - 0305 I_Get_Global 0x00000004 (00000004) - 0310 I_Add - 0311 I_Set_Global 0x00000004 (00000004) - 0316 I_Constant 0x00000015 (00000021) - 0321 I_Get_Global 0x00000003 (00000003) - 0326 I_Add - 0327 I_Set_Global 0x00000003 (00000003) - 0332 I_Get_Global 0x00000003 (00000003) - 0337 I_Get_Global 0x00000002 (00000002) - 0342 I_Greater_Equal - 0343 I_Jump_If_False 0x00000018 (00000024) - 0348 I_Get_Global 0x00000004 (00000004) - 0353 I_Array diff --git a/test/vm/math/math_instructions.t b/test/vm/math/math_instructions.t index 93617c5..59fee4e 100644 --- a/test/vm/math/math_instructions.t +++ b/test/vm/math/math_instructions.t @@ -1,112 +1,175 @@ $ NO_COLOR="1" print_instructions . Add - [CONSTANTS] - 0x00000000 (00000000) : 7 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 7 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Add + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Add $ NO_COLOR="1" print_instructions . Sub - [CONSTANTS] - 0x00000000 (00000000) : 7 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 7 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Sub + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Sub $ NO_COLOR="1" print_instructions . Div - [CONSTANTS] - 0x00000000 (00000000) : 7 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 7 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Div + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Div $ NO_COLOR="1" print_instructions . Mul - [CONSTANTS] - 0x00000000 (00000000) : 7 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 7 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Mul + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Mul $ NO_COLOR="1" print_instructions . Mod - [CONSTANTS] - 0x00000000 (00000000) : 7 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 7 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Mod + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Mod $ NO_COLOR="1" print_instructions . Pow - [CONSTANTS] - 0x00000000 (00000000) : 7 - 0x00000001 (00000001) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 7 + 0x00000001 (00000001) : 5 + 0x00000002 (00000002) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Pow + 0011 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000002 (00000002) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Pow $ NO_COLOR="1" print_instructions . MinusInt - [CONSTANTS] - 0x00000000 (00000000) : 5 + [ + [CONSTANTS] + 0x00000000 (00000000) : 5 + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Minus + 0006 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Minus $ NO_COLOR="1" print_instructions . MinusFloat - [CONSTANTS] - 0x00000000 (00000000) : 3.140000 + [ + [CONSTANTS] + 0x00000000 (00000000) : 3.140000 + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Minus + 0006 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Minus $ NO_COLOR="1" print_instructions . Math - [CONSTANTS] - 0x00000000 (00000000) : 5 - 0x00000001 (00000001) : 3 - 0x00000002 (00000002) : 2 - 0x00000003 (00000003) : 6 - 0x00000004 (00000004) : 4 - 0x00000005 (00000005) : 8 - 0x00000006 (00000006) : 10 - 0x00000007 (00000007) : 10 + [ + [CONSTANTS] + 0x00000000 (00000000) : 5 + 0x00000001 (00000001) : 3 + 0x00000002 (00000002) : 2 + 0x00000003 (00000003) : 6 + 0x00000004 (00000004) : 4 + 0x00000005 (00000005) : 8 + 0x00000006 (00000006) : 10 + 0x00000007 (00000007) : 10 + 0x00000008 (00000008) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Mul + 0011 I_Constant 0x00000002 (00000002) + 0016 I_Constant 0x00000003 (00000003) + 0021 I_Constant 0x00000004 (00000004) + 0026 I_Constant 0x00000005 (00000005) + 0031 I_Mul + 0032 I_Add + 0033 I_Constant 0x00000006 (00000006) + 0038 I_Pow + 0039 I_Div + 0040 I_Add + 0041 I_Constant 0x00000007 (00000007) + 0046 I_Minus + 0047 I_Add + 0048 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000008 (00000008) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Mul - 0011 I_Constant 0x00000002 (00000002) - 0016 I_Constant 0x00000003 (00000003) - 0021 I_Constant 0x00000004 (00000004) - 0026 I_Constant 0x00000005 (00000005) - 0031 I_Mul - 0032 I_Add - 0033 I_Constant 0x00000006 (00000006) - 0038 I_Pow - 0039 I_Div - 0040 I_Add - 0041 I_Constant 0x00000007 (00000007) - 0046 I_Minus - 0047 I_Add diff --git a/test/vm/record/record_instructions.t b/test/vm/record/record_instructions.t index f37fdc3..d9fdba5 100644 --- a/test/vm/record/record_instructions.t +++ b/test/vm/record/record_instructions.t @@ -1,181 +1,225 @@ $ NO_COLOR="1" print_instructions . Record - [CONSTANTS] - 0x00000000 (00000000) : "a" - 0x00000001 (00000001) : "b" - 0x00000002 (00000002) : "c" - 0x00000003 (00000003) : "d" - 0x00000004 (00000004) : 1 - 0x00000005 (00000005) : "foo" - 0x00000006 (00000006) : 3.141500 + [ + [CONSTANTS] + 0x00000000 (00000000) : "a" + 0x00000001 (00000001) : "b" + 0x00000002 (00000002) : "c" + 0x00000003 (00000003) : "d" + 0x00000004 (00000004) : 1 + 0x00000005 (00000005) : "foo" + 0x00000006 (00000006) : 3.141500 + 0x00000007 (00000007) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_True + 0031 I_Constant 0x00000006 (00000006) + 0036 I_Record 4 + 0041 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000007 (00000007) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_True - 0031 I_Constant 0x00000006 (00000006) - 0036 I_Record 4 $ NO_COLOR="1" print_instructions . RecordEmpty - [INSTRUCTIONS] - 0000 I_Record 0 + [ + [CONSTANTS] + 0x00000000 (00000000) : [ + 0000 I_Record 0 + 0005 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000000 (00000000) (free variables: 0) + ] + $ NO_COLOR="1" print_instructions . RecordNested - [CONSTANTS] - 0x00000000 (00000000) : "a" - 0x00000001 (00000001) : "b" - 0x00000002 (00000002) : "c" - 0x00000003 (00000003) : "d" - 0x00000004 (00000004) : 1 - 0x00000005 (00000005) : "foo" - 0x00000006 (00000006) : "e" - 0x00000007 (00000007) : "f" - 0x00000008 (00000008) : "g" - 0x00000009 (00000009) : "123" - 0x0000000A (00000010) : 321 - 0x0000000B (00000011) : 1 - 0x0000000C (00000012) : 2 - 0x0000000D (00000013) : 3 - 0x0000000E (00000014) : 4 - 0x0000000F (00000015) : 5 - 0x00000010 (00000016) : 6 - 0x00000011 (00000017) : 7 - 0x00000012 (00000018) : 8 - 0x00000013 (00000019) : 8 + [ + [CONSTANTS] + 0x00000000 (00000000) : "a" + 0x00000001 (00000001) : "b" + 0x00000002 (00000002) : "c" + 0x00000003 (00000003) : "d" + 0x00000004 (00000004) : 1 + 0x00000005 (00000005) : "foo" + 0x00000006 (00000006) : "e" + 0x00000007 (00000007) : "f" + 0x00000008 (00000008) : "g" + 0x00000009 (00000009) : "123" + 0x0000000A (00000010) : 321 + 0x0000000B (00000011) : 1 + 0x0000000C (00000012) : 2 + 0x0000000D (00000013) : 3 + 0x0000000E (00000014) : 4 + 0x0000000F (00000015) : 5 + 0x00000010 (00000016) : 6 + 0x00000011 (00000017) : 7 + 0x00000012 (00000018) : 8 + 0x00000013 (00000019) : 8 + 0x00000014 (00000020) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Constant 0x00000006 (00000006) + 0035 I_Constant 0x00000007 (00000007) + 0040 I_Constant 0x00000008 (00000008) + 0045 I_Constant 0x00000009 (00000009) + 0050 I_Constant 0x0000000A (00000010) + 0055 I_Constant 0x0000000B (00000011) + 0060 I_Constant 0x0000000C (00000012) + 0065 I_Constant 0x0000000D (00000013) + 0070 I_Constant 0x0000000E (00000014) + 0075 I_Constant 0x0000000F (00000015) + 0080 I_Constant 0x00000010 (00000016) + 0085 I_Constant 0x00000011 (00000017) + 0090 I_Constant 0x00000012 (00000018) + 0095 I_Constant 0x00000013 (00000019) + 0100 I_Array + 0101 I_Record 3 + 0106 I_True + 0107 I_Record 4 + 0112 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000014 (00000020) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Constant 0x00000006 (00000006) - 0035 I_Constant 0x00000007 (00000007) - 0040 I_Constant 0x00000008 (00000008) - 0045 I_Constant 0x00000009 (00000009) - 0050 I_Constant 0x0000000A (00000010) - 0055 I_Constant 0x0000000B (00000011) - 0060 I_Constant 0x0000000C (00000012) - 0065 I_Constant 0x0000000D (00000013) - 0070 I_Constant 0x0000000E (00000014) - 0075 I_Constant 0x0000000F (00000015) - 0080 I_Constant 0x00000010 (00000016) - 0085 I_Constant 0x00000011 (00000017) - 0090 I_Constant 0x00000012 (00000018) - 0095 I_Constant 0x00000013 (00000019) - 0100 I_Array - 0101 I_Record 3 - 0106 I_True - 0107 I_Record 4 $ NO_COLOR="1" print_instructions . RecordNested - [CONSTANTS] - 0x00000000 (00000000) : "a" - 0x00000001 (00000001) : "b" - 0x00000002 (00000002) : "c" - 0x00000003 (00000003) : "d" - 0x00000004 (00000004) : 1 - 0x00000005 (00000005) : "foo" - 0x00000006 (00000006) : "e" - 0x00000007 (00000007) : "f" - 0x00000008 (00000008) : "g" - 0x00000009 (00000009) : "123" - 0x0000000A (00000010) : 321 - 0x0000000B (00000011) : 1 - 0x0000000C (00000012) : 2 - 0x0000000D (00000013) : 3 - 0x0000000E (00000014) : 4 - 0x0000000F (00000015) : 5 - 0x00000010 (00000016) : 6 - 0x00000011 (00000017) : 7 - 0x00000012 (00000018) : 8 - 0x00000013 (00000019) : 8 + [ + [CONSTANTS] + 0x00000000 (00000000) : "a" + 0x00000001 (00000001) : "b" + 0x00000002 (00000002) : "c" + 0x00000003 (00000003) : "d" + 0x00000004 (00000004) : 1 + 0x00000005 (00000005) : "foo" + 0x00000006 (00000006) : "e" + 0x00000007 (00000007) : "f" + 0x00000008 (00000008) : "g" + 0x00000009 (00000009) : "123" + 0x0000000A (00000010) : 321 + 0x0000000B (00000011) : 1 + 0x0000000C (00000012) : 2 + 0x0000000D (00000013) : 3 + 0x0000000E (00000014) : 4 + 0x0000000F (00000015) : 5 + 0x00000010 (00000016) : 6 + 0x00000011 (00000017) : 7 + 0x00000012 (00000018) : 8 + 0x00000013 (00000019) : 8 + 0x00000014 (00000020) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Constant 0x00000005 (00000005) + 0030 I_Constant 0x00000006 (00000006) + 0035 I_Constant 0x00000007 (00000007) + 0040 I_Constant 0x00000008 (00000008) + 0045 I_Constant 0x00000009 (00000009) + 0050 I_Constant 0x0000000A (00000010) + 0055 I_Constant 0x0000000B (00000011) + 0060 I_Constant 0x0000000C (00000012) + 0065 I_Constant 0x0000000D (00000013) + 0070 I_Constant 0x0000000E (00000014) + 0075 I_Constant 0x0000000F (00000015) + 0080 I_Constant 0x00000010 (00000016) + 0085 I_Constant 0x00000011 (00000017) + 0090 I_Constant 0x00000012 (00000018) + 0095 I_Constant 0x00000013 (00000019) + 0100 I_Array + 0101 I_Record 3 + 0106 I_True + 0107 I_Record 4 + 0112 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000014 (00000020) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Constant 0x00000005 (00000005) - 0030 I_Constant 0x00000006 (00000006) - 0035 I_Constant 0x00000007 (00000007) - 0040 I_Constant 0x00000008 (00000008) - 0045 I_Constant 0x00000009 (00000009) - 0050 I_Constant 0x0000000A (00000010) - 0055 I_Constant 0x0000000B (00000011) - 0060 I_Constant 0x0000000C (00000012) - 0065 I_Constant 0x0000000D (00000013) - 0070 I_Constant 0x0000000E (00000014) - 0075 I_Constant 0x0000000F (00000015) - 0080 I_Constant 0x00000010 (00000016) - 0085 I_Constant 0x00000011 (00000017) - 0090 I_Constant 0x00000012 (00000018) - 0095 I_Constant 0x00000013 (00000019) - 0100 I_Array - 0101 I_Record 3 - 0106 I_True - 0107 I_Record 4 $ NO_COLOR="1" print_instructions . RecordAccessDot - [CONSTANTS] - 0x00000000 (00000000) : "a" - 0x00000001 (00000001) : "c" - 0x00000002 (00000002) : 1 - 0x00000003 (00000003) : "e" - 0x00000004 (00000004) : "123" - 0x00000005 (00000005) : "c" - 0x00000006 (00000006) : "e" + [ + [CONSTANTS] + 0x00000000 (00000000) : "a" + 0x00000001 (00000001) : "c" + 0x00000002 (00000002) : 1 + 0x00000003 (00000003) : "e" + 0x00000004 (00000004) : "123" + 0x00000005 (00000005) : "c" + 0x00000006 (00000006) : "e" + 0x00000007 (00000007) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Record 1 + 0030 I_Record 2 + 0035 I_Set_Local 0x00000000 (00000000) + 0040 I_Null + 0041 I_Pop + 0042 I_Get_Local 0x00000000 (00000000) + 0047 I_Constant 0x00000005 (00000005) + 0052 I_Dot_Index + 0053 I_Constant 0x00000006 (00000006) + 0058 I_Dot_Index + 0059 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000007 (00000007) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Record 1 - 0030 I_Record 2 - 0035 I_Set_Global 0x00000000 (00000000) - 0040 I_Null - 0041 I_Pop - 0042 I_Get_Global 0x00000000 (00000000) - 0047 I_Constant 0x00000005 (00000005) - 0052 I_Dot_Index - 0053 I_Constant 0x00000006 (00000006) - 0058 I_Dot_Index $ NO_COLOR="1" print_instructions . RecordAccessBracket - [CONSTANTS] - 0x00000000 (00000000) : "a" - 0x00000001 (00000001) : "c" - 0x00000002 (00000002) : 1 - 0x00000003 (00000003) : "e" - 0x00000004 (00000004) : "123" - 0x00000005 (00000005) : "c" - 0x00000006 (00000006) : "e" + [ + [CONSTANTS] + 0x00000000 (00000000) : "a" + 0x00000001 (00000001) : "c" + 0x00000002 (00000002) : 1 + 0x00000003 (00000003) : "e" + 0x00000004 (00000004) : "123" + 0x00000005 (00000005) : "c" + 0x00000006 (00000006) : "e" + 0x00000007 (00000007) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Constant 0x00000002 (00000002) + 0015 I_Constant 0x00000003 (00000003) + 0020 I_Constant 0x00000004 (00000004) + 0025 I_Record 1 + 0030 I_Record 2 + 0035 I_Set_Local 0x00000000 (00000000) + 0040 I_Null + 0041 I_Pop + 0042 I_Get_Local 0x00000000 (00000000) + 0047 I_Constant 0x00000005 (00000005) + 0052 I_Index + 0053 I_Constant 0x00000006 (00000006) + 0058 I_Index + 0059 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000007 (00000007) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Constant 0x00000002 (00000002) - 0015 I_Constant 0x00000003 (00000003) - 0020 I_Constant 0x00000004 (00000004) - 0025 I_Record 1 - 0030 I_Record 2 - 0035 I_Set_Global 0x00000000 (00000000) - 0040 I_Null - 0041 I_Pop - 0042 I_Get_Global 0x00000000 (00000000) - 0047 I_Constant 0x00000005 (00000005) - 0052 I_Index - 0053 I_Constant 0x00000006 (00000006) - 0058 I_Index diff --git a/test/vm/strings/strings_instructions.t b/test/vm/strings/strings_instructions.t index 8d080d1..676f893 100644 --- a/test/vm/strings/strings_instructions.t +++ b/test/vm/strings/strings_instructions.t @@ -1,43 +1,71 @@ $ NO_COLOR="1" print_instructions . String - [CONSTANTS] - 0x00000000 (00000000) : "Hello!" + [ + [CONSTANTS] + 0x00000000 (00000000) : "Hello!" + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) $ NO_COLOR="1" print_instructions . StringConcat - [CONSTANTS] - 0x00000000 (00000000) : "Hello " - 0x00000001 (00000001) : "World" - 0x00000002 (00000002) : "!" + [ + [CONSTANTS] + 0x00000000 (00000000) : "Hello " + 0x00000001 (00000001) : "World" + 0x00000002 (00000002) : "!" + 0x00000003 (00000003) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Constant 0x00000001 (00000001) + 0010 I_Concat + 0011 I_Constant 0x00000002 (00000002) + 0016 I_Concat + 0017 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000003 (00000003) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Constant 0x00000001 (00000001) - 0010 I_Concat - 0011 I_Constant 0x00000002 (00000002) - 0016 I_Concat $ NO_COLOR="1" print_instructions . StringInterpolation - [CONSTANTS] - 0x00000000 (00000000) : "World" - 0x00000001 (00000001) : "Hello " - 0x00000002 (00000002) : "!" + [ + [CONSTANTS] + 0x00000000 (00000000) : "World" + 0x00000001 (00000001) : "Hello " + 0x00000002 (00000002) : "!" + 0x00000003 (00000003) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Set_Local 0x00000000 (00000000) + 0010 I_Null + 0011 I_Pop + 0012 I_Constant 0x00000001 (00000001) + 0017 I_Get_Local 0x00000000 (00000000) + 0022 I_Concat + 0023 I_Constant 0x00000002 (00000002) + 0028 I_Concat + 0029 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000003 (00000003) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000) - 0005 I_Set_Global 0x00000000 (00000000) - 0010 I_Null - 0011 I_Pop - 0012 I_Constant 0x00000001 (00000001) - 0017 I_Get_Global 0x00000000 (00000000) - 0022 I_Concat - 0023 I_Constant 0x00000002 (00000002) - 0028 I_Concat $ NO_COLOR="1" print_instructions . EmptyString - [CONSTANTS] - 0x00000000 (00000000) : "" + [ + [CONSTANTS] + 0x00000000 (00000000) : "" + 0x00000001 (00000001) : [ + 0000 I_Constant 0x00000000 (00000000) + 0005 I_Return + ] + + [INSTRUCTIONS] + 0000 I_Closure 0x00000001 (00000001) (free variables: 0) + ] - [INSTRUCTIONS] - 0000 I_Constant 0x00000000 (00000000)