// A global will always be returned. FObject EnvironmentBind(FObject env, FObject sym) { FAssert(EnvironmentP(env)); FAssert(SymbolP(sym)); FObject gl = EqHashMapRef(AsEnvironment(env)->HashMap, sym, FalseObject); if (gl == FalseObject) { gl = MakeGlobal(sym, AsEnvironment(env)->Name, AsEnvironment(env)->Interactive); EqHashMapSet(AsEnvironment(env)->HashMap, sym, gl); } FAssert(GlobalP(gl)); return(gl); }
Interpreter::Interpreter(IInterpreterHost & host) : mHost(host) { // Build the global scope. // Object. mObject = MakeGlobal("Object"); AddPrimitive(mObject, "===", ObjectSame); AddPrimitive(mObject, "to-string", ObjectToString); AddPrimitive(mObject, "parent", ObjectGetParent); // Arrays. mArrayPrototype = MakeGlobal("Arrays"); AddPrimitive(mArrayPrototype, "count", ArrayCount); AddPrimitive(mArrayPrototype, "add:", ArrayAdd); AddPrimitive(mArrayPrototype, "at:", ArrayAt); AddPrimitive(mArrayPrototype, "at:put:", ArrayAtPut); AddPrimitive(mArrayPrototype, "remove-at:", ArrayRemoveAt); // Blocks. mBlockPrototype = MakeGlobal("Blocks"); AddPrimitive(mBlockPrototype, "call", BlockCall); AddPrimitive(mBlockPrototype, "call:", BlockCall); AddPrimitive(mBlockPrototype, "call::", BlockCall); AddPrimitive(mBlockPrototype, "call:::", BlockCall); AddPrimitive(mBlockPrototype, "call::::", BlockCall); AddPrimitive(mBlockPrototype, "call:::::", BlockCall); AddPrimitive(mBlockPrototype, "call::::::", BlockCall); AddPrimitive(mBlockPrototype, "call:::::::", BlockCall); AddPrimitive(mBlockPrototype, "call::::::::", BlockCall); AddPrimitive(mBlockPrototype, "call:::::::::", BlockCall); AddPrimitive(mBlockPrototype, "call::::::::::", BlockCall); // Fibers. mFiberPrototype = MakeGlobal("Fibers"); AddPrimitive(mFiberPrototype, "running?", FiberRunning); AddPrimitive(mFiberPrototype, "done?", FiberDone); // Numbers. mNumberPrototype = MakeGlobal("Numbers"); AddPrimitive(mNumberPrototype, "abs", NumberAbs); AddPrimitive(mNumberPrototype, "neg", NumberNeg); AddPrimitive(mNumberPrototype, "mod:", NumberMod); AddPrimitive(mNumberPrototype, "floor", NumberFloor); AddPrimitive(mNumberPrototype, "ceiling", NumberCeiling); AddPrimitive(mNumberPrototype, "sqrt", NumberSqrt); AddPrimitive(mNumberPrototype, "sin", NumberSin); AddPrimitive(mNumberPrototype, "cos", NumberCos); AddPrimitive(mNumberPrototype, "tan", NumberTan); AddPrimitive(mNumberPrototype, "asin", NumberAsin); AddPrimitive(mNumberPrototype, "acos", NumberAcos); AddPrimitive(mNumberPrototype, "atan", NumberAtan); AddPrimitive(mNumberPrototype, "atan:", NumberAtan2); AddPrimitive(mNumberPrototype, "+number:", NumberAdd); AddPrimitive(mNumberPrototype, "-number:", NumberSubtract); AddPrimitive(mNumberPrototype, "*number:", NumberMultiply); AddPrimitive(mNumberPrototype, "/number:", NumberDivide); AddPrimitive(mNumberPrototype, "=number:", NumberEquals); AddPrimitive(mNumberPrototype, "!=", NumberNotEquals); AddPrimitive(mNumberPrototype, "<", NumberLessThan); AddPrimitive(mNumberPrototype, ">", NumberGreaterThan); AddPrimitive(mNumberPrototype, "<=", NumberLessThanOrEqual); AddPrimitive(mNumberPrototype, ">=", NumberGreaterThanOrEqual); // Strings. mStringPrototype = MakeGlobal("Strings"); AddPrimitive(mStringPrototype, "count", StringCount); AddPrimitive(mStringPrototype, "at:", StringAt); AddPrimitive(mStringPrototype, "from:count:", StringFromCount); AddPrimitive(mStringPrototype, "hash-code", StringHashCode); AddPrimitive(mStringPrototype, "index-of:", StringIndexOf); // Ether. MakeGlobal("Ether"); // Io. Value io = MakeGlobal("Io"); AddPrimitive(io, "read-file:", IoReadFile); // Bare primitive object. Value primitives = MakeGlobal("*primitive*"); AddPrimitive(primitives, "string-concat:and:", PrimitiveStringConcat); AddPrimitive(primitives, "string-compare:to:", PrimitiveStringCompare); AddPrimitive(primitives, "write:", PrimitiveWrite); /* AddPrimitive(primitives, "new-fiber:", PrimitiveNewFiber); AddPrimitive(primitives, "current-fiber", PrimitiveGetCurrentFiber); AddPrimitive(primitives, "switch-to-fiber:passing:", PrimitiveSwitchToFiber); */ AddPrimitive(primitives, "callstack-depth", PrimitiveGetCallstackDepth); // The special singleton values. mNil = MakeGlobal("nil"); mTrue = MakeGlobal("true"); mFalse = MakeGlobal("false"); }