1 //: Extend 'new' to handle a unicode string literal argument or 'text'.
  2 
  3 //: A Mu text is an address to an array of characters.
  4 :(before "End Mu Types Initialization")
  5 put(Type_abbreviations, "text", new_type_tree("address:array:character"));
  6 
  7 :(scenario new_string)
  8 def main [
  9   1:text <- new [abc def]
 10   2:char <- index *1:text, 5
 11 ]
 12 # number code for 'e'
 13 +mem: storing 101 in location 2
 14 
 15 :(scenario new_string_handles_unicode)
 16 def main [
 17   1:text <- new [a«c]
 18   2:num <- length *1:text
 19   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.ext.get_all_modules</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.ext.html"><font color="#ffffff">ext</font></a>.get_all_modules</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/ext/get_all_modules.py">/home/hut/ranger/ranger/ext/get_all_modules.py</a></font></td></tr></table>
    <p><tt>#&nbsp;Copyright&nbsp;(C)&nbsp;2009,&nbsp;2010&nbsp;&nbsp;Roman&nbsp;Zimbelmann&nbsp;&lt;romanz@lavabit.com&gt;<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
#&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
#&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License<br>
#&nbsp;along&nbsp;with&nbsp;this&nbsp;program.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-get_all_modules"><strong>get_all_modules</strong></a>(dirname)</dt><dd><tt>returns&nbsp;a&nbsp;list&nbsp;of&nbsp;strings&nbsp;containing&nbsp;the&nbsp;names&nbsp;of&nbsp;modules&nbsp;in&nbsp;a&nbsp;directory</tt></dd></dl>
</td></tr></table>
</body></html>
"Delimiter">) return ""; 148 ostringstream tmp; 149 for (int curr = address+1; curr <= address+size; ++curr) { 150 ¦ tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr))); 151 } 152 return tmp.str(); 153 } 154 155 //:: some miscellaneous helpers now that we have text 156 157 //: assert: perform sanity checks at runtime 158 159 :(scenario assert) 160 % Hide_errors = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line. 161 def main [ 162 assert 0, [this is an assert in Mu] 163 ] 164 +error: this is an assert in Mu 165 166 :(before "End Primitive Recipe Declarations") 167 ASSERT, 168 :(before "End Primitive Recipe Numbers") 169 put(Recipe_ordinal, "assert", ASSERT); 170 :(before "End Primitive Recipe Checks") 171 case ASSERT: { 172 if (SIZE(inst.ingredients) != 2) { 173 ¦ raise << maybe(get(Recipe, r).name) << "'assert' takes exactly two ingredients rather than '" << inst.original_string << "'\n" << end(); 174 ¦ break; 175 } 176 if (!is_mu_scalar(inst.ingredients.at(0))) { 177 ¦ raise << maybe(get(Recipe, r).name) << "'assert' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); 178 ¦ break; 179 } 180 if (!is_literal_text(inst.ingredients.at(1)) && !is_mu_text(inst.ingredients.at(1))) { 181 ¦ raise << maybe(get(Recipe, r).name) << "'assert' requires a text as its second ingredient, but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); 182 ¦ break; 183 } 184 break; 185 } 186 :(before "End Primitive Recipe Implementations") 187 case ASSERT: { 188 if (!ingredients.at(0).at(0)) { 189 ¦ if (is_literal_text(current_instruction().ingredients.at(1))) 190 ¦ ¦ raise << current_instruction().ingredients.at(1).name << '\n' << end(); 191 ¦ else 192 ¦ ¦ raise << read_mu_text(ingredients.at(1).at(0)) << '\n' << end(); 193 } 194 break; 195 } 196 197 198 //: 'cheating' by using the host system 199 200 :(before "End Primitive Recipe Declarations") 201 _READ, 202 :(before "End Primitive Recipe Numbers") 203 put(Recipe_ordinal, "$read", _READ); 204 :(before "End Primitive Recipe Checks") 205 case _READ: { 206 break; 207 } 208 :(before "End Primitive Recipe Implementations") 209 case _READ: { 210 skip_whitespace(cin); 211 string result; 212 if (has_data(cin)) 213 ¦ cin >> result; 214 products.resize(1); 215 products.at(0).push_back(new_mu_text(result)); 216 break; 217 } 218 219 :(code) 220 void skip_whitespace(istream& in) { 221 while (true) { 222 ¦ if (!has_data(in)) break; 223 ¦ if (isspace(in.peek())) in.get(); 224 ¦ else break; 225 } 226 }