-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLibCompiler.hs
More file actions
32 lines (26 loc) · 810 Bytes
/
Copy pathLibCompiler.hs
File metadata and controls
32 lines (26 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
module LibCompiler where
import Data.Maybe
import Foreign.C.Types
import qualified Data.ByteString as BS
import Text.Trifecta (parseByteString, Result(..))
import Scripting.Lua
import Scripting.Lua.Raw
import Parser2
import CodeGenerator
foreign export ccall
compile :: LuaState -> IO CInt
filename :: BS.ByteString
filename = "/tmp/scheme2luac.luac"
compile :: LuaState -> IO CInt
compile l = do
-- putStrLn "compiling" -- for debugging
str :: BS.ByteString <- fromJust `fmap` peek l 1
-- print str -- for debugging
let tree = parseByteString parProgram mempty str
let luafunc = fmap evalWrapper tree
case luafunc of
Success x -> writeLuaFunc "/tmp/scheme2luac.luac" (Just x)
Failure _ -> return ()
push l filename
return 1