Skip to content

Commit

Permalink
Fixed some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
arucil committed Sep 24, 2018
1 parent 4e75a93 commit fc4ed09
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fgcolor=0x404040
bgcolor=0xafafaf

# wqx每个像素在屏幕上显示的大小
scale=3
scale=2

# 模拟器会将诸如FOR I=1 TO 300:NEXT这样的空FOR循环转换成SLEEP语句:SLEEP 300。
# 这个属性表示SLEEP X实际会延时(X * sleepfactor)微妙
Expand Down
35 changes: 17 additions & 18 deletions gvb/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ inline void Compiler::resolveRefs() { //解决label引用
break;
}
case Stmt::Type::RESTORE: {
Restore *r = static_cast<Restore *>(s);
auto r = static_cast<Restore *>(s);
if (!m_labels.count(r->label)) {
m_line = line;
m_label = label;
Expand Down Expand Up @@ -132,7 +132,7 @@ inline NewLine *Compiler::aLine() {
cerror("Label duplicate");
m_dataMan.addLabel(m_label);

NewLine *s = m_nodeMan.make<NewLine>(m_label, m_line);
auto s = m_nodeMan.make<NewLine>(m_label, m_line);
s->next = stmts();
return m_labels[m_label] = s; //记录一行的第一条语句
}
Expand Down Expand Up @@ -678,7 +678,7 @@ void Compiler::translateUserCall(Expr *e1, const string &s0, const string &s1) {

inline Stmt *Compiler::printstmt() {
peek();
Print *p1 = m_nodeMan.make<Print>();
auto p1 = m_nodeMan.make<Print>();

while (m_tok != ':' && m_tok != 10 && m_tok != -1 && m_tok != Token::ELSE) {
if (m_tok != ';' && m_tok != ',') {
Expand All @@ -690,15 +690,14 @@ inline Stmt *Compiler::printstmt() {
match('(');
Expr *e1 = expr(Value::Type::REAL);
match(')');
p1->exprs.push_back(
make_pair(m_nodeMan.make<FuncCall>(
Token::SPC == t ? Func::Type::SPC : Func::Type::TAB,
Value::Type::STRING, e1),
Print::Delimiter::NO));
p1->exprs.emplace_back(m_nodeMan.make<FuncCall>(
Token::SPC == t ? Func::Type::SPC : Func::Type::TAB,
Value::Type::STRING, e1),
Print::Delimiter::NO);
break;
}
default:
p1->exprs.push_back(make_pair(expr(), Print::Delimiter::NO));
p1->exprs.emplace_back(expr(), Print::Delimiter::NO);
break;
}
} else {
Expand Down Expand Up @@ -787,7 +786,7 @@ inline Stmt *Compiler::inputstmt() {
if (m_tok == '#' || m_tok == Token::INT) { //file input
int i1 = getFileNum();
match(',');
FInput *f1 = m_nodeMan.make<FInput>(i1);
auto f1 = m_nodeMan.make<FInput>(i1);
while (true) {
f1->ids.push_back(getId());
if (m_tok != ',')
Expand All @@ -803,7 +802,7 @@ inline Stmt *Compiler::inputstmt() {
peek();
match(';');
}
Input *i = m_nodeMan.make<Input>(prompt);
auto i = m_nodeMan.make<Input>(prompt);
while (true) {
i->ids.push_back(getId());
if (m_tok != ',')
Expand All @@ -818,7 +817,7 @@ inline Stmt *Compiler::writestmt() {
peek();
int i1 = getFileNum();
match(',');
Write *w = m_nodeMan.make<Write>(i1);
auto w = m_nodeMan.make<Write>(i1);
while (true) {
w->exprs.push_back(expr());
if (m_tok != ',')
Expand Down Expand Up @@ -930,7 +929,7 @@ inline Stmt *Compiler::fieldstmt() {
int fnum = getFileNum();
match(',');

Field *f1 = m_nodeMan.make<Field>(fnum);
auto f1 = m_nodeMan.make<Field>(fnum);
int total = 0;
while (true) {
int size = m_l.ival;
Expand All @@ -941,7 +940,7 @@ inline Stmt *Compiler::fieldstmt() {
if (getIdType(id) != Value::Type::STRING) {
cerror("Need string Id in FIELD: [%s]", id);
}
f1->fields.push_back(make_pair(size, id));
f1->fields.emplace_back(size, id);
total += size;
if (m_tok != ',')
break;
Expand All @@ -968,7 +967,7 @@ inline Stmt *Compiler::findLabel(Goto *s) {
if (i != m_labels.end()) {
s->stm = i->second;
} else {
m_refs.push_back(make_tuple(s, m_line, m_label));
m_refs.emplace_back(s, m_line, m_label);
}
return s;
}
Expand All @@ -983,7 +982,7 @@ inline Stmt *Compiler::findLabel(Restore *s) {
}

inline Stmt *Compiler::findLabel(On *s) {
m_refs.push_back(make_tuple(s, m_line, m_label));
m_refs.emplace_back(s, m_line, m_label);
return s;
}

Expand Down Expand Up @@ -1252,7 +1251,7 @@ Stmt *Compiler::translate(Stmt *head, Stmt *end) {
* 20 next
* */
if (cur->next != end && cur->next->type == Stmt::Type::FOR) {
Assign *a1 = static_cast<Assign *>(cur);
auto a1 = static_cast<Assign *>(cur);

if (a1->val->type == Expr::Type::REAL) {
Real *r = static_cast<Real *>(a1->val);
Expand All @@ -1276,7 +1275,7 @@ Stmt *Compiler::translate(Stmt *head, Stmt *end) {

m_nodeMan.destroy(r); // for i=X to n, remove X
a1->val = f1->dest; // for i=X to n --> i = n
XSleep *s1 = m_nodeMan.make<XSleep>(a1->val);
auto s1 = m_nodeMan.make<XSleep>(a1->val);
s1->next = f1->next;
a1->next = s1;
m_nodeMan.destroy(f1);
Expand Down
48 changes: 24 additions & 24 deletions gvb/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,17 @@ bool GVB::step() try {
break;

case Stmt::Type::LOAD: {
XLoad *l1 = static_cast<XLoad *>(s);
auto *l1 = static_cast<XLoad *>(s);
evalPop(l1->addr);
uint16_t addr = static_cast<uint16_t>(m_top.rval);
auto addr = static_cast<uint16_t>(m_top.rval);
for (auto i : l1->values) {
m_device.poke(addr++, i);
}
break;
}

case Stmt::Type::FPUTC: {
XFputc *p1 = static_cast<XFputc *>(s);
auto *p1 = static_cast<XFputc *>(s);
auto &file = m_files[p1->fnum];
if (!file.isOpen()) {
rerror("File not open: FPUTC #%i", p1->fnum + 1);
Expand All @@ -306,7 +306,7 @@ bool GVB::step() try {
}

case Stmt::Type::FSEEK: {
XFseek *p1 = static_cast<XFseek *>(s);
auto *p1 = static_cast<XFseek *>(s);
auto &file = m_files[p1->fnum];
if (!file.isOpen()) {
rerror("File not open: FSEEK #%i", p1->fnum + 1);
Expand All @@ -333,9 +333,9 @@ bool GVB::step() try {
}

evalPop(p1->addr);
uint16_t addr = static_cast<uint16_t>(m_top.rval);
auto addr = static_cast<uint16_t>(m_top.rval);
evalPop(p1->size);
for (size_t i = static_cast<size_t>(m_top.rval); !file.eof() && i-- > 0; ) {
for (auto i = static_cast<size_t>(m_top.rval); !file.eof() && i-- > 0; ) {
m_device.poke(addr++, static_cast<uint8_t>(file.readByte()));
}
break;
Expand All @@ -353,9 +353,9 @@ bool GVB::step() try {
}

evalPop(p1->addr);
uint16_t addr = static_cast<uint16_t>(m_top.rval);
auto addr = static_cast<uint16_t>(m_top.rval);
evalPop(p1->size);
for (size_t i = static_cast<size_t>(m_top.rval); i-- > 0; ) {
for (auto i = static_cast<size_t>(m_top.rval); i-- > 0; ) {
file.writeByte(static_cast<char>(m_device.peek(addr++)));
}
break;
Expand Down Expand Up @@ -564,7 +564,7 @@ inline Stmt *GVB::exe_while(While *w1) {
}
return nullptr;
} else {
m_loops.push_back(Loop(w1));
m_loops.emplace_back(w1);
return w1->next;
}
}
Expand Down Expand Up @@ -650,7 +650,7 @@ inline Stmt *GVB::exe_on(On *on1) {
if (m_subs.size() >= UINT16_MAX) {
rerror("Stack overflow in ON-GOSUB");
}
m_subs.push_back(Sub(m_line, m_label, on1->next));
m_subs.emplace_back(m_line, m_label, on1->next);
}

return on1->addrs[static_cast<size_t>(m_top.rval - 1)].stm;
Expand All @@ -674,7 +674,7 @@ inline void GVB::exe_locate(Locate *lc1) {
if (!inRangeCO(m_top.rval, 1, 21)) {
rerror("Illegal argument in LOCATE: col=%f", m_top.rval);
}
uint8_t col = static_cast<uint8_t>(m_top.rval - 1);
auto col = static_cast<uint8_t>(m_top.rval - 1);
if (nullptr == lc1->row && m_device.getX() > col) {
m_device.nextRow();
}
Expand All @@ -687,7 +687,7 @@ inline void GVB::exe_poke(Poke *p1) {
if (!inRangeCO(m_top.rval, 0, UINT16_MAX + 1)) {
rerror("Illegal address in POKE: %f", m_top.rval);
}
uint16_t addr = static_cast<uint16_t>(m_top.rval);
auto addr = static_cast<uint16_t>(m_top.rval);

evalPop(p1->val);
if (!inRangeCO(m_top.rval, 0, UINT8_MAX + 1)) {
Expand Down Expand Up @@ -1093,7 +1093,7 @@ inline void GVB::exe_ellipse(Ellipse *c1) {

inline void GVB::exe_paint(XPaint *p1) {
evalPop(p1->addr);
uint16_t addr = static_cast<uint16_t>(m_top.rval);
auto addr = static_cast<uint16_t>(m_top.rval);

evalPop(p1->x);
int x = static_cast<int>(m_top.rval);
Expand All @@ -1102,10 +1102,10 @@ inline void GVB::exe_paint(XPaint *p1) {
int y = static_cast<int>(m_top.rval);

evalPop(p1->w);
uint8_t w = static_cast<uint8_t>(m_top.rval);
auto w = static_cast<uint8_t>(m_top.rval);

evalPop(p1->h);
uint8_t h = static_cast<uint8_t>(m_top.rval);
auto h = static_cast<uint8_t>(m_top.rval);

Device::PaintMode mode;
if (nullptr == p1->mode)
Expand All @@ -1132,23 +1132,23 @@ void GVB::eval(Expr *e1) {
auto &val = getValue(static_cast<Id *>(e1));

if (Value::Type::INT == e1->vtype)
m_stack.push_back(Single(static_cast<double>(val.ival)));
m_stack.emplace_back(static_cast<double>(val.ival));
else
m_stack.push_back(val);
break;
}

case Expr::Type::REAL:
// 编译时确保rval一定有效,不需要再检查
m_stack.push_back(Single(static_cast<Real *>(e1)->rval));
m_stack.emplace_back(static_cast<Real *>(e1)->rval);
break;

case Expr::Type::STRING:
m_stack.push_back(Single(static_cast<Str *>(e1)->sval));
m_stack.emplace_back(static_cast<Str *>(e1)->sval);
break;

case Expr::Type::INKEY:
m_stack.push_back(Single(string(1u, static_cast<char>(m_device.getKey()))));
m_stack.emplace_back(string(1u, static_cast<char>(m_device.getKey())));
break;

case Expr::Type::FUNCCALL:
Expand Down Expand Up @@ -1194,7 +1194,7 @@ GVB::Single &GVB::getValue(Id *id1) {
rerror("Bad index in array: %s 0[%f]", ac1->id, m_top.rval);
}

unsigned total = static_cast<unsigned>(m_top.rval);
auto total = static_cast<unsigned>(m_top.rval);
for (size_t i = 1; i < ac1->indices.size(); ++i) {
evalPop(ac1->indices[i]);
if (!inRangeCO(m_top.rval, 0, a1.bounds[i])) {
Expand Down Expand Up @@ -1378,7 +1378,7 @@ inline void GVB::eval_func(FuncCall *fc) {
rerror("Illegal argument in MKI: %f",
m_stack.back().rval);
}
int16_t s1 = static_cast<int16_t>(m_stack.back().rval);
auto s1 = static_cast<int16_t>(m_stack.back().rval);
m_stack.back().sval.assign(reinterpret_cast<char *>(&s1),
reinterpret_cast<char *>(&s1) + 2);
break;
Expand Down Expand Up @@ -1434,7 +1434,7 @@ inline void GVB::eval_func(FuncCall *fc) {
if (m_top.rval < 0) {
rerror("Illegal count in RIGHT: %f", m_top.rval);
}
unsigned size = static_cast<unsigned>(m_stack.back().sval.size());
auto size = static_cast<unsigned>(m_stack.back().sval.size());
if (size > m_top.rval) {
m_stack.back().sval.erase(0, size - static_cast<unsigned>(m_top.rval));
}
Expand Down Expand Up @@ -1464,7 +1464,7 @@ inline void GVB::eval_func(FuncCall *fc) {
m_top.rval, m_stack.back().sval,
static_cast<int>(s.size()));
}
unsigned offset = static_cast<unsigned>(m_top.rval);
auto offset = static_cast<unsigned>(m_top.rval);

if (nullptr == fc->expr3)
m_top.rval = 1.;
Expand All @@ -1475,7 +1475,7 @@ inline void GVB::eval_func(FuncCall *fc) {
rerror("Illegal count in MID: %f", m_top.rval);
}
--offset;
unsigned count = static_cast<unsigned>(m_top.rval);
auto count = static_cast<unsigned>(m_top.rval);
if (offset + count > s.size())
count = static_cast<unsigned>(s.size() - offset);
s = s.substr(offset, count);
Expand Down
6 changes: 3 additions & 3 deletions gvb/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Stmt : Node { // 语句
Stmt * next;

public:
Stmt(Type type)
explicit Stmt(Type type)
: type(type), next(nullptr) { }
};

Expand Down Expand Up @@ -61,7 +61,7 @@ struct Str : Expr { // 字符串常量
std::string sval;

public:
Str(const std::string &s)
explicit Str(const std::string &s)
: Expr(Type::STRING, Value::Type::STRING),
sval(s) { }
};
Expand All @@ -70,7 +70,7 @@ struct Real : Expr { // 实数常量
double rval;

public:
Real(double d)
explicit Real(double d)
: Expr(Type::REAL, Value::Type::REAL),
rval(d) { }
};
Expand Down

0 comments on commit fc4ed09

Please sign in to comment.