Exemplo n.º 1
0
//
// Constructor
//
WFoeMotif::WFoeMotif( void		*f_parent_ctx,
		      Widget		f_parent_wid,
		      const char       	*f_name,
		      pwr_tObjid       	plcprogram,
		      ldh_tWBContext 	ldhwbctx,
		      ldh_tSesContext	ldhsesctx,
		      vldh_t_node      	nodeobject,
		      unsigned long	windowindex,
		      unsigned long	new_window,
		      int	       	f_map_window,
		      ldh_eAccess      	f_access,
		      foe_eFuncAccess	function_access,
		      unsigned int 	f_options,
		      pwr_tStatus      	*sts) :
  WFoe(f_parent_ctx,f_name,plcprogram,ldhwbctx,ldhsesctx,nodeobject,
       windowindex,new_window,f_map_window,f_access,function_access,f_options,sts),
  parent_wid(f_parent_wid), set_focus_disabled(0), focus_timerid(0)
{

  memset( &widgets, 0, sizeof(widgets));

  *sts = new_local( plcprogram, ldhwbctx, ldhsesctx,
		    nodeobject, windowindex, new_window, function_access);

  wow = new CoWowMotif( parent_wid);
}
Exemplo n.º 2
0
static value ex(const string &s, size_t curr) {
  value ret, id;
  bool running = true;
  while (running) {
    vector<value> tok;
    for (;;) {
      const auto next = s.find_first_of("; \r\t\n[(", curr);
      const auto last = next == string::npos ? s.size() : next;
      const auto len = last-curr;
      const auto c = s[last];
      if (len!=0) tok.push_back(stov(s.substr(curr,len)));
      if (c == '(' || c == '[') {
        const auto v = expr(s, c, curr);
        tok.push_back(v.first);
        curr = v.second;
      } else if (c == ';' || c == '\n') {curr=last+1; break;}
      else if (c == '\0') {curr=last; running=false; break;}
      else curr=last+1;
    }

    if (tok.size() == 0) return btov(false);
    auto const it = unique<builtinmap>()->find(vtos(tok[0]));
    if (it!=unique<builtinmap>()->end()) // try to call a builtin
      ret = it->second(tok);
    else if (tok.size() == 1 && vtos(tok[0]) == s) return stov(s); // literals
    else { // function call
      scope frame;
      for (size_t i = 1; i < tok.size(); ++i) new_local(to_string(i-1),tok[i]);
      ret = ex(vtos(tok[0]));
    }
  }
  return ret;
}
Exemplo n.º 3
0
Arquivo: cc.c Projeto: Fedjmike/mini-c
void new_param (char* ident) {
    int local = new_local(ident);

    //At and above the base pointer, in order, are:
    // 1. the old base pointer, [ebp]
    // 2. the return address, [ebp+W]
    // 3. the first parameter, [ebp+2W]
    //   and so on
    offsets[local] = word_size*(2 + param_no++);
}
Exemplo n.º 4
0
static value loop_builtin(args arg) {
  value last;
  auto const n = int(vtod(get(arg,2)));
  for (int i = 0; i < n; ++i) {
    try {
      new_local(vtos(get(arg,1)), stov(to_string(i)));
      last = ex(vtos(get(arg,3)));
    } catch (bool b) { if (b) break; else continue; }
  }
  return last;
}
Exemplo n.º 5
0
//
// Constructor
//
WFoeMotif::WFoeMotif( void *f_parent_ctx,
		      Widget f_parent_wid,
		      const char *f_name,
		      pwr_tObjid plcprogram,
		      ldh_tWBContext ldhwbctx,
		      ldh_tSesContext ldhsesctx,
		      int f_map_window,
		      ldh_eAccess	f_access,
		      unsigned int f_options,
		      pwr_tStatus *sts) :
  WFoe(f_parent_ctx,f_name,plcprogram,ldhwbctx,ldhsesctx,f_map_window,
       f_access,f_options,sts),
  parent_wid(f_parent_wid), set_focus_disabled(0), focus_timerid(0)
{
  int		size;
  pwr_tFullName	new_name;
  ldh_tSesContext ldhses;

  memset( &widgets, 0, sizeof(widgets));

  /* Check that it is possible to open a session */
  *sts = ldh_OpenSession(&ldhses, ldh_SessionToVol( ldhsesctx),
			access, ldh_eUtility_PlcEditor);
  if ( EVEN(*sts)) return;

  *sts = ldh_CloseSession(ldhses);

  /* New title */
  *sts = ldh_ObjidToName( ldhsesctx, plcprogram, ldh_eName_Hierarchy,
			  new_name, sizeof( new_name), &size);
  error_msg(*sts);
  if( EVEN(*sts)) return;

  strcpy( name, new_name);
  *sts = new_local( plcprogram,
		    ldhwbctx, ldhsesctx, 0, 0, 0,
		    foe_eFuncAccess_Edit);

  wow = new CoWowMotif( parent_wid);
}
Exemplo n.º 6
0
    } catch (bool b) { if (b) break; else continue; }
  }
  return last;
}
static value if_builtin(args arg) {
  return vtob(get(arg,1)) ? ex(vtos(get(arg,2))):
    (arg.size()>3?ex(vtos(get(arg,3))):btov(false));
}
#define O(S)CMDL(#S,[](args arg){return dtov(vtod(get(arg,1)) S vtod(get(arg,2)));})
O(+) O(-) O(/) O(*)
#undef O
#define O(S)CMDL(#S,[](args arg){return btov(vtod(get(arg,1)) S vtod(get(arg,2)));})
O(==) O(!=) O(<) O(>) O(<=) O(>=)
#undef O
CMDL("int",[](args arg){return stov(to_string(int(vtod(get(arg,1)))));})
CMDL("var",[](args arg){return new_local(vtos(get(arg,1)),arg.size()<3?btov(false):get(arg,2));})
CMDL("#", [](args){return btov(false);})
CMDL("..", [](args arg){return stov(vtos(get(arg,1))+vtos(get(arg,2)));})
CMDL("echo", [](args arg){cout<<vtos(get(arg,1));return get(arg,1);})
CMDL("^", [](args arg){return get(arg,1);})
CMDL("return", [](args arg)->value {throw get(arg,1);})
CMDL("do", [](args arg){try {return ex(vtos(get(arg,1)));} catch (value v) {return v;}})
CMDL("break", [](args arg)->value {throw true;})
CMDL("continue", [](args arg)->value {throw false;})
CMDN("while", while_builtin)
CMDN("loop", loop_builtin)
CMDN("?", if_builtin)
CMDN("$", getvar)
pair<string,bool> exec(const string &s) {
  try {ex(s); return make_pair("",true);}
  catch (const boodew_exception &e) {return make_pair(string(e.what()),false);}
Exemplo n.º 7
0
Arquivo: cc.c Projeto: Fedjmike/mini-c
void decl (int kind) {
    //A C declaration comes in three forms:
    // - Local decls, which end in a semicolon and can have an initializer.
    // - Parameter decls, which do not and cannot.
    // - Module decls, which end in a semicolon unless there is a function body.

    bool fn = false;
    bool fn_impl = false;
    int local;

    next();

    while (try_match("*"))
        ;

    //Owned (freed) by the symbol table
    char* ident = strdup(buffer);
    next();

    //Functions
    if (try_match("(")) {
        if (kind == decl_module)
            new_scope();

        //Params
        if (waiting_for(")")) do {
            decl(decl_param);
        } while (try_match(","));

        match(")");

        new_fn(ident);
        fn = true;

        //Body
        if (see("{")) {
            require(kind == decl_module, "a function implementation is illegal here\n");

            fn_impl = true;
            function(ident);
        }

    //Add it to the symbol table
    } else {
        if (kind == decl_local) {
            local = new_local(ident);

        } else
            (kind == decl_module ? new_global : new_param)(ident);
    }

    //Initialization

    if (see("="))
        require(!fn && kind != decl_param,
                fn ? "cannot initialize a function\n" : "cannot initialize a parameter\n");

    if (kind == decl_module) {
        fputs(".section .data\n", output);

        if (try_match("=")) {
            if (token == token_int)
                fprintf(output, "%s: .quad %d\n", ident, atoi(buffer));

            else
                error("expected a constant expression, found '%s'\n");

            next();

        //Static data defaults to zero if no initializer
        } else if (!fn)
            fprintf(output, "%s: .quad 0\n", ident);

        fputs(".section .text\n", output);

    } else if (try_match("=")) {
        expr(0);
        fprintf(output, "mov dword ptr [ebp%+d], eax\n", offsets[local]);
    }

    if (!fn_impl && kind != decl_param)
        match(";");
}