aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/elymasAsmOps.ey13
-rw-r--r--compiler/elymasGlobal.ey37
-rw-r--r--elymas/lib/sys/opt.ey2
3 files changed, 44 insertions, 8 deletions
diff --git a/compiler/elymasAsmOps.ey b/compiler/elymasAsmOps.ey
index d397f73..c029670 100644
--- a/compiler/elymasAsmOps.ey
+++ b/compiler/elymasAsmOps.ey
@@ -999,6 +999,19 @@ memoryAddressingVariants keys { ==variant memoryAddressingVariants variant . =*p
i imm16
} /movwImmMem deff
+{ ==mem ==disp ==i
+ mem bit64assert
+ disp 128 lt not { "Disp8 out of range" die } rep
+ i 65536 lt not { "Imm16 too large" die } rep
+
+ width16
+ mem regno %07 gt { 0 /none /none mem rex } rep
+ %C7
+ /zero mem modrm01
+ disp imm8
+ i imm16
+} /movwImmMemDisp8 deff
+
{ ==mem ==i
mem bit64assert
i 65536 65536 mul lt not { "Imm32 too large" die } rep
diff --git a/compiler/elymasGlobal.ey b/compiler/elymasGlobal.ey
index 2b7f2c1..a948b53 100644
--- a/compiler/elymasGlobal.ey
+++ b/compiler/elymasGlobal.ey
@@ -2833,6 +2833,35 @@
]] /ey! defv
> _ ==globalFunctions3 { defv }' ::allocateOffsetStruct
+ [[
+ # the length of the following opcodes needs to fit with the :jmpRel8 below
+ %48 16 /rdi :cmpbImmMemDisp8
+ /nonReplaced :jnzLbl8
+ %B8 17 /rdi :cmpbImmMemDisp8
+ /nonReplaced :jnzLbl8
+ %FF 26 /rdi :cmpbImmMemDisp8
+ /nonReplaced :jnzLbl8
+ %E0 27 /rdi :cmpbImmMemDisp8
+ /nonReplaced :jnzLbl8
+
+ 18 /rdi /rdi :movqMemDisp8Reg # use jump target instead of jump pad in new function object
+ 16 /rdi :subqImm8Reg
+ /grabRip :callqLbl32 # TODO: use rip-relative addressing
+ @grabRip
+ /rax :popqReg
+ /rdi 45 neg /rax :movqRegMemDisp8 # update the function code object we use
+ [ 46 :jmpRel8 ] _ len 2 neq { "unexpected opcode length" die } rep
+ 2 dearray 256 mul add
+ 37 neg /rax :movwImmMemDisp8 # don't do rewrite tests next time
+
+ @nonReplaced
+ /r14 /rsi :movqRegReg
+ /rdx /rdx :xorqRegReg
+ ::internalAllocateFunction /rax :movqImmReg
+ /rax :callqReg
+ /rax :pushqReg
+ ]] ==functionObjectWrapperCode # moved here so [[, ]] work correctly
+
<
# quote construction, push begin marker on stack
[
@@ -3024,13 +3053,7 @@
10 /rdi :addqImm8Reg
8 /rbp :addqImm8Reg
- [
- /r14 /rsi :movqRegReg
- /rdx /rdx :xorqRegReg
- ::internalAllocateFunction /rax :movqImmReg
- /rax :callqReg
- /rax :pushqReg
- ] ::unscopingFunctionFooter cat ::loadToRdi
+ functionObjectWrapperCode ::unscopingFunctionFooter cat ::loadToRdi
} {
# create constant function from inner code block
/rax /rdi :movqRegReg
diff --git a/elymas/lib/sys/opt.ey b/elymas/lib/sys/opt.ey
index 29e6d26..35345b4 100644
--- a/elymas/lib/sys/opt.ey
+++ b/elymas/lib/sys/opt.ey
@@ -1845,7 +1845,7 @@
rewriteConstantStar
rewriteConstantQuestionStar
rewriteIntegerTrace
- # rewriteArithmetics # SUPERSEDED BY rewriteIntegerTrace
+ rewriteArithmetics # mostly SUPERSEDED BY rewriteIntegerTrace
rewriteArithmeticsOptimistic
rewriteSimpleFunctions
testAllocatedScopeEscape