annotate modules/bytearray.tp @ 312:8511aac1ce82

Fix module references in macros
author Michael Pavone <pavone@retrodev.com>
date Fri, 05 Sep 2014 09:56:22 -0700
parents 2a0a88799737
children 4c669942c30d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4
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
5 normal <- :size {
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
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
11 } andCode: :sz {
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
12 bytes <- sz 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
13 buffer <- GC_MALLOC_ATOMIC: 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
14 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
15 }
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
296
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
17 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
18 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
19 } 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
20 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
21 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
22 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
23 }
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 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
26 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
27 } 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
28 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
29 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
30 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
31 }
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 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
34 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
35 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
36 } 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
37 (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
38 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
39 }
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 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
41 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
42 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
43 } 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
44 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
45 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
46 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
47 }
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
296
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
49 llMessage: shrinkTo withVars: {
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
50 newsize <- obj_int32 ptr
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
51 } andCode: :newsize {
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
52 if: (newsize num) < bytes {
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
53 bytes <- newsize num
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
54 }
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
55 self
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
56 }
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 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
59 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
60 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
61 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
62 } 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
63 //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
64 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
65 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
66 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
67 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
68 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
69 (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
70 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
71 }
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 string <- {
296
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
74 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
75 }
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
296
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
77 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
78 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
79 n <- length
296
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
80 i <- start
2a0a88799737 A number of fixes and enhancmenets to "normal" bytearrays
Michael Pavone <pavone@retrodev.com>
parents: 294
diff changeset
81 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
82 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
83 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
84 } 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
85 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
86 }
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 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
89 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
90 }
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 } _init_buf: size
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
93 }
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
94
178
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 executable <- :size {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 buf <- #{
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 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
98 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
99 llMessage: _init withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 sz <- obj_int32 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 } andCode: :sz {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 bytes <- sz num
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 buffer <- sbrk: bytes
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 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
105 self
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 llMessage: set withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 offset <- obj_int32 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 newval <- obj_uint8 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 } andCode: :offset newval {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
111 (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
112 self
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 llMessage: get withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 offset <- obj_int32 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 ret <- obj_uint8 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 } andCode: :offset {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
118 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
119 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
120 ret
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: run withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 fun <- uint64_t funptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 funret <- obj_uint64 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
125 } andCode: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 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
127 fun <- buffer
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 funret num!: ( fun: )
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 funret
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 llMessage: runWithArg withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 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
134 funret <- obj_uint64 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 arg <- obj_uint64 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 } andCode: :arg {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 fun <- buffer
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 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
139 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
140 funret
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 }
258
fb922651db29 Pass size parameter to _init in bytearray
Michael Pavone <pavone@retrodev.com>
parents: 180
diff changeset
143 buf _init: size
178
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
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 executableFromBytes <- :bytes {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147 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
148 acc + (el length)
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150 ba <- executable: totalSize
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
151 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
152 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
153 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
154 ba
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
155 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
156 }