From 6d2b1168e31d23ba4e9312d70607d2e67e5cd833 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 7 Aug 2015 12:56:09 -0700 Subject: 1951 - warn when copying scalars to arrays, etc. --- 020run.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to '020run.cc') diff --git a/020run.cc b/020run.cc index 1c76bbdb..151687f6 100644 --- a/020run.cc +++ b/020run.cc @@ -75,6 +75,20 @@ void run_current_routine() switch (current_instruction().operation) { // Primitive Recipe Implementations case COPY: { + if (SIZE(current_instruction().products) != SIZE(ingredients)) { + raise << "ingredients and products should match in '" << current_instruction().to_string() << "'\n" << end(); + break; + } + for (long long int i = 0; i < SIZE(ingredients); ++i) { + if (!is_mu_array(current_instruction().ingredients.at(i)) && is_mu_array(current_instruction().products.at(i))) { + raise << "can't copy " << current_instruction().ingredients.at(i).original_string << " to array " << current_instruction().products.at(i).original_string << "\n" << end(); + goto finish_instruction; + } + if (is_mu_array(current_instruction().ingredients.at(i)) && !is_mu_array(current_instruction().products.at(i))) { + raise << "can't copy array " << current_instruction().ingredients.at(i).original_string << " to " << current_instruction().products.at(i).original_string << "\n" << end(); + goto finish_instruction; + } + } copy(ingredients.begin(), ingredients.end(), inserter(products, products.begin())); break; } @@ -83,6 +97,7 @@ void run_current_routine() cout << "not a primitive op: " << current_instruction().operation << '\n'; } } + finish_instruction: if (SIZE(products) < SIZE(current_instruction().products)) { raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products! " << current_instruction().to_string() << end(); } @@ -240,6 +255,10 @@ bool is_literal(const reagent& r) { return SIZE(r.types) == 1 && r.types.at(0) == 0; } +bool is_mu_array(reagent r) { + return !r.types.empty() && r.types.at(0) == Type_ordinal["array"]; +} + :(scenario run_label) recipe main [ +foo @@ -261,3 +280,24 @@ recipe main [ 0 <- copy 34 ] -mem: storing 34 in location 0 + +:(scenario copy_checks_reagent_count) +% Hide_warnings = true; +recipe main [ + 1:number <- copy 34, 35 +] ++warn: ingredients and products should match in '1:number <- copy 34, 35' + +:(scenario write_scalar_to_array_disallowed) +% Hide_warnings = true; +recipe main [ + 1:array:number <- copy 34 +] ++warn: can't copy 34 to array 1:array:number + +:(scenario write_scalar_to_array_disallowed_2) +% Hide_warnings = true; +recipe main [ + 1:number, 2:array:number <- copy 34, 35 +] ++warn: can't copy 35 to array 2:array:number -- cgit 1.4.1-2-gfad0 ld?h=hlt&id=58a70a38cfa17d917fa701dfa9704ef47489d09a'>24-bold/main.mu
blob: aa2c07a1862341570ba597efd09078500f9caaf8 (plain) (blame)
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