Module: Yadriggy

Included in:
Checker
Defined in:
lib/yadriggy/eval.rb,
lib/yadriggy.rb,
lib/yadriggy/c.rb,
lib/yadriggy/py.rb,
lib/yadriggy/ast.rb,
lib/yadriggy/c/c.rb,
lib/yadriggy/type.rb,
lib/yadriggy/c/ffi.rb,
lib/yadriggy/assert.rb,
lib/yadriggy/syntax.rb,
lib/yadriggy/algebra.rb,
lib/yadriggy/c/ctype.rb,
lib/yadriggy/checker.rb,
lib/yadriggy/printer.rb,
lib/yadriggy/version.rb,
lib/yadriggy/c/config.rb,
lib/yadriggy/c/opencl.rb,
lib/yadriggy/eval_all.rb,
lib/yadriggy/ast_value.rb,
lib/yadriggy/c/codegen.rb,
lib/yadriggy/c/program.rb,
lib/yadriggy/py/import.rb,
lib/yadriggy/py/python.rb,
lib/yadriggy/py/syntax.rb,
lib/yadriggy/typecheck.rb,
lib/yadriggy/py/codegen.rb,
lib/yadriggy/source_code.rb,
lib/yadriggy/ast_location.rb,
lib/yadriggy/c/ctypecheck.rb,
lib/yadriggy/pretty_print.rb,
lib/yadriggy/ruby_typecheck.rb,
lib/yadriggy/ruby_typeinfer.rb,
lib/yadriggy/py/py_typechecker.rb

Overview

Yadriggy is a platform for building embedded DSLs.

It means mistletoe in Japanese.

Defined Under Namespace

Modules: Assert, AstHelper, C, Py Classes: ASTnode, ASTree, Algebra, ArrayLiteral, ArrayRef, ArrayRefField, Assign, BeginEnd, Binary, Block, Break, Call, CheckError, Checker, ClassDef, Command, CommonSuperType, CompositeType, Conditional, Const, ConstPathField, ConstPathRef, Def, Dots, Eval, EvalAlgebra, EvalAll, Exprs, FilePrinter, ForLoop, GlobalVariable, HashLiteral, Identifier, IdentifierOrCall, InstanceType, InstanceVariable, Label, Lambda, LocalVarType, Loop, MethodType, ModuleDef, Name, Number, OptionalRole, Parameters, Paren, PrettyPrinter, Printer, Program, Rescue, Reserved, ResultType, Return, RubyClass, RubyTypeChecker, RubyTypeInferer, SingularClassDef, StringInterpolation, StringLiteral, Super, SymbolLiteral, Syntax, SyntaxError, Type, TypeChecker, Unary, UnionType, VariableCall

Constant Summary collapse

DynType =

Dynamic type.

NonRubyType.new('#<Yadriggy::DynType>', 'DynType')
VERSION =
"1.4.0"
Undef =

Undefined value.

:undef
Void =

Void type.

NonRubyType.new('#<Yadriggy::Void>', 'Void')
@@debug =
0

Class Method Summary collapse

Class Method Details

.debugInteger

Current debug level (0, 1, or 2).

Returns:

  • (Integer)

    the current level.



25
# File 'lib/yadriggy.rb', line 25

def self.debug() @@debug end

.debug=(level) ⇒ Object

Sets the current debug level.

Parameters:

  • level (Integer)

    the debug level.



29
30
31
# File 'lib/yadriggy.rb', line 29

def self.debug=(level)
  @@debug = level
end

.define_syntax(&block) ⇒ Syntax

Defines syntax and returns a Syntax object. define_syntax is not available in a method body.

Parameters:

  • block (Proc)

    the syntax definition.

Returns:

  • (Syntax)

    the defined syntax.



11
12
13
14
15
16
17
18
# File 'lib/yadriggy/syntax.rb', line 11

def self.define_syntax(&block)
  ast = reify(block)
  if Syntax.check_syntax(ast.tree)
    Syntax.new(ast)
  else
    raise Syntax.last_error
  end
end

.reify(proc = nil) { ... } ⇒ ASTree|nil

Gets the abstract syntax tree (AST) of the given procedure proc. If proc is nil, the block argument is converted into an abstract syntax tree. The returned ASTree object is a container holding not only an AST but also other data. To get an AST, call Yadriggy::ASTree#tree on the ASTree object.

Yadriggy::ASTree#reify on the ASTree object obtains the ASTs of other procs and methods. It returns the same AST for the same proc or method since it records ASTs obtained before. The table of the recorded ASTs are shared among ASTree objects. Every call to reify on Yadriggy makes a new table. Hence,

ast1 = Yadriggy.reify(proc1)
ast2 = ast.reify(proc2)
a1 = Yadriggy.reify(proc1)  # a1 != ast1
a2 = a1.reify(proc2)        # a2 != ast2
b2 = a1.reify(proc2)        # b2 == a2

Although ast1 and a1, and ast2 and a2 are different copies of the AST of the same proc, a2 and b2 refer to the same AST.

Parameters:

  • proc (Method|UnboundMethod|Proc) (defaults to: nil)

    the procedure.

Yields:

  • the block is used as the procedure if proc is nil.

Returns:

  • (ASTree|nil)

    the abstract syntax tree.

See Also:



35
36
37
38
39
40
41
42
# File 'lib/yadriggy/ast.rb', line 35

def self.reify(proc = nil, &block)
  code = proc || block
  return nil if code.nil?
  # a is used only for bootstrapping.
  a = ASTree.new(ASTreeTable.new, code, '?', [:zsuper])
  a.astrees.delete(code)
  a.reify(code)
end

.reset_pryObject

Discards all the code given to Pry before. This should be called when the code given before includes a syntax error and hence reify cannot obtain an abstract syntax tree.



32
33
34
# File 'lib/yadriggy/source_code.rb', line 32

def self.reset_pry
  SourceCode.reset_pry
end