Mercurial > repos > tabletprog
annotate modules/bytearray.tp @ 353:95bc24c729e6
Move right hand parameter to cmp in _compileBinary to a temp reg if it is a constant since those are only supported in the left hand param currently
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 14 Apr 2015 19:54:03 -0700 |
parents | ff7ea11b4b60 |
children | 06dceff348ea |
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 } |
347
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
122 llMessage: length withVars: { |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
123 intret <- obj_int32 ptr |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
124 } andCode: { |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
125 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
|
126 intret num!: bytes |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
127 intret |
ff7ea11b4b60
Add length method to executable bytearrays
Michael Pavone <pavone@retrodev.com>
parents:
318
diff
changeset
|
128 } |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 llMessage: set 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 newval <- 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 newval { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 (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
|
134 self |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 llMessage: get withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 offset <- obj_int32 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 ret <- obj_uint8 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 } andCode: :offset { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 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
|
141 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
|
142 ret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 llMessage: run withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 fun <- uint64_t funptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 funret <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 } andCode: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 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
|
149 fun <- buffer |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 funret num!: ( fun: ) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 funret |
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 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 llMessage: runWithArg withVars: { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 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
|
156 funret <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 arg <- obj_uint64 ptr |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 } andCode: :arg { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 fun <- buffer |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 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
|
161 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
|
162 funret |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 } |
258
fb922651db29
Pass size parameter to _init in bytearray
Michael Pavone <pavone@retrodev.com>
parents:
180
diff
changeset
|
165 buf _init: size |
178
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 executableFromBytes <- :bytes { |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 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
|
170 acc + (el length) |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 ba <- executable: totalSize |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 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
|
174 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
|
175 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 ba |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 } |
e823e104b845
Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 } |