Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 29 additions & 47 deletions runtime/js/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

///////////// Array

import { caml_array_bound_error } from './fail.js';

//Provides: caml_array_sub mutable
function caml_array_sub(a, i, len) {
export function caml_array_sub(a, i, len) {
var a2 = new Array(len + 1);
a2[0] = 0;
for (var i2 = 1, i1 = i + 1; i2 <= len; i2++, i1++) {
Expand All @@ -28,21 +30,19 @@ function caml_array_sub(a, i, len) {
}

//Provides: caml_floatarray_sub mutable
//Requires: caml_array_sub
//Version: >= 5.3
function caml_floatarray_sub(a, i, len) {
export function caml_floatarray_sub(a, i, len) {
return caml_array_sub(a, i, len);
}

//Provides: caml_uniform_array_sub mutable
//Requires: caml_array_sub
//Version: >= 5.3
function caml_uniform_array_sub(a, i, len) {
export function caml_uniform_array_sub(a, i, len) {
return caml_array_sub(a, i, len);
}

//Provides: caml_array_append mutable
function caml_array_append(a1, a2) {
export function caml_array_append(a1, a2) {
var l1 = a1.length,
l2 = a2.length;
var l = l1 + l2 - 1;
Expand All @@ -56,21 +56,19 @@ function caml_array_append(a1, a2) {
}

//Provides: caml_floatarray_append mutable
//Requires: caml_array_append
//Version: >= 5.3
function caml_floatarray_append(a1, a2) {
export function caml_floatarray_append(a1, a2) {
return caml_array_append(a1, a2);
}

//Provides: caml_uniform_array_append mutable
//Requires: caml_array_append
//Version: >= 5.3
function caml_uniform_array_append(a1, a2) {
export function caml_uniform_array_append(a1, a2) {
return caml_array_append(a1, a2);
}

//Provides: caml_array_concat mutable
function caml_array_concat(l) {
export function caml_array_concat(l) {
var a = [0];
while (l !== 0) {
var b = l[1];
Expand All @@ -82,7 +80,7 @@ function caml_array_concat(l) {

//Provides: caml_floatarray_concat mutable
//Version: >= 5.4
function caml_floatarray_concat(l) {
export function caml_floatarray_concat(l) {
var a = [0];
while (l !== 0) {
var b = l[1];
Expand All @@ -94,7 +92,7 @@ function caml_floatarray_concat(l) {

//Provides: caml_uniform_array_concat mutable
//Version: >= 5.4
function caml_uniform_array_concat(l) {
export function caml_uniform_array_concat(l) {
var a = [0];
while (l !== 0) {
var b = l[1];
Expand All @@ -105,7 +103,7 @@ function caml_uniform_array_concat(l) {
}

//Provides: caml_array_blit
function caml_array_blit(a1, i1, a2, i2, len) {
export function caml_array_blit(a1, i1, a2, i2, len) {
if (i2 <= i1) {
for (var j = 1; j <= len; j++) a2[i2 + j] = a1[i1 + j];
} else {
Expand All @@ -115,81 +113,72 @@ function caml_array_blit(a1, i1, a2, i2, len) {
}

//Provides: caml_floatarray_blit
//Requires: caml_array_blit
function caml_floatarray_blit(a1, i1, a2, i2, len) {
export function caml_floatarray_blit(a1, i1, a2, i2, len) {
return caml_array_blit(a1, i1, a2, i2, len);
}

//Provides: caml_uniform_array_blit
//Requires: caml_array_blit
//Version: >= 5.3
function caml_uniform_array_blit(a1, i1, a2, i2, len) {
export function caml_uniform_array_blit(a1, i1, a2, i2, len) {
return caml_array_blit(a1, i1, a2, i2, len);
}

///////////// Pervasive
//Provides: caml_array_set (mutable, const, mutable)
//Requires: caml_array_bound_error
//Alias: caml_array_set_float
//Alias: caml_floatarray_set
//Alias: caml_array_set_addr
function caml_array_set(array, index, newval) {
export function caml_array_set(array, index, newval) {
if (index < 0 || index >= array.length - 1) caml_array_bound_error();
array[index + 1] = newval;
return 0;
}

//Provides: caml_array_get mutable (mutable, const)
//Requires: caml_array_bound_error
//Alias: caml_array_get_float
//Alias: caml_floatarray_get
//Alias: caml_array_get_addr
function caml_array_get(array, index) {
export function caml_array_get(array, index) {
if (index < 0 || index >= array.length - 1) caml_array_bound_error();
return array[index + 1];
}

//Provides: caml_array_fill
function caml_array_fill(array, ofs, len, v) {
export function caml_array_fill(array, ofs, len, v) {
for (var i = 0; i < len; i++) {
array[ofs + i + 1] = v;
}
return 0;
}

//Provides: caml_floatarray_fill
//Requires: caml_array_fill
//Version: >= 5.3
function caml_floatarray_fill(array, ofs, len, v) {
export function caml_floatarray_fill(array, ofs, len, v) {
return caml_array_fill(array, ofs, len, v);
}

//Provides: caml_floatarray_fill_unboxed
//Requires: caml_array_fill
//Version: >= 5.3
function caml_floatarray_fill_unboxed(array, ofs, len, v) {
export function caml_floatarray_fill_unboxed(array, ofs, len, v) {
return caml_array_fill(array, ofs, len, v);
}

//Provides: caml_uniform_array_fill
//Requires: caml_array_fill
//Version: >= 5.3
function caml_uniform_array_fill(array, ofs, len, v) {
export function caml_uniform_array_fill(array, ofs, len, v) {
return caml_array_fill(array, ofs, len, v);
}

//Provides: caml_check_bound (mutable, const)
//Requires: caml_array_bound_error
//Alias: caml_check_bound_gen
//Alias: caml_check_bound_float
function caml_check_bound(array, index) {
export function caml_check_bound(array, index) {
if (index >>> 0 >= array.length - 1) caml_array_bound_error();
return array;
}

//Provides: caml_array_make const (const, mutable)
//Requires: caml_array_bound_error
function caml_array_make(len, init) {
export function caml_array_make(len, init) {
if (len >>> 0 >= ((0x7fffffff / 4) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
Expand All @@ -199,14 +188,12 @@ function caml_array_make(len, init) {
}

//Provides: caml_make_vect const (const, mutable)
//Requires: caml_array_make
function caml_make_vect(len, init) {
export function caml_make_vect(len, init) {
return caml_array_make(len, init);
}

//Provides: caml_make_float_vect const (const)
//Requires: caml_array_bound_error
function caml_make_float_vect(len) {
export function caml_make_float_vect(len) {
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
Expand All @@ -216,9 +203,8 @@ function caml_make_float_vect(len) {
}

//Provides: caml_array_create_float const (const)
//Requires: caml_array_bound_error
//Version: >= 5.3
function caml_array_create_float(len) {
export function caml_array_create_float(len) {
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
Expand All @@ -227,8 +213,7 @@ function caml_array_create_float(len) {
return b;
}
//Provides: caml_floatarray_create const (const)
//Requires: caml_array_bound_error
function caml_floatarray_create(len) {
export function caml_floatarray_create(len) {
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
Expand All @@ -238,9 +223,8 @@ function caml_floatarray_create(len) {
}

//Provides: caml_floatarray_make const (const)
//Requires: caml_array_bound_error
//Version: >= 5.3
function caml_floatarray_make(len, init) {
export function caml_floatarray_make(len, init) {
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
Expand All @@ -250,15 +234,13 @@ function caml_floatarray_make(len, init) {
}

//Provides: caml_floatarray_make_unboxed const (const)
//Requires: caml_floatarray_make
//Version: >= 5.3
function caml_floatarray_make_unboxed(len, init) {
export function caml_floatarray_make_unboxed(len, init) {
return caml_floatarray_make(len, init);
}

//Provides: caml_uniform_array_make const (const)
//Requires: caml_array_make
//Version: >= 5.3
function caml_uniform_array_make(len, init) {
export function caml_uniform_array_make(len, init) {
return caml_array_make(len, init);
}
37 changes: 17 additions & 20 deletions runtime/js/backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

import { caml_failwith, caml_invalid_argument } from './fail.js';
import { jsoo_sys_getenv } from './sys.js';

//Provides: caml_record_backtrace_env_flag
//Requires: jsoo_sys_getenv
var caml_record_backtrace_env_flag = FLAG("with-js-error");
export let caml_record_backtrace_env_flag = FLAG("with-js-error");

(function () {
var r = jsoo_sys_getenv("OCAMLRUNPARAM");
Expand All @@ -35,60 +37,55 @@ var caml_record_backtrace_env_flag = FLAG("with-js-error");
})();

//Provides: caml_record_backtrace_runtime_flag
//Requires: caml_record_backtrace_env_flag
var caml_record_backtrace_runtime_flag = caml_record_backtrace_env_flag;
export let caml_record_backtrace_runtime_flag = caml_record_backtrace_env_flag;

//Provides: caml_ml_debug_info_status const
function caml_ml_debug_info_status() {
export function caml_ml_debug_info_status() {
return 0;
}
//Provides: caml_backtrace_status
//Requires: caml_record_backtrace_runtime_flag
function caml_backtrace_status(_unit) {
export function caml_backtrace_status(_unit) {
return caml_record_backtrace_runtime_flag ? 1 : 0;
}
//Provides: caml_get_exception_backtrace const
function caml_get_exception_backtrace() {
export function caml_get_exception_backtrace() {
return 0;
}
//Provides: caml_get_exception_raw_backtrace const
function caml_get_exception_raw_backtrace(_unit) {
export function caml_get_exception_raw_backtrace(_unit) {
return [0];
}
//Provides: caml_record_backtrace
//Requires: caml_record_backtrace_runtime_flag
function caml_record_backtrace(b) {
export function caml_record_backtrace(b) {
caml_record_backtrace_runtime_flag = b;
return 0;
}
//Provides: caml_convert_raw_backtrace const
function caml_convert_raw_backtrace() {
export function caml_convert_raw_backtrace() {
return [0];
}
//Provides: caml_raw_backtrace_length
function caml_raw_backtrace_length() {
export function caml_raw_backtrace_length() {
return 0;
}
//Provides: caml_raw_backtrace_next_slot
function caml_raw_backtrace_next_slot(_slot) {
export function caml_raw_backtrace_next_slot(_slot) {
return 0;
}
//Provides: caml_raw_backtrace_slot
//Requires: caml_invalid_argument
function caml_raw_backtrace_slot(_bt, _idx) {
export function caml_raw_backtrace_slot(_bt, _idx) {
caml_invalid_argument("Printexc.get_raw_backtrace_slot: index out of bounds");
}
//Provides: caml_restore_raw_backtrace
function caml_restore_raw_backtrace(_exn, _bt) {
export function caml_restore_raw_backtrace(_exn, _bt) {
return 0;
}
//Provides: caml_get_current_callstack const
function caml_get_current_callstack() {
export function caml_get_current_callstack() {
return [0];
}

//Provides: caml_convert_raw_backtrace_slot
//Requires: caml_failwith
function caml_convert_raw_backtrace_slot(_rbt) {
export function caml_convert_raw_backtrace_slot(_rbt) {
caml_failwith("caml_convert_raw_backtrace_slot");
}
Loading