Permalink
Browse files

structural changes (fixed segfault | args now have to be passed one a…

…t a time)
  • Loading branch information...
1 parent 784fa5c commit f9e029475bb3c3c19f1a4980874b5e3d5d08b4e2 @showstopper showstopper committed Mar 30, 2010
Showing with 31 additions and 18 deletions.
  1. +11 −7 tests/test_partial.ooc
  2. +1 −1 yajit/{ → x86-32}/BinarySeq.ooc
  3. +1 −1 yajit/x86-32/OpCodes.ooc
  4. +18 −9 yajit/x86-32/Partial.ooc
View
@@ -1,6 +1,5 @@
-use yajit
import structs/ArrayList
-import yajit/x86-32/Partial
+import ../yajit/x86-32/Partial
TestStruct: class {
@@ -53,17 +52,22 @@ main: func {
partial := Partial new()
function1 := partial genCode(test2, a, "iii") as Func -> String
function1(2, 3, 4) println()
- partial = Partial new()
+ "yaaay" println()
+ partial = Partial new()
function2 := partial genCode(test3, 4, "ii") as Func -> Int
printf("%d\n", function2(2, 2))
partial = Partial new()
- function3 := partial genCode(test4, closureArgs, "") as Func -> Int
+ partial addArgument(21)
+ partial addArgument(42)
+ partial addArgument(a)
+ function3 := partial genCode(test4, "") as Func -> Int
function3()
- /*
partial = Partial new()
- function4 := partial genCode(test5, closureArgs, "i") as Func -> Int
+ partial addArgument(21)
+ partial addArgument(42)
+ partial addArgument(a)
+ function4 := partial genCode(test5, "i") as Func -> Int
function4 (partial converseFloat(23.3))
- */
"Finished!" println()
}
@@ -13,7 +13,7 @@ BinarySeq: class {
transTable := HashMap<String, Int> new()
init: func ~withData (=size, .data) {
- this(size)
+ init(size)
index = size
memcpy(this data, data, size * sizeof(UChar))
}
View
@@ -1,4 +1,4 @@
-import ../BinarySeq
+import BinarySeq
OpCodes: class {
View
@@ -1,11 +1,12 @@
import structs/ArrayList
-import ../BinarySeq
+import BinarySeq
import OpCodes
Partial: class {
bseq: BinarySeq
+ arguments := ArrayList<Cell<Pointer>> new()
init: func {initSequence(1024)}
init: func ~withSize(s: Int) {initSequence(s)}
@@ -33,41 +34,48 @@ Partial: class {
}
}
+ addArgument: func<T>(param: T) {
+ arg := Cell<T> new(param)
+ this arguments add(arg)
+ }
+
genCode: func <T>(function: Pointer, closure: T, argSizes: String) -> Pointer {
pushNonClosureArgs(getBase(argSizes, bseq), argSizes)
pushClosure(closure)
finishSequence(function)
- bseq print()
+ //bseq print()
return bseq data as Func
}
- genCode: func ~multipleArgs(function: Pointer, closure: ArrayList<Cell<Pointer>>, argSizes: String) -> Pointer {
+ genCode: func ~multipleArgs(function: Pointer, argSizes: String) -> Pointer {
// IMPORTANT!! bug concerning choice of right polymorphic func
// even if a non-closure arg is smaller than 4 byte
// treating it as it'd have 4 bytes works
// should be fixed later on, but it's currently
// more important to have somehing working :)
- bseq := initSequence(1024)
- //closureArgs := closure clone() // cloning fixes problem with reverse (don't ask why^^)
- //closureArgs reverse()
+ arguments reverse()
pushNonClosureArgs(getBase(argSizes, bseq),argSizes)
- for (item: Cell<Pointer> in closure) {
+ for (item: Cell<Pointer> in arguments) {
T := item T
pushClosure(item val as Pointer)
}
finishSequence(function)
+ /*
printf("Code = ")
bseq print()
+ */
return bseq data as Func
}
initSequence: func(s: Int) -> BinarySeq {
bseq = BinarySeq new(s)
bseq append(OpCodes PUSH_EBP)
bseq append(OpCodes MOV_EBP_ESP)
+ /*
"Init sequence: " print()
bseq print()
"" println()
+ */
return bseq
}
@@ -76,12 +84,14 @@ Partial: class {
s := String new(c)
pushCallerArg(bseq transTable get(s))
bseq append(base& as UChar*, UChar size)
- base = base - bseq transTable get(s) //op transTable get(s)
+ base = base - bseq transTable get(s)
}
+ /*
printf("EndBase: %d\n", base)
"pushNonClosureArgs: " println()
bseq print()
"" println()
+ */
}
finishSequence: func(funcPtr: Pointer) {
@@ -100,6 +110,5 @@ Partial: class {
}
return base
}
-
}

0 comments on commit f9e0294

Please sign in to comment.