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

Use static_characters in buildC and buildC_b

parent db5930e6
Pipeline #20393 passed with stages
in 19 minutes and 32 seconds
......@@ -19,21 +19,17 @@ enum section_type {
#define _4chars2int(a,b,c,d) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)))
#define _7chars2int(a,b,c,d,e,f,g) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)+((uint64_t)e<<32)+((uint64_t)f<<40)+((uint64_t)g<<48)))
#define _8chars2int(a,b,c,d,e,f,g,h) ((uint64_t) (a+(b<<8)+(c<<16)+(d<<24)+((uint64_t)e<<32)+((uint64_t)f<<40)+((uint64_t)g<<48)+((uint64_t)h<<56)))
uint64_t unrelocator_preamble[146] = {
uint64_t unrelocator_preamble[658] = {
/* 0 */ 0, 0, 0, 7, _7chars2int('_','A','R','R','A','Y','_'),
/* 5 */ 0, 0, 0, 8, _8chars2int('_','S','T','R','I','N','G','_'),
/* 10 */ 0, 0, 0, 4, _4chars2int('B','O','O','L'),
/* 15 */ 0, 0, 0, 4, _4chars2int('C','H','A','R'),
/* 20 */ 0, 0, 0, 4, _4chars2int('R','E','A','L'),
/* 25 */ 0, 0, 0, 3, _3chars2int('I','N','T'),
/* 30 */ 26*8+2, 0, /* small integers */
26*8+2, 1, 26*8+2, 2, 26*8+2, 3, 26*8+2, 4, 26*8+2, 5,
26*8+2, 6, 26*8+2, 7, 26*8+2, 8, 26*8+2, 9, 26*8+2, 10,
26*8+2, 11, 26*8+2, 12, 26*8+2, 13, 26*8+2, 14, 26*8+2, 15,
26*8+2, 16, 26*8+2, 17, 26*8+2, 18, 26*8+2, 19, 26*8+2, 20,
26*8+2, 21, 26*8+2, 22, 26*8+2, 23, 26*8+2, 24, 26*8+2, 25,
26*8+2, 26, 26*8+2, 27, 26*8+2, 28, 26*8+2, 29, 26*8+2, 30,
26*8+2, 31, 26*8+2, 32,
/* 30 small integers */
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,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0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 658 */
};
void prepare_preamble(void) {
for (int i=0; i<=32; i++) {
unrelocator_preamble[30+i*2]=26*8+2; /* INT+2 */
unrelocator_preamble[30+i*2+1]=i;
}
for (int i=0; i<256; i++) {
unrelocator_preamble[146+i*2]=16*8+2; /* CHAR+2 */
unrelocator_preamble[146+i*2+1]=i;
}
}
void write_section(FILE *f, enum section_type type, uint32_t len, uint64_t *data) {
fwrite(&type, 1, sizeof(uint32_t), f);
fwrite(&len, 1, sizeof(uint32_t), f);
......@@ -103,6 +128,7 @@ int main(int argc, char **argv) {
struct program *program=state.program;
prepare_preamble();
write_section(output_file, ST_Preamble, sizeof(unrelocator_preamble)/sizeof(uint64_t), unrelocator_preamble);
write_section(output_file, ST_Code, program->code_size, program->code);
write_section(output_file, ST_Data, program->data_size, program->data);
......
#pragma once
extern uint64_t unrelocator_preamble[146];
extern uint64_t unrelocator_preamble[658];
['H','e','l','l','o',' ','W','o','r','l','d','!','
']
halt at 4
25208 499080 524288
23227 501061 524288
['H','e','l','l','o',' ','W','o','r','l','d','!','
']
halt at 4
123337 138807 262144
121205 140939 262144
(['I',' ','h','a','v','e',' ','o','n','l','y',' ','p','r','o','v','e','d',' ','i','t',' ','c','o','r','r','e','c','t','.'],['I',' ','h','a','v','e',' ','o','n','l','y',' ','p','r','o','v','e','d',' ','i','t',' ','c','o','r','r','e','c','t','.'])
halt at 4
913 523375 524288
673 523615 524288
(['I',' ','h','a','v','e',' ','o','n','l','y',' ','p','r','o','v','e','d',' ','i','t',' ','c','o','r','r','e','c','t','.'],['I',' ','h','a','v','e',' ','o','n','l','y',' ','p','r','o','v','e','d',' ','i','t',' ','c','o','r','r','e','c','t','.'])
halt at 4
909 261235 262144
669 261475 262144
False
halt at 4
282898 241390 524288
282268 242020 524288
True
halt at 4
174878 87266 262144
173871 88273 262144
(square.2,sub5.3,(sub5.3 0 10),sumints.4,reverse.5,foldr.6,ap1.7,ap3.8,map.9,repeat.10,([(IT1 37 '!'),(IT2 37 '!')],{InternalType2 (IT1 37 '!') 1,InternalType2 (IT2 37 '!') 2},[(InternalType2 (IT1 37 '!') 1),(InternalType2 (IT2 37 '!') 2)]))
halt at 55
67 524221 524288
63 524225 524288
(square.2,sub5.3,(sub5.3 0 10),sumints.4,reverse.5,foldr.6,ap1.7,ap3.8,map.9,repeat.10,([(IT1 37 '!'),(IT2 37 '!')],{InternalType2 (IT1 37 '!') 1,InternalType2 (IT2 37 '!') 2},[(InternalType2 (IT1 37 '!') 1),(InternalType2 (IT2 37 '!') 2)]))
halt at 55
67 262077 262144
63 262081 262144
(Right "15")
halt at 4
8517 515771 524288
8513 515775 524288
(Right "15")
halt at 4
8510 253634 262144
8506 253638 262144
[400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400]
halt at 4
11017561 1565351 12582912
8740001 3842911 12582912
[400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400,400]
halt at 4
5972580 318876 6291456
1688717 4602739 6291456
......@@ -18,4 +18,4 @@
"," 1 17 136 680 2380 6188 12376 19448 24310 24310 19448 12376 6188 2380 680 136 17 1
"]
halt at 4
8142 516146 524288
8106 516182 524288
......@@ -18,4 +18,4 @@
"," 1 17 136 680 2380 6188 12376 19448 24310 24310 19448 12376 6188 2380 680 136 17 1
"]
halt at 4
6830 255314 262144
6794 255350 262144
64000
halt at 4
11019686 1563226 12582912
10838527 1744385 12582912
64000
halt at 4
5313968 977488 6291456
4964838 1326618 6291456
[(Record A C 0 37 '~' 3.70000004768372),(Record A C 0 37 '~' 4.19999980926514),(Record A C 0 37 '%' 3.70000004768372),(Record A C 0 37 '%' 4.19999980926514),(Record A C 0 42 '~' 3.70000004768372),(Record A C 0 42 '~' 4.19999980926514),(Record A C 0 42 '%' 3.70000004768372),(Record A C 0 42 '%' 4.19999980926514),(Record A C 1 37 '~' 3.70000004768372),(Record A C 1 37 '~' 4.19999980926514),(Record A C 1 37 '%' 3.70000004768372),(Record A C 1 37 '%' 4.19999980926514),(Record A C 1 42 '~' 3.70000004768372),(Record A C 1 42 '~' 4.19999980926514),(Record A C 1 42 '%' 3.70000004768372),(Record A C 1 42 '%' 4.19999980926514),(Record A D 0 37 '~' 3.70000004768372),(Record A D 0 37 '~' 4.19999980926514),(Record A D 0 37 '%' 3.70000004768372),(Record A D 0 37 '%' 4.19999980926514),(Record A D 0 42 '~' 3.70000004768372),(Record A D 0 42 '~' 4.19999980926514),(Record A D 0 42 '%' 3.70000004768372),(Record A D 0 42 '%' 4.19999980926514),(Record A D 1 37 '~' 3.70000004768372),(Record A D 1 37 '~' 4.19999980926514),(Record A D 1 37 '%' 3.70000004768372),(Record A D 1 37 '%' 4.19999980926514),(Record A D 1 42 '~' 3.70000004768372),(Record A D 1 42 '~' 4.19999980926514),(Record A D 1 42 '%' 3.70000004768372),(Record A D 1 42 '%' 4.19999980926514),(Record B C 0 37 '~' 3.70000004768372),(Record B C 0 37 '~' 4.19999980926514),(Record B C 0 37 '%' 3.70000004768372),(Record B C 0 37 '%' 4.19999980926514),(Record B C 0 42 '~' 3.70000004768372),(Record B C 0 42 '~' 4.19999980926514),(Record B C 0 42 '%' 3.70000004768372),(Record B C 0 42 '%' 4.19999980926514),(Record B C 1 37 '~' 3.70000004768372),(Record B C 1 37 '~' 4.19999980926514),(Record B C 1 37 '%' 3.70000004768372),(Record B C 1 37 '%' 4.19999980926514),(Record B C 1 42 '~' 3.70000004768372),(Record B C 1 42 '~' 4.19999980926514),(Record B C 1 42 '%' 3.70000004768372),(Record B C 1 42 '%' 4.19999980926514),(Record B D 0 37 '~' 3.70000004768372),(Record B D 0 37 '~' 4.19999980926514),(Record B D 0 37 '%' 3.70000004768372),(Record B D 0 37 '%' 4.19999980926514),(Record B D 0 42 '~' 3.70000004768372),(Record B D 0 42 '~' 4.19999980926514),(Record B D 0 42 '%' 3.70000004768372),(Record B D 0 42 '%' 4.19999980926514),(Record B D 1 37 '~' 3.70000004768372),(Record B D 1 37 '~' 4.19999980926514),(Record B D 1 37 '%' 3.70000004768372),(Record B D 1 37 '%' 4.19999980926514),(Record B D 1 42 '~' 3.70000004768372),(Record B D 1 42 '~' 4.19999980926514),(Record B D 1 42 '%' 3.70000004768372),(Record B D 1 42 '%' 4.19999980926514)]
halt at 4
246524 277764 524288
245842 278446 524288
[(Record A C 0 37 '~' 3.7),(Record A C 0 37 '~' 4.2),(Record A C 0 37 '%' 3.7),(Record A C 0 37 '%' 4.2),(Record A C 0 42 '~' 3.7),(Record A C 0 42 '~' 4.2),(Record A C 0 42 '%' 3.7),(Record A C 0 42 '%' 4.2),(Record A C 1 37 '~' 3.7),(Record A C 1 37 '~' 4.2),(Record A C 1 37 '%' 3.7),(Record A C 1 37 '%' 4.2),(Record A C 1 42 '~' 3.7),(Record A C 1 42 '~' 4.2),(Record A C 1 42 '%' 3.7),(Record A C 1 42 '%' 4.2),(Record A D 0 37 '~' 3.7),(Record A D 0 37 '~' 4.2),(Record A D 0 37 '%' 3.7),(Record A D 0 37 '%' 4.2),(Record A D 0 42 '~' 3.7),(Record A D 0 42 '~' 4.2),(Record A D 0 42 '%' 3.7),(Record A D 0 42 '%' 4.2),(Record A D 1 37 '~' 3.7),(Record A D 1 37 '~' 4.2),(Record A D 1 37 '%' 3.7),(Record A D 1 37 '%' 4.2),(Record A D 1 42 '~' 3.7),(Record A D 1 42 '~' 4.2),(Record A D 1 42 '%' 3.7),(Record A D 1 42 '%' 4.2),(Record B C 0 37 '~' 3.7),(Record B C 0 37 '~' 4.2),(Record B C 0 37 '%' 3.7),(Record B C 0 37 '%' 4.2),(Record B C 0 42 '~' 3.7),(Record B C 0 42 '~' 4.2),(Record B C 0 42 '%' 3.7),(Record B C 0 42 '%' 4.2),(Record B C 1 37 '~' 3.7),(Record B C 1 37 '~' 4.2),(Record B C 1 37 '%' 3.7),(Record B C 1 37 '%' 4.2),(Record B C 1 42 '~' 3.7),(Record B C 1 42 '~' 4.2),(Record B C 1 42 '%' 3.7),(Record B C 1 42 '%' 4.2),(Record B D 0 37 '~' 3.7),(Record B D 0 37 '~' 4.2),(Record B D 0 37 '%' 3.7),(Record B D 0 37 '%' 4.2),(Record B D 0 42 '~' 3.7),(Record B D 0 42 '~' 4.2),(Record B D 0 42 '%' 3.7),(Record B D 0 42 '%' 4.2),(Record B D 1 37 '~' 3.7),(Record B D 1 37 '~' 4.2),(Record B D 1 37 '%' 3.7),(Record B D 1 37 '%' 4.2),(Record B D 1 42 '~' 3.7),(Record B D 1 42 '~' 4.2),(Record B D 1 42 '%' 3.7),(Record B D 1 42 '%' 4.2)]
halt at 4
259421 2723 262144
257686 4458 262144
(["","a0","%0","X0","a0a1","a0%1","a0X1","%0a2","%0%2","%0X2","X0a3","X0%3","X0X3","a0a1a4","a0a1%4","a0a1X4","a0%1a5","a0%1%5","a0%1X5","a0X1a6","a0X1%6","a0X1X6","%0a2a7","%0a2%7","%0a2X7","%0%2a8","%0%2%8","%0%2X8","%0X2a9"],[True,False,False,False,True,False,False,False,False,False,False,False,True,False,False,False,False,False,False,False,False,False,False,False,True,False,False,False,False,False],[True,False,True,True,False,True,False,False,True,True,False,True,True,False,True,False,False,True,True,False,True,False,False,True,False,False,True,True,False,True])
halt at 4
5273 519015 524288
4973 519315 524288
(["","a0","%0","X0","a0a1","a0%1","a0X1","%0a2","%0%2","%0X2","X0a3","X0%3","X0X3","a0a1a4","a0a1%4","a0a1X4","a0%1a5","a0%1%5","a0%1X5","a0X1a6","a0X1%6","a0X1X6","%0a2a7","%0a2%7","%0a2X7","%0%2a8","%0%2%8","%0%2X8","%0X2a9"],[True,False,False,False,True,False,False,False,False,False,False,False,True,False,False,False,False,False,False,False,False,False,False,False,True,False,False,False,False,False],[True,False,True,True,False,True,False,False,True,True,False,True,True,False,True,False,False,True,True,False,True,False,False,True,False,False,True,True,False,True])
halt at 4
5222 256922 262144
4922 257222 262144
......@@ -151,6 +151,7 @@ cycle_ptr :: Expr TWord
indirection_ptr :: Expr TWord
dNil_ptr :: Expr TWord
small_integer :: !(Expr TInt) -> Expr TWord
static_character :: !(Expr TChar) -> Expr TWord
caf_list :: Expr (TPtr (TPtr TWord))
push_c :: !(Expr TWord) !Target -> Target
......
......@@ -449,6 +449,9 @@ dNil_ptr = "(BC_WORD)&d___Nil[1]"
small_integer :: !(Expr TInt) -> Expr TWord
small_integer i = "(BC_WORD)(small_integers+2*"+-+i+-+")"
static_character :: !(Expr TChar) -> Expr TWord
static_character c = "(BC_WORD)(static_characters+2*"+-+c+-+")"
caf_list :: Expr (TPtr (TPtr TWord))
caf_list = "caf_list"
......
......@@ -152,6 +152,7 @@ cycle_ptr :: Expr TWord
indirection_ptr :: Expr TWord
dNil_ptr :: Expr TWord
small_integer :: !(Expr TInt) -> Expr TWord
static_character :: !(Expr TChar) -> Expr TWord
caf_list :: Expr (TPtr (TPtr TWord))
push_c :: !(Expr TWord) !Target -> Target
......
......@@ -774,7 +774,10 @@ dNil_ptr :: Expr TWord
dNil_ptr = Ei64_const ((141+1)*8)
small_integer :: !(Expr TInt) -> Expr TWord
small_integer i = Eadd (Ei64_const (8*31)) (Emul (Ei64_const 16) (cast_expr i))
small_integer i = Eadd (Ei64_const (8*31)) (Eshl (cast_expr i) (Ei64_const 4))
static_character :: !(Expr TChar) -> Expr TWord
static_character c = Eadd (Ei64_const (8*147)) (Eshl (cast_expr c) (Ei64_const 4))
caf_list :: Expr (TPtr (TPtr TWord))
caf_list = Ei64_const (97*8)
......
......@@ -208,19 +208,11 @@ all_instructions opts t = bootstrap $ collect_instructions opts $ map (\i -> i t
grow_a 1 :.
advance_ptr Hp 2
, instr "buildC" (Just 1) $
ensure_hp 2 :.
Hp @ 0 .= CHAR_ptr + lit_word 2 :.
Hp @ 1 .= Pc @ 1 :.
A @ 1 .= to_word Hp :.
grow_a 1 :.
advance_ptr Hp 2
A @ 1 .= static_character (to_char (Pc @ 1)) :.
grow_a 1
, instr "buildC_b" (Just 1) $
ensure_hp 2 :.
Hp @ 0 .= CHAR_ptr + lit_word 2 :.
Hp @ 1 .= B @ (Pc @ 1) :.
A @ 1 .= to_word Hp :.
grow_a 1 :.
advance_ptr Hp 2
A @ 1 .= static_character (to_char (B @ (Pc @ 1))) :.
grow_a 1
, instr "buildI" (Just 1) $
new_local TInt (to_int (Pc @ 1)) \i ->
if_then_else (lit_int 0 <=. i &&. i <=. lit_int 32)
......
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