Ejemplo n.º 1
0
 public static DynamicEnvironment Find(Symbol s)
 {
     for (DynamicEnvironment d = denv; d != null; d = d.InnerNext) {
         if (d.InnerSymbol == s)
             return d;
     }
     return null;
 }
Ejemplo n.º 2
0
 //.........................................................................
 public ApplyExpression(Cons args, IEnvironment env, Interpreter interpreter, Location loc)
 {
     InnerLocation = loc;
     InnerInterpreter = interpreter;
     InnerFExpression = interpreter.Analyze(args.First, env, loc);
     if (InnerFExpression is IVariable) {
         InnerFSymbol = ((IVariable)InnerFExpression).Symbol;
     }
     Int32 len = Cons.GetLength(args.Rest);
     InnerArgsExpressions = new IExpression[len];
     args = args.Rest;
     for (Int32 i = 0; i < InnerArgsExpressions.Length; i++, args = args.Rest) {
         InnerArgsExpressions[i] = interpreter.Analyze(args.First, env, loc);
     }
 }
Ejemplo n.º 3
0
 public static void Extend(Symbol sym, Object val)
 {
     if (!sym.IsDynamic)
         throw new LispException("Dynamic vars must have prefix *");
     denv = new DynamicEnvironment(sym, val, denv);
 }
Ejemplo n.º 4
0
 //.........................................................................
 protected DynamicEnvironment(Symbol sym, Object val, DynamicEnvironment next)
 {
     InnerSymbol = sym;
     InnerValue = val;
     InnerNext = next;
 }
Ejemplo n.º 5
0
 protected virtual void InternBuiltins()
 {
     BLOCK = InternAndExport("block");
     SET = InternAndExport("__set");
     FIRST = InternAndExport("first");
     REST = InternAndExport("rest");
     DEF = InternAndExport("def");
     IF = InternAndExport("if");
     FN = InternAndExport("fn");
     MACRO = InternAndExport("macro");
     OR = InternAndExport("or");
     WHILE = InternAndExport("while");
     BREAK = InternAndExport(":break");
     AMPOPT = InternAndExport("&optional");
     AMPKEY = InternAndExport("&key");
     AMPREST = InternAndExport("&rest");
     QUOTE = InternAndExport("quote");
     DLET = InternAndExport("dynamic-let");
     STR = InternAndExport("str");
     VECTOR = InternAndExport("vector");
     COMPARE = InternAndExport("compare");
     BACKQUOTE = InternAndExport("backquote");
     UNQUOTE = InternAndExport("unquote");
     UNQUOTE_SPLICING = InternAndExport("unquote-splicing");
     NIL = InternAndExportConstant("nil", null);
     TRUE = InternAndExportConstant("true", true);
     T = InternAndExportConstant("t", true);
     FALSE = InternAndExportConstant("false", false);
     EX = InternAndExport("!");
     LASTVAL = InternAndExport("$");
     NEXTLASTVAL = InternAndExport("$$");
     THIRDLASTVAL = InternAndExport("$$$");
     EOF = InternAndExport(":eof");
 }
Ejemplo n.º 6
0
 public void UnTrace(Symbol s)
 {
     InnerTraceList.Remove(s);
 }
Ejemplo n.º 7
0
 public void Trace(Symbol s)
 {
     InnerTraceList[s] = null;
 }
Ejemplo n.º 8
0
 //.........................................................................
 public Parameter(Symbol symbol, Specification spec, IExpression initCode)
 {
     if (symbol.IsDynamic)
         throw new LispException("Dynamic variables cannot be parameters to functions or let");
     if (symbol is Keyword)
         throw new LispException("Keywords cannot be parameters to functions or let");
     InnerSymbol = symbol;
     InnerSpec = spec;
     InnerInitCode = initCode;
 }
Ejemplo n.º 9
0
        public Symbol Intern(string name)
        {
            Symbol result = (Symbol)InnerTable[name];
            if (result == null) {
                if (name.StartsWith(":")) {
                    InnerTable[name] = result = new Keyword(InnerPackage, name);
                } else {
                    int firstdot = name.IndexOf('.');
                    int lastdot = name.LastIndexOf('.');
                    int lastcolon = name.LastIndexOf(':');
                    int nameLength = name.Length;

                    // .instance
                    // .[namespace.]type:explicitinstance
                    // [namespace.]type.
                    // [namespace.]type:static
                    // obj.member - transformed by reader
                    if ((firstdot != -1 || lastcolon != -1) && nameLength > 1) {
                        if (firstdot == 0)	//instance
                        {
                            if (lastcolon > 0)	  //explicitly qualified
                            {
                                String memberName = name.Substring(lastcolon + 1, nameLength - (lastcolon + 1));
                                Type type = InnerTypeResolver.FindType(name.Substring(1, lastcolon - 1));
                                InnerTable[name] = result = new CLSInstanceSymbol(InnerPackage, name, memberName, type);
                            } else {
                                String memberName = name.Substring(1, nameLength - 1);
                                InnerTable[name] = result = new CLSInstanceSymbol(InnerPackage, name, memberName, null);
                            }
                        } else if (lastcolon > 0)	//static
                        {
                            String memberName = name.Substring(lastcolon + 1, nameLength - (lastcolon + 1));
                            Type type = InnerTypeResolver.FindType(name.Substring(0, lastcolon));
                            InnerTable[name] = result = new CLSStaticSymbol(InnerPackage, name, memberName, type);
                        } else if (lastdot == nameLength - 1) //type
                        {
                            Type type;
                            InnerTypeResolver.FindType(name.Substring(0, lastdot), out type);
                            // TODO: то же нужно сделать со статиками, методами и т.п.
                            // получение типа должно производиться при выполнении, а не при парсинге!

                            InnerTable[name] = result = new CLSTypeSymbol(InnerPackage, name, type, InnerTypeResolver);
                        }
                    } else {
                        InnerTable[name] = result = new Symbol(InnerPackage, name);
                        result.IsDynamic = (name[0] == '*');
                    }
                }
            }
            return result;
        }
Ejemplo n.º 10
0
 public void AddSymbol(Symbol s)
 {
     InnerTable[s.Name] = s;
 }
Ejemplo n.º 11
0
 //.........................................................................
 public LocalVariable(Int32 level, Int32 index, Symbol name)
 {
     InnerLevel = level;
     InnerIndex = index;
     InnerSymbol = name;
 }
Ejemplo n.º 12
0
 //.........................................................................
 public GlobalVar(Symbol s)
 {
     InnerSymbol = s;
 }
Ejemplo n.º 13
0
 //.........................................................................
 public DynamicVar(Symbol s)
 {
     InnerSymbol = s;
 }