From 08ec0e46a3c1aeeb1058f44cd3a69c89e91ca0f3 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Mon, 12 Feb 2018 14:53:49 +0000 Subject: [PATCH] Remove the need for parens in `vector (routine ...) table` type. --- HISTORY.md | 2 ++ README.md | 3 ++- doc/SixtyPical.md | 5 +++-- eg/proto-game.60p | 2 +- src/sixtypical/parser.py | 15 ++++++++++----- tests/SixtyPical Compilation.md | 4 ++-- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index cba79b4..7810c0e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,8 @@ History of SixtyPical * Implements the "union rule for trashes" when analyzing `if` blocks. * Even if we `goto` another routine, we can't trash an output. * `static` storage locations local to routines can now be defined within routines. +* Small grammar change that obviates the need for parentheses in the type expression + `vector (routine ...) table`. * Fixed bug where `trash` was not marking the location as being virtually altered. 0.11 diff --git a/README.md b/README.md index b104d0c..578656e 100644 --- a/README.md +++ b/README.md @@ -67,11 +67,12 @@ is probably NP-complete. But doing it adeuqately is probably not that hard. ### And at some point... * `const`s that can be used in defining the size of tables, etc. -* Remove the need for `forward` and `vector () table` (make grammar changes) +* Remove the need for `forward` (lots of backpatching) * Tests, and implementation, ensuring a routine can be assigned to a vector of "wider" type * Check that the buffer being read or written to through pointer, appears in approporiate inputs or outputs set. (Associate each pointer with the buffer it points into.) * `static` pointers -- currently not possible because pointers must be zero-page, thus `@`, thus uninitialized. +* Question the value of the "consistent initialization" principle for `if` statement analysis. * `interrupt` routines -- to indicate that "the supervisor" has stored values on the stack, so we can trash them. * Error messages that include the line number of the source code. * Add absolute addressing in shl/shr, absolute-indexed for add, sub, etc. diff --git a/doc/SixtyPical.md b/doc/SixtyPical.md index 9dae554..79f4782 100644 --- a/doc/SixtyPical.md +++ b/doc/SixtyPical.md @@ -537,13 +537,14 @@ Grammar Program ::= {TypeDefn} {Defn} {Routine}. TypeDefn::= "typedef" Type Ident. Defn ::= Type Ident [Constraints] (":" Literal | "@" LitWord). - Type ::= "(" Type ")" | TypeExpr ["table" TypeSize]. + Type ::= TypeTerm ["table" TypeSize]. TypeExpr::= "byte" | "word" | "buffer" TypeSize | "pointer" - | "vector" Type + | "vector" TypeTerm | "routine" Constraints + | "(" Type ")" . TypeSize::= "[" LitWord "]". Constrnt::= ["inputs" LocExprs] ["outputs" LocExprs] ["trashes" LocExprs]. diff --git a/eg/proto-game.60p b/eg/proto-game.60p index 2b64ea9..b644eeb 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -87,7 +87,7 @@ word new_pos word table[256] actor_delta word delta -vector (logic_routine) table[256] actor_logic +vector logic_routine table[256] actor_logic vector logic_routine dispatch_logic byte table[32] press_fire_msg: "PRESS`FIRE`TO`PLAY" diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index f9423de..ce327db 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -136,6 +136,15 @@ class Parser(object): return size def defn_type(self): + type_ = self.defn_type_term() + + if self.scanner.consume('table'): + size = self.defn_size() + type_ = TableType(type_, size) + + return type_ + + def defn_type_term(self): type_ = None if self.scanner.consume('('): @@ -148,7 +157,7 @@ class Parser(object): elif self.scanner.consume('word'): type_ = TYPE_WORD elif self.scanner.consume('vector'): - type_ = self.defn_type() + type_ = self.defn_type_term() if not isinstance(type_, RoutineType): raise SyntaxError("Vectors can only be of a routine, not %r" % type_) type_ = VectorType(type_) @@ -167,10 +176,6 @@ class Parser(object): raise SyntaxError("Undefined type '%s'" % type_name) type_ = self.typedefs[type_name] - if self.scanner.consume('table'): - size = self.defn_size() - type_ = TableType(type_, size) - return type_ def defn_name(self): diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 87e1f14..ca4102a 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -634,9 +634,9 @@ Copying to and from a vector table. | outputs x | trashes a, z, n | one - | vector (routine + | vector routine | outputs x - | trashes a, z, n) + | trashes a, z, n | table[256] many | | routine bar outputs x trashes a, z, n {