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

Fix issue in unoptimised ABC where a jsr_eval_host_node did not cause the...

Fix issue in unoptimised ABC where a jsr_eval_host_node did not cause the evaluation of all references of the node
parent 9faa480e
Pipeline #14910 failed with stage
in 1 minute and 25 seconds
......@@ -45,8 +45,9 @@ import StdEnum,StdFunc
// Example: get a function from a bytecode file and apply it
Start :: *World -> [Int]
Start w
# ((intsquare,sub5,sub3_10,sumints,rev,foldr,ap1,ap3),w) = get_expression "../test/functions.bc" w
= use intsquare sub5 sub3_10 sumints rev foldr ap1 ap3
# ((intsquare,sub5,sub3_10,sumints,rev,foldr,ap1,ap3,map),w)
= get_expression "../test/functions.bc" w
= use intsquare sub5 sub3_10 sumints rev foldr ap1 ap3 map
where
use ::
(Int -> Int)
......@@ -57,8 +58,9 @@ where
(A.a b: (a b -> b) b [a] -> b)
((Int -> Int) -> Int)
((Int Int Int -> Int) -> Int)
(A.a b: (a -> b) [a] -> [b])
-> [Int]
use intsquare sub5 sub3_10 sumints rev foldr ap1 ap3 =
use intsquare sub5 sub3_10 sumints rev foldr ap1 ap3 map =
[ intsquare 6 + intsquare 1
, sub5 (last [1..47]) 1 2 3 (square 2)
, sub3_10 -20 -30 3
......@@ -69,8 +71,16 @@ where
, ap1 (flip (-) 5)
, ap3 (\x y z -> 10*x + 3*y + z)
, foldr (\x y -> x + y) 0 [1,2,3,4,5,6,7,8,1]
, toInt (last (rev [TestA,TestB]))
: map (\x -> if (x == 0 || x == 10) 37 42) [0,10]
]
:: TestT = TestA | TestB
instance toInt TestT
where
toInt TestA = 37
toInt TestB = 42
square :: Int -> Int
square x = x * x
......
......@@ -62,7 +62,7 @@ BC_WORD copy_to_interpreter(struct interpretation_environment *ie, BC_WORD *heap
#endif
BC_WORD *org_heap = heap;
heap[0] = (BC_WORD) host_symbol->interpreter_location + 2 + a_arity * 8;
heap[0] = (BC_WORD) host_symbol->interpreter_location + 2 + a_arity * 16;
if (a_arity + b_arity < 3) {
heap += 3;
......
......@@ -297,7 +297,7 @@ BC_WORD copy_interpreter_to_host(void *__dummy_0, void *__dummy_1,
#endif
if (!(node[0] & 2)) {
if (((BC_WORD*)node[0])[1] ==
if (*((BC_WORD*)node[0]) ==
#ifdef COMPUTED_GOTOS
(BC_WORD) instruction_labels[Cjsr_eval_host_node]
#else
......@@ -347,6 +347,8 @@ BC_WORD copy_interpreter_to_host_n(void *__dummy_0, void *__dummy_1,
fprintf(stderr,"Copying %p -> %p with %d argument(s)...\n", node, (void*)*node, n_args+1);
#endif
*++ie->asp = (BC_WORD)node;
va_start(arguments,n_args);
for (int i = 0; i <= n_args; i++) {
int hostid = va_arg(arguments, int);
......
......@@ -98,8 +98,7 @@ void build_host_nodes(void) {
# define INSTR(i) i
#endif
if (arity == 1) {
HOST_NODE_INSTRUCTIONS[6*arity-6] = INSTR(Crepl_args1);
HOST_NODE_INSTRUCTIONS[6*arity-5] = INSTR(Cjsr_eval_host_node);
HOST_NODE_INSTRUCTIONS[6*arity-6] = INSTR(Cjsr_eval_host_node);
} else if (arity <= 5) {
HOST_NODE_INSTRUCTIONS[6*arity-6] = INSTR(Cjsr_eval_host_node+arity-1);
HOST_NODE_INSTRUCTIONS[6*arity-3] = INSTR(
......
......@@ -7054,7 +7054,7 @@ case EVAL_TO_HNF_LABEL:
INSTRUCTION_BLOCK(jsr_eval_host_node):
{
BC_WORD *n=(BC_WORD*)asp[0];
int host_nodeid = n[1];
int host_nodeid = ((BC_WORD*)n[1])[1];
BC_WORD *host_node = ie->host->clean_ie->__ie_2->__ie_shared_nodes[3+host_nodeid];
#if DEBUG_CLEAN_LINKS > 1
fprintf(stderr,"\t%p -> [%d; %p -> %p]\n",(void*)asp[0],host_nodeid,host_node,(void*)*host_node);
......@@ -7071,11 +7071,14 @@ INSTRUCTION_BLOCK(jsr_eval_host_node):
#endif
}
/* TODO: if possible, it is more efficient to overwrite the old node
* instead of creating a new node.
/* TODO: if possible, it is more efficient to not create the new object at
* all.
*/
BC_WORD words_used = copy_to_interpreter(ie, hp, heap_free, host_node);
asp[0] = (BC_WORD) hp;
n[0] = hp[0];
n[1] = hp[1];
if (((int16_t*)(n[0]))[-1] >= 2)
n[2] = hp[2];
hp += words_used;
pc=(BC_WORD*)*csp++;
......
(square.2,sub5.3,(sub5.3 0 10),sumints.4,reverse.5,foldr.6,ap1.7,ap3.8)
(square.2,sub5.3,(sub5.3 0 10),sumints.4,reverse.5,foldr.6,ap1.7,ap3.8,map.9)
halt at 6
17 524271 524288
18 524270 524288
(square.2,sub5.3,(sub5.3 0 10),sumints.4,reverse.5,foldr.6,ap1.7,ap3.8)
(square.2,sub5.3,(sub5.3 0 10),sumints.4,reverse.5,foldr.6,ap1.7,ap3.8,map.9)
halt at 6
17 262127 262144
18 262126 262144
......@@ -2,7 +2,7 @@ module functions
import StdInt
Start = (square, sub5, sub5 0 10, sumints, reverse, foldr, ap1, ap3)
Start = (square, sub5, sub5 0 10, sumints, reverse, foldr, ap1, ap3, map)
square :: Int -> Int
square x = x * x
......@@ -29,3 +29,7 @@ ap1 f = f 42
ap3 :: (Int Int Int -> Int) -> Int
ap3 f = f 3 2 1
map :: (a -> b) [a] -> [b]
map f [x:xs] = [f x:map f xs]
map _ [] = []
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