Mercurial > repos > tabletprog
annotate modules/bytearray.tp @ 372:e857104bd183
Added reverse method to arrays
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 12 Aug 2015 19:16:41 -0700 |
parents | 06dceff348ea |
children | 0673ccbc7379 |
rev | line source |
---|---|
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 includeSystemHeader: "unistd.h" |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 includeSystemHeader: "sys/mman.h" |
318
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
4 |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
5 fromOpaque:withSize <- :opaque :size{ |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
6 #{ |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
7 llProperty: bytes withType: uint32_t |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
8 llProperty: buffer withType: (void ptr) |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
9 llMessage: _init_buf withVars: { |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
10 sz <- obj_int32 ptr |
318
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
11 opaque <- cpointer ptr |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
12 } andCode: :opaque sz { |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
13 bytes <- sz num |
318
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
14 buffer <- (opaque val) |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
15 self |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
16 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
17 |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
18 llMessage: _buf_ptr withVars: { |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
19 ptrret <- cpointer ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
20 } andCode: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
21 ptrret <- make_object: (addr_of: cpointer_meta) NULL 0 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
22 ptrret val!: buffer |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
23 ptrret |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
24 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
25 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
26 llMessage: length withVars: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
27 intret <- obj_int32 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
28 } andCode: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
29 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
30 intret num!: bytes |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
31 intret |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
32 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
33 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
34 llMessage: set withVars: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
35 offset <- obj_int32 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
36 newval <- obj_uint8 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
37 } andCode: :offset newval { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
38 (buffer castTo: (uint8_t ptr)) set: (offset num) (newval num) |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
39 self |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
40 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
41 llMessage: get withVars: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
42 offset <- obj_int32 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
43 ret <- obj_uint8 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
44 } andCode: :offset { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
45 ret <- make_object: (addr_of: obj_uint8_meta) NULL 0 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
46 ret num!: ((buffer castTo: (uint8_t ptr)) get: (offset num)) |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
47 ret |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
48 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
49 |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
50 llMessage: shrinkTo withVars: { |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
51 newsize <- obj_int32 ptr |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
52 } andCode: :newsize { |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
53 if: (newsize num) < bytes { |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
54 bytes <- newsize num |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
55 } |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
56 self |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
57 } |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
58 |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
59 llMessage: stringFrom:to withVars: { |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
60 from <- obj_int32 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
61 to <- obj_int32 ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
62 str <- string ptr |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
63 } andCode: :from :to { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
64 //probably should do some UTF-8 validation at some point |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
65 str <- make_object: (addr_of: string_meta) NULL 0 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
66 str bytes!: (to num) - (from num) |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
67 str len!: (str bytes) |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
68 str data!: (GC_MALLOC_ATOMIC: (str bytes) + 1) |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
69 memcpy: (str data) (buffer castTo: (uint8_t ptr)) + (from num) (str bytes) |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
70 (str data) set: (str bytes) 0 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
71 str |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
72 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
73 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
74 string <- { |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
75 stringFrom: 0 to: length |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
76 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
77 |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
78 findChar:from:else <- :char :start found :else { |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
79 notfound <- true |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
80 n <- length |
296
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
81 i <- start |
2a0a88799737
A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
294
diff
changeset
|
82 while: { notfound && i < n } do: { |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
83 if: (get: i) = char { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
84 notfound <- false |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
85 } else: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
86 i <- i + 1 |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
87 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
88 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
89 if: notfound else else: { |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
90 found: i |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
91 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
92 } |
318
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
93 } _init_buf: opaque size |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
94 } |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
95 |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
96 normal <- :size { |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
97 helper <- #{ |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
98 llMessage: alloc withVars: { |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
99 size <- obj_int32 ptr |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
100 opaqueret <- cpointer ptr |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
101 } andCode: :size { |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
102 opaqueret <- make_object: (addr_of: cpointer_meta) NULL 0 |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
103 opaqueret val!: (GC_MALLOC_ATOMIC: (size num)) |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
104 opaqueret |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
105 } |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
106 } |
4c669942c30d
Add bindings for SDL_CreateTexture, SDL_LockTexture, SDL_SetBlendMode and SDL_GetBlendMode in SDL module
Michael Pavone <pavone@retrodev.com>
parents:
296
diff
changeset
|
107 fromOpaque: (helper alloc: size) withSize: size |
294
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
108 } |
d1dc2d70bdfd
Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
109 |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 executable <- :size { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 buf <- #{ |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 llProperty: bytes withType: uint32_t |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 llProperty: buffer withType: (void ptr) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 llMessage: _init withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 sz <- obj_int32 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 } andCode: :sz { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 bytes <- sz num |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 buffer <- sbrk: bytes |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 mprotect: buffer bytes (PROT_READ or PROT_WRITE or PROT_EXEC) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 self |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } |
361
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
122 |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
123 llMessage: _buf_ptr withVars: { |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
124 ptrret <- cpointer ptr |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
125 } andCode: { |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
126 ptrret <- make_object: (addr_of: cpointer_meta) NULL 0 |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
127 ptrret val!: buffer |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
128 ptrret |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
129 } |
06dceff348ea
llcompile now has Hacky support for calling C functions using dl to lookup symbols and almost has support string constants
Michael Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
130 |
347
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
131 llMessage: length withVars: { |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
132 intret <- obj_int32 ptr |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
133 } andCode: { |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
134 intret <- make_object: (addr_of: obj_int32_meta) NULL 0 |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
135 intret num!: bytes |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
136 intret |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
137 } |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 llMessage: set withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 offset <- obj_int32 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 newval <- obj_uint8 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 } andCode: :offset newval { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 (buffer castTo: (uint8_t ptr)) set: (offset num) (newval num) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 self |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 llMessage: get withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 offset <- obj_int32 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 ret <- obj_uint8 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 } andCode: :offset { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 ret <- make_object: (addr_of: obj_uint8_meta) NULL 0 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 ret num!: ((buffer castTo: (uint8_t ptr)) get: (offset num)) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 ret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 llMessage: run withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 fun <- uint64_t funptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 funret <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 } andCode: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 funret <- make_object: (addr_of: obj_uint64_meta) NULL 0 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 fun <- buffer |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 funret num!: ( fun: ) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 funret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 llMessage: runWithArg withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 fun <- uint64_t funptr: uint64_t |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 funret <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 arg <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } andCode: :arg { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 fun <- buffer |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 funret <- make_object: (addr_of: obj_uint64_meta) NULL 0 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 funret num!: ( fun: (arg num) ) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 funret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 } |
258
fb922651db29
Pass size parameter to _init in bytearray
Michael Pavone <pavone@retrodev.com>
parents:
180
diff
changeset
|
174 buf _init: size |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 executableFromBytes <- :bytes { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 totalSize <- bytes fold: 0 with: :acc el { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 acc + (el length) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 ba <- executable: totalSize |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 bytes fold: 0 with: :idx el { |
180
270d31c6c4cd
Add support for jmps and labels in x86 module
Mike Pavone <pavone@retrodev.com>
parents:
178
diff
changeset
|
183 el flattenTo: ba at: idx |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 ba |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 } |