opal 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/docs/jarv.rdoc +27 -0
- data/lib/opal.rb +29 -0
- data/runtime/array.js +153 -0
- data/runtime/class.js +469 -0
- data/runtime/compar.js +73 -0
- data/runtime/dir.js +115 -0
- data/runtime/enum.js +74 -0
- data/runtime/file.js +165 -0
- data/runtime/gem.js +241 -0
- data/runtime/hash.js +181 -0
- data/runtime/init.js +59 -0
- data/runtime/load.js +251 -0
- data/runtime/module.js +98 -0
- data/runtime/number.js +148 -0
- data/runtime/object.js +522 -0
- data/runtime/opal.js +200 -0
- data/runtime/parse.js +2218 -0
- data/runtime/range.js +56 -0
- data/runtime/re.js +91 -0
- data/runtime/string.js +199 -0
- data/runtime/variable.js +184 -0
- data/runtime/vm.js +1150 -0
- data/runtime/yaml.js +33 -0
- data/tasks/build.rb +16 -0
- metadata +90 -0
data/runtime/hash.js
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
/*
|
2
|
+
* hash.js
|
3
|
+
* opal
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
var rb_cHash, rb_envtbl;
|
29
|
+
|
30
|
+
function rb_hash_alloc(klass) {
|
31
|
+
var hash = new RHash();
|
32
|
+
hash.klass = klass;
|
33
|
+
FL_SET(hash, T_HASH);
|
34
|
+
hash.ifnone = nil;
|
35
|
+
return hash;
|
36
|
+
};
|
37
|
+
|
38
|
+
function rb_hash_new() {
|
39
|
+
return rb_hash_alloc(rb_cHash);
|
40
|
+
};
|
41
|
+
|
42
|
+
function rb_hash_aset(hash, k, v) {
|
43
|
+
if (hash.keys.indexOf(k) == -1) {
|
44
|
+
hash.keys.push(k);
|
45
|
+
}
|
46
|
+
hash.dict[k] = v;
|
47
|
+
return v;
|
48
|
+
};
|
49
|
+
|
50
|
+
function rb_hash_aref(hash, k) {
|
51
|
+
if (hash.keys.indexOf(k) != -1) {
|
52
|
+
return hash.dict[k];
|
53
|
+
}
|
54
|
+
return hash.ifnone;
|
55
|
+
};
|
56
|
+
|
57
|
+
function rb_hash_size(hash) {
|
58
|
+
return hash.keys.length;
|
59
|
+
};
|
60
|
+
|
61
|
+
function rb_hash_has_key(hash, k) {
|
62
|
+
if (hash.keys.indexOf(k) != -1) {
|
63
|
+
return true;
|
64
|
+
}
|
65
|
+
return false;
|
66
|
+
};
|
67
|
+
|
68
|
+
function Init_Hash() {
|
69
|
+
rb_cHash = rb_define_class("Hash", rb_cObject);
|
70
|
+
// rb_include_module(rb_cHash, rb_mEnumerable);
|
71
|
+
// rb_define_alloc_func(rb_cHash, rb_hash_alloc);
|
72
|
+
|
73
|
+
// rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
|
74
|
+
// rb_define_singleton_method(rb_cHash, "try_convert", rb_hash_s_try_convert, 1);
|
75
|
+
|
76
|
+
// rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
|
77
|
+
// rb_define_method(rb_cHash,"initialize_copy", rb_hash_replace, 1);
|
78
|
+
// rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
|
79
|
+
|
80
|
+
// rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
|
81
|
+
// rb_define_method(rb_cHash,"to_a", rb_hash_to_a, 0);
|
82
|
+
// rb_define_method(rb_cHash,"to_s", rb_hash_inspect, 0);
|
83
|
+
// rb_define_method(rb_cHash,"inspect", rb_hash_inspect, 0);
|
84
|
+
|
85
|
+
// rb_define_method(rb_cHash,"==", rb_hash_equal, 1);
|
86
|
+
rb_define_method(rb_cHash,"[]", rb_hash_aref, 1);
|
87
|
+
// rb_define_method(rb_cHash,"hash", rb_hash_hash, 0);
|
88
|
+
// rb_define_method(rb_cHash,"eql?", rb_hash_eql, 1);
|
89
|
+
// rb_define_method(rb_cHash,"fetch", rb_hash_fetch_m, -1);
|
90
|
+
rb_define_method(rb_cHash,"[]=", rb_hash_aset, 2);
|
91
|
+
// rb_define_method(rb_cHash,"store", rb_hash_aset, 2);
|
92
|
+
// rb_define_method(rb_cHash,"default", rb_hash_default, -1);
|
93
|
+
// rb_define_method(rb_cHash,"default=", rb_hash_set_default, 1);
|
94
|
+
// rb_define_method(rb_cHash,"default_proc", rb_hash_default_proc, 0);
|
95
|
+
// rb_define_method(rb_cHash,"default_proc=", rb_hash_set_default_proc, 1);
|
96
|
+
// rb_define_method(rb_cHash,"key", rb_hash_key, 1);
|
97
|
+
// rb_define_method(rb_cHash,"index", rb_hash_index, 1);
|
98
|
+
rb_define_method(rb_cHash,"size", rb_hash_size, 0);
|
99
|
+
rb_define_method(rb_cHash,"length", rb_hash_size, 0);
|
100
|
+
// rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);
|
101
|
+
|
102
|
+
// rb_define_method(rb_cHash,"each_value", rb_hash_each_value, 0);
|
103
|
+
// rb_define_method(rb_cHash,"each_key", rb_hash_each_key, 0);
|
104
|
+
// rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0);
|
105
|
+
// rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
|
106
|
+
|
107
|
+
// rb_define_method(rb_cHash,"keys", rb_hash_keys, 0);
|
108
|
+
// rb_define_method(rb_cHash,"values", rb_hash_values, 0);
|
109
|
+
// rb_define_method(rb_cHash,"values_at", rb_hash_values_at, -1);
|
110
|
+
|
111
|
+
// rb_define_method(rb_cHash,"shift", rb_hash_shift, 0);
|
112
|
+
// rb_define_method(rb_cHash,"delete", rb_hash_delete, 1);
|
113
|
+
// rb_define_method(rb_cHash,"delete_if", rb_hash_delete_if, 0);
|
114
|
+
// rb_define_method(rb_cHash,"select", rb_hash_select, 0);
|
115
|
+
// rb_define_method(rb_cHash,"reject", rb_hash_reject, 0);
|
116
|
+
// rb_define_method(rb_cHash,"reject!", rb_hash_reject_bang, 0);
|
117
|
+
// rb_define_method(rb_cHash,"clear", rb_hash_clear, 0);
|
118
|
+
// rb_define_method(rb_cHash,"invert", rb_hash_invert, 0);
|
119
|
+
// rb_define_method(rb_cHash,"update", rb_hash_update, 1);
|
120
|
+
// rb_define_method(rb_cHash,"replace", rb_hash_replace, 1);
|
121
|
+
// rb_define_method(rb_cHash,"merge!", rb_hash_update, 1);
|
122
|
+
// rb_define_method(rb_cHash,"merge", rb_hash_merge, 1);
|
123
|
+
// rb_define_method(rb_cHash, "assoc", rb_hash_assoc, 1);
|
124
|
+
// rb_define_method(rb_cHash, "rassoc", rb_hash_rassoc, 1);
|
125
|
+
// rb_define_method(rb_cHash, "flatten", rb_hash_flatten, -1);
|
126
|
+
|
127
|
+
rb_define_method(rb_cHash,"include?", rb_hash_has_key, 1);
|
128
|
+
rb_define_method(rb_cHash,"member?", rb_hash_has_key, 1);
|
129
|
+
rb_define_method(rb_cHash,"has_key?", rb_hash_has_key, 1);
|
130
|
+
// rb_define_method(rb_cHash,"has_value?", rb_hash_has_value, 1);
|
131
|
+
// rb_define_method(rb_cHash,"key?", rb_hash_has_key, 1);
|
132
|
+
// rb_define_method(rb_cHash,"value?", rb_hash_has_value, 1);
|
133
|
+
|
134
|
+
// rb_define_method(rb_cHash,"compare_by_identity", rb_hash_compare_by_id, 0);
|
135
|
+
// rb_define_method(rb_cHash,"compare_by_identity?",rb_hash_compare_by_id_p, 0);
|
136
|
+
|
137
|
+
// rb_envtbl = rb_obj_alloc(rb_cObject);
|
138
|
+
// rb_extend_object(rb_envtbl, rb_mEnumerable);
|
139
|
+
|
140
|
+
// rb_define_singleton_method(rb_envtbl,"[]", rb_f_getenv, 1);
|
141
|
+
// rb_define_singleton_method(rb_envtbl,"fetch", env_fetch, -1);
|
142
|
+
// rb_define_singleton_method(rb_envtbl,"[]=", env_aset, 2);
|
143
|
+
// rb_define_singleton_method(rb_envtbl,"store", env_aset, 2);
|
144
|
+
// rb_define_singleton_method(rb_envtbl,"each", env_each_pair, 0);
|
145
|
+
// rb_define_singleton_method(rb_envtbl,"each_pair", env_each_pair, 0);
|
146
|
+
// rb_define_singleton_method(rb_envtbl,"each_key", env_each_key, 0);
|
147
|
+
// rb_define_singleton_method(rb_envtbl,"each_value", env_each_value, 0);
|
148
|
+
// rb_define_singleton_method(rb_envtbl,"delete", env_delete_m, 1);
|
149
|
+
// rb_define_singleton_method(rb_envtbl,"delete_if", env_delete_if, 0);
|
150
|
+
// rb_define_singleton_method(rb_envtbl,"clear", rb_env_clear, 0);
|
151
|
+
// rb_define_singleton_method(rb_envtbl,"reject", env_reject, 0);
|
152
|
+
// rb_define_singleton_method(rb_envtbl,"reject!", env_reject_bang, 0);
|
153
|
+
// rb_define_singleton_method(rb_envtbl,"select", env_select, 0);
|
154
|
+
// rb_define_singleton_method(rb_envtbl,"shift", env_shift, 0);
|
155
|
+
// rb_define_singleton_method(rb_envtbl,"invert", env_invert, 0);
|
156
|
+
// rb_define_singleton_method(rb_envtbl,"replace", env_replace, 1);
|
157
|
+
// rb_define_singleton_method(rb_envtbl,"update", env_update, 1);
|
158
|
+
// rb_define_singleton_method(rb_envtbl,"inspect", env_inspect, 0);
|
159
|
+
// rb_define_singleton_method(rb_envtbl,"rehash", env_none, 0);
|
160
|
+
// rb_define_singleton_method(rb_envtbl,"to_a", env_to_a, 0);
|
161
|
+
// rb_define_singleton_method(rb_envtbl,"to_s", env_to_s, 0);
|
162
|
+
// rb_define_singleton_method(rb_envtbl,"key", env_key, 1);
|
163
|
+
// rb_define_singleton_method(rb_envtbl,"index", env_index, 1);
|
164
|
+
// rb_define_singleton_method(rb_envtbl,"size", env_size, 0);
|
165
|
+
// rb_define_singleton_method(rb_envtbl,"length", env_size, 0);
|
166
|
+
// rb_define_singleton_method(rb_envtbl,"empty?", env_empty_p, 0);
|
167
|
+
// rb_define_singleton_method(rb_envtbl,"keys", env_keys, 0);
|
168
|
+
// rb_define_singleton_method(rb_envtbl,"values", env_values, 0);
|
169
|
+
// rb_define_singleton_method(rb_envtbl,"values_at", env_values_at, -1);
|
170
|
+
// rb_define_singleton_method(rb_envtbl,"include?", env_has_key, 1);
|
171
|
+
// rb_define_singleton_method(rb_envtbl,"member?", env_has_key, 1);
|
172
|
+
// rb_define_singleton_method(rb_envtbl,"has_key?", env_has_key, 1);
|
173
|
+
// rb_define_singleton_method(rb_envtbl,"has_value?", env_has_value, 1);
|
174
|
+
// rb_define_singleton_method(rb_envtbl,"key?", env_has_key, 1);
|
175
|
+
// rb_define_singleton_method(rb_envtbl,"value?", env_has_value, 1);
|
176
|
+
// rb_define_singleton_method(rb_envtbl,"to_hash", env_to_hash, 0);
|
177
|
+
// rb_define_singleton_method(rb_envtbl,"assoc", env_assoc, 1);
|
178
|
+
// rb_define_singleton_method(rb_envtbl,"rassoc", env_rassoc, 1);
|
179
|
+
|
180
|
+
// rb_define_global_const("ENV", rb_envtbl);
|
181
|
+
}
|
data/runtime/init.js
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
/*
|
2
|
+
* init.js
|
3
|
+
* opal
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
/**
|
28
|
+
Basically start opal.
|
29
|
+
*/
|
30
|
+
function ruby_init() {
|
31
|
+
rb_call_inits();
|
32
|
+
};
|
33
|
+
|
34
|
+
/**
|
35
|
+
embed script name/type
|
36
|
+
*/
|
37
|
+
function ruby_script(name) {
|
38
|
+
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
Init core.
|
44
|
+
*/
|
45
|
+
function rb_call_inits() {
|
46
|
+
Init_Object();
|
47
|
+
Init_top_self();
|
48
|
+
Init_Array();
|
49
|
+
Init_Number();
|
50
|
+
Init_String();
|
51
|
+
Init_Hash();
|
52
|
+
Init_Range();
|
53
|
+
Init_Regexp();
|
54
|
+
Init_File();
|
55
|
+
Init_Dir();
|
56
|
+
Init_VM();
|
57
|
+
Init_vm_eval();
|
58
|
+
Init_load();
|
59
|
+
};
|
data/runtime/load.js
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
/*
|
2
|
+
* load.js
|
3
|
+
* opal
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
/**
|
29
|
+
Entry point 1.
|
30
|
+
==============
|
31
|
+
|
32
|
+
This should be used for apps that do not require the vienna build tools. Simply
|
33
|
+
pass it the root .rb file that you wish to use. simples.
|
34
|
+
|
35
|
+
usage:
|
36
|
+
|
37
|
+
vm_rb_main('my_file.rb');
|
38
|
+
=> app runs.
|
39
|
+
|
40
|
+
All searches, for require() statements, look for .rb files, not bundles.
|
41
|
+
*/
|
42
|
+
function vm_rb_main(path) {
|
43
|
+
rb_call_inits();
|
44
|
+
rb_top_vm.search_style = ".rb";
|
45
|
+
if (path.substr(path.length - 3) === ".rb") {
|
46
|
+
path = path.substr(0, path.length - 3);
|
47
|
+
}
|
48
|
+
return rb_f_require(rb_top_self, path);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
Entry point 2.
|
53
|
+
==============
|
54
|
+
|
55
|
+
Used for the bundles appraoch, where all files are already pre-compiled, or
|
56
|
+
vn-server is used to deploy files. This basically means no raw .rb files will
|
57
|
+
need to be compiled, so all searches take place for .vngem files
|
58
|
+
|
59
|
+
This loads the .rb file from the app bundle.
|
60
|
+
|
61
|
+
This actually loads each vendor bundle and the app bundle from the server, and
|
62
|
+
then, only when that is complete, does it actually load and run the given file.
|
63
|
+
|
64
|
+
For now, synchronous callbacks: in future, this will be async to avoid blocking
|
65
|
+
browser. Will need to make use of callbacks.
|
66
|
+
*/
|
67
|
+
// function vm_bundle_main(filename) {
|
68
|
+
// if (!window.VN_VENDOR_PATH) VN_VENDOR_PATH = '/vendor';
|
69
|
+
// if (!window.VN_APPLICATION_PATH) VN_APPLICATION_PATH = '/';
|
70
|
+
// // VN_BOOTSTRAP_APPLICATION = "sample_controls";
|
71
|
+
// // VN_BOOTSTRAP_BUNDLES = ["vienna"];
|
72
|
+
// for (var i = 0; i < VN_BOOTSTRAP_BUNDLES.length; i++) {
|
73
|
+
// var fullpath = VN_VENDOR_PATH + '/' + VN_BOOTSTRAP_BUNDLES[i] + '.opal';
|
74
|
+
// // console.log("Need to load: " + fullpath);
|
75
|
+
// }
|
76
|
+
//
|
77
|
+
// // app
|
78
|
+
// var fullpath = VN_BOOTSTRAP_APPLICATION + '.js';
|
79
|
+
// // console.log("need to load " + fullpath);
|
80
|
+
// var r = new XMLHttpRequest();
|
81
|
+
// r.open("GET", fullpath, false);
|
82
|
+
// r.send(null);
|
83
|
+
// // console.log(r.responseText);
|
84
|
+
//
|
85
|
+
// // load the root gem
|
86
|
+
// // vn_gem_boot(VN_BOOTSTRAP_APPLICATION, "", r.responseText);
|
87
|
+
// // console.log(r.responseText);
|
88
|
+
// eval(r.responseText);
|
89
|
+
// // we can now start the VM
|
90
|
+
// // rb_call_inits();
|
91
|
+
//
|
92
|
+
//
|
93
|
+
//
|
94
|
+
// // run the main file
|
95
|
+
// // filename = '/' + filename + '.rb';
|
96
|
+
// // console.log(filename);
|
97
|
+
// // console.log(vn_fs_path_hash[filename]);
|
98
|
+
// // rb_require_file(filename);
|
99
|
+
// }
|
100
|
+
|
101
|
+
// /**
|
102
|
+
// Main entry point (ish). At this point, only the core library exists, and all the
|
103
|
+
// inits() have been called. In development mode, VN_MAIN_BNDLE_NAME will be used to
|
104
|
+
// load the root .rb file. In production mode, it will load the root .vn file. which
|
105
|
+
// is a bundle. for now, assume everything is a .vn file.
|
106
|
+
// */
|
107
|
+
// function rb_run_vm() {
|
108
|
+
// vn_bundle_load_at_path(VN_MAIN_BUNDLE_NAME, function(bundle) {
|
109
|
+
// var f = bundle.files['lib/' + VN_MAIN_BUNDLE_NAME + '.rb'];
|
110
|
+
// // require_file...
|
111
|
+
// var o = eval(f.source);
|
112
|
+
// // o is our opcodes..
|
113
|
+
// f.required = true;
|
114
|
+
//
|
115
|
+
// // run vm.
|
116
|
+
// rb_iseq_eval(o);
|
117
|
+
// });
|
118
|
+
// }
|
119
|
+
|
120
|
+
/**
|
121
|
+
Array of the loadpaths - i.e. where to look for 'require()' statements
|
122
|
+
*/
|
123
|
+
var ruby_loadpath;
|
124
|
+
|
125
|
+
/**
|
126
|
+
load path initialization
|
127
|
+
*/
|
128
|
+
function ruby_init_loadpath() {
|
129
|
+
ruby_loadpath = [""];
|
130
|
+
};
|
131
|
+
|
132
|
+
/**
|
133
|
+
Add path to the loadpaths array
|
134
|
+
*/
|
135
|
+
function ruby_incpush(path) {
|
136
|
+
ruby_loadpath.push(path);
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
/**
|
141
|
+
array of full filenames which have been included: these should be the same
|
142
|
+
names as appear in vn_fs_path_hash
|
143
|
+
*/
|
144
|
+
var rb_required_files = {};
|
145
|
+
|
146
|
+
/**
|
147
|
+
Actually do a require with the given filename.
|
148
|
+
|
149
|
+
Already checked file exists, and we pass the raw filename which is already in
|
150
|
+
the vn_fs_path_hash. This method marks the file as being already required and
|
151
|
+
will then exectute the file, by putting it to the top of the vm.
|
152
|
+
*/
|
153
|
+
function rb_require_file(file_path) {
|
154
|
+
if (rb_required_files[file_path]) {
|
155
|
+
// console.log("Already required " + file_path);
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
rb_required_files[file_path] = true;
|
159
|
+
if (file_path.substr(file_path.length - 3) === '.js') {
|
160
|
+
// THIS shoulesnt ever happen now..
|
161
|
+
throw "no js includes!"
|
162
|
+
|
163
|
+
// // javascript
|
164
|
+
// // with (window) {
|
165
|
+
// // eval(vn_fs_path_hash[file_path]);
|
166
|
+
// // }
|
167
|
+
// eval(vn_fs_path_hash[file_path]);
|
168
|
+
// if (window.execScript) {
|
169
|
+
//
|
170
|
+
// window.execScript(vn_fs_path_hash[file_path]);
|
171
|
+
// }
|
172
|
+
// else {
|
173
|
+
// with (window) {
|
174
|
+
// eval(vn_fs_path_hash[file_path]);
|
175
|
+
// }
|
176
|
+
//
|
177
|
+
// }
|
178
|
+
}
|
179
|
+
else {
|
180
|
+
// ruby
|
181
|
+
rb_iseq_eval(eval(vn_fs_path_hash[file_path]));
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
Main entry point for a require statement.
|
188
|
+
*/
|
189
|
+
function rb_f_require(obj, path) {
|
190
|
+
path = rb_file_s_expand_path(1, [path], nil);
|
191
|
+
// the file this was called from (basically last but one sf)
|
192
|
+
var called_from_file = rb_top_vm.cfs[rb_top_vm.cfs.length - 2].iseq[3];
|
193
|
+
var correct_path;
|
194
|
+
// console.log("want to require: " + path + '.rb');
|
195
|
+
// find the file..
|
196
|
+
var found = rb_find_require_path(path);
|
197
|
+
if (found === nil) {
|
198
|
+
throw "cannot find require: " + path + ", called from " + called_from_file;
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
// console.log(found);
|
202
|
+
rb_require_file(found);
|
203
|
+
return true;
|
204
|
+
}
|
205
|
+
};
|
206
|
+
|
207
|
+
/**
|
208
|
+
find a require statement path. Returns the full path, or nil if not found.
|
209
|
+
*/
|
210
|
+
function rb_find_require_path(path) {
|
211
|
+
var try_path;
|
212
|
+
for (var i = 0; i < ruby_loadpath.length; i++) {
|
213
|
+
// try base
|
214
|
+
try_path = ruby_loadpath[i] + path + '.rb';
|
215
|
+
if (vn_fs_path_hash[try_path]) {
|
216
|
+
return try_path;
|
217
|
+
}
|
218
|
+
// try without .rb extension incase we included it in path
|
219
|
+
try_path = ruby_loadpath[i] + path;
|
220
|
+
if (vn_fs_path_hash[try_path]) {
|
221
|
+
return try_path;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
return nil;
|
225
|
+
};
|
226
|
+
|
227
|
+
/**
|
228
|
+
load root path - only called from js
|
229
|
+
*/
|
230
|
+
function rb_loadpath(path) {
|
231
|
+
var found = rb_find_require_path(path);
|
232
|
+
if (found === nil) {
|
233
|
+
throw "cannot find require: " + path + ", called from " + called_from_file;
|
234
|
+
}
|
235
|
+
else {
|
236
|
+
rb_require_file(found);
|
237
|
+
return true;
|
238
|
+
}
|
239
|
+
};
|
240
|
+
|
241
|
+
/**
|
242
|
+
Load, parse, eval the given text
|
243
|
+
*/
|
244
|
+
function rb_eval_raw(str) {
|
245
|
+
|
246
|
+
}
|
247
|
+
|
248
|
+
function Init_load() {
|
249
|
+
// require
|
250
|
+
rb_define_method(rb_cBasicObject, "require", rb_f_require, 1);
|
251
|
+
}
|