import os import re import sys import lib.const as C from lib.enum import enum from lib.rlock import FLockFileHandler import util C.log_caller = enum(JAVASK="jsk", PSKETCH="psketch") def find_demo_name(argv): for i, arg in enumerate(argv): # main pasket: -p demo_name if arg == "-p": return (argv[i + 1], C.log_caller.JAVASK) # psketch: -o if arg == "-o": m = re.match(r".*/sk_([^/]*)/.*", argv[i + 1]) if m: demo = m.group(1) return (demo, C.log_caller.PSKETCH) return (None, None) class JskFileHandler(FLockFileHandler): def __init__(self, fileName, mode):
import lib.const as C from lib.enum import enum import util from meta import methods, classes, class_lookup from meta.program import Program from meta.clazz import Clazz, find_fld, find_mtds_by_sig, find_base from meta.method import Method, sig_match from meta.field import Field from meta.statement import Statement import meta.statement as st from meta.expression import Expression, typ_of_e import meta.expression as exp # constants regarding sketch C.SK = enum(z=u"bit", self=u"self") # global constants that should be placed at every sketch file _const = u'' # among class declarations in the template # exclude subclasses so that only the base class remains # (will make a virtual struct representing all the classes in that hierarchy) @takes(list_of(Clazz)) @returns(list_of(Clazz)) def rm_subs(clss): # { cname: Clazz(cname, ...), ... } decls = { cls.name: cls for cls in clss } # remove subclasses for cname in decls.keys():
from lib.enum import enum ENTITY_TYPE = enum("OBSTACLE")
from lib.enum import enum ENTITY_TYPE = enum( 'OBSTACLE', )
import lib.const as C # Terminals used at AST C.T = enum( ANNO="ANNOTATION", PKG="package", CLS="class", ITF="interface", ENUM="enum", EXT="extends", IMP="implements", THROWS="throws", DECL="DECL", FLD="FIELD", MTD="METHOD", TYPE="TYPE", NAME="NAME", PARA="PARAMS", ELT="ELEMS", STM="STAT", EXP="EXPR", ARG="ARGV", CAST="CAST", INS_OF="instanceof", HOLE=u"??", REG_L=u"{|", REG_R=u"|}", REGEN="REGEN", ) # constants regarding Java C.J = enum(
import cStringIO from antlr3.tree import CommonTree as AST from lib.typecheck import * import lib.const as C from lib.enum import enum from .. import util C.A = enum(OVERRIDE="Override", SUPWARN="SuppressWarnings", \ HARNESS="Harness") class Anno(object): def __init__(self, **kwargs): for key in kwargs: setattr(self, key, kwargs[key]) def __str__(self): buf = cStringIO.StringIO() buf.write('@' + self.name) attrs = [var for var in vars(self) if "name" not in var] if attrs: def var_to_str(var, print_var_too=True): s_attr = str(getattr(self, var)).replace('[','{').replace(']','}') if print_var_too: return var+"="+s_attr else: return s_attr buf.write('(')
import lib.const as C from lib.enum import enum from .. import util C.mod = enum(PR=u"private", PB=u"public", AB=u"abstract", ST=u"static", FN=u"final", GN=u"generator", HN=u"harness") C.PBST = [C.mod.PB, C.mod.ST] C.PRST = [C.mod.PR, C.mod.ST] C.sk_mod = [C.mod.GN, C.mod.HN] # snapshot of meta-class # Field # to assign unique id to an instance __fid = -1 # an array of all the instnaces whose id is equal to index being inserted # i.e., Field.flds(fid).id == fid __flds = [] def field_nonce(): global __fid __fid = __fid + 1 return __fid def fields(): global __flds return __flds def fields_reset(flds=[]):
from lib.enum import enum COLLISION_TYPE = enum( ('COL_PLAYER', 1 << 0), ('COL_BLOCK', 1 << 1), ('COL_ENEMY', 1 << 2), ('COL_PROJECTILE', 1 << 3), )
from lib.enum import enum MESSAGE_TYPE = enum( "CREATE_ENTITY", "DESTROY_ENTITY", "MOVE_ENTITY", "INIT_MOVEMENT_PLANNER", "JUMPED", "LANDED", "AIRBORNE", "COLLISION", "QUAD_TREE", )
from lib.enum import enum import util import sample from meta import methods, classes, class_lookup from meta.template import Template from meta.clazz import Clazz, find_fld, find_mtds_by_name, find_mtds_by_sig, find_base from meta.method import Method, sig_match from meta.field import Field from meta.statement import Statement import meta.statement as st from meta.expression import Expression, typ_of_e import meta.expression as exp # constants regarding sketch C.SK = enum(z=u"bit", self=u"self") # global constants that should be placed at every sketch file _const = u'' # among class declarations in the template # exclude subclasses so that only the base class remains # (will make a virtual struct representing all the classes in that hierarchy) @takes(list_of(Clazz)) @returns(list_of(Clazz)) def rm_subs(clss): # { cname: Clazz(cname, ...), ... } decls = { cls.name: cls for cls in clss } # remove subclasses for cname in decls.keys():
import os import re import sys import lib.const as C from lib.enum import enum from lib.rlock import FLockFileHandler import util C.log_caller = enum(PASKET="pasket", PSKETCH="psketch") def find_demo_name(argv): for i, arg in enumerate(argv): # main pasket: -p demo_name if arg == "-p": return (argv[i+1], C.log_caller.PASKET) # psketch: -o if arg == "-o": m = re.match(r".*/sk_([^/]*)/.*", argv[i+1]) if m: demo = m.group(1) return (demo, C.log_caller.PSKETCH) return (None, None) class PasketFileHandler(FLockFileHandler): def __init__(self, fileName, mode):
import os import re import sys import lib.const as C from lib.enum import enum from lib.rlock import FLockFileHandler import util C.log_caller = enum(PASKET="pasket", PSKETCH="psketch") def find_demo_name(argv): for i, arg in enumerate(argv): # main pasket: -p demo_name if arg == "-p": return (argv[i + 1], C.log_caller.PASKET) # psketch: -o if arg == "-o": m = re.match(r".*/sk_([^/]*)/.*", argv[i + 1]) if m: demo = m.group(1) return (demo, C.log_caller.PSKETCH) return (None, None) class PasketFileHandler(FLockFileHandler): def __init__(self, fileName, mode):
from antlr3.tree import CommonTree as AST from lib.typecheck import * import lib.const as C from lib.enum import enum import util # to avoid circular import (TODO: do we really need those annotations?) #from meta.expression import parse_e C.A = enum(OVERRIDE="Override", SUPWARN="SuppressWarnings", \ HARNESS="Harness", \ EVENT="Event", REACT="React", OBS="ObserverPattern", \ OBSS="Observers", ATTACH="Attach", DETACH="Detach", NOTI="Notified", \ STATE="State", ERR="Error", UPDATE="Update", \ SINGLE="Singleton", MULTI="Multiton", \ PUT="Put", APPEND="Append", ASSEM="Assemble", \ PROXY="Proxy", FACTORY="Factory", \ GET="Get", SET="Set", HAS="Has", IS="Is", \ NEW="New", OBJ="Object", \ CMP="Compare", CMP_STR="CompareString", \ TAG="Tag", ALL="All", CFG="CFG", MOCK="Mock") class Anno(object): def __init__(self, **kwargs): for key in kwargs: setattr(self, key, kwargs[key]) def __str__(self): buf = cStringIO.StringIO() buf.write('@' + self.name)
from lib.typecheck import * import lib.const as C from lib.enum import enum import lib.visit as v from .. import util from expression import Expression, parse_e, gen_E_id, gen_E_bop # s ::= e | assume e | assert e | return e? | e := e | if e s s? | while e s # | repeat e s # syntactic sugar borrowed from sketch # | minrepeat s # syntactic sugar borrowed from sketch # | for e e s | break | try s (catch e s)* (finally s)? # | s; s # represented as a list C.S = enum("EXP", "ASSUME", "ASSERT", "RETURN", "ASSIGN", "IF", "WHILE", "REPEAT", "MINREPEAT", "FOR", "BREAK", "TRY") class Statement(v.BaseNode): def __init__(self, k, **kwargs): self._kind = k for key in kwargs: setattr(self, key, kwargs[key]) @property def kind(self): return self._kind def __str__(self, e_printer=str): curried = lambda st: st.__str__(e_printer) buf = cStringIO.StringIO()
from lib.typecheck import * import lib.const as C from lib.enum import enum import lib.visit as v from .. import util from ..anno import parse_anno from . import class_lookup import clazz # e ::= anno | ?? | {| e* |} | c | id # | uop e | e bop e | e.e | e[e] # | new e | e(e*) | (e)e | e instanceof ty C.E = enum("ANNO", "HOLE", "GEN", "C", "ID", "UOP", "BOP", "DOT", "IDX", "NEW", "CALL", "CAST", "INS_OF") C.uop = ['+', '-', '~', '!', "++", "--"] C.bop = ["||", "&&", '|', '^', '&'] \ + ['+', '-', '*', '/', '%'] \ + ["<<", ">>>", ">>"] C.rop = ["==", "!=", "<=", ">=", '<', '>'] class Expression(v.BaseNode): def __init__(self, k, **kwargs): self._kind = k for key in kwargs: setattr(self, key, kwargs[key]) @property def kind(self):
from lib.enum import enum MESSAGE_TYPE = enum('CREATE_ENTITY', 'CLIENT_CONNECT', 'CREATE_BATTLE', 'PLAYER_BATTLE_MOVE')
from lib.typecheck import * import lib.const as C from lib.enum import enum import lib.visit as v from .. import util from ..anno import parse_anno from . import class_lookup import clazz # e ::= anno | ?? | {| e* |} | c | id # | uop e | e bop e | e.e | e[e] # | new e | e(e*) | (e)e | e instanceof ty C.E = enum("ANNO", "HOLE", "GEN", "C", "ID", "UOP", "BOP", "DOT", "IDX", "NEW", "CALL", "CAST", "INS_OF") C.uop = ["+", "-", "~", "!", "++", "--"] C.bop = ["||", "&&", "|", "^", "&"] + ["+", "-", "*", "/", "%"] + ["<<", ">>>", ">>"] C.rop = ["==", "!=", "<=", ">=", "<", ">"] class Expression(v.BaseNode): def __init__(self, k, **kwargs): self._kind = k for key in kwargs: setattr(self, key, kwargs[key]) @property def kind(self): return self._kind
import os import traceback import logging import logging.config import subprocess import sys from lib.enum import enum from lib.typecheck import * import lib.const as C # Terminals used at AST C.T = enum(ANNO="ANNOTATION", \ PKG="package", CLS="class", ITF="interface", ENUM="enum", \ EXT="extends", IMP="implements", THROWS="throws", \ DECL="DECL", FLD="FIELD", MTD="METHOD", \ TYPE="TYPE", NAME="NAME", PARA="PARAMS", ELT="ELEMS", \ STM="STAT", EXP="EXPR", ARG="ARGV", CAST="CAST", INS_OF="instanceof", \ HOLE=u"??", REG_L=u"{|", REG_R=u"|}", REGEN="REGEN") # constants regarding Java C.J = enum(MAIN=u"main", CLINIT=u"clinit", \ TRUE=u"true", FALSE=u"false", N=u"null", \ NEW="new", THIS=u"this", SUP=u"super", \ v=u"void", z=u"boolean", b=u"byte", s=u"short", c=u"char", \ i=u"int", j=u"long", f=u"float", d=u"double", \ V=u"Void", Z=u"Boolean", B=u"Byte", S=u"Short", C=u"Character", \ I=u"Integer", J=u"Long", F=u"Float", D=u"Double", \ OBJ=u"Object", RUN=u"Runnable", \ STR=u"String", SB=u"StringBuffer", \ MAP=u"Map", LST=u"List", STK=u"Stack", QUE=u"Queue", ITER=u"Iterator", \
from lib.enum import enum MESSAGE_TYPE = enum( 'CREATE_ENTITY', 'CLIENT_CONNECT', 'CREATE_BATTLE', 'PLAYER_BATTLE_MOVE' )
import lib.const as C from lib.enum import enum from .. import util C.mod = enum(PR=u"private", PB=u"public", \ AB=u"abstract", ST=u"static", FN=u"final", \ GN=u"generator", HN=u"harness") C.PBST = [C.mod.PB, C.mod.ST] C.PRST = [C.mod.PR, C.mod.ST] C.sk_mod = [C.mod.GN, C.mod.HN] # snapshot of meta-class # Field # to assign unique id to an instance __fid = -1 # an array of all the instnaces whose id is equal to index being inserted # i.e., Field.flds(fid).id == fid __flds = [] def field_nonce(): global __fid __fid = __fid + 1 return __fid def fields(): global __flds return __flds
import os import re import sys import lib.const as C from lib.enum import enum from lib.rlock import FLockFileHandler import util C.log_caller = enum(JAVASK="jsk", PSKETCH="psketch") def find_demo_name(argv): for i, arg in enumerate(argv): # main pasket: -p demo_name if arg == "-p": return (argv[i+1], C.log_caller.JAVASK) # psketch: -o if arg == "-o": m = re.match(r".*/sk_([^/]*)/.*", argv[i+1]) if m: demo = m.group(1) return (demo, C.log_caller.PSKETCH) return (None, None) class JskFileHandler(FLockFileHandler): def __init__(self, fileName, mode):
from lib.enum import enum MESSAGE_TYPE = enum( 'CREATE_ENTITY', 'MOVE_ENTITY', 'INIT_MOVEMENT_PLANNER', )
from lib.ecs.component.physics import PhysicsComponent from lib.ecs.component.render import AnimationRenderComponent from lib.vec2d import Vec2d from lib.command import Command from lib.physics.force import TimedForce from lib.audio.audio_manager import AudioManager from lib.enum import enum from oncilla.ecs.message_types import MESSAGE_TYPE audio_manager = AudioManager.get_instance() STATE_ID = enum( 'IDLE', 'JUMPING', 'AIRBORNE', ) class MoveLeftCommand(Command): def execute(self, entity): entity[SpiritStateComponent].move_left() def undo(self, entity): entity[SpiritStateComponent].move_left_stop() class MoveRightCommand(Command): def execute(self, entity): entity[SpiritStateComponent].move_right() def undo(self, entity):
from lib.ecs.component.state import StateComponent from lib.ecs.component.physics import PhysicsComponent from lib.ecs.component.render import AnimationRenderComponent from lib.vec2d import Vec2d from lib.command import Command from lib.physics.force import TimedForce from lib.audio.audio_manager import AudioManager from lib.enum import enum from oncilla.ecs.message_types import MESSAGE_TYPE from oncilla.ecs.entity.ice_shard import IceShard audio_manager = AudioManager.get_instance() STATE_ID = enum("IDLE", "JUMPING", "AIRBORNE") class MoveLeftCommand(Command): def execute(self, entity): entity[PlayerStateComponent].move_left() def undo(self, entity): entity[PlayerStateComponent].move_left_stop() class MoveRightCommand(Command): def execute(self, entity): entity[PlayerStateComponent].move_right() def undo(self, entity):
from lib.typecheck import * import lib.const as C from lib.enum import enum import lib.visit as v from .. import util from expression import Expression, parse_e, gen_E_id, gen_E_bop # s ::= e | assume e | assert e | return e? | e := e | if e s s? | while e s # | repeat e s # syntactic sugar borrowed from sketch # | minrepeat s # syntactic sugar borrowed from sketch # | for e e s | break | try s (catch e s)* (finally s)? # | s; s # represented as a list C.S = enum("EXP", "ASSUME", "ASSERT", "RETURN", "ASSIGN", "IF", "WHILE", "REPEAT", "MINREPEAT", "FOR", "BREAK", "TRY") class Statement(v.BaseNode): def __init__(self, k, **kwargs): self._kind = k for key in kwargs: setattr(self, key, kwargs[key]) @property def kind(self): return self._kind def __str__(self, e_printer=str): curried = lambda st: st.__str__(e_printer)