- added a 'new' intrinsic to create new objects from inside scripts.

This is not tested yet and likely to not working correctly yet. Will be fixed once I get far enough to use it later.
This commit is contained in:
Christoph Oelckers 2017-02-03 22:56:03 +01:00
commit 8578a5a12e
6 changed files with 106 additions and 0 deletions

View file

@ -72,6 +72,7 @@
#define RFRF MODE_AF | MODE_BF | MODE_CUNUSED
#define RSRS MODE_AS | MODE_BS | MODE_CUNUSED
#define RPRP MODE_AP | MODE_BP | MODE_CUNUSED
#define RPKP MODE_AP | MODE_BKP | MODE_CUNUSED
#define RXRXI8 MODE_AX | MODE_BX | MODE_CIMMZ
#define RPRPRP MODE_AP | MODE_BP | MODE_CP
#define RPRPKP MODE_AP | MODE_BP | MODE_CKP

View file

@ -759,6 +759,14 @@ begin:
assert(0);
NEXTOP;
OP(NEW_K):
OP(NEW):
{
PClass *cls = (PClass*)(op == OP_NEW ? reg.a[C] : konsta[C].v);
reg.a[B] = cls->CreateNew();
NEXTOP;
}
OP(TRY):
assert(try_depth < MAX_TRY_DEPTH);
if (try_depth >= MAX_TRY_DEPTH)

View file

@ -104,6 +104,8 @@ xx(TAIL_K, tail, KPI8, TAIL, 1, REGT_POINTER),
xx(RESULT, result, __BCP, NOP, 0, 0), // Result should go in register encoded in BC (in caller, after CALL)
xx(RET, ret, I8BCP, NOP, 0, 0), // Copy value from register encoded in BC to return value A, possibly returning
xx(RETI, reti, I8I16, NOP, 0, 0), // Copy immediate from BC to return value A, possibly returning
xx(NEW, new, RPRP, NOP, 0, 0),
xx(NEW_K, new, RPKP, NOP, 0, 0),
xx(TRY, try, I24, NOP, 0, 0), // When an exception is thrown, start searching for a handler at pc + ABC
xx(UNTRY, untry, I8, NOP, 0, 0), // Pop A entries off the exception stack
xx(THROW, throw, THROW, NOP, 0, 0), // A == 0: Throw exception object pB