-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
244 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello BaliJS!</title> | ||
</head> | ||
<body> | ||
<script> | ||
console.log("Hello Ferus!") | ||
console.warn("This is a warning") | ||
console.info("Very important information") | ||
console.error("Failed to send your very important data to Google") | ||
</script> | ||
<h1>Check your console, there must be a few log messages there :^)</h1> | ||
</body> | ||
</html> |
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,15 @@ | ||
import ferus_ipc/shared | ||
import bali/stdlib/console | ||
|
||
type | ||
JSExecPacket* = object | ||
name*: string | ||
kind: FerusMagic = feJSExec | ||
buffer*: string | ||
|
||
JSConsoleMessage* = object | ||
kind: FerusMagic = feJSConsoleMessage | ||
message*: string | ||
level*: ConsoleLevel | ||
|
||
export ConsoleLevel |
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,72 @@ | ||
import std/[logging, json, base64, net] | ||
import ferus_ipc/client/prelude | ||
import bali/grammar/prelude | ||
import bali/runtime/prelude | ||
import bali/stdlib/console | ||
import jsony | ||
import ../../components/shared/[nix, sugar] | ||
import ./ipc | ||
|
||
type | ||
JSProcess* = object | ||
ipc*: IPCClient | ||
parser*: Parser | ||
runtime*: Runtime | ||
|
||
proc initConsoleIPC*(js: var JSProcess) = | ||
var pJs = addr(js) | ||
|
||
attachConsoleDelegate( | ||
proc(level: ConsoleLevel, msg: string) = | ||
pJs[].ipc.send( | ||
JSConsoleMessage(message: msg, level: level) | ||
) | ||
) | ||
|
||
proc talk(js: var JSProcess, process: FerusProcess) = | ||
var count: cint | ||
|
||
discard nix.ioctl(js.ipc.socket.getFd().cint, nix.FIONREAD, addr count) | ||
|
||
if count < 1: | ||
return | ||
|
||
let | ||
data = js.ipc.receive() | ||
jdata = tryParseJson(data, JsonNode) | ||
|
||
if not *jdata: | ||
warn "Did not get any valid JSON data." | ||
warn data | ||
return | ||
|
||
let kind = (&jdata).getOrDefault("kind").getStr().magicFromStr() | ||
|
||
if not *kind: | ||
warn "No `kind` field inside JSON data provided." | ||
return | ||
|
||
case &kind | ||
of feJSExec: | ||
info "Executing JavaScript buffer" | ||
js.ipc.setState(Processing) | ||
let data = &tryParseJson(data, JSExecPacket) | ||
|
||
js.parser = newParser(data.buffer.decode()) | ||
js.runtime = newRuntime(data.name.decode(), js.parser.parse()) | ||
js.runtime.run() | ||
|
||
js.ipc.setState(Idling) | ||
else: | ||
discard | ||
|
||
proc jsProcessLogic*(client: var IPCClient, process: FerusProcess) {.inline.} = | ||
info "Entering JavaScript runtime process logic." | ||
var js = JSProcess(ipc: client) | ||
client.setState(Idling) | ||
client.poll() | ||
initConsoleIPC(js) | ||
setLogFilter(lvlNone) | ||
|
||
while true: | ||
js.talk(process) |
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
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
Oops, something went wrong.