Implements the interpreter (immediate) mode of Irontalk, which also acts as the compiler (since compiling is just message passing done at compile time).
Exemplo n.º 1
0
 public BlockEvaluator(STBlock block, Compiler compiler, Context context)
 {
     Block = block;
     Compiler = compiler;
     Result = null;
     Context = context;
 }
Exemplo n.º 2
0
        public STBlock(Node blockLiteral, Context context, Compiler compiler)
        {
            Compiler = compiler;
            OuterContext = context;
            Context = new LocalContext(context, true);

            BlockLiteral = blockLiteral;
            BlockArgumentNames = new string[0];
            LocalVariableNames = new string[0];

            int i = 1;

            Node blockParams = null;

            if (blockLiteral[i].Name == "block_params")
                blockParams = blockLiteral[i++];

            if (blockLiteral[i].Name == "sequence") {
                Sequence = blockLiteral[i++];

                if (Sequence[0].Name == "var_def") {
                    List<string> varNames = new List<string>();
                    var vardef = Sequence[0];
                    for (int j = 1, max = vardef.Count; j < max; ++j) {
                        if (vardef[j].Name == "VAR_DELIM") break;
                        var varName = (vardef[j] as Token).Image;
                        varNames.Add (varName);
                        Context.Declare(varName);
                    }

                    LocalVariableNames = varNames.ToArray();
                }
            }

            if (blockParams != null) {
                var parms = blockParams;
                List<string> parmNames = new List<string>();
                for (int j = 0, max = parms.Count; j < max; ++j) {
                    var child = parms[j];
                    if (child.Name == "VAR_DELIM")
                        break;
                    var parmName = (parms[++j] as Token).Image;
                    parmNames.Add (parmName);
                    Context.Declare(parmName);
                }

                BlockArgumentNames = parmNames.ToArray();
            }
        }