int main(int argc, char *argv[]) { ASTNode *a = (ASTNode*)0x1; ASTNode *b = (ASTNode*)0x2; Environment *env = new Environment(0, "globl_env"); env->add("a", a); env->add("a", a); env->add("b", b); ASTNode* n = env->lookup("b"); if (n) printf("n: %p\n", n); else printf("cannot found\n"); Environment *f1_env = new Environment(env, "f1_env"); ASTNode *fa = (ASTNode*)0x11; ASTNode *fb = (ASTNode*)0x22; f1_env->add("a", fa); f1_env->add("b", fb); n = f1_env->lookup("b"); if (n) printf("n: %p\n", n); else printf("cannot found\n"); return 0; }
void ExpressionCallWithNamedParameters::assign(Environment &env, Co<Expression> value) const { if (bindings.size() > 0) { Expression::assign(env, value); } else { Co<ExpressionDefine> define = Co<ExpressionDefine>(new ExpressionDefine(name, value)); env.add(name, Co<ExpressionClosure>(new ExpressionClosure(define, env))); } }
ReaderClass* initialize() { // initialize global variables ReaderClass* reader = new LispReader; // initialize the value of true Symbol* truesym = new Symbol("T"); trueExpr = truesym; falseExpr = emptyList(); // initialize the commands environment Environment* cmds = commands; cmds->add(new Symbol("set"), new SetStatement); // initialize the global environment Environment* ge = globalEnvironment; ge->add(new Symbol("if"), new IfStatement); ge->add(new Symbol("+"), new IntegerBinaryFunction(PlusFunction)); ge->add(new Symbol("-"), new IntegerBinaryFunction(MinusFunction)); ge->add(new Symbol("*"), new IntegerBinaryFunction(TimesFunction)); ge->add(new Symbol("/"), new IntegerBinaryFunction(DivideFunction)); ge->add(new Symbol("="), new BinaryFunction(EqualFunction)); ge->add(new Symbol("<"), new BooleanBinaryFunction(LessThanFunction)); ge->add(new Symbol(">"), new BooleanBinaryFunction(GreaterThanFunction)); ge->add(new Symbol("cons"), new SaslConsFunction); ge->add(new Symbol("car"), new UnaryFunction(CarFunction)); ge->add(new Symbol("cdr"), new UnaryFunction(CdrFunction)); ge->add(new Symbol("number?"), new BooleanUnary(NumberpFunction)); ge->add(new Symbol("symbol?"), new BooleanUnary(SymbolpFunction)); ge->add(new Symbol("list?"), new BooleanUnary(ListpFunction)); ge->add(new Symbol("null?"), new BooleanUnary(NullpFunction)); ge->add(new Symbol("primop?"), new BooleanUnary(PrimoppFunction)); ge->add(new Symbol("closure?"), new BooleanUnary(ClosurepFunction)); ge->add(new Symbol("print"), new UnaryFunction(PrintFunction)); ge->add(new Symbol("lambda"), new LambdaFunction); ge->add(truesym, truesym); ge->add(new Symbol("nil"), emptyList()); return reader; }
/// APLInitialize ReaderClass* initialize() { // initialize global variables ReaderClass* reader = new APLreader; // initialize the statement environment Environment* cmds = commands; cmds->add(new Symbol("define"), new DefineStatement); // initialize the value ops environment Environment* vo = valueOps; vo->add(new Symbol("if"), new IfStatement); vo->add(new Symbol("begin"), new BeginStatement); vo->add(new Symbol("set"), new SetStatement); vo->add(new Symbol("+"), new APLScalarFunction(PlusFunction)); vo->add(new Symbol("-"), new APLScalarFunction(MinusFunction)); vo->add(new Symbol("*"), new APLScalarFunction(TimesFunction)); vo->add(new Symbol("/"), new APLScalarFunction(DivideFunction)); vo->add(new Symbol("max"), new APLScalarFunction(scalarMax)); vo->add(new Symbol("or"), new APLScalarFunction(scalarOr)); vo->add(new Symbol("and"), new APLScalarFunction(scalarAnd)); vo->add(new Symbol("="), new APLScalarFunction(scalarEq)); vo->add(new Symbol("<"), new APLScalarFunction(LessThanFunction)); vo->add(new Symbol(">"), new APLScalarFunction(GreaterThanFunction)); vo->add(new Symbol("+/"), new APLReduction(PlusFunction)); vo->add(new Symbol("-/"), new APLReduction(MinusFunction)); vo->add(new Symbol("*/"), new APLReduction(TimesFunction)); vo->add(new Symbol("//"), new APLReduction(DivideFunction)); vo->add(new Symbol("max/"), new APLReduction(scalarMax)); vo->add(new Symbol("or/"), new APLReduction(scalarOr)); vo->add(new Symbol("and/"), new APLReduction(scalarAnd)); vo->add(new Symbol("compress"), new CompressionFunction); vo->add(new Symbol("shape"), new ShapeFunction); vo->add(new Symbol("ravel"), new RavelFunction); vo->add(new Symbol("restruct"), new RestructFunction); vo->add(new Symbol("cat"), new CatenationFunction); vo->add(new Symbol("indx"), new IndexFunction); vo->add(new Symbol("trans"), new TransposeFunction); vo->add(new Symbol("[]"), new SubscriptFunction); vo->add(new Symbol("print"), new UnaryFunction(PrintFunction)); return reader; }