Commit 52e44f31 authored by Camil Staps's avatar Camil Staps 🚀

Add wasm stubs for file I/O instructions

parent 4b663a9e
Pipeline #29155 failed with stages
in 7 minutes and 12 seconds
......@@ -16,11 +16,12 @@ enum section_type {
ST_Start
};
#define _2chars2int(a,b) ((uint64_t) (a+(b<<8)))
#define _3chars2int(a,b,c) ((uint64_t) (a+(b<<8)+(c<<16)))
#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 prelinker_preamble[664] = {
uint64_t prelinker_preamble[669] = {
/* 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'),
......@@ -66,6 +67,8 @@ uint64_t prelinker_preamble[664] = {
/* 660 static booleans */
10*8+2,0, 10*8+2,1,
/* 664 */
258, 2, _2chars2int('i','i'), 4, _4chars2int('F','I','L','E'),
/* 669 */
};
void prepare_preamble(void) {
......
#pragma once
extern uint64_t prelinker_preamble[664];
extern uint64_t prelinker_preamble[669];
definition module specialized
import target
instr_halt :: !Target -> Target
instr_divLU :: !Target -> Target
instr_mulUUL :: !Target -> Target
instr_RtoAC :: !Target -> Target
instr_closeF :: !Target -> Target
instr_endF :: !Target -> Target
instr_errorF :: !Target -> Target
instr_flushF :: !Target -> Target
instr_openF :: !Target -> Target
instr_positionF :: !Target -> Target
instr_readFC :: !Target -> Target
instr_readFI :: !Target -> Target
instr_readFR :: !Target -> Target
instr_readFS :: !Target -> Target
instr_readLineF :: !Target -> Target
instr_seekF :: !Target -> Target
instr_stderrF :: !Target -> Target
instr_stdioF :: !Target -> Target
instr_writeFC :: !Target -> Target
instr_writeFI :: !Target -> Target
instr_writeFR :: !Target -> Target
instr_writeFS :: !Target -> Target
instr_writeFString :: !Target -> Target
implementation module specialized
import target
import wasm
instr_halt :: !Target -> Target
instr_halt t = (
append (Ecall "clean_halt" [expr_to_ex Pc, expr_to_ex Hp_free, Eget (Global "g-hp-size")]) :.
append (Ereturn (Econst I32 0))
) t
instr_divLU :: !Target -> Target
instr_divLU t = instr_unimplemented t // TODO
instr_mulUUL :: !Target -> Target
instr_mulUUL t = instr_unimplemented t // TODO
instr_RtoAC :: !Target -> Target
instr_RtoAC t = (
new_local TReal (to_real (B @ 0)) \r ->
new_local TPtrOffset (ex_to_expr (Ecall "clean_RtoAC_words_needed" [expr_to_ex r])) \lw ->
ensure_hp lw :.
A @ 1 .= to_word Hp :.
Hp .= (ex_to_expr (Ecall "clean_RtoAC" [expr_to_ex Hp,expr_to_ex r]) ::: TPtr TWord) :.
advance_ptr Pc 1 :.
advance_ptr A 1 :.
advance_ptr B 1
) t
instr_closeF :: !Target -> Target
instr_closeF t = instr_unimplemented t
instr_endF :: !Target -> Target
instr_endF t = instr_unimplemented t
instr_errorF :: !Target -> Target
instr_errorF t = instr_unimplemented t
instr_flushF :: !Target -> Target
instr_flushF t = instr_unimplemented t
instr_openF :: !Target -> Target
instr_openF t = instr_unimplemented t
instr_positionF :: !Target -> Target
instr_positionF t = instr_unimplemented t
instr_readFC :: !Target -> Target
instr_readFC t = instr_unimplemented t
instr_readFI :: !Target -> Target
instr_readFI t = instr_unimplemented t
instr_readFR :: !Target -> Target
instr_readFR t = instr_unimplemented t
instr_readFS :: !Target -> Target
instr_readFS t = instr_unimplemented t
instr_readLineF :: !Target -> Target
instr_readLineF t = instr_unimplemented t
instr_seekF :: !Target -> Target
instr_seekF t = instr_unimplemented t
instr_stderrF :: !Target -> Target
instr_stderrF t = instr_unimplemented t
instr_stdioF :: !Target -> Target
instr_stdioF t = instr_unimplemented t
instr_writeFC :: !Target -> Target
instr_writeFC t = instr_unimplemented t
instr_writeFI :: !Target -> Target
instr_writeFI t = instr_unimplemented t
instr_writeFR :: !Target -> Target
instr_writeFR t = instr_unimplemented t
instr_writeFS :: !Target -> Target
instr_writeFS t = instr_unimplemented t
instr_writeFString :: !Target -> Target
instr_writeFString t = instr_unimplemented t
......@@ -3,24 +3,32 @@ definition module target
import StdEnv
import StdMaybe
import interpretergen
from wasm import :: Type
from wasm import :: Type, :: Ex
class wasm_type a :: !a -> Type
instance wasm_type TWord, TPtrOffset, TBool, TChar, TShort, TInt, TReal, (TPtr t)
:: Target
:: TempVars
:: Target =
{ stmts :: ![Ex]
, instrs :: ![String]
, temp_vars :: !TempVars
}
append e t :== {t & stmts=[e:t.stmts]}
:: Expr t
cast_expr :: !(Expr t) -> Expr u
expr_to_ex :: !(Expr t) -> Ex
ex_to_expr :: !Ex -> Expr t
start :: Target
bootstrap :: ![String] -> [String]
collect_instructions :: !Options ![Target] -> [String]
instr_unimplemented :: !Target -> Target
instr_halt :: !Target -> Target
instr_divLU :: !Target -> Target
instr_mulUUL :: !Target -> Target
instr_RtoAC :: !Target -> Target
lit_word :: !Int -> Expr TWord
lit_hword :: !Int -> Expr TPtrOffset
......@@ -138,6 +146,7 @@ A :: Expr (TPtr TWord)
B :: Expr (TPtr TWord)
Pc :: Expr (TPtr TWord)
Hp :: Expr (TPtr TWord)
Hp_free :: Expr TPtrOffset
BOOL_ptr :: Expr TWord
CHAR_ptr :: Expr TWord
......@@ -145,6 +154,7 @@ INT_ptr :: Expr TWord
REAL_ptr :: Expr TWord
ARRAY__ptr :: Expr TWord
STRING__ptr :: Expr TWord
FILE_ptr :: Expr TWord
jmp_ap_ptr :: !Int -> Expr (TPtr TWord)
cycle_ptr :: Expr TWord
indirection_ptr :: Expr TWord
......
......@@ -51,12 +51,6 @@ where
, tv_f64 :: !Int
}
:: Target =
{ stmts :: ![Ex]
, instrs :: ![String]
, temp_vars :: !TempVars
}
start :: Target
start =
{ instrs = []
......@@ -64,8 +58,6 @@ start =
, temp_vars = {tv_i32=0,tv_i64=0,tv_f64=0}
}
append e t :== {t & stmts=[e:t.stmts]}
new_temp_var :: !Type !Target -> (!Variable, !Target)
new_temp_var tp t
# tp = case tp of
......@@ -88,8 +80,17 @@ f64_temp_vars =: {#{#'v','d',i} \\ i <- ['0'..'0']}
:: Expr t :== Ex
cast_expr :: !Ex -> Ex
cast_expr e = e
cast_expr :: !(Expr t) -> Expr u
cast_expr e = cast e
where
cast :: !Ex -> Ex
cast e = e
expr_to_ex :: !(Expr t) -> Ex
expr_to_ex e = e
ex_to_expr :: !Ex -> Expr t
ex_to_expr e = e
bootstrap :: ![String] -> [String]
bootstrap instrs = instrs
......@@ -298,30 +299,6 @@ where
fix_type :: !t !(Expr t) -> Expr t
fix_type _ e = e
instr_halt :: !Target -> Target
instr_halt t = (
append (Ecall "clean_halt" [cast_expr Pc, Hp_free, Eget (Global "g-hp-size")]) :.
append (Ereturn (Econst I32 0))
) t
instr_divLU :: !Target -> Target
instr_divLU t = instr_unimplemented t // TODO
instr_mulUUL :: !Target -> Target
instr_mulUUL t = instr_unimplemented t // TODO
instr_RtoAC :: !Target -> Target
instr_RtoAC t = (
new_local TReal (to_real (B @ 0)) \r ->
new_local TPtrOffset (Ecall "clean_RtoAC_words_needed" [r]) \lw ->
ensure_hp lw :.
A @ 1 .= to_word Hp :.
Hp .= (Ecall "clean_RtoAC" [Hp,r] ::: TPtr TWord) :.
advance_ptr Pc 1 :.
advance_ptr A 1 :.
advance_ptr B 1
) t
lit_word :: !Int -> Expr TWord
lit_word w = Econst I64 w
......@@ -707,6 +684,9 @@ ARRAY__ptr = Econst I64 (0*8)
STRING__ptr :: Expr TWord
STRING__ptr = Econst I64 (5*8)
FILE_ptr :: Expr TWord
FILE_ptr = Econst I64 (664*8)
jmp_ap_ptr :: !Int -> Expr (TPtr TWord)
jmp_ap_ptr i = Econst I32 ((98+i)*8)
......
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