diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-04-03 12:53:33 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-04-03 12:53:33 -0700 |
commit | a8007cc4839609a293908423ea37e6fc3a52d1c8 (patch) | |
tree | be77e1e36582500d163bd491aa2d2a5741644a94 /cpp | |
parent | 07d35c4af3275b32f4b2e5d870faea67c1ea6285 (diff) | |
download | mu-a8007cc4839609a293908423ea37e6fc3a52d1c8.tar.gz |
1011 - string-equal now working
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/010vm | 2 | ||||
-rw-r--r-- | cpp/013run | 6 | ||||
-rw-r--r-- | cpp/025name | 2 | ||||
-rw-r--r-- | cpp/core.mu | 36 |
4 files changed, 44 insertions, 2 deletions
diff --git a/cpp/010vm b/cpp/010vm index 8363720c..82544193 100644 --- a/cpp/010vm +++ b/cpp/010vm @@ -87,6 +87,8 @@ void setup_types() { Type[address].name = "address"; int boolean = Type_number["boolean"] = Next_type_number++; Type[boolean].name = "boolean"; + int character = Type_number["character"] = Next_type_number++; + Type[character].name = "character"; int array = Type_number["array"] = Next_type_number++; Type[array].name = "array"; // End Mu Types Initialization. diff --git a/cpp/013run b/cpp/013run index 180c862e..48de68d0 100644 --- a/cpp/013run +++ b/cpp/013run @@ -41,8 +41,9 @@ void run(routine rr) { size_t& pc = running_at(rr); // Running one instruction. if (instructions[pc].is_label) { ++pc; continue; } +//? cout << "AAA " << Trace_stream << " ^" << Trace_stream->dump_layer << "$\n"; //? 1 trace("run") << "instruction " << recipe_name(rr) << '/' << pc; -//? cout << instructions[pc].operation << '\n'; //? 1 +//? cout << "operation " << instructions[pc].operation << '\n'; //? 3 switch (instructions[pc].operation) { // Primitive Recipe Implementations. case COPY: { @@ -88,6 +89,9 @@ if (argc > 1) { fin.close(); } + Trace_stream = new trace_stream; +//? Trace_stream->dump_layer = "all"; //? 1 + transform_all(); recipe_number r = Recipe_number[string("main")]; if (r) run(r); dump_memory(); diff --git a/cpp/025name b/cpp/025name index 6d3b6d2c..f5ab234d 100644 --- a/cpp/025name +++ b/cpp/025name @@ -47,7 +47,7 @@ void transform_names(const recipe_number r) { } for (size_t out = 0; out < inst.products.size(); ++out) { if (is_raw(inst.products[out])) continue; -//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 3 +//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 4 //? cout << inst.products[out].types[0] << '\n'; //? 1 if (inst.products[out].name == "default-space") inst.products[out].initialized = true; diff --git a/cpp/core.mu b/cpp/core.mu new file mode 100644 index 00000000..b1fd34d2 --- /dev/null +++ b/cpp/core.mu @@ -0,0 +1,36 @@ +recipe string-equal [ + default-space:address:space <- new location:type, 30:literal + a:address:array:character <- next-ingredient + a-len:integer <- length a:address:array:character/deref + b:address:array:character <- next-ingredient + b-len:integer <- length b:address:array:character/deref + # compare lengths + { + length-equal?:boolean <- equal a-len:integer, b-len:integer + break-if length-equal?:boolean + reply 0:literal + } + # compare each corresponding character + i:integer <- copy 0:literal + { + done?:boolean <- greater-or-equal i:integer, a-len:integer + break-if done?:boolean + a2:character <- index a:address:array:character/deref, i:integer + b2:character <- index b:address:array:character/deref, i:integer + { + chars-match?:boolean <- equal a2:character, b2:character + break-if chars-match?:boolean + reply 0:literal + } + i:integer <- add i:integer, 1:literal + loop + } + reply 1:literal +] + +recipe main [ + default-space:address:space <- new location:type, 30:literal + x:address:array:character <- new [abc] + y:address:array:character <- new [abd] + 3:boolean/raw <- string-equal x:address:array:character, y:address:array:character +] |