annotate modules/bytearray.tp @ 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.
author Michael Pavone <pavone@retrodev.com>
date Thu, 24 Jul 2014 21:58:26 -0700
parents fb922651db29
children 2a0a88799737
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: {
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray to bytearray module. Add read:to method to os module for reading into a bytearray.
Michael Pavone <pavone@retrodev.com>
parents: 258
diff changeset
10 sz <_ 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
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
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 llMessage: _buf_ptr 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
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
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 llMessage: stringFrom:to 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
50 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
51 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
52 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
53 } 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
54 //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
55 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
56 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
57 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
58 str data!: (GC_MALLOC_ATOMIC: (str bytes) + 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
59 memcpy: (str data) buffer (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
60 (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
61 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
62 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 string <- {
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 stringFrom: 0 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
66 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 findChar:else <- :char found :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
69 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
70 n <- length
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 i <- 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
72 while: { notFound && i < n } do: {
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 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
74 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
75 } 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
76 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
77 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 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
80 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
81 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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 } _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
84 }
d1dc2d70bdfd Move OS module out of backend Javascript into a proper module file. Add normal bytearray 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
178
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 executable <- :size {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 buf <- #{
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 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
89 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
90 llMessage: _init withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
91 sz <- obj_int32 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
92 } andCode: :sz {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
93 bytes <- sz num
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
94 buffer <- sbrk: bytes
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 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
96 self
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
97 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 llMessage: set withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 offset <- obj_int32 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 newval <- obj_uint8 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 } andCode: :offset newval {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 (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
103 self
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 llMessage: get withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 offset <- obj_int32 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 ret <- obj_uint8 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108 } andCode: :offset {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
109 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
110 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
111 ret
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113 llMessage: run withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114 fun <- uint64_t funptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
115 funret <- obj_uint64 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
116 } andCode: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
117 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
118 fun <- buffer
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
119 funret num!: ( fun: )
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 funret
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
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 llMessage: runWithArg withVars: {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
124 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
125 funret <- obj_uint64 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 arg <- obj_uint64 ptr
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
127 } andCode: :arg {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 fun <- buffer
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129 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
130 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
131 funret
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 }
258
fb922651db29 Pass size parameter to _init in bytearray
Michael Pavone <pavone@retrodev.com>
parents: 180
diff changeset
134 buf _init: size
178
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
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
137 executableFromBytes <- :bytes {
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
138 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
139 acc + (el length)
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
140 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
141 ba <- executable: totalSize
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 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
143 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
144 }
e823e104b845 Add initial work on bytearrays with support for allocating executable memory
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 ba
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 }