Skip to content

Commit d403e49

Browse files
committedAug 14, 2016
Start adding interpreter tests.
1 parent ed43535 commit d403e49

File tree

4 files changed

+2090
-103
lines changed

4 files changed

+2090
-103
lines changed
 

Diff for: ‎machine/test/test.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class VMTest {
2525
Configuration config;
2626

2727

28-
void setup_call_frame(CallFrame* cf, int size) {
28+
void setup_call_frame(CallFrame* cf, StackVariables* scope, int size) {
29+
scope->initialize(cNil, cNil, Module::create(state), 0);
30+
2931
cf->prepare(size);
3032
cf->stack_ptr_ = cf->stk - 1;
3133
cf->previous = NULL;
@@ -34,7 +36,7 @@ class VMTest {
3436
cf->compiled_code = nil<CompiledCode>();
3537
cf->flags = 0;
3638
cf->top_scope_ = NULL;
37-
cf->scope = NULL;
39+
cf->scope = scope;
3840
cf->arguments = NULL;
3941
}
4042

Diff for: ‎machine/test/test_instructions.hpp

+196-101
Large diffs are not rendered by default.

Diff for: ‎machine/test/test_interpreter.hpp

+1,840
Large diffs are not rendered by default.

Diff for: ‎rakelib/instruction_parser.rb

+50
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,56 @@ def generate_prototypes(filename)
859859
end
860860
end
861861

862+
def generate_interpreter_tests(filename)
863+
insns = objects.select { |x| x.kind_of? Instruction }
864+
File.open filename, "wb" do |file|
865+
file.puts <<-EOD
866+
\#include "machine/test/test.hpp"
867+
868+
\#include "call_frame.hpp"
869+
\#include "object_utils.hpp"
870+
871+
\#include "interpreter.hpp"
872+
873+
class TestInterpreter : public CxxTest::TestSuite, public VMTest {
874+
public:
875+
876+
void setUp() {
877+
create();
878+
}
879+
880+
void tearDown() {
881+
destroy();
882+
}
883+
EOD
884+
885+
insns.each do |obj|
886+
file.puts <<-EOD
887+
888+
void test_interpreter_#{obj.name}() {
889+
CallFrame* call_frame = ALLOCA_CALL_FRAME(1);
890+
StackVariables* scope = ALLOCA_STACKVARIABLES(0);
891+
setup_call_frame(call_frame, scope, 1);
892+
893+
intptr_t opcodes[#{obj.arguments.size+2}];
894+
opcodes[0] =
895+
reinterpret_cast<intptr_t>(instructions::data_#{obj.name}.interpreter_address);#{obj.arguments.map.with_index { |x, i| "\n opcodes[#{i+1}] = 0; // #{x}" }.join}
896+
opcodes[#{obj.arguments.size+1}] =
897+
reinterpret_cast<intptr_t>(instructions::data_ret.interpreter_address);
898+
899+
// TODO: instructions
900+
// interpreter::#{obj.name}(state, call_frame, opcodes);
901+
902+
TS_ASSERT(true);
903+
// TS_ASSERT_EQUALS(call_frame->ip(), instructions::data_#{obj.name}.width);
904+
}
905+
EOD
906+
end
907+
908+
file.puts "};"
909+
end
910+
end
911+
862912
def generate_instruction_data(filename)
863913
File.open filename, "wb" do |file|
864914
file.puts '#ifndef RBX_INSTRUCTIONS_DATA_HPP'

0 commit comments

Comments
 (0)
Please sign in to comment.