me_cpu.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  (C) 2005-2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>*/
00003 /*  ### ### ### ######### ######### #########*/
00004 /*  Package description*/
00005 
00006 /*  Implementation of ME virtual machines, object-based API to the*/
00007 /*  state values provided by "grammar::me::cpu::core".*/
00008 
00009 /*  ### ### ### ######### ######### #########*/
00010 /*  Requisites*/
00011 
00012 package require snit
00013 package require grammar::me::cpu::core
00014 
00015 /*  ### ### ### ######### ######### #########*/
00016 /*  Implementation*/
00017 
00018 snit::type ::grammar::me::cpu {
00019     constructor {code_} {
00020     /*  The 'core new' call validates the code as well.*/
00021 
00022      state =  [core::new $code_]
00023     return
00024     }
00025 
00026     ret  lc     (type location)     {return [core::lc     $state $location]}
00027     ret  tok    (type args)         {return [eval [linsert $args 0 core::tok $state]]}
00028     ret  pc     ()             {return [core::pc     $state]}
00029     ret  iseof  ()             {return [core::iseof  $state]}
00030     ret  at     ()             {return [core::at     $state]}
00031     ret  cc     ()             {return [core::cc     $state]}
00032     ret  sv     ()             {return [core::sv     $state]}
00033     ret  ok     ()             {return [core::ok     $state]}
00034     ret  error  ()             {return [core::error  $state]}
00035     ret  lstk   ()             {return [core::lstk   $state]}
00036     ret  astk   ()             {return [core::astk   $state]}
00037     ret  mstk   ()             {return [core::mstk   $state]}
00038     ret  estk   ()             {return [core::estk   $state]}
00039     ret  rstk   ()             {return [core::rstk   $state]}
00040     ret  nc     ()             {return [core::nc     $state]}
00041     ret  ast    ()             {return [core::ast    $state]}
00042     ret  halted ()             {return [core::halted $state]}
00043     ret  code   ()             {return [core::code   $state]}
00044 
00045     ret  eof () {
00046     core::eof state
00047     return
00048     }
00049 
00050     ret  put (type tok , type lex , type line , type col) {
00051     core::put state $tok $lex $line $col
00052     return
00053     }
00054 
00055     ret  putstring (type str , type lvar , type cvar) {
00056     upvar 1 $lvar line $cvar col
00057     foreach ch [split $str {}] {
00058         core::put state $ch {} $line $col
00059         if {$ch eq "\n"} {
00060         incr line
00061         set  col 0
00062         } else {
00063         incr col
00064         }
00065     }
00066     return
00067     }
00068 
00069     ret  run (optional n =-1) {
00070     core::run state $n
00071     return
00072     }
00073 
00074     ret  pull (type next) {
00075     while {1} {
00076         core::run state
00077         if {[core::halted $state]} break
00078 
00079         set tokdata [uplevel \#0 $next]
00080         if {![llength $tokdata]} break
00081         if {[llength $tokdata] != 4} {
00082         return -code error "Bad callback result, expected 4 elements"
00083         }
00084         foreach {tok lex line col} $tokdata break
00085         core::put state $tok $lex $line $col
00086     }
00087     }
00088 
00089     ret  reset () {
00090     set state [core::new [core::code $state]]
00091     return
00092     }
00093 
00094     /*  ### ### ### ######### ######### #########*/
00095     /*  Data structures*/
00096 
00097     variable state ; /*  State of ME cpu handled here.*/
00098 }
00099 
00100 /*  ### ### ### ######### ######### #########*/
00101 /*  Ready*/
00102 
00103 package provide grammar::me::cpu 0.2
00104 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1