aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Assembler.hs3
-rw-r--r--JackCompiler.hs3
-rw-r--r--jackos/Memory.jack2
3 files changed, 6 insertions, 2 deletions
diff --git a/Assembler.hs b/Assembler.hs
index ca79a48..47959ea 100644
--- a/Assembler.hs
+++ b/Assembler.hs
@@ -80,12 +80,15 @@ stripJunk xs = filter (not . null) $ (filter (not . (flip elem " \t")) . head .
stripLabels :: [[Char]] -> [[Char]]
stripLabels = filter (not . (elem '('))
+-- For labels
addLabels :: [[Char]] -> Int -> Map [Char] [Char] -> Map [Char] [Char]
addLabels [] _ table = table
addLabels ((hd:tl):rest) addr table
| hd == '(' = addLabels rest addr (Map.insert (init tl) (int2Bin16 addr) table)
| otherwise = addLabels rest (addr + 1) table
+-- For variables, addr is the current instruction address, vaddr is the
+-- variable memory address (to be assigned)
addSyms :: [[Char]] -> Int -> Int -> Map [Char] [Char] -> Map [Char] [Char]
addSyms [] _ _ table = table
addSyms ((hd:tl):rest) addr vaddr table
diff --git a/JackCompiler.hs b/JackCompiler.hs
index f651f62..d0c375b 100644
--- a/JackCompiler.hs
+++ b/JackCompiler.hs
@@ -1,4 +1,5 @@
--- Jack Compiler, as the coursework of Project 11 of Nand2Tetris course (http://nand2tetris.org/).
+-- Jack Compiler, as the coursework of Project 11 of Nand2Tetris
+-- course (http://nand2tetris.org/).
-- Author: Yuchen Pei (me@ypei.me)
-- Date: 2018-01-15
{-# LANGUAGE FlexibleContexts #-}
diff --git a/jackos/Memory.jack b/jackos/Memory.jack
index 54e04aa..82c10dd 100644
--- a/jackos/Memory.jack
+++ b/jackos/Memory.jack
@@ -53,7 +53,7 @@ class Memory {
let heap[current + 1] = heap[current + 1] - size2;
let newLast = current + heap[current + 1] + 2;
let heap[newLast] = heap[current];
- let heap[current] = newLast;
+ let heap[current] = newLast; // This seems to be wrong - a free segment pointing to an allocated segment - will cause double allocation.
let heap[newLast + 1] = size;
return heap + newLast + 2;
}