Add more arith operators

master
rubenwardy 2016-02-21 18:29:27 +00:00
parent 4078f97878
commit 4f8751df0f
4 changed files with 58 additions and 12 deletions

View File

@ -83,7 +83,7 @@ For example, "hello" ends up with
| . | oint | Output a as int |
| , | ochr | Output a as char |
| & | iint | Input a as int |
| ~ | ichr | Input a as chat |
| ~ | ichr | Input a as char |
| g | get | a=y, b=x, get (x, y) |
| p | put | a=y, b=x, c=v. set (x, y) = v |

View File

@ -1,11 +1,23 @@
> 24*8- v
@ ,*25,"1" _ v
v <
> 24%2- v
> 24*8- v Test *-, returns 0
@ ,*25,"1" _ v Assert
v .0 <
> 24%2- v 2 % 4
@ ,*25,"2" _ v
v <
> "0", v
v <
> 0. 25*, @
> |
> 1. 25*, @
v .0 <
> 1 ! v Test !1 == 0
@ ,*25,"1" _ v
v .0 <
> 0 ! v Test !0 == 1
v .0 _ v
@ ,*25,"1" <
0 > 1. 25*, @ Test V if
> |
v.0 <
1 > 0. 25*, @ Test v if 2
> |
> 1. 25*, @

View File

@ -1 +1 @@
01
000000

View File

@ -192,6 +192,34 @@ public:
}
};
class NotSR : public Subroutine
{
public:
virtual void run(Thread *th)
{
char a = th->pop();
std::cerr << "Not " << (int)a << std::endl;
th->push((a == 0) ? 1 : 0);
th->move();
}
};
class GtSR : public Subroutine
{
public:
virtual void run(Thread *th)
{
char a = th->pop();
char b = th->pop();
if (b > a)
th->push(1);
else
th->push(0);
th->move();
}
};
class TemplateSR : public Subroutine
{
public:
@ -239,6 +267,10 @@ void VM::assignStandardSR(Thread *th)
c->operators['|'] = 11;
c->operators[':'] = 12;
c->operators['%'] = 13;
c->operators['!'] = 14;
c->operators['`'] = 15;
// TODO: ? # [ ] \ $ & ~ g p M P R L
}
void VM::init(Canvas *canvas)
@ -264,6 +296,8 @@ void VM::init(Canvas *canvas)
loadSubroutine(new VIfSR);
loadSubroutine(new DupSR);
loadSubroutine(new ModSR);
loadSubroutine(new NotSR);
loadSubroutine(new GtSR);
assignStandardSR(th);
}