Skip to content

Commit

Permalink
Merge pull request #250 from tomhea/feature/faster-ptr
Browse files Browse the repository at this point in the history
Feature/faster ptr
  • Loading branch information
tomhea authored Nov 18, 2023
2 parents 78c85f4 + f3463b3 commit 31ec349
Show file tree
Hide file tree
Showing 45 changed files with 1,312 additions and 430 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Programs won't work on their first run. They just can't. That's why we support t
- `-b NAME [NAME ...]`: Places breakpoints at every specified label NAMEs (note that label names are long: [more information about labels](flipjump/README.md#generated-label-names)). (requires `-b`)
- `-B NAME [NAME ...]`: Places breakpoints at every label that contains one of the given NAMEs. (requires `-b`)

The debugger can single-step, read-memory, read flipjump variables (bit/hex/byte, and their vectors), continue, or skip forward a fixed number of opcodes.

# Get Started with FlipJump
- Install flipjump: `pip install flipjump`
Expand Down
8 changes: 6 additions & 2 deletions flipjump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ The whole interpretation is done within the [run()](interpretter/fjm_run.py) fun
More about [how to run](../README.md#how-to-run).
![Running the compiled calculator](../res/calc__run.jpg)

The Interpreter has a built-in debugger, and it's activated by specifying breakpoints when called (via the [breakpoints.py](interpretter/debugging/breakpoints.py)'s `BreakpointHandler`).
The debugger can stop on the next breakpoint, or on a fixed number of executed ops after the current breakpoint.
### The Debugger

The Interpreter has a built-in debugger, and it's activated by specifying breakpoints when called (via the [breakpoints.py](interpretter/debugging/breakpoints.py)'s `BreakpointHandler`).
The debugger can stop on the next breakpoint, read memory, read flipjump variables, or on a fixed number of executed ops after the current breakpoint.
In order to call the debugger with the right labels, get familiar with the [generating label names](README.md#Generated-Label-Names) (and see the debugger-image there), and use the `-d`/`-b`/`-B` cli options.
More about [how to debug](../README.md#how-to-debug).

### Macro Usage

The [macro_usage_graph.py](interpretter/debugging/macro_usage_graph.py) file exports a feature to present the macro-usage (which are the most used macros, and what % do they take from the overall flipjump ops) in a graph.
In order to view it, run the assembler with `--stats` (requires plotly to be installed (installed automatically with `pip install flipjump[stats]`)).
For example:
Expand Down
7 changes: 6 additions & 1 deletion flipjump/assembler/fj_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def NL(self, t: Token) -> Token:
self.lineno += 1
return t

def ignore_line_continuation(self, t: Token) -> Token:
self.lineno += 1
return t

def error(self, t: Token) -> None:
global error_occurred, all_errors
error_occurred = True
Expand All @@ -193,7 +197,8 @@ def _get_main_macro_code_position(first_file: Tuple[str, Path]) -> CodePosition:
# noinspection PyUnusedLocal,PyUnresolvedReferences,PyPep8Naming
class FJParser(sly.Parser):
tokens = FJLexer.tokens
# TODO add Unary Minus (-), Unary Not (~). Maybe add logical or (||) and logical and (&&). Maybe handle power (**).
# TODO #249 - add Unary Minus (-), Unary Not (~).
# Maybe add logical or (||) and logical and (&&). Maybe handle power (**).
precedence = (
('right', '?', ':'),
('left', '|'),
Expand Down
5 changes: 4 additions & 1 deletion flipjump/assembler/preprocessor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import collections
import sys
from typing import Dict, Tuple, Iterable, Union, Deque, Set, List, Optional

from flipjump.interpretter.debugging.macro_usage_graph import show_macro_usage_pie_graph
from flipjump.utils.constants import MACRO_SEPARATOR_STRING, STARTING_LABEL_IN_MACROS_STRING, \
DEFAULT_MAX_MACRO_RECURSION_DEPTH
DEFAULT_MAX_MACRO_RECURSION_DEPTH, GAP_BETWEEN_PYTHONS_AND_PREPROCESSOR_MACRO_RECURSION_DEPTH
from flipjump.utils.exceptions import FlipJumpPreprocessorException, FlipJumpExprException
from flipjump.assembler.inner_classes.expr import Expr
from flipjump.assembler.inner_classes.ops import FlipJump, WordFlip, Label, Segment, Reserve, MacroCall, RepCall, \
Expand Down Expand Up @@ -105,6 +106,8 @@ def __init__(self,
self.result_ops.append(first_segment)

self.max_recursion_depth = max_recursion_depth
if max_recursion_depth + GAP_BETWEEN_PYTHONS_AND_PREPROCESSOR_MACRO_RECURSION_DEPTH < sys.getrecursionlimit():
sys.setrecursionlimit(max_recursion_depth + GAP_BETWEEN_PYTHONS_AND_PREPROCESSOR_MACRO_RECURSION_DEPTH)

def patch_last_wflip_address(self) -> None:
self.last_new_segment.wflip_start_address = self.curr_address
Expand Down
30 changes: 12 additions & 18 deletions flipjump/flipjump_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from flipjump.assembler import assembler
from flipjump.fjm.fjm_consts import FJMVersion, SUPPORTED_VERSIONS_NAMES
from flipjump.fjm.fjm_writer import Writer
from flipjump.utils.exceptions import FlipJumpException
from flipjump.interpretter.io_devices.StandardIO import StandardIO
from flipjump.utils.constants import LAST_OPS_DEBUGGING_LIST_DEFAULT_LENGTH, DEFAULT_MAX_MACRO_RECURSION_DEPTH
from flipjump.utils.functions import get_file_tuples, get_temp_directory_suffix
Expand Down Expand Up @@ -78,23 +77,18 @@ def run(in_fjm_path: Path, debug_file: Optional[Path], args: argparse.Namespace,
if debug_file:
verify_file_exists(error_func, debug_file)

try:
flipjump_quickstart.debug(
in_fjm_path,
debug_file,
breakpoints_addresses=set(),
breakpoints=set(args.breakpoint),
breakpoints_contains=set(args.breakpoint_contains),
io_device=StandardIO(not args.no_output),
show_trace=args.trace,
print_time=not args.silent,
print_termination=not args.silent,
last_ops_debugging_list_length=args.debug_ops_list,
)
except FlipJumpException as e:
print()
print(e)
exit(1)
flipjump_quickstart.debug(
in_fjm_path,
debug_file,
breakpoints_addresses=set(),
breakpoints=set(args.breakpoint),
breakpoints_contains=set(args.breakpoint_contains),
io_device=StandardIO(not args.no_output),
show_trace=args.trace,
print_time=not args.silent,
print_termination=not args.silent,
last_ops_debugging_list_length=args.debug_ops_list,
)


def get_version(version: Optional[int], is_outfile_specified: bool) -> FJMVersion:
Expand Down
6 changes: 3 additions & 3 deletions flipjump/flipjump_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def run_test_output(fjm_path: Path,
last_ops_debugging_list_length=last_ops_debugging_list_length)

try:
assert expected_termination_cause == termination_statistics.termination_cause
assert expected_output.decode(IO_BYTES_ENCODING) == \
io_device.get_output(allow_incomplete_output=True).decode(IO_BYTES_ENCODING)
assert termination_statistics.termination_cause == expected_termination_cause
assert io_device.get_output(allow_incomplete_output=True).decode(IO_BYTES_ENCODING) == \
expected_output.decode(IO_BYTES_ENCODING)
return True
except AssertionError as assertion_error:
if should_raise_assertion_error:
Expand Down
Loading

0 comments on commit 31ec349

Please sign in to comment.