mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-01-10 02:29:23 +00:00
Refactor to replace some sketchy code with code actually in use.
--HG-- rename : src/sixtypical/objects.py => src/sixtypical/model.py
This commit is contained in:
parent
15e6a732f5
commit
dd4c50fc50
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1 @@
|
||||
*.o
|
||||
*.hi
|
||||
*.pyc
|
||||
|
@ -40,6 +40,7 @@ For 0.3:
|
||||
* explicitly-addressed memory locations.
|
||||
* generate 6502 code (either Ophis assembler or machine code `PRG` files.)
|
||||
* `while` loops.
|
||||
* `repeat` loops.
|
||||
* a little demo that actually compiles and runs on a C64 emulator.
|
||||
|
||||
For 0.4 and/or beyond:
|
||||
|
@ -3,7 +3,7 @@
|
||||
import sys
|
||||
|
||||
from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
||||
from sixtypical.parser import ConstantRef, LocationRef
|
||||
from sixtypical.model import ConstantRef, LocationRef
|
||||
|
||||
|
||||
UNINITIALIZED = 'UNINITIALIZED'
|
||||
|
@ -1,7 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
||||
from sixtypical.parser import ConstantRef, LocationRef
|
||||
from sixtypical.model import ConstantRef, LocationRef
|
||||
|
||||
|
||||
# TODO: should not inherit from dict
|
||||
|
30
src/sixtypical/model.py
Normal file
30
src/sixtypical/model.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""Data/storage model for SixtyPical."""
|
||||
|
||||
class LocationRef(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __repr__(self):
|
||||
return 'LocationRef(%r)' % self.name
|
||||
|
||||
|
||||
class ConstantRef(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __repr__(self):
|
||||
return 'ConstantRef(%r)' % self.value
|
||||
|
||||
|
||||
# TODO type=byte
|
||||
|
||||
REG_A = LocationRef('a')
|
||||
REG_X = LocationRef('x')
|
||||
REG_Y = LocationRef('y')
|
||||
|
||||
# TODO type=bit
|
||||
|
||||
FLAG_Z = LocationRef('z')
|
||||
FLAG_C = LocationRef('c')
|
||||
FLAG_N = LocationRef('n')
|
||||
FLAG_V = LocationRef('v')
|
@ -1,31 +0,0 @@
|
||||
|
||||
|
||||
class Type(object):
|
||||
pass
|
||||
|
||||
class BitType(Type):
|
||||
pass
|
||||
|
||||
class ByteType(Type):
|
||||
pass
|
||||
|
||||
class MemoryLocation(object):
|
||||
def __init__(self, name, type_=ByteType, readonly=False):
|
||||
self.name = name
|
||||
self.type_ = type_
|
||||
self.readonly = readonly
|
||||
|
||||
|
||||
regA = MemoryLocation('a')
|
||||
regX = MemoryLocation('x')
|
||||
regY = MemoryLocation('y')
|
||||
|
||||
regC = MemoryLocation('c', type=BitType)
|
||||
regZ = MemoryLocation('z', type=BitType)
|
||||
regN = MemoryLocation('n', type=BitType)
|
||||
regV = MemoryLocation('v', type=BitType)
|
||||
|
||||
|
||||
class Context(dict):
|
||||
# maps MemoryLoction -> properties: uninitialized, initialized, written
|
||||
pass
|
@ -3,6 +3,7 @@
|
||||
import re
|
||||
|
||||
from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
||||
from sixtypical.model import LocationRef, ConstantRef
|
||||
|
||||
|
||||
class Scanner(object):
|
||||
@ -69,28 +70,6 @@ class Scanner(object):
|
||||
return False
|
||||
|
||||
|
||||
# - - - -
|
||||
|
||||
|
||||
class LocationRef(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def __repr__(self):
|
||||
return 'LocationRef(%r)' % self.name
|
||||
|
||||
|
||||
class ConstantRef(object):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __repr__(self):
|
||||
return 'ConstantRef(%r)' % self.value
|
||||
|
||||
|
||||
# - - - -
|
||||
|
||||
|
||||
class Parser(object):
|
||||
def __init__(self, text):
|
||||
self.scanner = Scanner(text)
|
||||
|
Loading…
x
Reference in New Issue
Block a user