Mercurial > repos > tabletprog
annotate modules/bytearray.tp @ 331:61f5b794d939
Breaking change: method call syntax now always uses the syntactic receiver as the actual receiver. This makes its behavior different from function call syntax, but solves some problems with methods being shadowed by local variables and the like.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 28 Mar 2015 14:21:04 -0700 |
parents | 4c669942c30d |
children | ff7ea11b4b60 |
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 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 llMessage: set withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 offset <- obj_int32 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 newval <- obj_uint8 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 } andCode: :offset newval { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 (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
|
127 self |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 llMessage: get withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 offset <- obj_int32 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 ret <- obj_uint8 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 } andCode: :offset { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 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
|
134 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
|
135 ret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 llMessage: run withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 fun <- uint64_t funptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 funret <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } andCode: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 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
|
142 fun <- buffer |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 funret num!: ( fun: ) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 funret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 llMessage: runWithArg withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 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
|
149 funret <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 arg <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } andCode: :arg { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 fun <- buffer |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 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
|
154 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
|
155 funret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |
258
fb922651db29
Pass size parameter to _init in bytearray
Michael Pavone <pavone@retrodev.com>
parents:
180
diff
changeset
|
158 buf _init: size |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 executableFromBytes <- :bytes { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 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
|
163 acc + (el length) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 ba <- executable: totalSize |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 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
|
167 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
|
168 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 ba |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |