Persistent canvas for subprograms
parent
e5089f9b31
commit
8ad488f484
|
@ -0,0 +1,3 @@
|
||||||
|
> v
|
||||||
|
v _ "a" 51 p R
|
||||||
|
> 51g R
|
|
@ -1,3 +1,3 @@
|
||||||
> v
|
> v
|
||||||
v P "A"0"add"0 < Load ::add, call it l.
|
v P "A"0"add"0 < Load ::add, call it A
|
||||||
> 2 2 A . 25*, @
|
> 2 2 A . 25*, @
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
> v
|
||||||
|
v P "A"0"sp_getput"0 < Load ::sp_getput, call it l.
|
||||||
|
> A 1 A , 25*, @
|
|
@ -0,0 +1 @@
|
||||||
|
a
|
|
@ -94,6 +94,11 @@ For example, to pass "hello" as a parameter would be:
|
||||||
| R | rtn | Return to caller |
|
| R | rtn | Return to caller |
|
||||||
| L | lock | Hide the stack before a certain cell - use to stop bugs overwriting previous program's stack elements. |
|
| L | lock | Hide the stack before a certain cell - use to stop bugs overwriting previous program's stack elements. |
|
||||||
|
|
||||||
|
Calling P will load the subprogram's canvas into memory. Any changes to the Canvas
|
||||||
|
in one subprogram call will be kept and seen by the next.
|
||||||
|
|
||||||
|
See submodule_getput.rf which calls sp_getput.rf
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -265,7 +265,10 @@ public:
|
||||||
char y = th->pop();
|
char y = th->pop();
|
||||||
char x = th->pop();
|
char x = th->pop();
|
||||||
Canvas *c = th->cursor->canvas;
|
Canvas *c = th->cursor->canvas;
|
||||||
th->push(c->get(x, y));
|
char v = c->get(x, y);
|
||||||
|
th->push(v);
|
||||||
|
|
||||||
|
std::cerr << "Got " << v << " from " << (int)x << ", " << (int)y << std::endl;
|
||||||
|
|
||||||
th->move();
|
th->move();
|
||||||
}
|
}
|
||||||
|
@ -281,6 +284,7 @@ public:
|
||||||
char v = th->pop();
|
char v = th->pop();
|
||||||
Canvas *c = th->cursor->canvas;
|
Canvas *c = th->cursor->canvas;
|
||||||
c->set(x, y, v);
|
c->set(x, y, v);
|
||||||
|
std::cerr << "Put " << v << " to " << (int)x << ", " << (int)y << std::endl;
|
||||||
|
|
||||||
th->move();
|
th->move();
|
||||||
}
|
}
|
||||||
|
@ -321,25 +325,18 @@ public:
|
||||||
class StartRufungeSR : public Subroutine
|
class StartRufungeSR : public Subroutine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Canvas *canvas = new Canvas();
|
||||||
std::string module;
|
std::string module;
|
||||||
std::string file;
|
std::string file;
|
||||||
virtual void run(VM *vm, Thread *th)
|
virtual void run(VM *vm, Thread *th)
|
||||||
{
|
{
|
||||||
Canvas *d = new Canvas();
|
|
||||||
std::string filepath = std::string("examples/") + file + ".rf";
|
std::string filepath = std::string("examples/") + file + ".rf";
|
||||||
if (d->readFromFile(filepath.c_str())) {
|
std::cerr << "Entering " << filepath << std::endl;
|
||||||
std::cerr << "Loaded " << filepath << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cerr << "Error! Unable to load SR "
|
|
||||||
<< module << "::" << file << std::endl;
|
|
||||||
th->state = ETS_DEAD;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
th->move();
|
th->move();
|
||||||
|
|
||||||
Cursor *cursor = new Cursor();
|
Cursor *cursor = new Cursor();
|
||||||
cursor->canvas = d;
|
cursor->canvas = canvas;
|
||||||
th->pushCursor(cursor);
|
th->pushCursor(cursor);
|
||||||
vm->assignStandardSR(th);
|
vm->assignStandardSR(th);
|
||||||
}
|
}
|
||||||
|
@ -369,10 +366,23 @@ public:
|
||||||
c = th->pop();
|
c = th->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load canvas
|
||||||
|
Canvas *d = new Canvas();
|
||||||
|
std::string filepath = std::string("examples/") + file + ".rf";
|
||||||
|
if (d->readFromFile(filepath.c_str())) {
|
||||||
|
std::cerr << "Loaded " << filepath << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error! Unable to load SR "
|
||||||
|
<< module << "::" << file << std::endl;
|
||||||
|
th->state = ETS_DEAD;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Load as operator
|
// Load as operator
|
||||||
StartRufungeSR *sr = new StartRufungeSR;
|
StartRufungeSR *sr = new StartRufungeSR;
|
||||||
sr->module = module;
|
sr->module = module;
|
||||||
sr->file = file;
|
sr->file = file;
|
||||||
|
sr->canvas = d;
|
||||||
th->cursor->operators[op] = vm->loadSubroutine(sr);
|
th->cursor->operators[op] = vm->loadSubroutine(sr);
|
||||||
std::cerr << "Loaded rufunge operator " << op << " to be "
|
std::cerr << "Loaded rufunge operator " << op << " to be "
|
||||||
<< module << "::" << file << std::endl;
|
<< module << "::" << file << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue