Skip to content
Browse files

drop labels and goto from stages 0 and 1

  • Loading branch information...
1 parent c9988fe commit 650fdfe0f840527f2d1c3f18b9810c2b0b57b008 @NotFound committed
Showing with 50 additions and 299 deletions.
  1. +48 −0 t/advanced/04goto.t
  2. +0 −45 t/label.t
  3. +0 −57 t/switch.t
  4. +2 −111 winxedst0.cpp
  5. +0 −86 winxedst1.winxed
View
48 t/advanced/04goto.t
@@ -0,0 +1,48 @@
+#! winxed
+
+// Test goto and labels
+
+using extern Test.More plan, is;
+
+function main [main] ()
+{
+ plan(3);
+
+ nested_labels();
+ out_label();
+}
+
+function nested_labels()
+{
+ int i = 0;
+ next:
+ {
+ int j = 0;
+ next:
+ j = j + 1;
+ if (j < 7)
+ goto next;
+ if (i == 0)
+ is(j, 7, 'nested label: in block');
+ }
+ i = i + 1;
+ if (i < 10)
+ goto next;
+ is(i, 10, 'nested label: out of block');
+}
+
+function out_label()
+{
+ int i = 0;
+ int j;
+ for (j in [1, 2, 3, 4, 5] )
+ {
+ i = j;
+ if (j == 3)
+ goto out;
+ }
+ out:
+ is(i, 3, 'goto label outside block');
+}
+
+// End
View
45 t/label.t
@@ -1,45 +0,0 @@
-#! winxed
-
-function main()
-{
- using extern Test.More;
- using Test.More.plan;
-
- plan(3);
-
- nested_labels();
- out_label();
-}
-
-function nested_labels()
-{
- using Test.More.is;
-
- int i= 0;
-next:
- {
- int j= 0;
- next:
- j = j + 1;
- if (j < 7) goto next;
- if (i == 0)
- is (j, 7, 'nested label: in block');
- }
- i = i + 1;
- if (i < 10) goto next;
- is (i, 10, 'nested label: out of block');
-}
-
-function out_label()
-{
- using Test.More.is;
- int i= 0;
- int j;
- for (j in [1, 2, 3, 4, 5] )
- {
- i= j;
- if (j == 3) goto out;
- }
-out:
- is (i, 3, 'goto label outside block');
-}
View
57 t/switch.t
@@ -1,57 +0,0 @@
-#! winxed
-# Basic tests for switch instrucion
-
-function main()
-{
- using extern Test.More;
- using Test.More.plan;
- using Test.More.is;
- plan (12);
-
- var a= ['a', 'b', 'c', 'd'];
- int i= 0;
- int j= 0;
-next:
- switch (i)
- {
- case 0:
- is(a[i], 'a', 'int 1');
- is(j, 0, 'int 2');
- j = j + 1;
- break;
- case 1:
- is(a[i], 'b', 'int 3');
- is(j, 1, 'int 4');
- j = j + 1;
- break;
- case 2:
- is(a[i], 'c', 'int 5');
- is(j, 2, 'int 6');
- j = j + 1;
- break;
- default:
- is(j, 3, 'int 7');
- }
- i = i + 1;
- if (i < 4) goto next;
- is(j, 3, 'int 8');
-
- i= 0;
-next2:
- switch(a[i])
- {
- case 'a':
- is (i, 0, 'string 1');
- break;
- case 'b':
- is (i, 1, 'string 2');
- break;
- case 'c':
- is (i, 2, 'string 3');
- break;
- default:
- is (i, 3, 'string 4');
- }
- i = i + 1;
- if (i < 4) goto next2;
-}
View
113 winxedst0.cpp
@@ -740,17 +740,11 @@ class Block : public BlockBase
char checkconstant(const std::string &name) const;
ConstantValue getconstant(const std::string &name) const;
std::string genlabel();
- std::string gennamedlabel(const std::string &name);
- virtual std::string getnamedlabel(const std::string &name) = 0;
protected:
- typedef std::map<std::string, std::string> NamedLabels;
- std::string findlabel(const std::string &name);
typedef std::map<std::string, char> Locals;
Locals locals;
typedef std::map<std::string, ConstantValue> Constants;
Constants constants;
-private:
- NamedLabels namedlabels;
};
class InBlock : public BlockBase
@@ -872,23 +866,6 @@ std::string Block::genlabel()
return genlocallabel();
}
-std::string Block::gennamedlabel(const std::string &name)
-{
- std::string gen = genlabel();
- namedlabels.insert(std::make_pair(name, gen));
- //std::cerr << name << "<-" << gen << '\n';
- return gen;
-}
-
-std::string Block::findlabel(const std::string &name)
-{
- NamedLabels::iterator it= namedlabels.find (name);
- if (it != namedlabels.end() )
- return it->second;
- else
- return std::string();
-}
-
//**********************************************************************
class SubBlock : public Block
@@ -927,7 +904,6 @@ class SubBlock : public Block
parent.freetempregs();
}
std::string genlocallabel();
- std::string getnamedlabel(const std::string &name);
ClassStatement *findclass(const ClassKey &classkey)
{
return parent.findclass(classkey);
@@ -996,12 +972,6 @@ std::string SubBlock::genlocallabel()
return l.str();
}
-std::string SubBlock::getnamedlabel(const std::string &name)
-{
- std::string label = findlabel(name);
- return label.empty () ? parent.getnamedlabel(name) : label;
-}
-
//**********************************************************************
class NamespaceKey
@@ -1087,8 +1057,6 @@ class FunctionBlock : public SubBlock
tempp= std::vector<std::string>();
}
private:
- std::string getnamedlabel(const std::string &name);
-
unsigned int subblocks;
unsigned int nreg;
unsigned int nlabel;
@@ -1163,15 +1131,6 @@ std::string FunctionBlock::genlocallabel()
return l.str();
}
-std::string FunctionBlock::getnamedlabel(const std::string &name)
-{
- std::string label= findlabel(name);
- if (label.empty () )
- throw SyntaxError("Label " + name + " not found", Token());
- //std::cerr << name << ": " << label << '\n';
- return label;
-}
-
//**********************************************************************
class FunctionStatement;
@@ -1819,17 +1778,6 @@ class LabelStatement: public SubStatement
std::string codename;
};
-class GotoStatement: public SubStatement
-{
-public:
- GotoStatement(Block &block, const Token &st, Tokenizer &tk);
- void emit (Emit &e);
-private:
- Token start;
- Block &bl;
- std::string labelname;
-};
-
//**********************************************************************
class ReturnStatement : public SubStatement
@@ -2131,7 +2079,6 @@ class ClassStatement : public SubBlock
}
std::string genlocallabel() { throw InternalError("No Class labels"); }
- std::string getnamedlabel(const std::string&) { throw InternalError("No Class labels"); }
std::string genlocalregister(char) { throw InternalError("No Class registers"); }
Token start;
@@ -2280,8 +2227,6 @@ BaseStatement *parseStatement(Block &block, Tokenizer &tk)
if (t.iskeyword("return"))
return new ReturnStatement(block, tk);
- if (t.iskeyword("goto"))
- return new GotoStatement(block, t, tk);
if (t.iskeyword("break"))
return new BreakStatement(block, tk);
if (t.iskeyword("continue"))
@@ -2301,60 +2246,8 @@ BaseStatement *parseStatement(Block &block, Tokenizer &tk)
if (t.iskeyword("try"))
return new TryStatement(block, t, tk);
- if (t.isidentifier() )
- {
- Token t2= tk.get();
- if (t2.isop(':'))
- return new LabelStatement(block, t.identifier());
- else
- {
- tk.unget(t2);
- tk.unget(t);
- return new ExprStatement(block, tk);
- }
- }
- else
- {
- tk.unget(t);
- return new ExprStatement(block, tk);
- }
-}
-
-//**********************************************************************
-
-LabelStatement::LabelStatement(Block &block, const std::string &name) :
- SubStatement(block),
- labelname(name),
- codename(block.gennamedlabel(name))
-{
-}
-
-void LabelStatement::emit (Emit &e)
-{
- e << INDENTLABEL << codename << ":"
- " # " << labelname << '\n';
-}
-
-//**********************************************************************
-
-GotoStatement::GotoStatement(Block &block, const Token &st, Tokenizer &tk) :
- SubStatement(block),
- start(st),
- bl(block)
-{
- Token t= tk.get();
- labelname= t.identifier();
- t= tk.get();
- if (!t.isop(';'))
- throw Expected ("';' after label", t);
-}
-
-void GotoStatement::emit (Emit &e)
-{
- e.annotate(start);
- e <<
- INDENT "goto " << bl.getnamedlabel(labelname) <<
- " # " << labelname << '\n';
+ tk.unget(t);
+ return new ExprStatement(block, tk);
}
//**********************************************************************
@@ -6575,8 +6468,6 @@ class NamespaceBlockBase : public Block
private:
std::string genlocallabel()
{ throw InternalError("No Namespace labels"); }
- std::string getnamedlabel(const std::string&)
- { throw InternalError("No Namespace labels"); }
std::string genlocalregister(char)
{ throw InternalError("No Namespace registers"); }
void freelocalregister(const std::string&)
View
86 winxedst1.winxed
@@ -2392,8 +2392,6 @@ function parseStatement(tk, owner)
break;
case 'return':
return new ReturnStatement(t, tk, owner);
- case 'goto':
- return new GotoStatement(t, tk, owner);
case 'if':
return new IfStatement(t, tk, owner);
case 'while':
@@ -2414,12 +2412,6 @@ function parseStatement(tk, owner)
return new TryStatement(t, tk, owner);
}
- if (t.isidentifier()) {
- var t2 = tk.get();
- if (t2.isop(':'))
- return new LabelStatement(t, owner);
- tk.unget(t2);
- }
tk.unget(t);
return new ExprStatement(t, tk, owner);
}
@@ -2455,14 +2447,6 @@ class Statement : CommonBase
{
return self.owner.genlabel();
}
- function getlabel(name)
- {
- return self.owner.getlabel(name);
- }
- function createlabel(name)
- {
- return self.owner.createlabel(name);
- }
function createconst(name, string type, int flags [optional])
{
return self.owner.createconst(name, type, flags);
@@ -7433,54 +7417,6 @@ class ReturnStatement : Statement
}
//*********************************************
-// LabelStatement
-//*********************************************
-
-class LabelStatement : Statement
-{
- var name;
- var value;
- function LabelStatement(n, owner)
- {
- self.Statement(n, owner);
- self.name = n;
- self.value = self.createlabel(n);
- }
- function optimize() { return self; }
- function emit(e)
- {
- self.annotate(e);
- e.emitlabel(self.value, 'label ' + string(self.name));
- }
-}
-
-//*********************************************
-// GotoStatement
-//*********************************************
-
-class GotoStatement : Statement
-{
- var label;
-
- function GotoStatement(start, tk, owner)
- {
- self.Statement(start, owner);
- var t = tk.get();
- RequireIdentifier(t);
- self.label = t;
- ExpectOp(';', tk);
- }
- function optimize() { return self; }
- function emit(e)
- {
- self.annotate(e);
- string label = self.label;
- string value = self.getlabel(label);
- e.emitgoto(value, 'goto ' + label);
- }
-}
-
-//*********************************************
// ConditionalStatement
//*********************************************
@@ -8835,12 +8771,10 @@ function parseVolatile(start, tk, owner)
class CompoundStatement : MultiStatementBase, BlockStatement
{
var end;
- var labels;
function CompoundStatement(start, tk, owner)
{
self.BlockStatement(start, owner);
- self.labels = {};
self.statements = [];
var t;
while (! (t = tk.get()).isop('}')) {
@@ -8852,26 +8786,6 @@ class CompoundStatement : MultiStatementBase, BlockStatement
}
self.end = t;
}
- function getlabel(var name)
- {
- string s = name;
- var labels = self.labels;
- string exist = labels[s];
- if (exist == null || exist == '')
- exist = self.owner.getlabel(name);
- return exist;
- }
- function createlabel(var name)
- {
- string s = name;
- var labels = self.labels;
- string exist = labels[s];
- if (exist != null && exist != '')
- SyntaxError('Label already defined', name);
- string value = self.genlabel();
- labels[s] = value;
- return value;
- }
function getend() { return self.end; }
function emit(var e)
{

0 comments on commit 650fdfe

Please sign in to comment.
Something went wrong with that request. Please try again.