From 36594a43e0503bef1a894320deb3182af74902dc Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 18 Feb 2015 10:49:46 -0800 Subject: 779 - first scenario tested in literate C++ version --- cpp/literate/010vm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'cpp/literate/010vm') diff --git a/cpp/literate/010vm b/cpp/literate/010vm index 8d427c43..4ae5c16a 100644 --- a/cpp/literate/010vm +++ b/cpp/literate/010vm @@ -14,8 +14,6 @@ struct recipe { vector step; }; -const int idle = 0; // always the first entry in the recipe book - :(before "struct recipe") // Each instruction is either of the form: // product1, product2, product3, ... <- operation ingredient1, ingredient2, ingredient3, ... @@ -53,6 +51,8 @@ struct property { :(before "End Globals") // Locations refer to a common 'memory'. Each location can store a number. unordered_map Memory; +:(before "End Setup") + Memory.clear(); :(after "Types") // Types encode how the numbers stored in different parts of memory are @@ -68,6 +68,16 @@ typedef int type_number; unordered_map Type_number; unordered_map Type; int Next_type_number = 1; +:(code) +void setup_types() { + Type.clear(); Type_number.clear(); + Type_number["literal"] = 0; + Next_type_number = 1; + int integer = Type_number["integer"] = Next_type_number++; + Type[integer].size = 1; +} +:(before "End Setup") + setup_types(); :(before "End Types") // You can construct arbitrary new types. Types are either 'records', containing @@ -83,6 +93,22 @@ struct type_info { type_info() :size(0) {} }; +:(code) +// It's all very well to construct recipes out of other recipes, but we need +// to know how to do *something* out of the box. For the following +// recipes there are only codes, no entries in the book, because mu just knows +// what to do for them. +void setup_recipes() { + Recipe.clear(); Recipe_number.clear(); + Recipe_number["idle"] = 0; + Next_recipe_number = 1; + Recipe_number["copy"] = Next_recipe_number++; +} +:(before "End Types") +const int idle = 0; // always the first entry in the recipe book +:(before "End Setup") + setup_recipes(); + :(code) @@ -113,3 +139,7 @@ string slurp_until(istream& in, char delim) { } return out.str(); } + + + +:(before "End Setup") -- cgit 1.4.1-2-gfad0