|
@@ -1,10 +1,18 @@
|
|
part of trisc;
|
|
part of trisc;
|
|
|
|
|
|
|
|
+class internal{
|
|
|
|
+ static final haltMe = new tryte(-13);
|
|
|
|
+ static final nop = new tryte.zero();
|
|
|
|
+}
|
|
|
|
+
|
|
abstract class CPU{
|
|
abstract class CPU{
|
|
static const int ok = 0;
|
|
static const int ok = 0;
|
|
static const int stop = 1;
|
|
static const int stop = 1;
|
|
static const int skip = 2;
|
|
static const int skip = 2;
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ bool get debug;
|
|
|
|
+ set debug(bool);
|
|
|
|
+
|
|
void reset();
|
|
void reset();
|
|
int next();
|
|
int next();
|
|
}
|
|
}
|
|
@@ -18,36 +26,64 @@ class ProcFactory{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+typedef int IRhandler(op);
|
|
|
|
+
|
|
class _cpu extends CPU{
|
|
class _cpu extends CPU{
|
|
int27 ir;
|
|
int27 ir;
|
|
int27 pc;
|
|
int27 pc;
|
|
int step = 0;
|
|
int step = 0;
|
|
-
|
|
|
|
|
|
+ bool _debug = false;
|
|
|
|
+
|
|
int27 start = new int27.zero();
|
|
int27 start = new int27.zero();
|
|
RAM mem;
|
|
RAM mem;
|
|
-
|
|
|
|
- Function handler(){
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ bool get debug => _debug;
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ set debug(bool x){
|
|
|
|
+ this._debug = x;
|
|
}
|
|
}
|
|
-
|
|
|
|
- void parse(int27 ir, Function(e)){
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ IRhandler handler(){
|
|
|
|
+ return (op){
|
|
|
|
+
|
|
|
|
+ };
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ int parse(int27 ir, IRhandler h){
|
|
|
|
+ tryte format = short(ir >> 24);
|
|
|
|
+ if(format == internal.nop){
|
|
|
|
+ return CPU.skip;
|
|
|
|
+ }else if(format == internal.haltMe){
|
|
|
|
+ halt.on(condition: !debug, code: 146);
|
|
|
|
+ return CPU.stop;
|
|
|
|
+ }else{
|
|
|
|
+ return h(Op.parse(ir));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@override
|
|
@override
|
|
void reset(){
|
|
void reset(){
|
|
ir = new int27.zero();
|
|
ir = new int27.zero();
|
|
pc = start;
|
|
pc = start;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@override
|
|
@override
|
|
int next(){
|
|
int next(){
|
|
step++;
|
|
step++;
|
|
ir = new Mapper(mem)[pc.toInt()];
|
|
ir = new Mapper(mem)[pc.toInt()];
|
|
|
|
+ fmt.fine("step $step: [$pc]");
|
|
pc += new int27.one();
|
|
pc += new int27.one();
|
|
- return parse(ir, handler());
|
|
|
|
|
|
+ if(pc.toInt() == new Mapper(mem).length)
|
|
|
|
+ pc = new int27.zero();
|
|
|
|
+ fmt.fine(new Trits(ir));
|
|
|
|
+
|
|
|
|
+ int ret = parse(ir, handler());
|
|
|
|
+ fmt.fine("step $step: $ret");
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
_cpu(this.mem, this.start){
|
|
_cpu(this.mem, this.start){
|
|
reset();
|
|
reset();
|
|
}
|
|
}
|