aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2013-09-22 11:26:45 +0200
committerDrahflow <drahflow@gmx.de>2013-09-22 11:26:45 +0200
commit65b530782c309fa7bd9b3781f23a0ce0a3b29a3b (patch)
tree7af0f9e9d7a9828582f6bebf0732c396f855dd6a /compiler
parenteea02bbc59f4f0ece2756cdc846d351238d2b6a7 (diff)
=abc and |abc now optimized to static access
Diffstat (limited to 'compiler')
-rw-r--r--compiler/elymasAsm.ey40
-rw-r--r--compiler/elymasAsmLib.ey4
-rw-r--r--compiler/elymasGlobal.ey69
-rw-r--r--compiler/elymasGlobalSys.ey57
-rw-r--r--compiler/elymasGlobalSysOpt.ey2
-rw-r--r--compiler/standardClient.ey2
6 files changed, 141 insertions, 33 deletions
diff --git a/compiler/elymasAsm.ey b/compiler/elymasAsm.ey
index ca3bdd7..fcb584a 100644
--- a/compiler/elymasAsm.ey
+++ b/compiler/elymasAsm.ey
@@ -73,19 +73,39 @@
} /modrm00 deff
{ ==mem ==reg
- mem [ /spl /sp /esp /rsp ] streq any not assert
-
- %40
- mem regno %07 band add
- reg regno 8 mul %38 band add
+ mem [ /spl /sp /esp /rsp ] streq any {
+ # actually encode sib with rsp index register (to get it ignored)
+ %40
+ /sib regno %07 band add
+ reg regno 8 mul %38 band add
+
+ # sib-byte
+ %00 # index = 1 (ignored anyway)
+ %38 /rsp regno 8 mul band add # (ignored)
+ %07 mem regno band add
+ } {
+ %40
+ mem regno %07 band add
+ reg regno 8 mul %38 band add
+ } ? *
} /modrm01 deff
{ ==mem ==reg
- mem [ /spl /sp /esp /rsp ] streq any not assert
-
- %80
- mem regno %07 band add
- reg regno 8 mul %38 band add
+ mem [ /spl /sp /esp /rsp ] streq any {
+ # actually encode sib with rsp index register (to get it ignored)
+ %80
+ /sib regno %07 band add
+ reg regno 8 mul %38 band add
+
+ # sib-byte
+ %00 # index = 1 (ignored anyway)
+ %38 /rsp regno 8 mul band add # (ignored)
+ %07 mem regno band add
+ } {
+ %80
+ mem regno %07 band add
+ reg regno 8 mul %38 band add
+ } ? *
} /modrm10 deff
{ ==mem ==reg
diff --git a/compiler/elymasAsmLib.ey b/compiler/elymasAsmLib.ey
index e54c5c0..0cb2c6e 100644
--- a/compiler/elymasAsmLib.ey
+++ b/compiler/elymasAsmLib.ey
@@ -81,8 +81,8 @@
{ %00 %00 %00 %00 %00 %60 %00 %00 } /HEAPBASE deff
{ %00 %00 %00 %00 %00 %50 %00 %00 } /BLOCKBASE deff
{ %00 %00 %00 %00 %00 %40 %00 %00 } /MARKBASE deff
- # 4096 16 mul 8 mul ==ALLOCCHUNKSIZE # minimum ALLOCCHUNKSIZE
- 4096 16 mul 8 mul 256 mul ==ALLOCCHUNKSIZE # FIXME: there is still some wonkyness with freezing
+ 4096 16 mul 8 mul ==ALLOCCHUNKSIZE # minimum ALLOCCHUNKSIZE
+ # 4096 16 mul 8 mul 256 mul ==ALLOCCHUNKSIZE # FIXME: there is still some wonkyness with freezing
<
# current end of heap memory (grows upwards)
diff --git a/compiler/elymasGlobal.ey b/compiler/elymasGlobal.ey
index eb5fe8b..1820725 100644
--- a/compiler/elymasGlobal.ey
+++ b/compiler/elymasGlobal.ey
@@ -1459,6 +1459,9 @@
58 /rax :btsqImm8Mem
/alreadyOptimized :jcLbl8
/rax :pushqReg
+
+ ::currentScope /rcx :movqImmReg
+ /rcx :pushqMem
/rax :pushqReg
/rax :movqImmOOBReg "sys" ::string
@@ -1477,6 +1480,7 @@
/rax :callqReg
/rcx :popqReg # result object (not necessarily new code object though)
+ /rax :popqReg # pop returned scope object
/rax :popqReg # old object
/rax /rcx :cmpqRegReg
@@ -2312,28 +2316,55 @@
# rax == (inner) code object on heap
# create function which
- # returns a function with the current scope captured
- :quoteEncodingBufferCode /rdi :movqImmReg
- :quoteEncodingBufferObjects /rbp :movqImmReg
- ::unscopingFunctionHeader ::loadToRdi
-
- # 1. load inner code block
- [ /rdi :movqImmOOBReg ] _ len 2 eq assert
- 2 dearray 256 mul add
- /rdi :movwImmMem
- /rax 2 /rdi :movqRegMemDisp8
- /rax 0 /rbp :movqRegMemDisp8
- 10 /rdi :addqImm8Reg
- 8 /rbp :addqImm8Reg
-
- [
- ::currentScope /rax :movqImmReg
- /rax /rsi :movqMemReg
+ capturing {
+ # returns a function with the current scope captured
+ :quoteEncodingBufferCode /rdi :movqImmReg
+ :quoteEncodingBufferObjects /rbp :movqImmReg
+ ::unscopingFunctionHeader ::loadToRdi
+
+ # load inner code block
+ [ /rdi :movqImmOOBReg ] _ len 2 eq assert
+ 2 dearray 256 mul add
+ /rdi :movwImmMem
+ /rax 2 /rdi :movqRegMemDisp8
+ /rax 0 /rbp :movqRegMemDisp8
+ 10 /rdi :addqImm8Reg
+ 8 /rbp :addqImm8Reg
+
+ [
+ ::currentScope /rax :movqImmReg
+ /rax /rsi :movqMemReg
+ /rdx /rdx :xorqRegReg
+ ::internalAllocateFunction /rax :movqImmReg
+ /rax :callqReg
+ /rax :pushqReg
+ ] ::unscopingFunctionFooter cat ::loadToRdi
+ } {
+ # create constant function from inner code block
+ /rax /rdi :movqRegReg
+ /rsi /rsi :xorqRegReg # non-capturing
/rdx /rdx :xorqRegReg
::internalAllocateFunction /rax :movqImmReg
/rax :callqReg
- /rax :pushqReg
- ] ::unscopingFunctionFooter cat ::loadToRdi
+
+ :quoteEncodingBufferCode /rdi :movqImmReg
+ :quoteEncodingBufferObjects /rbp :movqImmReg
+ ::unscopingFunctionHeader ::loadToRdi
+
+ # rax == function object
+
+ [ /rax :movqImmOOBReg ] _ len 2 eq assert
+ 2 dearray 256 mul add
+ /rdi :movwImmMem
+ /rax 2 /rdi :movqRegMemDisp8
+ /rax 0 /rbp :movqRegMemDisp8
+ 10 /rdi :addqImm8Reg
+ 8 /rbp :addqImm8Reg
+
+ [
+ /rax :pushqReg
+ ] ::unscopingFunctionFooter cat ::loadToRdi
+ } ? *
::internalAllocateCodeFromEncodingBuffer /rax :movqImmReg
/rax :callqReg
diff --git a/compiler/elymasGlobalSys.ey b/compiler/elymasGlobalSys.ey
index 3a1c988..55f2369 100644
--- a/compiler/elymasGlobalSys.ey
+++ b/compiler/elymasGlobalSys.ey
@@ -2,7 +2,7 @@
"sys" enterSubScope
<
- # handle an identifier in the current scope according to current quote level
+ # handle an identifier in a given scope according to current quote level
# 0 -> scope to execute identifier in
# 1 -> identifier to handle
# 0 <- scope after execution
@@ -29,6 +29,61 @@
8 /r15 :addqImm8Reg
:retn
]] /eyexecuteIdentifier defv
+
+ # resolve an identifier in a given scope and return full resolve information
+ # 0 -> scope to resolve identifier in
+ # 1 -> identifier to resolve
+ # 0 <- address of resolved object (0 if nonexistent)
+ # 1 <- activation mode and constness of element (only present if resolution successful)
+ # 2 <- memory address of entry (only present if resolution successful)
+ # 3 <- number of parent pointers followed (only present if resolution successful)
+ # 4 <- entry index * 8 within scope (only present if resolution successful)
+ # 5 <- 0 if within scope data area, 1 if within extension area (only present if resolution successful)
+ [[
+ 8 /r15 :subqImm8Reg
+ /r15 :popqMem
+
+ /rdi :popqReg
+ /rsi :popqReg
+
+ ::internalResolve /rax :movqImmReg
+ /rax :callqReg
+
+ /rax /rax :andqRegReg
+ /failure :jzLbl32
+
+ 48 /r15 :subqImm8Reg
+ /rbp 40 /r15 :movqRegMemDisp8
+ /rsi 32 /r15 :movqRegMemDisp8
+ /rdi 24 /r15 :movqRegMemDisp8
+ /rcx 16 /r15 :movqRegMemDisp8
+ /rdx 8 /r15 :movqRegMemDisp8
+ /rax /r15 :movqRegMem
+
+ [ 40 32 24 16 8 0 ] { ==o
+ ::internalAllocateInteger /rax :movqImmReg
+ /rax :callqReg
+ /rax :pushqReg
+ o /r15 /rdx :movqMemDisp8Reg
+ /rdx 8 /rax :movqRegMemDisp8
+ } each
+
+ 48 /r15 :addqImm8Reg
+ /done :jmpLbl8
+
+ @failure
+
+ ::internalAllocateInteger /rax :movqImmReg
+ /rax :callqReg
+ /rax :pushqReg
+ 0 8 /rax :andqImm8MemDisp8
+
+ @done
+
+ /r15 :pushqMem
+ 8 /r15 :addqImm8Reg
+ :retn
+ ]] /eyresolveInfo defv
> _ ==globalFunctions { defv }' ::allocateOffsetStruct
[
diff --git a/compiler/elymasGlobalSysOpt.ey b/compiler/elymasGlobalSysOpt.ey
index 01fb1c0..8275e51 100644
--- a/compiler/elymasGlobalSysOpt.ey
+++ b/compiler/elymasGlobalSysOpt.ey
@@ -4,7 +4,9 @@
<
# stub
# 0 -> code object
+ # 1 -> current scope
# 0 <- same code object (if different object, optimization would have taken place)
+ # 1 <- current scope (value ignored)
[[
:retn
]] /eyhook defv
diff --git a/compiler/standardClient.ey b/compiler/standardClient.ey
index 87f2ab2..643a805 100644
--- a/compiler/standardClient.ey
+++ b/compiler/standardClient.ey
@@ -885,7 +885,7 @@
# %40 ==? section header size, %38 == program header size
metaSections len allocSections len add %40 mul
allocSections len %38 mul add
- %40 add ==dataOffset
+ %40 add ==?dataOffset
metaSections { ==s
dataOffset s .setDataOffset
dataOffset s .dataSize add =dataOffset