Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: packages/petitparser/lib/src/lisp/natives.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 part of lisp; 1 part of petitparser.lisp;
2 2
3 /** 3 /// The native functions.
4 * The native functions.
5 */
6 class Natives { 4 class Natives {
7 5
8 /** Imports the native functions into the [environment]. */ 6 /// Imports the native functions into the [environment].
9 static Environment import(Environment environment) { 7 static Environment import(Environment environment) {
10 8
11 // basic functions 9 // basic functions
12 environment.define(new Name('define'), _define); 10 environment.define(new Name('define'), _define);
13 environment.define(new Name('lambda'), _lambda); 11 environment.define(new Name('lambda'), _lambda);
14 environment.define(new Name('quote'), _quote); 12 environment.define(new Name('quote'), _quote);
15 environment.define(new Name('eval'), _eval); 13 environment.define(new Name('eval'), _eval);
16 environment.define(new Name('apply'), _apply); 14 environment.define(new Name('apply'), _apply);
17 environment.define(new Name('let'), _let); 15 environment.define(new Name('let'), _let);
18 environment.define(new Name('set!'), _set); 16 environment.define(new Name('set!'), _set);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (args.head is Name) { 52 if (args.head is Name) {
55 return env.define(args.head, evalList(env, args.tail)); 53 return env.define(args.head, evalList(env, args.tail));
56 } else if (args.head.head is Name) { 54 } else if (args.head.head is Name) {
57 return env.define( 55 return env.define(
58 args.head.head, _lambda(env, new Cons(args.head.tail, args.tail))); 56 args.head.head, _lambda(env, new Cons(args.head.tail, args.tail)));
59 } else { 57 } else {
60 throw new ArgumentError('Invalid define: $args'); 58 throw new ArgumentError('Invalid define: $args');
61 } 59 }
62 } 60 }
63 61
64 static _lambda(Environment lambda_env, lambda_args) { 62 static _lambda(Environment lambdaEnv, lambdaArgs) {
65 return (Environment env, args) { 63 return (Environment evalEnv, evalArgs) {
66 var inner = lambda_env.create(); 64 var inner = lambdaEnv.create();
67 var names = lambda_args.head; 65 var names = lambdaArgs.head;
68 var values = evalArguments(env, args); 66 var values = evalArguments(evalEnv, evalArgs);
69 while (names != null && values != null) { 67 while (names != null && values != null) {
70 inner.define(names.head, values.head); 68 inner.define(names.head, values.head);
71 names = names.tail; 69 names = names.tail;
72 values = values.tail; 70 values = values.tail;
73 } 71 }
74 return evalList(inner, lambda_args.tail); 72 return evalList(inner, lambdaArgs.tail);
75 }; 73 };
76 } 74 }
77 75
78 static _quote(Environment env, args) { 76 static _quote(Environment env, args) {
79 return args; 77 return args;
80 } 78 }
81 79
82 static _eval(Environment env, args) { 80 static _eval(Environment env, args) {
83 return eval(env.create(), eval(env, args.head)); 81 return eval(env.create(), eval(env, args.head));
84 } 82 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 245 }
248 246
249 static _cdrSet(Environment env, args) { 247 static _cdrSet(Environment env, args) {
250 var cons = eval(env, args.head); 248 var cons = eval(env, args.head);
251 if (cons is Cons) { 249 if (cons is Cons) {
252 cons.tail = eval(env, args.tail.head); 250 cons.tail = eval(env, args.tail.head);
253 } 251 }
254 return cons; 252 return cons;
255 } 253 }
256 } 254 }
OLDNEW
« no previous file with comments | « packages/petitparser/lib/src/lisp/name.dart ('k') | packages/petitparser/lib/src/lisp/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698