aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrahflow <drahflow@gmx.de>2013-01-23 10:02:54 +0100
committerDrahflow <drahflow@gmx.de>2013-01-23 10:02:54 +0100
commitaba7b3fa8bd92c66760009d0a2762df3539c36cd (patch)
tree923c57882554805ce85516b516ac536ea1847167
parentd7fbde238c596c3f7cbc5471a0efb32481bdf6b8 (diff)
dom, rep, =[] done
dom now correctly calls .dom on structs rep loops 0 times, not 2^64 times when called with 0 =[] implemented
-rw-r--r--compiler/elymasAsm.ey9
-rw-r--r--compiler/elymasAsmLib.ey191
-rwxr-xr-xexamples/compiler-missing.sh1
l---------examples/working-compiler/array-assign.test1
l---------examples/working-compiler/dom.test1
l---------examples/working-compiler/qsort.test1
-rw-r--r--examples/working/array-assign.ey4
-rw-r--r--examples/working/array_assign.ey4
8 files changed, 146 insertions, 66 deletions
diff --git a/compiler/elymasAsm.ey b/compiler/elymasAsm.ey
index f09a47f..54f6c7a 100644
--- a/compiler/elymasAsm.ey
+++ b/compiler/elymasAsm.ey
@@ -821,6 +821,15 @@
scale idx mem sib
} /popqMemIndexScale deff
+ { ==mem ==idx ==scale ==disp
+ mem regno %07 gt idx regno %07 gt or { 1 /none idx mem rex } rep
+ disp 128 lt assert
+ %8F
+ /zero /sib modrm01
+ scale idx mem sib
+ disp imm8
+ } /popqMemIndexScaleDisp8 deff
+
{ ==reg
reg regno %07 gt { 1 /none /none reg rex } rep
%58 reg regno %07 band add
diff --git a/compiler/elymasAsmLib.ey b/compiler/elymasAsmLib.ey
index 2b11dcd..b5a338d 100644
--- a/compiler/elymasAsmLib.ey
+++ b/compiler/elymasAsmLib.ey
@@ -34,7 +34,7 @@
str len :imm64
] str strToUTF8Bytes cat
[ 8 str len 8 mod sub %00 rep ] cat
- } /toErrString deff
+ } /toConstString deff
<
# current end of heap memory (grows upwards)
@@ -50,12 +50,16 @@
[ %00 %00 %00 %00 %00 %00 %00 %00 ] ==currentQuoted
# error strings
- "unresolved name: " toErrString ==errUnresolvedName
- "neither string nor array in len" toErrString ==errNeitherStringNorArrayInLen
- "not an executable thing" toErrString ==errNotExecutable
- "neither string nor array in cat" toErrString ==errNeitherStringNorArrayInCat
- "type mismatch within cat" toErrString ==errMismatchInCat
- "non-array passed to dom" toErrString ==errNotArrayInDom
+ "unresolved name: " toConstString ==errUnresolvedName
+ "neither string nor array in len" toConstString ==errNeitherStringNorArrayInLen
+ "not an executable thing" toConstString ==errNotExecutable
+ "neither string nor array in cat" toConstString ==errNeitherStringNorArrayInCat
+ "type mismatch within cat" toConstString ==errMismatchInCat
+ "non-array passed to dom" toConstString ==errNotArrayInDom
+ "non-array passed to =[]" toConstString ==errNotArrayInArrayAssign
+
+ # more constant strings
+ "dom" toConstString ==strDom
> { defv }' allocateOffsetStruct
{ _ =*array len _ 4 div ==largeMoves
@@ -898,6 +902,48 @@
:retn
] :labelResolve /ey] defv
+ # assign array cell
+ # 0 -> array
+ # 1 -> index in array
+ # 2 -> value to assign
+ [
+ 8 /r15 :subqImm8Reg
+ /r15 :popqMem
+
+ /rbx :popqReg
+ 7 /rbx /cl :movbMemDisp8Reg
+ %F0 /cl :andbImmReg
+ %70 /cl :cmpbImmReg
+ /arrayAssign :jeLbl8
+
+ errNotArrayInArrayAssign /rdi :movqImmReg
+ internalDumpErrorString /rax :movqImmReg
+ /rax :callqReg
+ :ud2
+
+ @arrayAssign
+ /rax :popqReg
+ 8 /rax /rax :movqMemDisp8Reg
+
+ /rbx /ecx :movlMemReg # load array length
+ 3 /rcx :shrqImm8Reg # divide by object pointer size
+ /rcx :decqReg # rcx == number of elements in array
+
+ /rdx /rdx :xorqRegReg
+
+ # TODO: think about skipping this if index fits
+ /rcx :divqReg
+
+ # rbx == array object on heap
+ # rdx == correct array index
+
+ 8 8 /rdx /rbx :popqMemIndexScaleDisp8 # directly pop into array cell
+
+ /r15 :pushqMem
+ 8 /r15 :addqImm8Reg
+ :retn
+ ] :labelResolve /ey=[] defv
+
# length of array or string
# 0 -> array / string
# 0 <- number of elements / characters
@@ -1017,60 +1063,6 @@
:retn
] :labelResolve /eycat defv
- # domain of an array
- # 0 -> array
- # 0 <- an array containing the integers from 0 to len 1 sub
- [
- 8 /r15 :subqImm8Reg
- /r15 :popqMem
-
- /rax :popqReg
- 7 /rax /cl :movbMemDisp8Reg
- %F0 /cl :andbImmReg
- %70 /cl :cmpbImmReg
- /arrayDom :jeLbl8
-
- errNotArrayInDom /rdi :movqImmReg
- internalDumpErrorString /rax :movqImmReg
- /rax :callqReg
- :ud2
-
- @arrayDom
- /rax /edi :movlMemReg
- 8 /rdi :subqImm8Reg # substract header length
-
- internalAllocateArray /rax :movqImmReg
- /rax :callqReg
- /rax :pushqReg # result on stack
-
- 8 /rax /rdi :leaqMemDisp8Reg
- /rbx /rbx :xorqRegReg
- /rax /ecx :movlMemReg
- 3 /rcx :shrqImm8Reg
- /rcx :decqReg
-
- @loop
- /rcx /rbx :cmpqRegReg
- /end :jnbLbl8
-
- /rdi :pushqReg
- /rcx :pushqReg
- 16 /rdi :movqImmReg
- internalAllocate /rax :movqImmReg
- /rax :callqReg
- /rcx :popqReg
- /rdi :popqReg
- /rax 8 /rbx /rdi :movqRegMemIndexScale # store in array
- /rbx 8 /rax :movqRegMemDisp8 # store value in int
- /rbx :incqReg
- /loop :jmpLbl8
-
- @end
- /r15 :pushqMem
- 8 /r15 :addqImm8Reg
- :retn
- ] :labelResolve /eydom defv
-
# push array contents on stack
# 0 -> number of elements to push
# 1 -> array
@@ -1532,6 +1524,9 @@
/rcx :popqReg
8 /rcx /rcx :movqMemDisp8Reg
+ /rcx /rcx :testqRegReg
+ /end :jzLbl8
+
@loop
/rcx /r15 :movqRegMem
@@ -1542,6 +1537,7 @@
/r15 /rcx :movqMemReg
/loop :loopLbl8
+ @end
16 /r15 :addqImm8Reg
/r15 :pushqMem
@@ -1756,6 +1752,72 @@
> _ ==globalFunctions2 { defv }' allocateOffsetStruct
<
+ # domain of an array
+ # 0 -> array
+ # 0 <- an array containing the integers from 0 to len 1 sub
+ [
+ 8 /r15 :subqImm8Reg
+ /r15 :popqMem
+
+ /rax :popqReg
+ 7 /rax /cl :movbMemDisp8Reg
+ %F0 /cl :andbImmReg
+ %70 /cl :cmpbImmReg
+ /arrayDom :jeLbl8
+ %20 /cl :cmpbImmReg
+ /scopeDom :jeLbl8
+
+ errNotArrayInDom /rdi :movqImmReg
+ internalDumpErrorString /rax :movqImmReg
+ /rax :callqReg
+ :ud2
+
+ @arrayDom
+ /rax /edi :movlMemReg
+ 8 /rdi :subqImm8Reg # substract header length
+
+ internalAllocateArray /rax :movqImmReg
+ /rax :callqReg
+ /rax :pushqReg # result on stack
+
+ 8 /rax /rdi :leaqMemDisp8Reg
+ /rbx /rbx :xorqRegReg
+ /rax /ecx :movlMemReg
+ 3 /rcx :shrqImm8Reg
+ /rcx :decqReg
+
+ @loop
+ /rcx /rbx :cmpqRegReg
+ /end :jnbLbl8
+
+ /rdi :pushqReg
+ /rcx :pushqReg
+ 16 /rdi :movqImmReg
+ internalAllocate /rax :movqImmReg
+ /rax :callqReg
+ /rcx :popqReg
+ /rdi :popqReg
+ /rax 8 /rbx /rdi :movqRegMemIndexScale # store in array
+ /rbx 8 /rax :movqRegMemDisp8 # store value in int
+ /rbx :incqReg
+ /loop :jmpLbl8
+
+ @end
+ /r15 :pushqMem
+ 8 /r15 :addqImm8Reg
+ :retn
+
+ @scopeDom
+ /rax :pushqReg
+ strDom /rax :movqImmReg
+ /rax :pushqReg
+ |ey. /rax :movqImmReg
+ /rax :callqReg
+ /end :jmpLbl8
+ ] :labelResolve /eydom defv
+ > _ ==globalFunctions3 { defv }' allocateOffsetStruct
+
+ <
# quote construction, push begin marker on stack
[
/rax :popqReg
@@ -1951,7 +2013,11 @@
} /constStringCode deff
[
- globalFunctions keys len globalFunctions2 keys len globalMacros keys len add add /rdi :movqImmReg
+ globalFunctions keys len
+ globalFunctions2 keys len add
+ globalFunctions3 keys len add
+ globalMacros keys len add
+ /rdi :movqImmReg
/rsi /rsi :xorqRegReg
internalAllocateScope /rax :movqImmReg
/rax :callqReg
@@ -1981,6 +2047,7 @@
} /createScopeEntries deff
globalFunctions keys eydeff createScopeEntries
globalFunctions2 keys eydeff createScopeEntries
+ globalFunctions3 keys eydeff createScopeEntries
globalMacros keys eydefq createScopeEntries
] :execute
diff --git a/examples/compiler-missing.sh b/examples/compiler-missing.sh
new file mode 100755
index 0000000..13474dd
--- /dev/null
+++ b/examples/compiler-missing.sh
@@ -0,0 +1 @@
+{( cd working-compiler; ls *.test ); (cd working; ls *.ey)} | sed -e 's/\..*//g' | sort | uniq -c | sort -nr
diff --git a/examples/working-compiler/array-assign.test b/examples/working-compiler/array-assign.test
new file mode 120000
index 0000000..67d7f95
--- /dev/null
+++ b/examples/working-compiler/array-assign.test
@@ -0,0 +1 @@
+../working/array-assign.ey \ No newline at end of file
diff --git a/examples/working-compiler/dom.test b/examples/working-compiler/dom.test
new file mode 120000
index 0000000..4a02d38
--- /dev/null
+++ b/examples/working-compiler/dom.test
@@ -0,0 +1 @@
+../working/dom.ey \ No newline at end of file
diff --git a/examples/working-compiler/qsort.test b/examples/working-compiler/qsort.test
new file mode 120000
index 0000000..73d3b70
--- /dev/null
+++ b/examples/working-compiler/qsort.test
@@ -0,0 +1 @@
+../working/qsort.ey \ No newline at end of file
diff --git a/examples/working/array-assign.ey b/examples/working/array-assign.ey
new file mode 100644
index 0000000..34cf6e4
--- /dev/null
+++ b/examples/working/array-assign.ey
@@ -0,0 +1,4 @@
+[ 1 2 3 4 ] /a defv
+0 6 a =[]
+
+a dump
diff --git a/examples/working/array_assign.ey b/examples/working/array_assign.ey
deleted file mode 100644
index b369e5b..0000000
--- a/examples/working/array_assign.ey
+++ /dev/null
@@ -1,4 +0,0 @@
-[ 1 2 3 4 ] =a
-0 2 a =[]
-
-a dump