Skip to content

Commit 6ea3c2d

Browse files
committed
Intermediate
1 parent 5d7fc22 commit 6ea3c2d

File tree

7 files changed

+271
-255
lines changed

7 files changed

+271
-255
lines changed

YukimiScript.CodeGen.Lua/Lua.fs

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,49 @@
11
module YukimiScript.CodeGen.Lua
22

33
open YukimiScript.Parser
4-
open YukimiScript.Parser.Dom
54
open YukimiScript.Parser.Elements
65

76

8-
let generateLua (x: Dom) : string =
7+
let generateLua (Intermediate scenes) : string =
98
let luaCall (x: string) =
109
let i = x.LastIndexOf '.'
1110
x.[..i-1] + ":" + x.[i+1..]
1211

1312
let sb = System.Text.StringBuilder ()
14-
sb.Append("return function(api) return {") |> ignore
13+
sb.AppendLine("return function(api) return {") |> ignore
1514

16-
x.Scenes
17-
|> List.iter (fun (defination, block, debugInfo) ->
15+
scenes
16+
|> List.iter (fun (IntermediateScene (defination, commands)) ->
1817
sb .Append(" [\"")
1918
.Append(Constants.string2literal defination.Name)
2019
.Append("\"] = {") |> ignore
2120

22-
if debugInfo.Comment.IsSome then
23-
sb .Append(" -- ")
24-
.Append(debugInfo.Comment.Value) |> ignore
25-
2621
sb.AppendLine() |> ignore
2722

28-
block
29-
|> List.iter (fun (op, debugInfo) ->
30-
match op with
31-
| EmptyLine -> ()
32-
| CommandCall c ->
33-
sb .Append(" function() ")
34-
.Append(luaCall <| "api." + c.Callee)
35-
.Append("(") |> ignore
36-
37-
let args =
38-
c.UnnamedArgs
39-
|> List.map (function
40-
| Symbol "true" -> "true"
41-
| Symbol "false" -> "false"
42-
| Symbol "null" | Symbol "nil" -> "nil"
43-
| Symbol x -> luaCall <| "api." + x
44-
| Integer x -> string x
45-
| Number x -> string x
46-
| String x -> "\"" + Constants.string2literal x + "\"")
47-
48-
if not <| List.isEmpty args then
49-
args
50-
|> List.reduce (fun a b -> a + ", " + b)
51-
|> sb.Append
52-
|> ignore
53-
54-
sb.Append(") end,") |> ignore
55-
56-
| _ -> failwith "This construction is not supported."
57-
58-
if debugInfo.Comment.IsSome then
59-
sb.Append(" -- ").Append(debugInfo.Comment.Value) |> ignore
23+
commands
24+
|> List.iter (fun c ->
25+
sb .Append(" function() ")
26+
.Append(luaCall <| "api." + c.Callee)
27+
.Append("(") |> ignore
28+
29+
let args =
30+
c.UnnamedArgs
31+
|> List.map (function
32+
| Symbol "true" -> "true"
33+
| Symbol "false" -> "false"
34+
| Symbol "null" | Symbol "nil" -> "nil"
35+
| Symbol x -> "api." + x
36+
| Integer x -> string x
37+
| Number x -> string x
38+
| String x -> "\"" + Constants.string2literal x + "\"")
39+
40+
if not <| List.isEmpty args then
41+
args
42+
|> List.reduce (fun a b -> a + ", " + b)
43+
|> sb.Append
44+
|> ignore
45+
46+
sb.Append(") end,") |> ignore
6047

6148
sb.AppendLine() |> ignore
6249
)

YukimiScript.CommandLineTool/Compile.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let private findRepeat (items: (string * Elements.DebugInformation) seq) =
4343
else Some (key, matches |> Seq.map snd))
4444

4545

46-
let checkRepeat errStringing (dom: Dom.Dom) =
46+
let checkRepeat errStringing (dom: Dom) =
4747
dom.Externs
4848
|> Seq.map (fun (Elements.ExternCommand (cmd, _), dbg) -> cmd, dbg)
4949
|> findRepeat
@@ -108,7 +108,7 @@ let loadLibs errStringing libPaths =
108108
|> List.fold Dom.merge Dom.empty
109109

110110

111-
let loadSrc errStringing (lib: Dom.Dom) srcPath =
111+
let loadSrc errStringing (lib: Dom) srcPath =
112112
Dom.merge lib (loadDom errStringing srcPath)
113113
|> Dom.expandTextCommands
114114
|> Dom.expandUserMacros

YukimiScript.CommandLineTool/Program.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ let doAction errStringing =
101101
targets
102102
|> List.iter (function
103103
| Lua output ->
104-
let functionName = Path.GetFileNameWithoutExtension inputFile
105-
let lua = YukimiScript.CodeGen.Lua.generateLua dom
104+
let lua = YukimiScript.CodeGen.Lua.generateLua <| Intermediate.ofDom dom
106105
File.WriteAllText(output, lua, Text.Encoding.UTF8))
107106

108107
| Dgml (inputDir, outDgml, options) ->

YukimiScript.Parser/Diagram.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module YukimiScript.Parser.Diagram
22

33
open YukimiScript.Parser.Elements
4-
open YukimiScript.Parser.Dom
54
open YukimiScript.Parser.Macro
65
open System.IO
76

0 commit comments

Comments
 (0)