MVP #1
1
TODO.md
1
TODO.md
@ -1,5 +1,4 @@
|
|||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- Implement foldl for bytes
|
- Implement foldl for bytes
|
||||||
- Replace ___new_reference___ by stdlib.alloc.__alloc__
|
|
||||||
- Implement a trace() builtin for debugging
|
- Implement a trace() builtin for debugging
|
||||||
|
|||||||
@ -376,7 +376,6 @@ def module(inp: ourlang.Module) -> wasm.Module:
|
|||||||
]
|
]
|
||||||
|
|
||||||
result.functions = [
|
result.functions = [
|
||||||
_generate____new_reference___(inp), # Old allocator
|
|
||||||
stdlib_alloc.__init__,
|
stdlib_alloc.__init__,
|
||||||
stdlib_alloc.__find_free_block__,
|
stdlib_alloc.__find_free_block__,
|
||||||
stdlib_alloc.__alloc__,
|
stdlib_alloc.__alloc__,
|
||||||
@ -390,32 +389,9 @@ def module(inp: ourlang.Module) -> wasm.Module:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _generate____new_reference___(mod: ourlang.Module) -> wasm.Function:
|
|
||||||
return wasm.Function(
|
|
||||||
'___new_reference___',
|
|
||||||
'___new_reference___',
|
|
||||||
[
|
|
||||||
('alloc_size', type_(mod.types['i32']), ),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
('result', type_(mod.types['i32']), ),
|
|
||||||
],
|
|
||||||
type_(mod.types['i32']),
|
|
||||||
[
|
|
||||||
i32.const(0),
|
|
||||||
i32.const(0),
|
|
||||||
i32.load(),
|
|
||||||
wasm.Statement('local.tee', '$result', comment='Address for this call'),
|
|
||||||
wasm.Statement('local.get', '$alloc_size'),
|
|
||||||
i32.add(),
|
|
||||||
i32.store(comment='Address for the next call'),
|
|
||||||
wasm.Statement('local.get', '$result'),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def _generate_tuple_constructor(inp: ourlang.TupleConstructor) -> Statements:
|
def _generate_tuple_constructor(inp: ourlang.TupleConstructor) -> Statements:
|
||||||
yield wasm.Statement('i32.const', str(inp.tuple.alloc_size()))
|
yield wasm.Statement('i32.const', str(inp.tuple.alloc_size()))
|
||||||
yield wasm.Statement('call', '$___new_reference___')
|
yield wasm.Statement('call', '$stdlib.alloc.__alloc__')
|
||||||
|
|
||||||
yield wasm.Statement('local.set', '$___new_reference___addr')
|
yield wasm.Statement('local.set', '$___new_reference___addr')
|
||||||
|
|
||||||
@ -434,7 +410,7 @@ def _generate_tuple_constructor(inp: ourlang.TupleConstructor) -> Statements:
|
|||||||
|
|
||||||
def _generate_struct_constructor(inp: ourlang.StructConstructor) -> Statements:
|
def _generate_struct_constructor(inp: ourlang.StructConstructor) -> Statements:
|
||||||
yield wasm.Statement('i32.const', str(inp.struct.alloc_size()))
|
yield wasm.Statement('i32.const', str(inp.struct.alloc_size()))
|
||||||
yield wasm.Statement('call', '$___new_reference___')
|
yield wasm.Statement('call', '$stdlib.alloc.__alloc__')
|
||||||
|
|
||||||
yield wasm.Statement('local.set', '$___new_reference___addr')
|
yield wasm.Statement('local.set', '$___new_reference___addr')
|
||||||
|
|
||||||
|
|||||||
@ -186,7 +186,7 @@ class Module(WatSerializable):
|
|||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.imports: List[Import] = []
|
self.imports: List[Import] = []
|
||||||
self.functions: List[Function] = []
|
self.functions: List[Function] = []
|
||||||
self.memory = ModuleMemory(b'\x04') # For ___new_reference___
|
self.memory = ModuleMemory()
|
||||||
|
|
||||||
def to_wat(self) -> str:
|
def to_wat(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class Suite:
|
|||||||
# Check if code formatting works
|
# Check if code formatting works
|
||||||
assert self.code_py == '\n' + phasm_render(runner.phasm_ast) # \n for formatting in tests
|
assert self.code_py == '\n' + phasm_render(runner.phasm_ast) # \n for formatting in tests
|
||||||
|
|
||||||
# runner.call('stdlib.alloc.__init__')
|
runner.call('stdlib.alloc.__init__')
|
||||||
|
|
||||||
wasm_args = []
|
wasm_args = []
|
||||||
if args:
|
if args:
|
||||||
@ -101,12 +101,9 @@ class Suite:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(arg, bytes):
|
if isinstance(arg, bytes):
|
||||||
# TODO: Implement and use the bytes constructor function
|
adr = runner.call('stdlib.types.__alloc_bytes__', len(arg))
|
||||||
# TODO: call upon stdlib.alloc.__init__ and stdlib.alloc.__alloc__
|
|
||||||
adr = runner.call('___new_reference___', len(arg) + 4)
|
|
||||||
sys.stderr.write(f'Allocation 0x{adr:08x} {repr(arg)}\n')
|
sys.stderr.write(f'Allocation 0x{adr:08x} {repr(arg)}\n')
|
||||||
|
|
||||||
runner.interpreter_write_memory(adr, len(arg).to_bytes(4, byteorder='little'))
|
|
||||||
runner.interpreter_write_memory(adr + 4, arg)
|
runner.interpreter_write_memory(adr + 4, arg)
|
||||||
wasm_args.append(adr)
|
wasm_args.append(adr)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user