Last active
June 16, 2019 16:24
-
-
Save fogti/cb287d286e3e7af14a3a1768a9aaf7dd to your computer and use it in GitHub Desktop.
Zscheile Extensible Programming Language
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
ZSXPL -- Zscheile Extensible Programming Language | |
Types: | |
ptr shared_ptr<obj> 0x00 | |
int int64_t 0x01 | |
uint uint64_t 0x02 | |
double double 0x03 | |
stream int32_t(_fd) 0x04 | |
string string 0x10 | |
stack vector 0x11 | |
hash-array unordered_map 0x12 | |
plugin shared_ptr<plg> 0x13 | |
plghandle shared_ptr<plgh> 0x14 | |
Argument decls: | |
they are 8bit values = (($adid << 6) + $n) with ($n < 64) | |
0x0 I:$ immediate int | |
0x1 C:$ const addr | |
0x2 R:$ register id | |
0x3 S:$ stack id | |
Conventions: | |
S:0 is defined to be argv at the beginning of .entry | |
is used as standard argument array | |
PLUGIN [$file = ""] is aliased to PLUGIN nullptr internally | |
Commands: | |
most binary commands follow the convention, | |
that the first argument is the target and the | |
second argument is the source. | |
SET/GET ops | |
0x00 SET $to $from | |
0x01 PUSH S:$to $from | |
0x02 POP S:$ (discards the top of the stack) | |
0x03 GET_ $to $from (*$from) | |
0x04 _SET $to $from (*$to) | |
0x05 _SET_ $to $from (*to, *from) | |
0x06 HAT2P $to $from $x (&$from[$x] --> pointer) | |
CONV/MONAD ops | |
0x10 STREAM $to $from | |
0x11 PLUGIN $to $file $modname | |
0x12 HANDLE $to $from $args | |
0x13 POINTER $to $from ($to = &$from : pointer) | |
0x14 EXPLODE $to $from $x (converts a string to a vector, with sep = $x (sep.empty --> every char)) | |
0x15 IMPLODE $to $from $x (converts a vector to a string) | |
0x16 NOT $to $from (converts $from to a truth value and inverts it) | |
CONTROL-FLOW ops | |
0x20 JMP $x (jumps to $x, with $x (should be an int) as an index into map) | |
0x21 CJMP $x $b (cjmp jumps to $x if $b evaluates to a truth value = true) | |
0x22 CALL $x (jumps to $x, pushes call stack) | |
0x23 RET $x (returns to calling function with return value $x) | |
File format: | |
[HEADER] | |
ZSXPLO'\0' | |
conptr = &CONSTS | |
mapptr = &MAP | |
[CONSTS] | |
(for each): TYPE(1b) LEN(8b) DATA(xLEN) | |
[MAP] | |
(for each): CONST_NAME_REF CODE_REF | |
[CODE] | |
... | |
Notes: | |
References to consts should refer to the exact location relative to the | |
beginning of the file, not an index. | |
Example: "hello world" ---- | |
[HEADER] | |
ZSXPLO'\0' | |
conptr = &CONSTS | |
mapptr = &MAP | |
[CONSTS] | |
string(6) ".entry" | |
string(12) "hello world\n" | |
[MAP] | |
0 &CODE | |
[CODE] | |
STREAM R:1 I:1 | |
WRITE R:1 C:1 | |
RET I:0 | |
---- | |
Example: "echox" ---- | |
[HEADER]... | |
[CONSTS] | |
string(6) ".entry" | |
string(9) "my_errmsg" | |
string(11) "handle_fail" | |
string(0) "" | |
string(5) "spawn" | |
string(3) ".L0" | |
[MAP] | |
0 &CODE+.entry | |
1 &CODE+my_errmsg | |
2 &CODE+handle_fail | |
5 &CODE+.L0 | |
[CODE] | |
my_errmsg: | |
; expect the error string in R:0 | |
... | |
handle_fail: | |
; expect the value to check in R:0 | |
; expect the potential error message in R:1 | |
CJMP I:5 R:0 | |
; ok, something failed | |
SET R:0 R:1 | |
CALL I:1 | |
RET I:1 | |
.L0: | |
; everything is ok | |
RET I:0 | |
.entry: | |
PLUGIN R:0 C:4 C:5 | |
CALL I:2 | |
RET I:0 | |
---- |
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
: ZSXPL_TYPE | |
0x00 POINTER | |
0x01 INT | |
0x02 UINT | |
0x03 DOUBLE | |
0x04 STREAM | |
0x0a STRING | |
0x0b STACK | |
0x0c HASHARR | |
0x0d PLUGIN | |
0x0e PLGHDL | |
: ZSXPL_ADCL | |
0 IMM_INT | |
1 CONST | |
2 REG | |
3 STACK | |
: ZSXPL_OP | |
; == SET/GET ops | |
0x00 SET $to $from | |
0x01 PUSH S:$to $from | |
0x02 POP S:$ ; discards the top of the stack | |
0x03 GET_ $to $from ; $to, *$from | |
0x04 _SET $to $from ; *$to, $from | |
0x05 _SET_ $to $from ; *$to, *$from | |
0x06 HAT2P $to $from $x ; &$from[$x] --> pointer | |
; == CONV/MONAD ops | |
0x10 STREAM $to $from | |
0x11 PLUGIN $to $file $modname | |
0x12 HANDLE $to $from $args | |
0x13 POINTER $to $from ; $to = &$from : pointer | |
0x14 EXPLODE $to $from $x ; converts a string to a vector, with sep = $x (sep.empty --> every char) | |
0x15 IMPLODE $to $from $x ; converts a vector to a string | |
0x16 NOT $to $from ; converts $from to a truth value and inverts it | |
; == CONTROL-FLOW ops | |
0x20 JMP $x ; jumps to $x, with $x (should be an int) as an index into map | |
0x21 CJMP $x $b ; cjmp jumps to $x if $b evaluates to a truth value = true | |
0x22 CALL $x ; jumps to $x, pushes call stack | |
0x23 RET $x ; returns to calling function with return value $x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment