Permalink
Browse files

Closes #60 (removed arithmetic/bitwise metamethods)

  • Loading branch information...
JarrettBillingsley committed Feb 7, 2013
1 parent 84b753a commit 9da2ebbcb22c7b1a3aded92bf355bf158a1c157f
Showing with 241 additions and 721 deletions.
  1. +0 −315 croc/api_interpreter.d
  2. +14 −127 croc/base_metamethods.d
  3. +0 −4 croc/base_opcodes.d
  4. +152 −201 croc/interpreter.d
  5. +72 −65 croc/stdlib_vector.d
  6. +3 −9 downloads/croc.vim
View
@@ -3259,299 +3259,6 @@ void slicea(CrocThread* t, word container)
pop(t, 3);
}
/**
These all perform the given mathematical operation on the two values at the given indices, and push
the result of that operation onto the stack. Metamethods (including reverse versions) will be called.
Don'_t use these functions if you're looking to do some serious number crunching on ints and floats. Just
get the values and do the computation in D.
Params:
a = The slot of the first value.
b = The slot of the second value.
Returns:
The stack index of the newly-pushed result.
*/
word add(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binOpImpl(t, MM.Add, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word sub(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binOpImpl(t, MM.Sub, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word mul(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binOpImpl(t, MM.Mul, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word div(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binOpImpl(t, MM.Div, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word mod(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binOpImpl(t, MM.Mod, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/**
Negates the value at the given index and pushes the result. Calls opNeg metamethods.
Like the binary operations, don'_t use this unless you need the actual Croc semantics, as it's
less efficient than just getting a number and negating it.
Params:
o = The slot of the value to negate.
Returns:
The stack index of the newly-pushed result.
*/
word neg(CrocThread* t, word o)
{
auto oslot = fakeToAbs(t, o);
pushNull(t);
negImpl(t, t.stackIndex - 1, &t.stack[oslot]);
return stackSize(t) - 1;
}
/**
These all perform the given reflexive mathematical operation on the value at the given slot, using
the value at the top of the stack for the rhs. The rhs is popped. These call metamethods.
Like the other mathematical methods, it's more efficient to perform the operation directly on numbers
rather than to use these methods. Use these only if you need the Croc semantics.
Params:
o = The slot of the object to perform the reflexive operation on.
*/
void addeq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinOpImpl(t, MM.AddEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void subeq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinOpImpl(t, MM.SubEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void muleq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinOpImpl(t, MM.MulEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void diveq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinOpImpl(t, MM.DivEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void modeq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinOpImpl(t, MM.ModEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/**
These all perform the given bitwise operation on the two values at the given indices, _and push
the result of that operation onto the stack. Metamethods (including reverse versions) will be called.
Don'_t use these functions if you're looking to do some serious number crunching on ints. Just
get the values _and do the computation in D.
Params:
a = The slot of the first value.
b = The slot of the second value.
Returns:
The stack index of the newly-pushed result.
*/
word and(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binaryBinOpImpl(t, MM.And, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word or(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binaryBinOpImpl(t, MM.Or, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word xor(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binaryBinOpImpl(t, MM.Xor, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word shl(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binaryBinOpImpl(t, MM.Shl, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word shr(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binaryBinOpImpl(t, MM.Shr, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/// ditto
word ushr(CrocThread* t, word a, word b)
{
auto aslot = fakeToAbs(t, a);
auto bslot = fakeToAbs(t, b);
pushNull(t);
binaryBinOpImpl(t, MM.UShr, t.stackIndex - 1, &t.stack[aslot], &t.stack[bslot]);
return stackSize(t) - 1;
}
/**
Bitwise complements the value at the given index and pushes the result. Calls opCom metamethods.
Like the binary operations, don'_t use this unless you need the actual Croc semantics, as it's
less efficient than just getting a number and complementing it.
Params:
o = The slot of the value to complement.
Returns:
The stack index of the newly-pushed result.
*/
word com(CrocThread* t, word o)
{
auto oslot = fakeToAbs(t, o);
pushNull(t);
comImpl(t, t.stackIndex - 1, &t.stack[oslot]);
return stackSize(t) - 1;
}
/**
These all perform the given reflexive bitwise operation on the value at the given slot, using
the value at the top of the stack for the rhs. The rhs is popped. These call metamethods.
Like the other bitwise methods, it's more efficient to perform the operation directly on numbers
rather than to use these methods. Use these only if you need the Croc semantics.
Params:
o = The slot of the object to perform the reflexive operation on.
*/
void andeq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinaryBinOpImpl(t, MM.AndEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void oreq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinaryBinOpImpl(t, MM.OrEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void xoreq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinaryBinOpImpl(t, MM.XorEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void shleq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinaryBinOpImpl(t, MM.ShlEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void shreq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinaryBinOpImpl(t, MM.ShrEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/// ditto
void ushreq(CrocThread* t, word o)
{
mixin(apiCheckNumParams!("1"));
auto oslot = fakeToAbs(t, o);
reflBinaryBinOpImpl(t, MM.UShrEq, oslot, &t.stack[t.stackIndex - 1]);
pop(t);
}
/**
Concatenates the top num parameters on the stack, popping them all and pushing the result on the stack.
@@ -3639,28 +3346,6 @@ bool as(CrocThread* t, word obj, word base)
return asImpl(t, getValue(t, obj), getValue(t, base));
}
/**
Increments the value at the given _slot. Calls opInc metamethods.
Params:
slot = The stack index of the value to increment.
*/
void inc(CrocThread* t, word slot)
{
incImpl(t, fakeToAbs(t, slot));
}
/**
Decrements the value at the given _slot. Calls opDec metamethods.
Params:
slot = The stack index of the value to decrement.
*/
void dec(CrocThread* t, word slot)
{
decImpl(t, fakeToAbs(t, slot));
}
/**
Gets the class of instances, base class of classes, or the parent namespace of namespaces and
pushes it onto the stack. Throws an error if the value at the given _slot is not a class, instance,
Oops, something went wrong.

0 comments on commit 9da2ebb

Please sign in to comment.