public static IP5Any ArrayReplace(Runtime runtime, IP5Array array, IP5Any offset, IP5Any count, params IP5Any[] values) { int start = offset.AsInteger(runtime); int length = count.AsInteger(runtime); int max = array.GetCount(runtime); if (start < 0) start = max + start; if (length < 0) length = max + length - start; return array.Replace(runtime, start, length, values); }
public static IP5Any ArraySplice(Runtime runtime, IP5Array array, IP5Any offset, IP5Any count) { int start, length, max = array.GetCount(runtime); if (offset == null) start = 0; else start = offset.AsInteger(runtime); if (start < 0) start = max + start; if (count == null) length = max - start; else length = count.AsInteger(runtime); if (length < 0) length = max + length - start; return array.Splice(runtime, start, length); }
public override void Set(Runtime runtime, IP5Any other) { var str = value.AsString(runtime); var intval = other.AsInteger(runtime); int byte_offset = (offset * bits) / 8; int bit_offset = (offset * bits) % 8; int mask = ((1 << bits) - 1); var t = new System.Text.StringBuilder(str.Length); foreach (char c in str) t.Append(c); while (byte_offset >= t.Length) t.Append((char)0); int changed = (t[byte_offset] & ~(mask << bit_offset)) | ((intval & mask) << bit_offset); t[byte_offset] = (char)changed; value.SetString(runtime, t.ToString()); }
public IP5Any GetItemOrUndef(Runtime runtime, IP5Any index, bool create) { int idx = GetItemIndex(runtime, index.AsInteger(runtime), false); if (create) return new P5NetArrayItem(array, type, idx); else return NetGlue.WrapValue(array[idx]); }
public P5Scalar Repeat(Runtime runtime, IP5Any c) { int count = c.AsInteger(runtime); string val = AsString(runtime); var str = new System.Text.StringBuilder(); for (int i = 0; i < count; ++i) str.Append(val); return new P5Scalar(runtime, str.ToString()); }
public static P5Scalar RightShiftScalars(Runtime runtime, P5Scalar res, IP5Any left, IP5Any right) { res.SetInteger(runtime, left.AsInteger(runtime) >> right.AsInteger(runtime)); return res; }
public static P5Range MakeRange(Runtime runtime, IP5Any start, IP5Any end) { // TODO handle string range return new P5Range(runtime, start.AsInteger(runtime), end.AsInteger(runtime)); }
public static IP5Any LocalizeArrayElement(Runtime runtime, IP5Array array, IP5Any index, ref SavedValue state) { int int_index = array.GetItemIndex(runtime, index.AsInteger(runtime), true); var saved = array.LocalizeElement(runtime, int_index); state.container = array; state.int_key = int_index; state.value = saved; return array.GetItem(runtime, int_index); }
public static P5Scalar Chr(Runtime runtime, IP5Any value) { var i = value.AsInteger(runtime); return new P5Scalar(runtime, new string((char)i, 1)); }
public P5Vec(Runtime runtime, IP5Any value, IP5Any offset, IP5Any bits) { body = new P5VecBody(runtime, value.AsScalar(runtime), offset.AsInteger(runtime), bits.AsInteger(runtime)); }