Skip to content

Commit

Permalink
implement read str operation
Browse files Browse the repository at this point in the history
  • Loading branch information
SPY committed Jun 2, 2018
1 parent 99b0b3d commit e36e76d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 5 additions & 0 deletions rts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
console.log(loadString(strAddr))
return makeInt(0)
}

function strRead() {
return makeString(prompt('Idris requires input:'))
}

function getCharWidth(code) {
if (code < 0x80) {
Expand Down Expand Up @@ -355,6 +359,7 @@
raiseError,
gc,
strWrite,
strRead,
strDouble,
doubleStr,
printVal,
Expand Down
18 changes: 7 additions & 11 deletions src/IRTS/CodegenWasm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mkWasm defs stackSize heapSize =
-- gc <- importFunction "rts" "gc" () [I32]
raiseError <- importFunction "rts" "raiseError" () [I32]
strWrite <- importFunction "rts" "strWrite" i32 [I32]
strRead <- importFunction "rts" "strRead" i32 []
printVal <- importFunction "rts" "printVal" () [I32]
strDouble <- importFunction "rts" "strDouble" i32 [I32]
doubleStr <- importFunction "rts" "doubleStr" i32 [I32]
Expand Down Expand Up @@ -433,6 +434,7 @@ mkWasm defs stackSize heapSize =
strSubstrFn = strSubstr,
strRevFn = strRev,
strWriteFn = strWrite,
strReadFn = strRead,
strIntFn = strInt,
intStrFn = intStr,
strDoubleFn = strDouble,
Expand Down Expand Up @@ -498,6 +500,7 @@ data GlobalBindings = GB {
strSubstrFn :: Fn (Proxy I32),
strRevFn :: Fn (Proxy I32),
strWriteFn :: Fn (Proxy I32),
strReadFn :: Fn (Proxy I32),
strIntFn :: Fn (Proxy I32),
strDoubleFn :: Fn (Proxy I32),
doubleStrFn :: Fn (Proxy I32),
Expand Down Expand Up @@ -714,34 +717,24 @@ genReserve n = do
(forM_ [0..n-1] $ \i -> store stackTop (i32c 0) (i * 4) 2)

{-
Left to implement:
data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
| LUDiv IntTy | LSDiv ArithTy | LURem IntTy | LSRem ArithTy
| LAnd IntTy | LOr IntTy | LXOr IntTy | LCompl IntTy
| LSHL IntTy | LLSHR IntTy | LASHR IntTy
| LEq ArithTy | LLt IntTy | LLe IntTy | LGt IntTy | LGe IntTy
| LSLt ArithTy | LSLe ArithTy | LSGt ArithTy | LSGe ArithTy
| LSExt IntTy IntTy | LZExt IntTy IntTy | LTrunc IntTy IntTy
| LStrConcat | LStrLt | LStrEq | LStrLen
| LIntFloat IntTy | LFloatInt IntTy | LIntStr IntTy | LStrInt IntTy
| LFloatStr | LStrFloat | LChInt IntTy | LIntCh IntTy
| LBitCast ArithTy ArithTy -- Only for values of equal width
| LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
| LFATan2 | LFSqrt | LFFloor | LFCeil | LFNegate
| LStrHead | LStrTail | LStrCons | LStrIndex | LStrRev | LStrSubstr
| LReadStr | LWriteStr
-- system info
| LSystemInfo
| LFork
| LPar -- evaluate argument anywhere, possibly on another
-- core or another machine. 'id' is a valid implementation
| LExternal Name
| LCrash
| LNoOp
-}
-- data NativeTy = IT8 | IT16 | IT32 | IT64
-- data IntTy = ITFixed NativeTy | ITNative | ITBig | ITChar
Expand Down Expand Up @@ -1010,6 +1003,9 @@ makeOp loc LWriteStr [_, reg] = do
str <- getRegVal reg
strWrite <- asks strWriteFn
setRegVal loc $ call strWrite [str]
makeOp loc LReadStr [_] = do
strRead <- asks strReadFn
setRegVal loc $ call strRead []

makeOp loc LCrash [reg] = do
str <- getRegVal reg
Expand Down

0 comments on commit e36e76d

Please sign in to comment.