Commits

UENISHI Kota  committed eebb137

aaaa

  • Participants
  • Parent commits 1d2821b

Comments (0)

Files changed (1)

File c++/v8/main.cpp

   //  Handle<String> source = String::New("'Hello' + ', World!'");
   // Handle<String> source = String::New("[32, 234, 23/4, {asfd:\"asdf\"}, \"hello\"];");
   //  Handle<String> source = String::New("{ someatom: 23, anotheratom: 3.3 };");
+  const char* pcode =
+    "function map(f, l){"
+    "  var ret = []; for(var i=0, len=l.length; i<len; i++ ) {"
+    "  ret[i] = f(l[i]); } return ret;"
+    "}"
+    "function fold(f, acc0, l){"
+    "  var ret = acc0; for(var i=0, len=l.length; i<len; i++ ) {"
+    "  ret = f(l[i], ret); } return ret;"
+    "};"
+    ;
+  ScriptData* script_data = ScriptData::PreCompile(String::New(pcode));
   const char* code =
-    "function id(x){  return x; } "
+    //    "function id(__x__){  return __x__; } "
     "function add(x, y){ return x+y; } "
-    "function map(f, l){ var ret = []; for(var i=0, len=l.length; i<len; i++ ) {"
-    "   ret[i] = f(l[i]); } return ret; }"
-    "function fold(f, acc0, l){ var ret = acc0; for(var i=0, len=l.length; i<len; i++ ) {"
-    "   ret = f(l[i], ret); } return ret; }"
-    "fold(add, 0, map(id, [10, 23, 23]));"
+    "1+1;";//"add(1, 1);"
+    //    "fold(add, 0, map(id, [10, 23, 23]));"
     ;
   Handle<String> source = String::New(code);
-
   // Compile the source code.
-  Handle<Script> script = Script::Compile(source);
+  Handle<Script> script = Script::Compile(source, NULL, script_data, Handle<String>());
   
   // Run the script to get the result.
   Handle<Value> result = script->Run();