summary refs log tree commit diff stats
path: root/tests/cpp
Commit message (Expand)AuthorAgeFilesLines
* join simple testArne Döring2018-11-231-1/+10
* activated more tests, allow input in test specArne Döring2018-11-231-0/+1
* updated tests to be executedArne Döring2018-11-231-0/+1
* Fixes discard bug in cpp codegen (#9747) [backport]cooldome2018-11-191-1/+11
* fixes #5549Araq2018-10-301-0/+10
* Closes #6986narimiran2018-10-281-0/+16
* fixes #9222 (#9224)cooldome2018-10-092-0/+26
* Fix linking issue in cpp codegenLemonBoy2018-09-191-0/+9
* disable Nimble dependencies for appveyorAraq2018-09-141-1/+1
* make tests green againAraq2018-08-131-0/+1
* Generate dynlib strings as a single rope (#8247)LemonBoy2018-07-081-0/+7
* fix #7653Zahary Karadjov2018-06-101-0/+16
* make tests green againAndreas Rumpf2018-04-221-11/+5
* Static[T] fixes (#7333)zah2018-03-242-2/+2
* Fixes #6837 (#7271)cooldome2018-03-021-1/+15
* genTryCpp codegen. Fixes #7232. Fixes #7239 (#7240)cooldome2018-02-221-1/+21
* Alternative fix for #4910 that covers #6892; fixes #6892 (#6938)cooldome2017-12-171-3/+11
* fixes another sighashes problemAraq2017-12-081-0/+1
* Fixes #5979 (#5980)Yuriy Glukhov2017-11-191-0/+10
* use targets from test spec when running testament tests (#6687)Jacek Sieka2017-11-1519-15/+24
* fixes #4910Araq2017-10-141-0/+8
* fixes #6016 union alias trigger bad codegen (#6117)andri lim2017-08-031-0/+17
* attempt to fix a compilation problem caused by nimcacheZahary Karadjov2017-05-131-0/+424
* fixes #5142Araq2016-12-231-0/+8
* make travis greenAraq2016-12-221-1/+2
* fixes #5140Araq2016-12-221-0/+28
* added missing fileAndreas Rumpf2016-12-211-0/+4
* fixes #5136Andreas Rumpf2016-12-211-0/+10
* Merge branch 'devel' into sighashesAraq2016-12-171-0/+22
|\
| * reworked emit pragma; fixes #4730Andreas Rumpf2016-12-171-0/+22
* | make tsigbreak.nim compileAndreas Rumpf2016-12-121-0/+28
|/
* attempt to make travis green againAraq2016-12-011-1/+1
* fixes #5081Araq2016-12-011-0/+3
* fixes #4625Andreas Rumpf2016-09-131-0/+22
* fixes #2259, fixes #1389Andreas Rumpf2016-06-021-0/+10
* Added test casemjendrusch2016-04-171-0/+9
* Fix a few deprecation warningsdef2016-01-251-1/+1
* fixes #3299Araq2015-10-151-0/+11
* Rename rawsockets module to nativesocketsAdam Strzelecki2015-10-031-1/+1
* tests: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-041-1/+1
* fixes #2841Araq2015-07-221-0/+6
* fixes #1888Araq2015-04-271-0/+17
* added test for #2536Araq2015-04-241-0/+38
* fixes #2505, fixes #1853, fixes #2522Araq2015-04-202-1/+2
* The getSubsystem<T> example in the manual currently fails with a codegen errorZahary Karadjov2015-04-142-4/+24
* importing of C++ nested generics like std::vector<T>::iterator, using the apo...Zahary Karadjov2015-04-131-0/+21
* fixes #1717, fixes #2324Araq2015-03-221-0/+20
* Add test for fix in f8d6d74368ea14403d1d455db30b669750e71651.Philip Wernersbach2015-03-151-0/+14
* some love for the testsuite; fixed regressionsAraq2015-03-012-2/+2
* Add test for #1460def2015-02-041-0/+5
title='author Kartik K. Agaram <vc@akkartik.com> 2016-04-24 11:54:30 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2016-04-24 11:54:30 -0700 2864 - replace all address:shared with just address' href='/akkartik/mu/commit/034new_text.cc?h=hlt&id=b0bf5321de2ba32f3b92c2faf6b7b68a06b6b432'>b0bf5321 ^
7c9def3c ^

b0bf5321 ^


d9630e06 ^

7c9def3c ^

d9630e06 ^



78c50205 ^
d9630e06 ^

b0bf5321 ^

ad2604e8 ^
b0bf5321 ^
192d59d3 ^
7c9def3c ^
b0bf5321 ^
ad2604e8 ^

b0bf5321 ^














78c50205 ^
b0bf5321 ^
7fd01071 ^
b0bf5321 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139



                                                                       
                                                                          


                      
                         
                            





                                      
                      
                         
                            





                                       
                                                   
                                       
                                                                            
                                                                
                                                                 
                       
                                                                                        




                                                                                
                                         


                                               
                  
                                                         





                                                                                                              





                                                                  

                                                                                                                    
                                                    
                   








                                                 

                      


              
                                            
                    
                       
                                  



                          

                      




                                    

                     


             

                                 

                     



                                  
                                                

                                    

                                                               
                                 
          
                                      
                                                                                                                  
 

                                                














                                                                   
                                  
                              
                              







                                                                          
//: Extend 'new' to handle a unicode string literal argument or 'text'.

//: A Mu text is an address to an array of characters.
:(before "End Mu Types Initialization")
put(Type_abbreviations, "text", new_type_tree("address:array:character"));

:(scenario new_string)
def main [
  1:text <- new [abc def]
  2:char <- index *1:text, 5
]
# number code for 'e'
+mem: storing 101 in location 2

:(scenario new_string_handles_unicode)
def main [
  1:text <- new [a«c]
  2:num <- length *1:text
  3:char <- index *1:text, 1
]
+mem: storing 3 in location 2
# unicode for '«'
+mem: storing 171 in location 3

:(before "End NEW Check Special-cases")
if (is_literal_text(inst.ingredients.at(0))) break;
:(before "Convert 'new' To 'allocate'")
if (inst.name == "new" && is_literal_text(inst.ingredients.at(0))) continue;
:(after "case NEW" following "Primitive Recipe Implementations")
  if (is_literal_text(current_instruction().ingredients.at(0))) {
    products.resize(1);
    products.at(0).push_back(new_mu_text(current_instruction().ingredients.at(0).name));
    trace(9999, "mem") << "new string alloc: " << products.at(0).at(0) << end();
    break;
  }

:(code)
int new_mu_text(const string& contents) {
  // allocate an array just large enough for it
  int string_length = unicode_length(contents);
//?   Total_alloc += string_length+1;
//?   ++Num_alloc;
  int result = allocate(string_length+/*array length*/1);
  trace(9999, "mem") << "storing string refcount 0 in location " << result << end();
  put(Memory, result, 0);
  int curr_address = result+/*skip refcount*/1;
  trace(9999, "mem") << "storing string length " << string_length << " in location " << curr_address << end();
  put(Memory, curr_address, string_length);
  ++curr_address;  // skip length
  int curr = 0;
  const char* raw_contents = contents.c_str();
  for (int i = 0; i < string_length; ++i) {
    uint32_t curr_character;
    assert(curr < SIZE(contents));
    tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]);
    trace(9999, "mem") << "storing string character " << curr_character << " in location " << curr_address << end();
    put(Memory, curr_address, curr_character);
    curr += tb_utf8_char_length(raw_contents[curr]);
    ++curr_address;
  }
  // mu strings are not null-terminated in memory
  return result;
}

//: stash recognizes strings

:(scenario stash_string)
def main [
  1:text <- new [abc]
  stash [foo:], 1:text
]
+app: foo: abc

:(before "End print Special-cases(r, data)")
if (is_mu_text(r)) {
  assert(scalar(data));
  return read_mu_text(data.at(0));
}

:(scenario unicode_string)
def main [
  1:text <- new []
  stash [foo:], 1:text
]
+app: foo: 

:(scenario stash_space_after_string)
def main [
  1:text <- new [abc]
  stash 1:text, [foo]
]
+app: abc foo

:(scenario stash_string_as_array)
def main [
  1:text <- new [abc]
  stash *1:text
]
+app: 3 97 98 99

//: fixes way more than just stash
:(before "End Preprocess is_mu_text(reagent x)")
if (!canonize_type(x)) return false;

//: Allocate more to routine when initializing a literal string
:(scenario new_string_overflow)
% Initial_memory_per_routine = 3;
def main [
  1:address:num/raw <- new number:type
  2:text/raw <- new [a]  # not enough room in initial page, if you take the refcount and array length into account
]
+new: routine allocated memory from 1000 to 1003
+new: routine allocated memory from 1003 to 1006

//: helpers
:(code)
int unicode_length(const string& s) {
  const char* in = s.c_str();
  int result = 0;
  int curr = 0;
  while (curr < SIZE(s)) {  // carefully bounds-check on the string
    // before accessing its raw pointer
    ++result;
    curr += tb_utf8_char_length(in[curr]);
  }
  return result;
}

string read_mu_text(int address) {
  if (address == 0) return "";
  ++address;  // skip refcount
  int size = get_or_insert(Memory, address);
  if (size == 0) return "";
  ostringstream tmp;
  for (int curr = address+1; curr <= address+size; ++curr) {
    tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr)));
  }
  return tmp.str();
}