本文整理汇总了C#中Wren.Core.Objects.Obj类的典型用法代码示例。如果您正苦于以下问题:C# Obj类的具体用法?C# Obj怎么用?C# Obj使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Obj类属于Wren.Core.Objects命名空间,在下文中一共展示了Obj类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:34,代码来源:Meta.cs
示例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];
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:8,代码来源:ObjMap.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:11,代码来源:ObjMap.cs
示例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);
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:18,代码来源:ObjFiber.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:24,代码来源:ObjFn.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:15,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:6,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:17,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:8,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:22,代码来源:WrenVM.cs
示例11: prim_fn_toString
static bool prim_fn_toString(WrenVM vm, Obj[] args, int stackStart)
{
args[stackStart] = Obj.MakeString("<fn>");
return true;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:5,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:33,代码来源:WrenVM.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:12,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:41,代码来源:CoreLibrary.cs
示例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;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:24,代码来源:WrenVM.cs
示例16: prim_list_insert
static bool prim_list_insert(WrenVM vm, Obj[] args, int stackStart)
{
ObjList list = (ObjList)args[stackStart];
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;
if (index >= 0 && index <= list.Count())
{
list.Insert(args[stackStart + 2], index);
args[stackStart] = args[stackStart + 2];
return true;
}
vm.Fiber.Error = Obj.MakeString("Index out of bounds.");
return false;
}
// count + 1 here so you can "insert" at the very end.
vm.Fiber.Error = Obj.MakeString("Index must be an integer.");
return false;
}
vm.Fiber.Error = Obj.MakeString("Index must be a number.");
return false;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:29,代码来源:CoreLibrary.cs
示例17: prim_list_count
static bool prim_list_count(WrenVM vm, Obj[] args, int stackStart)
{
ObjList list = args[stackStart] as ObjList;
if (list != null)
{
args[stackStart] = new Obj(list.Count());
return true;
}
vm.Fiber.Error = Obj.MakeString("Trying to clear a non-list");
return false;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:12,代码来源:CoreLibrary.cs
示例18: prim_list_clear
static bool prim_list_clear(WrenVM vm, Obj[] args, int stackStart)
{
ObjList list = args[stackStart] as ObjList;
if (list == null)
{
vm.Fiber.Error = Obj.MakeString("Trying to clear a non-list");
return false;
}
list.Clear();
args[stackStart] = Obj.Null;
return true;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:13,代码来源:CoreLibrary.cs
示例19: prim_map_iterate
private static bool prim_map_iterate(WrenVM vm, Obj[] args, int stackStart)
{
ObjMap map = (ObjMap)args[stackStart];
if (map.Count() == 0)
{
args[stackStart] = Obj.False;
return true;
}
// Start one past the last entry we stopped at.
if (args[stackStart + 1].Type == ObjType.Num)
{
if (args[stackStart + 1].Num < 0)
{
args[stackStart] = Obj.False;
return true;
}
int index = (int)args[stackStart + 1].Num;
if (index == args[stackStart + 1].Num)
{
args[stackStart] = index > map.Count() || map.Get(index) == Obj.Undefined ? Obj.False : new Obj(index + 1);
return true;
}
vm.Fiber.Error = Obj.MakeString("Iterator must be an integer.");
return false;
}
// If we're starting the iteration, start at the first used entry.
if (args[stackStart + 1] == Obj.Null)
{
args[stackStart] = new Obj(1);
return true;
}
vm.Fiber.Error = Obj.MakeString("Iterator must be a number.");
return false;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:40,代码来源:CoreLibrary.cs
示例20: ImportVariable
private bool ImportVariable(Obj moduleName, Obj variableName, out Obj result)
{
ObjModule module = GetModule(moduleName);
if (module == null)
{
result = Obj.MakeString("Could not load module");
return false; // Should only look up loaded modules
}
ObjString variable = variableName as ObjString;
if (variable == null)
{
result = Obj.MakeString("Variable name must be a string");
return false;
}
int variableEntry = module.Variables.FindIndex(v => v.Name == variable.ToString());
// It's a runtime error if the imported variable does not exist.
if (variableEntry == -1)
{
result = Obj.MakeString(string.Format("Could not find a variable named '{0}' in module '{1}'.", variableName, moduleName));
return false;
}
result = module.Variables[variableEntry].Container;
return true;
}
开发者ID:robotii,项目名称:Wren.NET,代码行数:28,代码来源:WrenVM.cs
注:本文中的Wren.Core.Objects.Obj类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论