Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#641 from cronomantic/master
Browse files Browse the repository at this point in the history
New parameter to set the heap address
  • Loading branch information
boriel committed Jan 1, 2023
2 parents f5f183d + c550c6b commit 6a98501
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ and type `zxbc` (on Windows) or `zxbc.py` (OSX, Linux). You should see a zxbasic
```
usage: zxbc [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE] [-T] [-t] [-B] [-a] [-A]
[-S ORG] [-e STDERR] [--array-base ARRAY_BASE]
[--string-base STRING_BASE] [-Z] [-H HEAP_SIZE] [--debug-memory]
[--string-base STRING_BASE] [-Z] [-H HEAP_SIZE]
[--heap-adddress HEAP_ADDRESS] [--debug-memory]
[--debug-array] [--strict-bool] [--enable-break] [-E] [--explicit]
[-D DEFINES] [-M MEMORY_MAP] [-i] [-I INCLUDE_PATH] [--strict]
[--version]
Expand Down
2 changes: 2 additions & 0 deletions docs/zxb.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ ZXB provides several (and useful) command line options. To see them, just type *
Sinclair BASIC features: ATTR, SCREEN$, POINT
-H HEAP_SIZE, --heap-size HEAP_SIZE
Sets heap size in bytes (default 4768 bytes)
--heap-size HEAP_ADDRESS
Sets the start address of the heap
--debug-memory Enables out-of-memory debug
--debug-array Enables array boundary checking
--strict-bool Enforce boolean values to be 0 or 1
Expand Down
11 changes: 9 additions & 2 deletions src/arch/z80/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="org", type=int, default=32768)
# Default HEAP SIZE (Dynamic memory) in bytes
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
# Default HEAP ADDRESS (Dynamic memory) address
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_address", type=int, default=None, ignore_none=False)


def init():
Expand All @@ -370,6 +372,8 @@ def init():
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="org", type=int, default=32768)
# Default HEAP SIZE (Dynamic memory) in bytes
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
# Default HEAP ADDRESS (Dynamic memory) address
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_address", type=int, default=None, ignore_none=False)
# Labels for HEAP START (might not be used if not needed)
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_start_label", type=str, default=f"{NAMESPACE}.ZXBASIC_MEM_HEAP")
# Labels for HEAP SIZE (might not be used if not needed)
Expand Down Expand Up @@ -802,8 +806,11 @@ def emit_start():

if REQUIRES.intersection(MEMINITS) or f"{NAMESPACE}.__MEM_INIT" in INITS:
heap_init.append("; Defines HEAP SIZE\n" + OPTIONS.heap_size_label + " EQU " + str(OPTIONS.heap_size))
heap_init.append(OPTIONS.heap_start_label + ":")
heap_init.append("DEFS %s" % str(OPTIONS.heap_size))
if OPTIONS.heap_address is None:
heap_init.append(OPTIONS.heap_start_label + ":")
heap_init.append("DEFS %s" % str(OPTIONS.heap_size))
else:
heap_init.append("; Defines HEAP ADDRESS\n" + OPTIONS.heap_start_label + " EQU %s" % OPTIONS.heap_address)

heap_init.append(
"; Defines USER DATA Length in bytes\n"
Expand Down
2 changes: 2 additions & 0 deletions src/arch/zxnext/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def init():
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="org", type=int, default=32768)
# Default HEAP SIZE (Dynamic memory) in bytes
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_size", type=int, default=4768, ignore_none=True) # A bit more than 4K
# Default HEAP ADDRESS (Dynamic memory) address
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_address", type=int, default=None, ignore_none=False)
# Labels for HEAP START (might not be used if not needed)
OPTIONS(Action.ADD_IF_NOT_DEFINED, name="heap_start_label", type=str, default=f"{NAMESPACE}.ZXBASIC_MEM_HEAP")
# Labels for HEAP SIZE (might not be used if not needed)
Expand Down
4 changes: 4 additions & 0 deletions src/zxbc/args_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def parse_options(args: List[str] = None):
if OPTIONS.org is None:
parser.error(f"Invalid --org option '{options.org}'")

OPTIONS.heap_address = (
OPTIONS.heap_address if options.heap_address is None else src.api.utils.parse_int(options.heap_address)
)

if options.defines:
for i in options.defines:
macro = list(i.split("=", 1))
Expand Down
1 change: 1 addition & 0 deletions src/zxbc/args_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def parser() -> argparse.ArgumentParser:
parser_.add_argument(
"-H", "--heap-size", type=int, help=f"Sets heap size in bytes (default {OPTIONS.heap_size} bytes)"
)
parser_.add_argument("--heap-address", type=str, default=None, help="Sets the heap address.")
parser_.add_argument("--debug-memory", action="store_true", default=None, help="Enables out-of-memory debug")
parser_.add_argument("--debug-array", action="store_true", default=None, help="Enables array boundary checking")
parser_.add_argument("--strict-bool", action="store_true", default=None, help="Enforce boolean values to be 0 or 1")
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/test_cmdline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
usage: zxbc.py [-h] [-d] [-O OPTIMIZE] [-o OUTPUT_FILE]
[-T | -t | -A | --parse-only] [-B] [-a] [-S ORG] [-e STDERR]
[--array-base ARRAY_BASE] [--string-base STRING_BASE] [-Z]
[-H HEAP_SIZE] [--debug-memory] [--debug-array] [--strict-bool]
[--enable-break] [-E] [--explicit] [-D DEFINES] [-M MEMORY_MAP]
[-i | +i] [-I INCLUDE_PATH] [--strict] [--headerless]
[--version] [--append-binary APPEND_BINARY]
[-H HEAP_SIZE] [--heap-address HEAP_ADDRESS] [--debug-memory]
[--debug-array] [--strict-bool] [--enable-break] [-E]
[--explicit] [-D DEFINES] [-M MEMORY_MAP] [-i | +i]
[-I INCLUDE_PATH] [--strict] [--headerless] [--version]
[--append-binary APPEND_BINARY]
[--append-headless-binary APPEND_HEADLESS_BINARY] [-N]
[--arch ARCH] [--expect-warnings EXPECT_WARNINGS]
[-W DISABLE_WARNING] [+W ENABLE_WARNING] [--hide-warning-codes]
Expand Down

0 comments on commit 6a98501

Please sign in to comment.