Verified Commit e17c8dd4 authored by Camil Staps's avatar Camil Staps 🚀

Replace desc numbers by desc in C for portability

parent 55407b98
Pipeline #15826 passed with stages
in 14 minutes and 19 seconds
......@@ -69,9 +69,8 @@ deserialize {graph,descinfo,modules,bytecode} thisexe w
| isNothing pgm = abort "Failed to parse bytecode\n"
# pgm = fromJust pgm
# int_syms = getInterpreterSymbols pgm
# int_syms = {s \\ s <- matchSymbols [s \\ s <-: host_syms] int_syms}
#! graph = replace_symbols_in_graph graph descinfo modules int_syms
# int_syms = {#s \\ s <- matchSymbols [s \\ s <-: host_syms] int_syms}
# int_syms = {#lookup_symbol_value d modules int_syms \\ d <-: descinfo}
# stack = malloc (IF_INT_64_OR_32 8 4 * STACK_SIZE)
# asp = stack
......@@ -82,7 +81,7 @@ deserialize {graph,descinfo,modules,bytecode} thisexe w
pgm
heap HEAP_SIZE stack STACK_SIZE
asp bsp csp heap
# graph_node = string_to_interpreter graph ie_settings
# graph_node = string_to_interpreter int_syms graph ie_settings
#! (ie,_) = make_finalizer ie_settings
# ie = {ie_finalizer=ie, ie_snode_ptr=0, ie_snodes=unsafeCreateArray 1}
= (interpret ie (Finalizer 0 0 graph_node), w)
......@@ -119,11 +118,35 @@ where
ccall get_host_symbols "p:p"
}
string_to_interpreter :: !String !Pointer -> Pointer
string_to_interpreter graph ie = code {
ccall string_to_interpreter "Sp:p"
string_to_interpreter :: !{#Int} !String !Pointer -> Pointer
string_to_interpreter symbol_values graph ie = code {
ccall string_to_interpreter "ASp:p"
}
lookup_symbol_value :: !DescInfo !{#String} !{#Symbol} -> Int
lookup_symbol_value {di_prefix_arity_and_mod,di_name} mod_a symbols
# prefix_n = di_prefix_arity_and_mod bitand 0xff
# module_n = (di_prefix_arity_and_mod >> 8)-1
# module_name = mod_a.[module_n]
| prefix_n<PREFIX_D
# symbol_name = make_symbol_name module_name di_name prefix_n
# symbol_value = get_symbol_value symbol_name symbols
| prefix_n<=1
| symbol_value== -1
= abort ("lookup_desc_info not found "+++symbol_name)
= symbol_value
| symbol_value== -1
= abort ("lookup_desc_info not found "+++symbol_name)
= symbol_value+2
# symbol_name = make_symbol_name module_name di_name PREFIX_D
# symbol_value = get_symbol_value symbol_name symbols
| symbol_value== -1
= abort ("lookup_desc_info not found "+++symbol_name)
# arity = prefix_n - PREFIX_D
= symbol_value+(arity*8*2)+2
where
PREFIX_D = 4
STACK_SIZE :== (512 << 10) * 2
HEAP_SIZE :== 2 << 20
......
......@@ -78,7 +78,8 @@ BC_WORD *build_start_node(struct interpretation_environment *ie) {
return hp;
}
BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_environment *ie) {
BC_WORD *string_to_interpreter(BC_WORD *descriptors, uint64_t *clean_string,
struct interpretation_environment *ie) {
int len = *(int*)clean_string;
uint64_t *s = &clean_string[1];
BC_WORD *node = ie->hp;
......@@ -103,14 +104,16 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
} else {
a_size_stack[0]--;
BC_WORD desc=(BC_WORD)s[i];
BC_WORD_S desc=(BC_WORD)s[i];
s[i]=(BC_WORD)ie->hp;
if (desc & 1) { /* redirection */
if (desc < 0) { /* redirection */
**ptr_stack-- = (BC_WORD) s[i+(desc-1)/8];
continue;
}
desc=descriptors[desc-1];
#if DEBUG_CLEAN_LINKS > 1
fprintf(stderr,"\t");
for (int16_t *a=(int16_t*)ie->csp-1; a>a_size_stack; a--)
......@@ -146,7 +149,11 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
ie->hp+=1+len;
} else if (desc == (BC_WORD)&__ARRAY__+2) {
BC_WORD size=(BC_WORD)s[i+1];
#if DEBUG_CLEAN_LINKS > 1
fprintf(stderr,"; __ARRAY__ " BC_WORD_FMT,size);
#endif
BC_WORD elem_desc=(BC_WORD)s[i+2];
elem_desc=elem_desc==0 ? 0 : descriptors[elem_desc-1];
**ptr_stack--=(BC_WORD)ie->hp;
ie->hp[0]=desc;
ie->hp[1]=size;
......
......@@ -4,4 +4,4 @@
copy_to_string_with_names :: a -> (!*{#Char},!*{#DescInfo},!*{#String});
copy_from_string_with_names :: !*{#Char} !*{#DescInfo} !*{#String} !{#Symbol} -> (.a,!Int);
+replace_symbols_in_graph :: !*{#Char} !*{#DescInfo} !*{#String} !{#Symbol} -> *{#Char};
+make_symbol_name :: !String !String !Int -> String;
--- a/graph_copy_with_names.icl
+++ b/graph_copy_with_names.icl
@@ -61,7 +61,7 @@ get_thunk_arity_32 a = code {
get_thunk_arity_64 :: !Int -> Int;
get_thunk_arity_64 a = code {
- load_si32 -4
+ load_si16 -4
}
get_thunk_descriptor a :== IF_INT_64_OR_32 (get_thunk_descriptor_64_platform a) (get_thunk_descriptor_32_platform a);
@@ -721,7 +721,7 @@ lookup_symbol_value {di_prefix_arity_and_mod,di_name} mod_a symbols
| symbol_value== -1
= abort ("lookup_desc_info not found "+++symbol_name);
# arity = prefix_n - PREFIX_D;
- = symbol_value+(arity*size_element_descriptor_currying)+2;
+ = symbol_value+(arity*size_element_descriptor_currying*2)+2;
lookup_symbol_values desc_info_a mod_a symbols
= {#lookup_symbol_value desc_info mod_a symbols \\ desc_info <-: desc_info_a};
@@ -754,7 +754,7 @@ replace_desc_numbers_by_descs i s symbol_a symbol_offset array_desc
= replace_desc_numbers_by_descs (i+(IF_INT_64_OR_32 24 12)) s symbol_a symbol_offset array_desc;
# d = symbol_a.[d-1];
# d = d+symbol_offset;
- # s=store_int_in_string s (i+IF_INT_64_OR_32 16 8) array_desc;
+ # s=store_int_in_string s (i+IF_INT_64_OR_32 16 8) d;
#! l = get_D_from_string s (i+IF_INT_64_OR_32 8 4);
| is_Int_D d
# l = l << IF_INT_64_OR_32 3 2;
@@ -773,12 +773,14 @@ replace_desc_numbers_by_descs i s symbol_a symbol_offset array_desc
= replace_desc_numbers_by_descs (i+(IF_INT_64_OR_32 24 12)+l) s symbol_a symbol_offset array_desc;
= abort (toString l+++" "+++toString d);
-copy_from_string_with_names :: !*{#Char} !*{#DescInfo} !*{#String} !{#Symbol} -> (.a,!Int);
-copy_from_string_with_names s desc_s_a mod_s_a symbols
+replace_symbols_in_graph :: !*{#Char} !*{#DescInfo} !*{#String} !{#Symbol} -> *{#Char};
+replace_symbols_in_graph s desc_s_a mod_s_a symbols
# symbol_offset = if (is_using_desc_relative_to_array == 1) (((get_array_D {}) - (get_symbol_value "__ARRAY__" symbols)) - 2) 0;
# array_desc = if (is_using_desc_relative_to_array == 1) ((get_array_D {} - 2)) 0;
# symbol_a = lookup_symbol_values desc_s_a mod_s_a symbols;
- # s = replace_desc_numbers_by_descs 0 s symbol_a symbol_offset array_desc;
- = copy_from_string s;
-
+ = replace_desc_numbers_by_descs 0 s symbol_a symbol_offset array_desc;
+copy_from_string_with_names :: !*{#Char} !*{#DescInfo} !*{#String} !{#Symbol} -> (.a,!Int);
+copy_from_string_with_names s desc_s_a mod_s_a symbols
+ # s = replace_symbols_in_graph s desc_s_a mod_s_a symbols;
+ = copy_from_string s;
@@ -393,7 +393,8 @@
# b_size = arity>>8;
= b_size;
+make_symbol_name :: !String !String !Int -> String;
make_symbol_name "_system" descriptor_name prefix
= case descriptor_name of {
"INT"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment