about summary refs log blame commit diff stats
path: root/archive/1.vm/018constant.cc
blob: bbf3a4121a0162ace67786fb40018f5ddd01a8c5 (plain) (tree)
1
2
3
4
5
6
7




                                        

          










                                                          









                                                                    
 

           










                                                           









                                                                     


          


                                        










                                                          









                                                                    
//: A few literal constants.

:(before "End Mu Types Initialization")
put(Type_ordinal, "literal-boolean", 0);

//: 'true'

:(code)
void test_true() {
  load(
      "def main [\n"
      "  1:boolean <- copy true\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "parse:   ingredient: {true: \"literal-boolean\"}\n"
  );
}

:(before "End Parsing reagent")
if (name == "true") {
  if (type != NULL) {
    raise << "'true' is a literal and can't take a type\n" << end();
    return;
  }
  type = new type_tree("literal-boolean");
  set_value(1);
}

//: 'false'

:(code)
void test_false() {
  load(
      "def main [\n"
      "  1:boolean <- copy false\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "parse:   ingredient: {false: \"literal-boolean\"}\n"
  );
}

:(before "End Parsing reagent")
if (name == "false") {
  if (type != NULL) {
    raise << "'false' is a literal and can't take a type\n" << end();
    return;
  }
  type = new type_tree("literal-boolean");
  set_value(0);
}

//: 'null'

:(before "End Mu Types Initialization")
put(Type_ordinal, "literal-address", 0);

:(code)
void test_null() {
  load(
      "def main [\n"
      "  1:address:number <- copy null\n"
      "]\n"
  );
  CHECK_TRACE_CONTENTS(
      "parse:   ingredient: {null: \"literal-address\"}\n"
  );
}

:(before "End Parsing reagent")
if (name == "null") {
  if (type != NULL) {
    raise << "'null' is a literal and can't take a type\n" << end();
    return;
  }
  type = new type_tree("literal-address");
  set_value(0);
}
an class="bp">self.contains_point(y, x) def draw(self): """ Draw the object. Called on every main iteration if visible. Containers should call draw() on their contained objects here. Override this! """ def destroy(self): """ Called when the object is destroyed. Override this! """ def contains_point(self, y, x): """ Test whether the point (with absolute coordinates) lies within the boundaries of this object. """ return (x >= self.x and x < self.x + self.wid) and \ (y >= self.y and y < self.y + self.hei) def click(self, event): """ Called when a mouse key is pressed and self.focused is True. Override this! """ pass def press(self, key): """ Called when a key is pressed and self.focused is True. Override this! """ pass def poke(self): """Called before drawing, even if invisible""" if self._old_visible != self.visible: self._old_visible = self.visible self.need_redraw = True if not self.visible: self.win.erase() def finalize(self): """ Called after every displayable is done drawing. Override this! """ pass def resize(self, y, x, hei=None, wid=None): """Resize the widget""" do_move = True try: maxy, maxx = self.env.termsize except TypeError: pass else: if hei is None: hei = maxy - y if wid is None: wid = maxx - x if x < 0 or y < 0: raise ValueError("Starting point below zero!") #if wid < 1 or hei < 1: # raise OutOfBoundsException("WID and HEI must be >=1!") if x + wid > maxx and y + hei > maxy: raise ValueError("X and Y out of bounds!") if x + wid > maxx: raise ValueError("X out of bounds!") if y + hei > maxy: raise ValueError("Y out of bounds!") window_is_cleared = False if hei != self.hei or wid != self.wid: #log("resizing " + str(self)) self.win.erase() self.need_redraw = True window_is_cleared = True try: self.win.resize(hei, wid) except: # Not enough space for resizing... try: self.win.mvderwin(0, 0) do_move = True self.win.resize(hei, wid) except: pass #raise ValueError("Resizing Failed!") self.hei, self.wid = self.win.getmaxyx() if do_move or y != self.paryx[0] or x != self.paryx[1]: if not window_is_cleared: self.win.erase() self.need_redraw = True #log("moving " + str(self)) try: self.win.mvderwin(y, x) except: pass self.paryx = self.win.getparyx() self.y, self.x = self.paryx if self.parent: self.y += self.parent.y self.x += self.parent.x def __str__(self): return self.__class__.__name__ class DisplayableContainer(Displayable): """ DisplayableContainers are Displayables which contain other Displayables. This is also an abstract class. The methods draw, poke, finalize, click, press and destroy are extended here and will recursively call the function on all contained objects. New methods: add_child(object) -- add the object to the container. remove_child(object) -- remove the object from the container. New attributes: container -- a list with all contained objects (rw) """ def __init__(self, win, env=None, fm=None, settings=None): if env is not None: self.env = env if fm is not None: self.fm = fm if settings is not None: self.settings = settings self.container = [] Displayable.__init__(self, win) # ------------------------------------ extended or overidden methods def poke(self): """Recursively called on objects in container""" Displayable.poke(self) for displayable in self.container: displayable.poke() def draw(self): """Recursively called on visible objects in container""" for displayable in self.container: if self.need_redraw: displayable.need_redraw = True if displayable.visible: displayable.draw() self.need_redraw = False def finalize(self): """Recursively called on visible objects in container""" for displayable in self.container: if displayable.visible: displayable.finalize() def press(self, key): """Recursively called on objects in container""" focused_obj = self._get_focused_obj() if focused_obj: focused_obj.press(key) return True return False def click(self, event): """Recursively called on objects in container""" focused_obj = self._get_focused_obj() if focused_obj and focused_obj.click(event): return True for displayable in self.container: if displayable.visible and event in displayable: if displayable.click(event): return True return False def destroy(self): """Recursively called on objects in container""" for displayable in self.container: displayable.destroy() # ----------------------------------------------- new methods def add_child(self, obj): """Add the objects to the container.""" if obj.parent: obj.parent.remove_child(obj) self.container.append(obj) obj.parent = self def remove_child(self, obj): """Remove the object from the container.""" try: self.container.remove(obj) except ValueError: pass else: obj.parent = None def _get_focused_obj(self): # Finds a focused displayable object in the container. for displayable in self.container: if displayable.focused: return displayable try: obj = displayable._get_focused_obj() except AttributeError: pass else: if obj is not None: return obj return None