From 224474d7fd04263b7300d22df337c33b97de5fe5 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 9 Oct 2017 01:19:33 -0700 Subject: 4011 - start of sub-x86 VM --- subx/000organization.cc | 42 +++++++++++++++++++----------------------- subx/001help.cc | 4 ++-- subx/002test.cc | 17 ++++++++--------- subx/003trace.cc | 2 +- subx/Readme.md | 14 +++++++++++++- subx/clean | 2 +- 6 files changed, 44 insertions(+), 37 deletions(-) (limited to 'subx') diff --git a/subx/000organization.cc b/subx/000organization.cc index a29a8813..d9f072f9 100644 --- a/subx/000organization.cc +++ b/subx/000organization.cc @@ -79,14 +79,14 @@ //: //: This 'subsetting guarantee' ensures that this directory contains a //: cleaned-up narrative of the evolution of this codebase. Organizing -//: autobiographically allows a newcomer to rapidly orient himself, reading the -//: first few files to understand a simple gestalt of a program's core purpose -//: and features, and later gradually working his way through other features as -//: the need arises. -//: -//: Programmers shouldn't need to understand everything about a program to hack -//: on it. But they shouldn't be prevented from a thorough understanding of -//: each aspect either. The goal of layers is to reward curiosity. +//: autobiographically allows a newcomers to rapidly orient themselves, +//: reading the first few files to understand a simple gestalt of a program's +//: core purpose and features, and later gradually working their way through +//: other features as the need arises. +//: +//: Programmers shouldn't need to understand everything about a program to +//: hack on it. But they shouldn't be prevented from a thorough understanding +//: of each aspect either. The goal of layers is to reward curiosity. // Includes // End Includes @@ -94,24 +94,24 @@ // Types // End Types -// Prototypes are auto-generated in the 'build' script; define your functions -// in any order. Just be sure to declare each function header all on one line. -// Our auto-generation scripts are too minimal and simple-minded to handle -// anything else. +// Function prototypes are auto-generated in the 'build' script; define your +// functions in any order. Just be sure to declare each function header all on +// one line, ending with the '{'. Our auto-generation scripts are too minimal +// and simple-minded to handle anything else. #include "function_list" // by convention, files ending with '_list' are auto-generated // Globals // // All statements in this section should always define a single variable on a // single line. The 'build' script will simple-mindedly auto-generate extern -// declarations for them. Don't forget to define (not just declare) constants -// with extern linkage in this section, since C++ global constants have -// internal linkage by default. +// declarations for them. Remember to define (not just declare) constants with +// extern linkage in this section, since C++ global constants have internal +// linkage by default. // // End Globals int main(int argc, char* argv[]) { - atexit(teardown); + atexit(reset); // End One-time Setup @@ -124,17 +124,13 @@ int main(int argc, char* argv[]) { // Unit Tests // End Unit Tests -//: our first directive; will move the include above the program +//: our first directive; insert the following header at the start of the program :(before "End Includes") #include //: Without directives or with the :(code) directive, lines get added at the //: end. :(code) -void setup() { - // End Setup -} - -void teardown() { - // End Teardown +void reset() { + // End Reset } diff --git a/subx/001help.cc b/subx/001help.cc index d20d8144..ca1cb106 100644 --- a/subx/001help.cc +++ b/subx/001help.cc @@ -105,7 +105,7 @@ bool starts_with(const string& s, const string& pat) { //: 5. Integer overflow is guarded against at runtime using the -ftrapv flag //: to the compiler, supported by Clang (GCC version only works sometimes: //: http://stackoverflow.com/questions/20851061/how-to-make-gcc-ftrapv-work). -:(before "atexit(teardown)") +:(before "atexit(reset)") initialize_signal_handlers(); // not always necessary, but doesn't hurt //? cerr << INT_MAX+1 << '\n'; // test overflow //? assert(false); // test SIGABRT @@ -141,7 +141,7 @@ void dump_and_exit(int sig, unused siginfo_t* dummy1, unused void* dummy2) { #include //: For good measure we'll also enable SIGFPE. -:(before "atexit(teardown)") +:(before "atexit(reset)") feenableexcept(FE_OVERFLOW | FE_UNDERFLOW); //? assert(sizeof(int) == 4 && sizeof(float) == 4); //? // | exp | mantissa diff --git a/subx/002test.cc b/subx/002test.cc index 1d8efb08..f6623c90 100644 --- a/subx/002test.cc +++ b/subx/002test.cc @@ -19,7 +19,6 @@ const test_fn Tests[] = { :(before "End Globals") bool Run_tests = false; bool Passed = true; // set this to false inside any test to indicate failure -long Num_failures = 0; :(before "End Includes") #define CHECK(X) \ @@ -37,7 +36,7 @@ long Num_failures = 0; return; /* Currently we stop at the very first failure. */ \ } -:(before "End Setup") +:(before "End Reset") Passed = true; :(before "End Commandline Parsing") @@ -50,18 +49,21 @@ if (Run_tests) { // Test Runs // we run some tests and then exit; assume no state need be maintained afterward + long num_failures = 0; // End Test Run Initialization time_t t; time(&t); cerr << "C tests: " << ctime(&t); for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) { //? cerr << "running .build/test_list line " << (i+1) << '\n'; run_test(i); + if (Passed) cerr << '.'; + else ++num_failures; } cerr << '\n'; // End Tests - if (Num_failures > 0) { - cerr << Num_failures << " failure" - << (Num_failures > 1 ? "s" : "") + if (num_failures > 0) { + cerr << num_failures << " failure" + << (num_failures > 1 ? "s" : "") << '\n'; return 1; } @@ -74,13 +76,10 @@ void run_test(size_t i) { cerr << "no test " << i << '\n'; return; } - setup(); + reset(); // End Test Setup (*Tests[i])(); // End Test Teardown - teardown(); - if (Passed) cerr << '.'; - else ++Num_failures; } bool is_integer(const string& s) { diff --git a/subx/003trace.cc b/subx/003trace.cc index 2810b420..939d39f1 100644 --- a/subx/003trace.cc +++ b/subx/003trace.cc @@ -80,7 +80,7 @@ struct trace_line { bool Hide_errors = false; bool Dump_trace = false; string Dump_label = ""; -:(before "End Setup") +:(before "End Reset") Hide_errors = false; Dump_trace = false; Dump_label = ""; diff --git a/subx/Readme.md b/subx/Readme.md index 4a444b0a..5af4f750 100644 --- a/subx/Readme.md +++ b/subx/Readme.md @@ -1,3 +1,15 @@ +## The SubX VM + Bytecode interpreter for a subset of the 32-bit x86 ISA. -I'm currently building this over at https://github.com/tekknolagi/stackx/tree/ak +To build: + + ``` + ./build + ``` + +To run tests: + + ``` + ./subx + ``` diff --git a/subx/clean b/subx/clean index 6294eb56..39593221 100755 --- a/subx/clean +++ b/subx/clean @@ -1,6 +1,6 @@ #!/bin/sh set -v -rm -rf subx.cc subx *_list *.dSYM +rm -rf subx.cc subx *_list subx.core *.dSYM test $# -gt 0 && exit 0 # convenience: 'clean top-level' to leave subsidiary tools alone rm -rf ../enumerate/enumerate ../tangle/tangle ../tangle/*_list ../*/*.dSYM -- cgit 1.4.1-2-gfad0