-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add module: ModuleRemote - Add task: TKUI - Add window: Remote window
- Loading branch information
Showing
10 changed files
with
296 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/priv/bajdcc/LALR1/interpret/module/ModuleRemote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package priv.bajdcc.LALR1.interpret.module; | ||
|
||
import priv.bajdcc.LALR1.grammar.Grammar; | ||
import priv.bajdcc.LALR1.grammar.runtime.*; | ||
import priv.bajdcc.LALR1.ui.UIRemoteWindow; | ||
import priv.bajdcc.LALR1.ui.drawing.UIGraphics; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.concurrent.LinkedBlockingDeque; | ||
|
||
/** | ||
* 【模块】远程用户界面 | ||
* | ||
* @author bajdcc | ||
*/ | ||
public class ModuleRemote implements IInterpreterModule { | ||
|
||
private static ModuleRemote instance = new ModuleRemote(); | ||
private UIRemoteWindow remote; | ||
private UIGraphics graphics; | ||
private Queue<Character> queue = new LinkedBlockingDeque<>(1024); | ||
private Queue<Character> queueDisplay = new ArrayDeque<>(); | ||
private StringBuilder sb = new StringBuilder(); | ||
|
||
public void setGraphics() { | ||
if (remote == null) { | ||
remote = new UIRemoteWindow(); | ||
graphics = remote.getUIGraphics(); | ||
} | ||
} | ||
|
||
public void addInputChar(char c) { | ||
queue.add(c); | ||
} | ||
|
||
public void addDisplayChar(char c) { | ||
queueDisplay.add(c); | ||
} | ||
|
||
public static ModuleRemote getInstance() { | ||
return instance; | ||
} | ||
|
||
@Override | ||
public String getModuleName() { | ||
return "sys.remote"; | ||
} | ||
|
||
@Override | ||
public RuntimeCodePage getCodePage() throws Exception { | ||
String base = "import \"sys.base\";\n" + | ||
"import \"sys.list\";\n" + | ||
"import \"sys.proc\";\n" + | ||
"import \"sys.string\";\n" + | ||
"var g_remote_print = func ~(str) {\n" + | ||
" var remote_int = call g_create_pipe(\"int#0\");\n" + | ||
" foreach (var c : call g_range_string(str)) {\n" + | ||
" call g_write_pipe(remote_int, c);\n" + | ||
" }\n" + | ||
"};\n" + | ||
"export \"g_remote_print\";\n" + | ||
"var g_remote_printn = func ~(str) {\n" + | ||
" call g_remote_print(str);\n" + | ||
" call g_remote_println();\n" + | ||
"};\n" + | ||
"export \"g_remote_printn\";\n" + | ||
"var g_remote_println = func ~() {\n" + | ||
" call g_remote_print(g_endl);\n" + | ||
"};\n" + | ||
"export \"g_remote_println\";\n" + | ||
"call g_remote_init();\n" + | ||
"\n"; | ||
|
||
Grammar grammar = new Grammar(base); | ||
RuntimeCodePage page = grammar.getCodePage(); | ||
IRuntimeDebugInfo info = page.getInfo(); | ||
buildRemoteMethods(info); | ||
|
||
return page; | ||
} | ||
|
||
private void buildRemoteMethods(IRuntimeDebugInfo info) { | ||
info.addExternalFunc("g_remote_init", new IRuntimeDebugExec() { | ||
@Override | ||
public String getDoc() { | ||
return "显示初始化"; | ||
} | ||
|
||
@Override | ||
public RuntimeObjectType[] getArgsType() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public RuntimeObject ExternalProcCall(List<RuntimeObject> args, | ||
IRuntimeStatus status) throws Exception { | ||
if (graphics == null) | ||
setGraphics(); | ||
return null; | ||
} | ||
}); | ||
info.addExternalFunc("g_remote_print_internal", new IRuntimeDebugExec() { | ||
@Override | ||
public String getDoc() { | ||
return "显示输出"; | ||
} | ||
|
||
@Override | ||
public RuntimeObjectType[] getArgsType() { | ||
return new RuntimeObjectType[]{RuntimeObjectType.kChar}; | ||
} | ||
|
||
@Override | ||
public RuntimeObject ExternalProcCall(List<RuntimeObject> args, | ||
IRuntimeStatus status) throws Exception { | ||
graphics.drawText((char) args.get(0).getObj()); | ||
return null; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package priv.bajdcc.LALR1.interpret.os.task; | ||
|
||
import priv.bajdcc.LALR1.interpret.os.IOSCodePage; | ||
|
||
/** | ||
* 【服务】用户界面 | ||
* | ||
* @author bajdcc | ||
*/ | ||
public class TKUI implements IOSCodePage { | ||
@Override | ||
public String getName() { | ||
return "/task/ui"; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return "import \"sys.base\";\n" + | ||
"import \"sys.list\";\n" + | ||
"import \"sys.proc\";\n" + | ||
"import \"sys.task\";\n" + | ||
"import \"sys.remote\";\n" + | ||
"\n" + | ||
"call g_set_process_desc(\"ui service\");\n" + | ||
"call g_set_process_priority(74);\n" + | ||
"\n" + | ||
"var tid = 3;\n" + | ||
"var handle = call g_create_pipe(\"TASKSEND#\" + tid);\n" + | ||
"\n" + | ||
"var time = func ~(msg, caller) {\n" + | ||
" var id = call g_map_get(msg, \"id\");\n" + | ||
" if (call g_is_null(id)) {\n" + | ||
" call g_map_put(msg, \"error\", 1);\n" + | ||
" call g_map_put(msg, \"val\", \"invalid task argument - id\");\n" + | ||
" return;\n" + | ||
" }\n" + | ||
" if (id == \"print\") {\n" + | ||
" var arg = call g_map_get(msg, \"arg\");\n" + | ||
" var str = \"\";\n" + | ||
" var len = call g_array_size(arg);\n" + | ||
" foreach (var i : call g_range(2, len - 1)) {\n" + | ||
" let str = str + call g_array_get(arg, i);\n" + | ||
" }\n" + | ||
" call g_remote_print(str);\n" + | ||
" call g_map_put(msg, \"val\", str);\n" + | ||
" }" + | ||
"};\n" + | ||
"\n" + | ||
"var handler = func ~(ch) {\n" + | ||
" if (ch == 'E') {\n" + | ||
" call g_destroy_pipe(handle);\n" + | ||
" return;\n" + | ||
" }\n" + | ||
" var msg = call g_query_share(\"TASKDATA#\" + tid);\n" + | ||
" var caller = call g_query_share(\"TASKCALLER#\" + tid);\n" + | ||
" call time(msg, caller);\n" + | ||
" var handle = call g_create_pipe(\"TASKRECV#\" + tid);\n" + | ||
" var f = func ~(ch) {\n" + | ||
" if (ch == 'E') { call g_destroy_pipe(handle); }" + | ||
" };\n" + | ||
" call g_read_pipe(handle, f);\n" + | ||
"};\n" + | ||
"\n" + | ||
"var data = {};\n" + | ||
"call g_task_add_proc(3, data);\n" + | ||
"\n" + | ||
"call g_read_pipe(handle, handler);\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package priv.bajdcc.LALR1.ui; | ||
|
||
import priv.bajdcc.LALR1.ui.drawing.UIGraphics; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
|
||
/** | ||
* 【界面】远程渲染界面 | ||
* | ||
* @author bajdcc | ||
*/ | ||
public class UIRemotePanel extends JPanel { | ||
|
||
private UIGraphics graphics; | ||
|
||
public UIRemotePanel() { | ||
this.graphics = new UIGraphics(800, 600, 70, 23, 11, 25, 1); | ||
this.setFocusable(true); | ||
} | ||
|
||
public UIGraphics getUIGraphics() { | ||
return graphics; | ||
} | ||
|
||
public void paint(Graphics g) { | ||
graphics.paint((Graphics2D) g); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package priv.bajdcc.LALR1.ui; | ||
|
||
import priv.bajdcc.LALR1.ui.drawing.UIGraphics; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.WindowEvent; | ||
|
||
/** | ||
* 【界面】远程用户界面 | ||
* | ||
* @author bajdcc | ||
*/ | ||
public class UIRemoteWindow extends JFrame { | ||
private UIRemotePanel panel; | ||
|
||
public UIRemotePanel getPanel() { | ||
return panel; | ||
} | ||
|
||
public UIRemoteWindow() { | ||
panel = new UIRemotePanel(); | ||
this.setTitle("jMiniOS Remote Window"); | ||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); | ||
this.setPreferredSize(new Dimension(800, 600)); | ||
this.setContentPane(panel); | ||
this.pack(); | ||
this.setLocationRelativeTo(null); | ||
this.setResizable(false); | ||
this.setVisible(true); | ||
this.setTimer(); | ||
} | ||
|
||
private void close() { | ||
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); | ||
} | ||
|
||
public UIGraphics getUIGraphics() { | ||
return this.panel.getUIGraphics(); | ||
} | ||
|
||
private void setTimer() { | ||
new Timer(33, e -> { | ||
panel.repaint(); | ||
}).start(); | ||
} | ||
} |