Mercurial > repos > rhope
changeset 81:dbe95bfec970
Very basic file access is now working; however, there's a bug involving assigning a literal to a named pipe inside a conditional block that needs fixing
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 22 Jul 2010 05:39:08 +0000 |
parents | d78613686a38 |
children | 2e2e55fc12f9 |
files | cbackend.rhope ctobin file.rhope testfileread.rhope todo.txt |
diffstat | 5 files changed, 73 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/cbackend.rhope Wed Jul 21 00:45:13 2010 -0400 +++ b/cbackend.rhope Thu Jul 22 05:39:08 2010 +0000 @@ -675,7 +675,7 @@ { dest <- [pdest]Make Op[func] source <- [psource]Make Op[func] - out <- [func]Add Statement[ [[[dest]Append[" = &("]]Append[source]]Append["->payload)"] ] + out <- [func]Add Statement[ [[[dest]Append[" = (void*)("]]Append[source]]Append[" + 1)"] ] } Array Raw Pointer@C Function[func,psource,pdest:out] @@ -778,6 +778,7 @@ Func Base@C Function[func,tocall,args,type:out] { + Print[ [[func]Name >>]Append[ [": Func Base("]Append[tocall] ] ] rargs <- Map[args, ["Make Op"]Set Input[1, func]] If[[[rargs]Length] > [[func]Last NumParams >>]]
--- a/ctobin Wed Jul 21 00:45:13 2010 -0400 +++ b/ctobin Thu Jul 22 05:39:08 2010 +0000 @@ -20,3 +20,5 @@ $CC -o $bin $2 "$1.c" blueprint.c context.c fixed_alloc.c object.c +cd .. +
--- a/file.rhope Wed Jul 21 00:45:13 2010 -0400 +++ b/file.rhope Thu Jul 22 05:39:08 2010 +0000 @@ -5,10 +5,12 @@ Foreign C:libc { - open[name(Array,Raw Pointer),flags(Int32,Naked):filedes(Int32,Naked)] + open[name(Array,Raw Pointer),flags(Int32,Naked),mode(UInt32,Naked):filedes(Int32,Naked)] close[filedes(Int32,Naked):status(Int32,Naked)] fsync[filedes(Int32,Naked):status(Int32,Naked)] - fstat[filedes(Int32,Naked),buf(Stat,Raw Pointer):err(Int32,Naked),buf] + fstat[filedes(Int32,Naked),buf(Stat,Raw Pointer,Mutable):err(Int32,Naked),buf] + lseek[filedes(Int32,Naked),offset(Int64,Naked),whence(Int32,Naked):out(Int64,Naked)] + ftruncate[filedes(Int32,Naked),length(Int64,Naked):status(Int32,Naked)] } Blueprint Stat @@ -76,26 +78,28 @@ Open@File[file,mode:out,error] { If[[mode]=["r"]] - { - imode <- 0i32 - type <- File Read() + { + imode <- Val[0i32] + type <- Val[File Read()] out <- Val[ofile] }{ If[[mode]=["w"]] { - imode <- 65i32 - type <- File Write() + imode <- Val[65i32] + type <- Val[File Write()] out <- Val[ofile] + If[[fd]!=[-1i32]] + { lseek[fd, 0i64, 2i32] } }{ ,error <- If[[mode]=["rw"]] { - imode <- 66i32 - type <- File ReadWrite() + imode <- Val[66i32] + type <- Val[File ReadWrite()] out <- [ofile]Read Offset <<[0i64] } } } - fd <- open[[file]Name >>] + fd <- open[[[[file]Name >>]Flatten]Buffer >>, imode, 438u32] error <- If[[fd]=[-1i32]] {} { ofile <- [[[Build[type] @@ -123,12 +127,36 @@ String@File[file:out,error] { - ,error <- [file]Open["w"] + f,error <- [file]Open["r"] { out,error <- String[~] + { Close[f] } } } +Truncate@File[file:out,error] +{ + f,error <- [file]Open["w"] + { + out,error <- Truncate[f] + } +} + +Write@File[file,data:out,error] +{ + f,error <- [file]Open["w"] + { + out,error <- [f]Write[data] + } +} + + +String@File Read[file:out,error] +{ + ,error <- [file]Read[[file]Length] + { out <- String[~] } +} + Read@File Read[file,inbytes(Int32):data,outfile,error] { readbytes, mdata <- read[[file]Descriptor >>, [Array[]]Set[inbytes, 0u8], Int64[inbytes]] @@ -175,4 +203,32 @@ out <- File[[file]Name >>] } +Length@File Write[file:out] +{ + out <- Trunc Int32[[[file]Info >>]Size >>] +} +Truncate@File Write[file:out,err] +{ + err <- If[ftruncate[[file]Descriptor >>, 0i64]] {} + { + err <- If[lseek[[file]Descriptor >>, 0i64, 0i32]] {} + { out <- [file]Info <<[ [[file]Info >>]Size <<[0i64] ] } + } +} + +Write@File Write[file,data(Array):out,err] +{ + err <- If[write[[file]Descriptor >>, data, Int64[[data]Length >>]]] {} + { + out <- file + } +} + +Close@File Write[file:out] +{ + fsync[[file]Descriptor >>] + { close[[file]Descriptor >>] } + out <- File[[file]Name >>] +} +
--- a/testfileread.rhope Wed Jul 21 00:45:13 2010 -0400 +++ b/testfileread.rhope Thu Jul 22 05:39:08 2010 +0000 @@ -1,8 +1,7 @@ Main[] { - f <- [File["test.txt"]]Open["r"] - ,data <- [f]Read[[f]Length] - Print[String[data]] + f <- File["test.txt"] + Print[String[f]] }
--- a/todo.txt Wed Jul 21 00:45:13 2010 -0400 +++ b/todo.txt Thu Jul 22 05:39:08 2010 +0000 @@ -4,8 +4,6 @@ Fix Array and Worker memory leaks Needed for compiler to be self-hosting: - Finish implementation of String - Finish implementation of List Add support for List literals in compiler Implement Dictionary Implement File