I've been writing a Lisp implementation on top of Parrot for the last several months (and I'm just about at the point where I'm ready to unleash it upon the world). I seem to have run up against some issues which *appear* to be related to the garbage collector collecting objects that aren't ready to be collected yet. (I say "appear" because I'm unsure as to how to check when an object is being collected and the memory returned to the system - for all I know this could be entirely my fault.)


I've included a much pared down example IMC file which on an x86 Linux machine will produce a segmentation fault and on a Mac OS X 10.3 machine produces a bus error. Running with the garbage collection disabled (ie. with the -G flag) does not produce these errors.

If anyone could point me towards what is going wrong, I would MOST appreciate it - it's been driving me nuts. (I've been following Parrot internals only superficially for the past little while so I'm entirely unfamiliar with the garbage collection system.) I have only a vague
inclination that it has to do somehow with the Hash class (based on how various bugs manifest themselves in my program).


The Parrot version is the latest CVS checkout as of 10 minutes ago.

Regards,

Cory
.macro PACKAGE (P,N)
  .P = new "LispPackage"
  .P._set_name_as_string(.N)  
.endm

.macro STRING (R,S)
  .R = new "LispString"
  .R = .S
.endm

.macro SYMBOL (R,N)
  .R = new "LispSymbol"
  .R._set_name_as_string(.N)
.endm

.sub _main @MAIN
  .local pmc package1
  .local pmc package2
  .local pmc package3
  .local pmc symbol
  .local int count

  _init_types()

  .PACKAGE(package1, "COMMON-LISP")

  symbol = package1._intern_symbol("T")

  count = 0
LOOP:
  print count
  print ": "
  print "looking up symbol: T\n"
  symbol = package1._lookup_symbol("T")

  .PACKAGE(package3, "SYSTEM")

  package3._import_symbol(symbol)

  symbol = package1._lookup_symbol("T")
  package2 = symbol._get_package()

  inc count
  goto LOOP
  
  end
.end

.sub _init_types
  .local pmc class

  # Create the LispPackage class
  newclass class, "LispPackage"

  addattribute class, "internal"
  addattribute class, "name"

  # Create the LispString class
  subclass class, "String", "LispString"

  # Create the LispSymbol class
  newclass class, "LispSymbol"

  addattribute class, "function"
  addattribute class, "name"
  addattribute class, "package"
.end

.namespace ["LispPackage"]

.sub __init method
  .local pmc value

  value = new Hash
  setattribute self, "LispPackage\0internal", value
.end

.sub _lookup_symbol method
  .param string name
  .local string type
  .local pmc symbol
  .local pmc hash

  getattribute hash, self,  "LispPackage\0internal"
  symbol = hash[name]

  typeof type, symbol

  if type == "None" goto SYMBOL_NOT_FOUND
  goto DONE

SYMBOL_NOT_FOUND:
  null symbol
  goto DONE

DONE:
  .return(symbol)
.end

.sub _import_symbol method
  .param pmc symbol
  .local string symname
  .local pmc hash

  symname = symbol._get_name_as_string()

  getattribute hash, self,  "LispPackage\0internal"
  hash[symname] = symbol

  .return(symbol)
.end

.sub _intern_symbol method
  .param string name
  .local string type
  .local pmc symbol
  .local pmc status
  .local pmc hash

  getattribute hash, self,  "LispPackage\0internal"
  symbol = hash[name]

  typeof type, symbol
  if type != "None" goto DONE

  .SYMBOL(symbol, name)
  hash[name] = symbol

  symbol._set_package(self)

  goto DONE

DONE:
  .return(symbol)
.end

.sub _get_name_as_string method
  .local pmc name
  .local string retv

  getattribute name, self, "LispPackage\0name"
  retv = name

  .return(retv)
.end

.sub _set_name_as_string method
  .param string name
  .local pmc retv

  .STRING(retv, name)

  setattribute self, "LispPackage\0name", retv

  .return(retv)
.end

.sub __get_string method
  .local pmc name
  .local pmc tmps
  .local pmc retv

  getattribute name, self, "LispPackage\0name"

  retv = new String
  tmps = new String

  tmps = "#<PACKAGE "

  concat retv, tmps, name

  tmps = ">"
  concat retv, retv, tmps

  .pcc_begin_return
  .return retv
  .pcc_end_return
.end

.namespace ["LispSymbol"]

.sub _get_name_as_string method
  .local pmc name
  .local string retv

  getattribute name, self, "LispSymbol\0name"
  retv = name

  .return(retv)
.end

.sub _set_name_as_string method
  .param string name
  .local pmc retv

  .STRING(retv, name)

  setattribute self, "LispSymbol\0name", retv

  .return(retv)
.end

.sub _get_package method
  .local pmc retv

  getattribute retv, self, "LispSymbol\0package"

  .return(retv)
.end

.sub _set_package method
  .param pmc package

  setattribute self, "LispSymbol\0package", package

  .return(package)
.end

.sub __get_string method
  .local pmc name

  getattribute name, self, "LispSymbol\0name"

  .pcc_begin_return
  .return name
  .pcc_end_return
.end

.namespace [""]

Reply via email to