Overview
SHA1 Hash: | c75f0d5f1ecba9a0bff8d1e76650fa35f082fae3 |
---|---|
Date: | 2010-11-24 21:32:01 |
User: | kinaba |
Comment: | Enriched the runtime. a.b is now runtime error, not undefined value if the field b does not exist. Added rand(n) and gensym(). |
Timelines: | family | ancestors | descendants | both | trunk |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [f65680e1d2]
- sym-trunk inherited from [f65680e1d2]
Changes
Modified index.dd from [9e5b0b6dd62ac7dd] to [5308ff05201ec907].
599 </p> 599 </p> 600 )) 600 )) 601 601 602 $(SECTION 外部とのやりとり, $(SECBODY 602 $(SECTION 外部とのやりとり, $(SECBODY 603 $(TABLE 603 $(TABLE 604 $(TR $(TH print) $(TD (a)) $(TD a を文字列化標準出力に改行付きで表示)) 604 $(TR $(TH print) $(TD (a)) $(TD a を文字列化標準出力に改行付きで表示)) 605 $(TR $(TH argv) $(TD ) $(TD スクリプトに渡された引数文字列のconsリスト)) 605 $(TR $(TH argv) $(TD ) $(TD スクリプトに渡された引数文字列のconsリスト)) > 606 $(TR $(TH gensym) $(TD ()) $(TD エセgensym。変数名として他とからなそうな文字列を返します)) > 607 $(TR $(TH rand) $(TD (n)) $(TD 0 以上 n 未満の自然数をランダム生成します)) 606 ) 608 ) 607 )) 609 )) 608 <br /> 610 <br /> 609 611 610 $(SECTION データ型判定, $(SECBODY 612 $(SECTION データ型判定, $(SECBODY 611 $(TABLE 613 $(TABLE 612 $(TR $(TH _isint) $(TD (a)) $(TD a が整数なら 1、でなければ 0)) 614 $(TR $(TH _isint) $(TD (a)) $(TD a が整数なら 1、でなければ 0))
Modified polemy/runtime.d from [641d49d7fd647519] to [6911dbe256744186].
5 * 5 * 6 * Runtime library for Polemy programming language. 6 * Runtime library for Polemy programming language. 7 */ 7 */ 8 module polemy.runtime; 8 module polemy.runtime; 9 import polemy._common; 9 import polemy._common; 10 import polemy.layer; 10 import polemy.layer; 11 import polemy.failure; 11 import polemy.failure; > 12 import polemy.fresh; 12 import polemy.value; 13 import polemy.value; 13 import polemy.eval; 14 import polemy.eval; 14 import std.stdio; 15 import std.stdio; > 16 import std.random; 15 17 16 /// enroll the native implementations of primitive functions 18 /// enroll the native implementations of primitive functions 17 19 18 void enrollRuntimeLibrary( Evaluator e ) 20 void enrollRuntimeLibrary( Evaluator e ) 19 { 21 { 20 // arithmetic operations 22 // arithmetic operations 21 e.addPrimitive("+", ValueLayer, 23 e.addPrimitive("+", ValueLayer, ................................................................................................................................................................................ 60 (Value v){return new IntValue(cast(FunValue)v !is null);} ); 62 (Value v){return new IntValue(cast(FunValue)v !is null);} ); 61 e.addPrimitive("_isundefined", ValueLayer, 63 e.addPrimitive("_isundefined", ValueLayer, 62 (Value v){return new IntValue(cast(UndefinedValue)v !is null);} 64 (Value v){return new IntValue(cast(UndefinedValue)v !is null);} 63 e.addPrimitive("_istable", ValueLayer, 65 e.addPrimitive("_istable", ValueLayer, 64 (Value v){return new IntValue(cast(Table)v !is null);} ); 66 (Value v){return new IntValue(cast(Table)v !is null);} ); 65 // table 67 // table 66 e.addPrimitive(".", ValueLayer, (Table t, StrValue s){ 68 e.addPrimitive(".", ValueLayer, (Table t, StrValue s){ 67 return (t.has(s.data, ValueLayer) ? t.get(s.data, ValueLayer) : | 69 if( t.has(s.data, ValueLayer) ) > 70 return t.get(s.data, ValueLayer); > 71 throw genex!RuntimeException(text("table do not have the field " 68 }); 72 }); 69 e.addPrimitive(".?", ValueLayer, (Table t, StrValue s){ 73 e.addPrimitive(".?", ValueLayer, (Table t, StrValue s){ 70 return new IntValue(t.has(s.data, ValueLayer)); 74 return new IntValue(t.has(s.data, ValueLayer)); 71 }); 75 }); 72 e.addPrimitive(".=", ValueLayer, (Table t, StrValue s, Value v){ 76 e.addPrimitive(".=", ValueLayer, (Table t, StrValue s, Value v){ 73 auto t2 = new Table(t, Table.Kind.NotPropagateSet); 77 auto t2 = new Table(t, Table.Kind.NotPropagateSet); 74 t2.set(s.data, ValueLayer, v); 78 t2.set(s.data, ValueLayer, v); 75 return t2; 79 return t2; 76 }); 80 }); 77 e.addPrimitive("{}", ValueLayer, (){ 81 e.addPrimitive("{}", ValueLayer, (){ 78 return new Table; 82 return new Table; 79 }); 83 }); 80 // IO | 84 // IO and others 81 e.addPrimitive("print", ValueLayer, (Value a){ writeln(a); return new In 85 e.addPrimitive("print", ValueLayer, (Value a){ writeln(a); return new In > 86 e.addPrimitive("gensym", ValueLayer, (){ return new StrValue(freshVarNam > 87 auto rand = Mt19937(unpredictableSeed); > 88 e.addPrimitive("rand", ValueLayer, (IntValue n){ > 89 return new IntValue( uniform(0,cast(int)n.data.toInt(),rand) ); > 90 }); 82 } 91 }