History

Add new Exec module - similar to Command module but no UI context Update all current limbo modules to implement Exec instead of Command module Add new type signature building API to asm library Include the official RFC1321 (MD5) reference implementation only for use in type signature generation - NOTE: The MD5 implementation in the asm library should NOT be used for any other purpose

arr committed 10 years ago

Commit 77ee7d81 parent 8549d3410 files · +923 −28Browse files

Showing the changes to src/exec/main.cpp (1 of 10 files). Show all

Unified · Split

src/exec/main.cpp+20−22
@@ -11,10 +11,12 @@ · 10 unmodified lines
11#include <builtin_module.h>11#include <builtin_module.h>
12#include <debug.h>12#include <debug.h>
13#include <exceptions.h>13#include <exceptions.h>
14#include <vm_asm.h>
14#include "exec.h"15#include "exec.h"
15 16
16using namespace disvm;17using namespace disvm;
17using namespace disvm::runtime;18using namespace disvm::runtime;
19using namespace disvm::assembly::sigkind;
18 20
19namespace21namespace
20{22{
@@ -88,20 +90,16 @@ namespace · 67 unmodified lines
88 };90 };
89 91
90 // Initialize the module base register92 // Initialize the module base register
91 const auto mp_type = type_descriptor_t::create(12, { 0xe0 });93 const auto mp_type = type_descriptor_t::create(8, { 0xc0 });
92 e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory));94 e.original_mp.reset(vm_alloc_t::allocate(mp_type, vm_alloc_t::zero_memory));
93 auto mp_base = e.original_mp->get_allocation<pointer_t>();95 auto mp_base = e.original_mp->get_allocation<pointer_t>();
94 mp_base[0] = command_module_path->get_allocation();96 mp_base[0] = command_module_path->get_allocation();
95 97
96 // [TODO] Implement the UI context for the command
97 mp_base[1] = nullptr;
98
99 if (args != nullptr)98 if (args != nullptr)
100 mp_base[2] = args->get_allocation();99 mp_base[1] = args->get_allocation();
101 100
102 // Define the frame offsets for the two arguments101 // Define the frame offsets for the two arguments
103 const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset;102 const auto first_arg_offset = vm_frame_constants::limbo_first_arg_register_offset;
104 const auto second_arg_offset = first_arg_offset + vm_frame_constants::register_size_in_bytes;
105 103
106 e.code_section =104 e.code_section =
107 {105 {
@@ -124,17 +122,9 @@ namespace · 16 unmodified lines
124 { vm_exec_op_t122 { vm_exec_op_t
125 {123 {
126 opcode_t::movp,124 opcode_t::movp,
127 { address_mode_t::offset_indirect_mp, 4, 0 }, // UI context125 { address_mode_t::offset_indirect_mp, 4, 0 }, // Argument list
128 { address_mode_middle_t::none },
129 { address_mode_t::offset_double_indirect_fp, 24, first_arg_offset } // module call frame -> UI context offset
130 }
131 },
132 { vm_exec_op_t
133 {
134 opcode_t::movp,
135 { address_mode_t::offset_indirect_mp, 8, 0 }, // Argument list
136 { address_mode_middle_t::none },126 { address_mode_middle_t::none },
137 { address_mode_t::offset_double_indirect_fp, 24, second_arg_offset } // module call frame -> argument list offset127 { address_mode_t::offset_double_indirect_fp, 24, first_arg_offset } // module call frame -> argument list offset
138 }128 }
139 },129 },
140 { vm_exec_op_t130 { vm_exec_op_t
@@ -148,13 +138,21 @@ namespace · 7 unmodified lines
148 { vm_exec_op_t{ opcode_t::ret,{ address_mode_t::none },{ address_mode_middle_t::none },{ address_mode_t::none } } },138 { vm_exec_op_t{ opcode_t::ret,{ address_mode_t::none },{ address_mode_middle_t::none },{ address_mode_t::none } } },
149 };139 };
150 140
151 // Create import section for Command141 // Create import section for Exec
152 // See limbo/Command.m for type details142 // See limbo/Exec.m for type details
153 {143 {
154 import_function_t func{};144 import_function_t func;
155 145
156 // [TODO] Create mechanism to generated type signatures146 const auto exec_init_sig = 0x2e01144a;
157 func.sig = 0x4244b354;147
148 // Validate the hard-coded type signature on debug builds.
149#if !defined(NDEBUG)
150 sig_stream_t m;
151 m << Tfunction::create(Tlist::create(Tstring::id)).returns(Tnone::id);
152 assert(exec_init_sig == m.get_signature_hash());
153 assert(exec_init_sig == sig_stream_t::compute_signature_hash("f(Ls)n"));
154#endif
155 func.sig = exec_init_sig;
158 156
159 std::array<uint8_t, 5> func_name = { "init" };157 std::array<uint8_t, 5> func_name = { "init" };
160 func.name = std::make_unique<vm_string_t>(func_name.size() - 1, func_name.data());158 func.name = std::make_unique<vm_string_t>(func_name.size() - 1, func_name.data());