Explicit literal compilation

This commit is contained in:
Piotr Wiszowaty 2014-07-30 22:40:18 +02:00 committed by Piotr Wiszowaty
parent b6eca43f13
commit c892085cd6

22
foco65
View File

@ -400,23 +400,17 @@ class Forth:
x1 = self.pop(token) x1 = self.pop(token)
self.push(x1 / x2) self.push(x1 / x2)
elif token == "]": elif token == "]":
self.word.add("lit")
tos = self.pop(token)
if isinstance(tos, int):
txt = str(tos)
else:
txt = tos.output(self.text_section)
self.word.add(txt)
self.set_state("compile") self.set_state("compile")
elif self.isnumber(token): elif self.isnumber(token):
self.push(self.tonumber(token.text)) self.push(self.tonumber(token.text))
elif token is not None: elif token is not None:
word = self.words.find(token.text) word = self.words.find(token.text)
if word is not None: if word is not None:
word.used = True
if isinstance(word, Constant): if isinstance(word, Constant):
self.push(self.tonumber(word.value)) self.push(self.tonumber(word.value))
else: else:
raise ParseError("not a constant '%s'" % token, token.line, token.column) self.push(word.name)
else: else:
raise UnknownWord(token) raise UnknownWord(token)
@ -479,6 +473,16 @@ class Forth:
target1.update(word.ip()) target1.update(word.ip())
elif token == "[": elif token == "[":
self.set_state("interpret") self.set_state("interpret")
elif token == "literal":
self.word.add("lit")
tos = self.pop(token)
if isinstance(tos, int):
txt = str(tos)
elif isinstance(tos, str):
txt = tos
else:
txt = tos.output(self.text_section)
self.word.add(txt)
elif token == "do": elif token == "do":
word.add("do", "do") word.add("do", "do")
self.push(word.ip()) self.push(word.ip())
@ -552,7 +556,7 @@ class Forth:
self.items.append(Code("\n org *+%d" % count, self.data_section)) self.items.append(Code("\n org *+%d" % count, self.data_section))
def parse_comma(self, token): def parse_comma(self, token):
item = Code("\n dta a(%d)" % self.pop(token), self.data_section) item = Code("\n dta a(%s)" % self.pop(token), self.data_section)
self.items.append(item) self.items.append(item)
def parse_c_comma(self, token): def parse_c_comma(self, token):