Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (impfunc createStringFromBytes (ret string) (arg intptr) (arg u32))
- (impfunc sprintf (conv C)
- (ret i32) // int
- (arg intptr) // char* buf
- (arg intptr) // const char* fmt
- (vararg)
- )
- (impfunc memcpy (conv C)
- (ret intptr) // void*
- (arg intptr) // void* dst
- (arg intptr) // const void* src
- (arg intptr) // size_t size
- )
- (class stringbuffer
- (var buffer (? (handle (array u8))))
- (var size u32)
- (func getString (ret string) (body
- (return (call createStringFromBytes (cast intptr buffer) (prop buffer size)))
- ))
- (func reserve (ret void) (arg u32 sz) (body
- (if (eq buffer null) (block
- (set buffer (new (array u8) sz))
- (return)
- ))
- (if (lt (prop buffer size) sz) (block
- (var newsz (add size sz))
- (var newbuf (new (array u8) newsz))
- // TODO arrayCopy
- (if buffer
- (call memcpy newbuf buffer (cast intptr size))
- )
- (set buffer newbuf)
- ))
- ))
- (func writeRaw (ret void) (arg intptr buf) (arg u32 sz) (body
- (call reserve (add sz size))
- (call memcpy (add (cast intptr buffer) (cast intptr size)) buf (cast intptr sz))
- (set size (add size sz))
- ))
- (func write (ret void) (arg string str) (body
- (call writeRaw (prop str cStringPtr) (prop str size))
- ))
- (func write (ret void) (arg i32 i32val) (body
- (var buf (array u8 32))
- (call writeRaw buf (call sprintf (cast intptr buf) (prop "%d" cStringPtr) i32val))
- ))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement