From c71eaca633b2622fa71130693b07b0df103f965a Mon Sep 17 00:00:00 2001 From: inglorion Date: Thu, 21 Aug 2014 21:06:11 -0700 Subject: [PATCH] added array_map --- bootstrap/src/antimony/array_sb.voo | 34 ++++++++++++++++++++++++++++++++++ configure | 1 + src/antimony/array_sb.sb | 19 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 bootstrap/src/antimony/array_sb.voo create mode 100644 src/antimony/array_sb.sb diff --git a/bootstrap/src/antimony/array_sb.voo b/bootstrap/src/antimony/array_sb.voo new file mode 100644 index 0000000..678b833 --- /dev/null +++ b/bootstrap/src/antimony/array_sb.voo @@ -0,0 +1,34 @@ +section data +section functions +export sbJ_array_map +import sbJ_allocate_words sbJ_array_t sbJ_false sbJ_lt +align +sbJ_array_map: +function sbJ_fun sbJ_arr + block + let sbJ_len get-word sbJ_arr 1 + let sbJ__sb_G1 add sbJ_len 2 + let sbJ_result call sbJ_allocate_words sbJ__sb_G1 + set-word sbJ_result 0 sbJ_array_t + set-word sbJ_result 1 sbJ_len + block + let _sb_G5 0 + let sbJ_max add sbJ_len 2 + let sbJ_i 2 +_sb_G6: + let sbJ__sb_G2 call sbJ_lt sbJ_i sbJ_max + set _sb_G5 sbJ__sb_G2 + ifeq _sb_G5 @sbJ_false + goto _sb_G7 + end if + let sbJ__sb_G3 get-word sbJ_arr sbJ_i + let sbJ__sb_G4 call sbJ_fun sbJ__sb_G3 + set-word sbJ_result sbJ_i sbJ__sb_G4 + set sbJ_i add sbJ_i 1 + goto _sb_G6 +_sb_G7: + end block + return sbJ_result + end block +end function + diff --git a/configure b/configure index 663c0cc..ec88704 100755 --- a/configure +++ b/configure @@ -58,6 +58,7 @@ libantimony_sources=' antimony_reader antimony_writer array +array_sb allocate blob blob_sb diff --git a/src/antimony/array_sb.sb b/src/antimony/array_sb.sb new file mode 100644 index 0000000..5934370 --- /dev/null +++ b/src/antimony/array_sb.sb @@ -0,0 +1,19 @@ +section functions +export array_map +import allocate_words array_t false lt + +function array_map fun arr { + let len get-word arr 1 + let result allocate_words (add len 2) + set-word result 0 array_t + set-word result 1 len + loop { + let max add len 2 + var i = 2 + do + while (lt i max) + set-word result i (fun (get-word arr i)) + set i add i 1 + } + return result +} -- 2.11.4.GIT