aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/elymasAsm.ey9
-rw-r--r--compiler/elymasGlobalSys.ey30
-rw-r--r--elymas/lib/sys/opt.ey70
3 files changed, 109 insertions, 0 deletions
diff --git a/compiler/elymasAsm.ey b/compiler/elymasAsm.ey
index dcd5797..a27f34e 100644
--- a/compiler/elymasAsm.ey
+++ b/compiler/elymasAsm.ey
@@ -531,6 +531,15 @@
/two reg modrm11
} /callqReg deff
+ memoryAddressingVariants keys { ==variant memoryAddressingVariants variant . =*parse
+ { parse ==mem
+ mem .base regno %07 gt mem .idx regno %07 gt or
+ { 0 /none mem .idx mem .base rex } rep
+ %FF
+ /two mem .encode
+ } /callq variant defOp
+ } each
+
{
%FC
} /cld deff
diff --git a/compiler/elymasGlobalSys.ey b/compiler/elymasGlobalSys.ey
index 1f95e0b..912d5c0 100644
--- a/compiler/elymasGlobalSys.ey
+++ b/compiler/elymasGlobalSys.ey
@@ -81,6 +81,36 @@
8 /r15 :addqImm8Reg
:retn
]] /eyresolveInfo defv
+
+ # return information about the captured scope of a function
+ # 0 -> function object
+ # 0 <- any scope captured
+ # 1 <- if any scope was caputered, that scope
+ [[
+ 8 /r15 :subqImm8Reg
+ /r15 :popqMem
+
+ /rsi :popqReg
+ 8 /rsi /rsi :movqMemDisp8Reg
+ /rsi /rsi :testqRegReg
+ /noScopeCaptured :jzLbl8
+
+ /rsi :pushqReg # push scope
+ 1 /rax :movqImmReg
+ 63 /rax :btsqImm8Reg
+ /rax :pushqReg
+
+ /done :jmpLbl8
+
+ @noScopeCaptured
+ 63 /rsi :btsqImm8Reg
+ /rsi :pushqReg
+
+ @done
+ /r15 :pushqMem
+ 8 /r15 :addqImm8Reg
+ :retn
+ ]] /eycapturedScope defv
> _ ==globalFunctions { defv }' ::allocateOffsetStruct
[
diff --git a/elymas/lib/sys/opt.ey b/elymas/lib/sys/opt.ey
index b82156f..4afda2e 100644
--- a/elymas/lib/sys/opt.ey
+++ b/elymas/lib/sys/opt.ey
@@ -127,6 +127,8 @@
/STATICWRITE ==:STATICWRITE
/STATICDOT ==:STATICDOT
/NATIVE ==:NATIVE
+ /UNTYPEDSCOPEDSTAR ==:UNTYPEDSCOPEDSTAR
+ /UNTYPEDUNSCOPEDSTAR ==:UNTYPEDUNSCOPEDSTAR
{ =*f ==t
t { f } { 0 } ? *
@@ -241,6 +243,50 @@
} each
} /rewriteConstantDot deffst
+ { _ ==logic
+ 1 logic len range { ==i i logic * ==entry 0 entry * ==action i 1 sub logic * ==last
+ [
+ { action CALL streq
+ { 1 entry * "*" | +rawCodeAddress eq }' andif
+ { 0 last * STATICTYPED streq }' andif
+ }' {
+ 4 last * +rawObject ==executedObject
+ executedObject sys .typed .type ==type
+
+ type [
+ { "failed to optimize 'execution' of integer typed object" die }
+ { } # TODO string case
+ { "failed to optimize 'execution' of scope typed object" die }
+ { "failed to optimize 'execution' of name table" die }
+ { "failed to optimize 'execution' of extension area" die }
+ {
+ # TODO think about handling typed functions
+ executedObject sys .typed .inputs len { } {
+ # handle untyped function
+ executedObject sys .capturedScope {
+ -- # ignore concrete scope
+ [ UNTYPEDSCOPEDSTAR ] i logic =[]
+ } {
+ [ UNTYPEDUNSCOPEDSTAR ] i logic =[]
+ } ? *
+ } ? *
+ }
+ { "failed to optimize 'execution' of raw function opcodes object" die }
+ { } # TODO array code
+ { "failed to optimize 'execution' of function type descriptor" die }
+ { "objects of type 09 should not appear" die }
+ { "objects of type 10 should not appear" die }
+ { "objects of type 11 should not appear" die }
+ { "objects of type 12 should not appear" die }
+ { "objects of type 13 should not appear" die }
+ { "objects of type 14 should not appear" die }
+ { "objects of type 15 should not appear" die }
+ ] * *
+ }
+ ] conds
+ } each
+ } /rewriteConstantStar deffst
+
{ ==logic
[ NOP ] ==last
[ logic { ==entry 0 entry * ==action
@@ -480,6 +526,7 @@
containsScopeModifications not |rewriteConstantPipe rep
containsScopeModifications not |rewriteConstantEquals rep
containsScopeModifications not |rewriteConstantDot rep
+ containsScopeModifications not |rewriteConstantStar rep
rewriteStackOps
{ =*entry 0 entry ==action
[
@@ -588,6 +635,29 @@
] emitOpcodes
}
+ { action UNTYPEDSCOPEDSTAR streq }' {
+ [
+ /rax :popqReg
+ 8 /r15 :subqImm8Reg
+ /r14 /r15 :movqRegMem
+ 8 /rax /r14 :movqMemDisp8Reg
+ 24 /rax /rax :movqMemDisp8Reg
+ 16 /rax :addqImm8Reg
+ /rax :callqReg
+ /r15 /r14 :movqMemReg
+ 8 /r15 :addqImm8Reg
+ ] emitOpcodes
+ }
+
+ { action UNTYPEDUNSCOPEDSTAR streq }' {
+ [
+ /rax :popqReg
+ 24 /rax /rax :movqMemDisp8Reg
+ 16 /rax :addqImm8Reg
+ /rax :callqReg
+ ] emitOpcodes
+ }
+
{ action NATIVE streq }' {
1 entry emitOpcodes
}