本文整理汇总了C#中Wren.Core.Objects.Obj类的典型用法代码示例。如果您正苦于以下问题:C# Obj类的具体用法?C# Obj怎么用?C# Obj使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Obj类属于Wren.Core.Objects命名空间,在下文中一共展示了Obj类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Eval
static bool Eval(WrenVM vm, Obj[] args, int stackStart)
{
if (args[stackStart + 1] is ObjString)
{
// Eval the code in the module where the calling function was defined.
Obj callingFn = vm.Fiber.GetFrame().Fn;
ObjModule module = (callingFn is ObjFn)
? ((ObjFn)callingFn).Module
: ((ObjClosure)callingFn).Function.Module;
// Compile it.
ObjFn fn = Compiler.Compile(vm, module, "", args[stackStart + 1].ToString(), false);
if (fn == null)
{
vm.Fiber.Error = Obj.MakeString("Could not compile source code.");
return false;
}
// TODO: Include the compile errors in the runtime error message.
// Create a fiber to run the code in.
ObjFiber evalFiber = new ObjFiber(fn) { Caller = vm.Fiber };
// Switch to the fiber.
args[stackStart] = evalFiber;
return false;
}
vm.Fiber.Error = Obj.MakeString("Source code must be a string.");
return false;
}
示例2: GetKey
public Obj GetKey(int index)
{
if (index < 0 || index >= _entries.Count)
return Undefined;
Obj[] v = new Obj[_entries.Count];
_entries.Keys.CopyTo(v, 0);
return v[index];
}
示例3: Remove
// Removes [key] from [map], if present. Returns the value for the key if found
// or `NULL_VAL` otherwise.
public Obj Remove(Obj key)
{
Obj v;
if (!_entries.TryGetValue(key, out v))
return Null;
_entries.Remove(key);
return v;
}
示例4: ResetFiber
// Resets [fiber] back to an initial state where it is ready to invoke [fn].
private void ResetFiber(Obj fn)
{
Stack = new Obj[InitialStackSize];
Capacity = InitialStackSize;
Frames = new List<CallFrame>();
// Push the stack frame for the function.
StackTop = 0;
NumFrames = 1;
OpenUpvalues = null;
Caller = null;
Error = null;
CallerIsTrying = false;
CallFrame frame = new CallFrame { Fn = fn, StackStart = 0, Ip = 0 };
Frames.Add(frame);
}
示例5: ObjFn
// TODO: The argument list here is getting a bit gratuitous.
// Creates a new function object with the given code and constants. The new
// function will take over ownership of [bytecode] and [sourceLines]. It will
// copy [constants] into its own array.
public ObjFn(ObjModule module,
Obj[] constants,
int numUpvalues, int arity,
byte[] bytecode, ObjString debugSourcePath,
string debugName, int[] sourceLines)
{
Bytecode = bytecode;
Constants = constants;
Module = module;
NumUpvalues = numUpvalues;
NumConstants = constants.Length;
Arity = arity;
/* Debug Information */
SourcePath = debugSourcePath;
Name = debugName;
SourceLines = sourceLines;
ClassObj = WrenVM.FnClass;
}
示例6: prim_map_containsKey
static bool prim_map_containsKey(WrenVM vm, Obj[] args, int stackStart)
{
ObjMap map = (ObjMap)args[stackStart];
if (ValidateKey(args[stackStart + 1]))
{
Obj v = map.Get(args[stackStart + 1]);
args[stackStart] = Obj.Bool(v != Obj.Undefined);
return true;
}
vm.Fiber.Error = Obj.MakeString("Key must be a value type or fiber.");
return false;
}
示例7: prim_map_count
static bool prim_map_count(WrenVM vm, Obj[] args, int stackStart)
{
ObjMap m = (ObjMap)args[stackStart];
args[stackStart] = new Obj(m.Count());
return true;
}
示例8: prim_map_subscriptSetter
static bool prim_map_subscriptSetter(WrenVM vm, Obj[] args, int stackStart)
{
if (ValidateKey(args[stackStart + 1]))
{
ObjMap map = args[stackStart] as ObjMap;
if (map != null)
{
map.Set(args[stackStart + 1], args[stackStart + 2]);
}
args[stackStart] = args[stackStart + 2];
return true;
}
vm.Fiber.Error = Obj.MakeString("Key must be a value type or fiber.");
return false;
}
示例9: prim_map_clear
static bool prim_map_clear(WrenVM vm, Obj[] args, int stackStart)
{
ObjMap m = args[stackStart] as ObjMap;
if (m != null)
m.Clear();
args[stackStart] = Obj.Null;
return true;
}
示例10: BindMethod
// Defines [methodValue] as a method on [classObj].
private static bool BindMethod(bool isStatic, int symbol, ObjClass classObj, Obj methodContainer)
{
// If we are binding a foreign method, just return, as this will be handled later
if (methodContainer is ObjString)
return true;
ObjFn methodFn = methodContainer as ObjFn ?? ((ObjClosure)methodContainer).Function;
Method method = new Method { MType = MethodType.Block, Obj = methodContainer };
if (isStatic)
classObj = classObj.ClassObj;
// Methods are always bound against the class, and not the metaclass, even
// for static methods, because static methods don't have instance fields
// anyway.
Compiler.BindMethodCode(classObj, methodFn);
classObj.BindMethod(symbol, method);
return true;
}
示例11: prim_fn_toString
static bool prim_fn_toString(WrenVM vm, Obj[] args, int stackStart)
{
args[stackStart] = Obj.MakeString("<fn>");
return true;
}
示例12: LoadModule
private ObjFiber LoadModule(Obj name, string source)
{
ObjModule module = GetModule(name);
// See if the module has already been loaded.
if (module == null)
{
module = new ObjModule(name as ObjString);
// Store it in the VM's module registry so we don't load the same module
// multiple times.
_modules.Set(name, module);
// Implicitly import the core module.
ObjModule coreModule = GetCoreModule();
foreach (ModuleVariable t in coreModule.Variables)
{
DefineVariable(module, t.Name, t.Container);
}
}
ObjFn fn = Compiler.Compile(this, module, name.ToString(), source, true);
if (fn == null)
{
// TODO: Should we still store the module even if it didn't compile?
return null;
}
ObjFiber moduleFiber = new ObjFiber(fn);
// Return the fiber that executes the module.
return moduleFiber;
}
示例13: prim_list_add
static bool prim_list_add(WrenVM vm, Obj[] args, int stackStart)
{
ObjList list = args[stackStart] as ObjList;
if (list == null)
{
vm.Fiber.Error = Obj.MakeString("Trying to add to a non-list");
return false;
}
list.Add(args[stackStart + 1]);
args[stackStart] = args[stackStart + 1];
return true;
}
示例14: prim_list_iterate
static bool prim_list_iterate(WrenVM vm, Obj[] args, int stackStart)
{
ObjList list = (ObjList)args[stackStart];
// If we're starting the iteration, return the first index.
if (args[stackStart + 1] == Obj.Null)
{
if (list.Count() != 0)
{
args[stackStart] = new Obj(0.0);
return true;
}
args[stackStart] = Obj.False;
return true;
}
if (args[stackStart + 1].Type == ObjType.Num)
{
int index = (int)args[stackStart + 1].Num;
if (args[stackStart + 1].Num == index)
{
if (!(index < 0) && !(index >= list.Count() - 1))
{
// Move to the next index.
args[stackStart] = new Obj(index + 1);
return true;
}
// Stop if we're out of bounds.
args[stackStart] = Obj.False;
return true;
}
vm.Fiber.Error = Obj.MakeString("Iterator must be an integer.");
return false;
}
vm.Fiber.Error = Obj.MakeString("Iterator must be a number.");
return false;
}
示例15: CheckArity
bool CheckArity(Obj[] args, int numArgs, int stackStart)
{
ObjFn fn = args[stackStart] as ObjFn;
ObjClosure c = args[stackStart] as ObjClosure;
if (c != null)
{
fn = c.Function;
}
if (fn == null)
{
Fiber.Error = Obj.MakeString("Receiver must be a function or closure.");
return false;
}
if (numArgs - 1 < fn.Arity)
{
Fiber.Error = Obj.MakeString("Function expects more arguments.");
return false;
}
return true;
}