Compiler

Syndicate content 5 

As a developer, you have probably spent at least some time writing repetetive code. You may have even found yourself wishing you could generate the code programmatically. If this sounds familiar, this article is for you!

We'll start with an example. Note: the following examples use the %DynamicObject interface, which requires Caché 2016.2 or later. If you are unfamiliar with this class, check out the documentation here: Using JSON in Caché. It's really cool!

Example

You have a %Persistent class that you use to store data. Now, suppose that you are ingesting some data in JSON format, using the %DynamicObject interface. How do you map the %DynamicObject structure to your class? One solution is to simply write code to copy the values over directly

Last comment 22 November 2016
+ 15   0 7
1029

views

+ 15

rating

Class Queries in InterSystems Caché is a useful tool that separates SQL queries from Caché Object Script code. Basically, it works like this: suppose that you want to use the same SQL query with different arguments in several different places.In this case you can avoid code duplication by declaring the query body as a class query and then calling this query by name. This approach is also convenient for custom queries, in which the task of obtaining the next row is defined by a developer. Sounds interesting? Then read on!

Last comment 9 December 2016
+ 14   0 9
3685

views

+ 14

rating

This is a translation of the following article. Thanks @Evgeny Shvarov  for the help in translation.

Let's assume that you wrote a program that shows "Hello World!", for example:

  write "Hello, World!"

The program works and everyone is happy.

With time, however, your program becomes more complex, gets more features and you eventually need to show the same string in different languages. Moreover you don't know the number and names of these languages.

The spoiler below contains a description of how the task of multi-language localization is solved in Caché.

Last comment 20 May 2017
+ 8   0 1
320

views

+ 8

rating

In this article I would like to tell you about macros in InterSystems Caché. A macro is a symbolic name that is replaced with a set of instructions during compilation. A macro can “unfold” in various instruction sets each time it is called, depending on the parameters passed to it and activated scenarios. This can be both static code and the result of ObjectScript execution. Let's take a look at how you can use them in your application.

Last comment 24 July 2017
+ 8   0 5
1030

views

+ 8

rating

In my previous article, we reviewed possible use-cases for macros, so let’s now proceed to a more comprehensive example of macros usability. In this article we will design and build a logging system.

Logging system

Logging system is a useful tool for monitoring the work of an application that saves a lot of time during debugging and monitoring. Our system would consist of two parts:

  • Storage class (for log records)
  • Set of macros that automatically add a new record to the log

Last comment 24 March 2017
+ 6   1 8
887

views

+ 6

rating

Greetings! This article describes yet another simple way of creating installers for the solutions based on InterSystems Caché. The topic covers applications, which can be installed or completely removed from Caché with one action only. If you are still documenting installation instructions that have more than one step to do to install your application — it’s high time you automated this process. 

Last comment 10 May 2016
+ 5   0 6
996

views

+ 5

rating

The attached file contains an example of code generation using ObjectGenerators which builds a very simple homemade RuleEngine. 

Code generation is an excellent way of increasing performance moving run-time calculations to compile-time.

We could generate code creating routines or implemeting methods using ObjectGenerators. In this example we are using ObjectGenerators.

Update: Rule Engine is now on GitHub https://github.com/intersystems-ib/cache-iat-ruleengine

A very simple code generated method

For starters, let's begin with a very basic code generated method

+ 4   0 1
0

comments

348

views

+ 4

rating

On the back of my recent post on writing bug-less code I wanted to raise a few suggestions (to ISC) that would help prevent certain types of bugs at compile time. I've probably missed a few, but these are the main ones in my mind. Please contribute more suggestions.

Btw, these also serve as potential gotchas for new COS developers.

I except that introducing these types of changes can cause legacy code problems. Particularly where developers do some interesting overloading of method arguments. Therefore I would see these as an option that would need to be enabled and that it won't prevent compilation (it would warn not error).

As an alternative I could see these being implemented as a Lint tool. This is something I (and perhaps the community) would be willing to do if we had an open source AST tree as a starting block (if anyone is aware of one in existence for COS)

Last comment 18 April 2017
+ 4   0 1
677

views

+ 4

rating

In most cases, if one class depends on another, the class compiler will detect this and determine the correct compilation order. For example:

  • Compiling a superclass triggers compilation of its subclasses.
  • Compiling a custom datatype class triggers compilation of any classes with a property of that type.

Yet sometimes, a developer needs to specify compilation order. InterSystems class definitions contain two keywords for this, DependsOn and CompileAfter, that are very similar but not identical. They are useful during development, and also when importing and compiling a set of classes for the first time.

The documentation for these keywords is here

Last comment 31 January 2019
+ 4   0 3
400

views

+ 4

rating

Here you have an easy way to write and execute COS code from your unix scripts. This way one does not need to write routines or even open Studio or Atelier. It can be an option for simple and small actions for instance things like installation tasks or compiling.

See sample bash script (compile.sh) to compile classes:

#!/bin/bash
#####################################################################
# Script to compile classes
# $1 = NAMESPACE
# $2 = ClassName
#
# For example:
# ./compile.sh "SAMPLES" "Sample.Person" 
#####################################################################
echo -n "username:"
read username
echo -n "password:"
read pwd

csession HSINSTANCE -U "$1" <<EOFF
$username
$pwd
set status = \$SYSTEM.OBJ.Compile("$2")
h
EOFF

This is the output from the console

Last comment 14 October 2016
+ 4   0 3
457

views

+ 4

rating

Hi all!

I'm developing a mini-framework to implement annotations in Cache. I want to support two kind of annotations: metadata and method decorators. I've got stuck trying to implement the second one.

Metadata

With metadata annotations I can add metadata to any kind of target. A target can be a method/classmethod, parameter, property and class.

For example

Last answer 25 January 2017 Last comment 26 January 2017
+ 3   0 2
438

views

+ 3

rating

Due to a new project I'm getting involved inside %Installer stuff deeper than ever I'd be happy to. Most of it was pretty easy to get, thanks to documentation, articles and SAMPLES example, while I can't dig good solution for one problem. I'm trying to import and compile some classes, willing to ignore two types of errors: 5202 (NothingToCompile) and 5373 (PredecessorClassDoesNotExist - a normal case when SNMP sampling class is compiled for the 1st time, before it was registered). 

I've tried the following:

Last answer 28 March 2017 Last comment 28 March 2017
+ 3   0 1
202

views

+ 3

rating

So another topic that has been of interest to a number of people since the beta was put up last week is in regard to Studio Hooks and Atelier. This requires a bit of background and then some discussion of how the architecture of Atelier necessitates some changes and then what our current thinking on the subject is.

Studio hooks were added to Cache over 10 years ago. They have two primary usages. The first is that on an appropriate action such as creating a new document, or compiling a document a callback is executed whose job is to interact with external source control systems. This is done by writing COS scripts that “do the right thing” for a given source control system based on the callback invoked. All of this code ran on the server and used all the facilities available on the server such as locks and transactions etc

Last comment 3 March 2016
+ 3   0 6
947

views

+ 3

rating

The class %Compiler.UDL.TextServices arrived in 2015.1, bringing us methods for exporting a class in UDL format (i.e. looking just like we're used to seeing it in Studio), and importing a UDL format definition back into a namespace. Some source control tools including our Deltanji are now able to use UDL format, resulting in diffs that are easier to understand.

Last comment 1 February 2017
+ 1   0 1
139

views

+ 1

rating

I have just imported our Ensemble project (not a really big one, like two man-years) into my MacBook Air  Ensemble 2016.3 instance to test many things (document model, etc.), Atelier among the others.

The "Production view" is not here, and I miss it.

The opening of Diagram Editor for BP is pretty hidden. I would even like having a switch, which would default to the Diagram Editor. 

Anytime I click on the Open Diagram Editor, it waits for a while, ten produces an error and only then I can see the diagram.

The error says: Your Studio browser is no longer valid... etc.

I cannot find an easy access to the Save or Compile command, once I do some changes in the respective BP via the Diagram Editor.

Compiling larger amount of classes produces an error: 

No conflicting files to resolve.

Compile failed: Gateway Timeout

Compiling identical set of classes "per partes" goes well, however

Last answer 6 December 2018
+ 1   0 3
0

comments

281

views

+ 1

rating

I'm looking at adding multilingual support to a couple of open source projects I'm working on. The solutions are already developed in CSP so I am not looking for alternative approaches.

I'm wondering what would be the best approach for CSP and separate JavaScript files.

Initially I was wondering if I should bake the default system language text at compile time, or provide the end user with a language selection option at run time.

I came across $$$TEXT reading the docs...

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...

and have also discovered the localization manager which looks to be really handy...

https://community.intersystems.com/post/cach%C3%A9-localization-manager-...

Last answer 11 May 2017 Last comment 12 September 2017
+ 1   0 1
259

views

+ 1

rating

When I try to compile through Atelier (Compile Project), I noticed that in compilation with error it returns this message 'Failed to read /api/atelier/v1/ ...':

No additional Atelier files to synchronize.
Compile failed: Failed to read /api/atelier/v1/ERP/action/compile?flags=ck
Compile failed: Failed to read /api/atelier/v1/ERP/action/compile?flags=ck
Compile failed: Failed to read /api/atelier/v1/ERP/action/compile?flags=ck
Compile failed: Failed to read /api/atelier/v1/ERP/action/compile?flags=ck

Does anyone know what can it be?

I'm using Atelier beta (latest), with web application configured as Password Authenticated and a user with %ALL.

Last comment 24 July 2018
+ 1   0 4
0

answers

224

views

+ 1

rating

Using our cool new debugging extension for Visual Studio Code I'm trying to debug a CreateProjection method of a class, but when I compile it the work apparently gets done in one of the worker jobs, so my breakpoint never triggers.

Is there a compiler flag or qualifier to force the compilation to be done in-process rather than getting handed off to a worker job?

Last answer 2 October 2018 Last comment 4 October 2018
+ 1   0 3
190

views

+ 1

rating

The definitions of these two compiler keywords looks very similar to me.

Is there any difference between these two keywords ?

When I declare a parent class as Abstract, its child class could be compiled successfully.

However, when I  declare a parent class as NoExtent, some compile errors about storage references get pop up for its child classes.

Thanks.

Last answer 27 September 2017
0   0 1
0

comments

129

views

0

rating

hi-

Can someone give me an example of how to JOB a class method that requires an array of values to be passed to it by reference.  

This is what I tried, but am getting compile errors because of the .params

job ##class(%SYSTEM.OBJ.FM2Class).All(.params)::5

Any thoughts on how to accomplish this, the simplest way.  I would like to avoid writing all of this to some global and having to write some wrapper to pick it up and then call the class method, which I certainly could do.  but is this the only way to do it?

Last answer 2 October 2017 Last comment 2 October 2017
0   0 2
436

views

0

rating

Is the default language (i.e., $$$DefaultLanguage, which is used as the basis for localization with $$$Text/etc. at compile time) always "en" for new Caché installations, or could it be different? How is this determined? I don't see an option to select a language during Caché installation.

Also, is there a supported/preferred API for setting the default language? Looking at %occMessages.inc, one option would be:

Set $$$DefaultLanguageNode = "en"

But I'd expect there to be a classmethod for this somewhere (and haven't managed to find it yet)

Last comment 2 March 2016
0   0 4
0

answers

172

views

0

rating

I am currently trying to add a condition to a routing rule that uses the %Source property of a routing rule.  Unfortunately I am getting compile errors when I use the "%", and if I get PROPERTY DOES NOT EXIST if I try and use any of field. I have tried referencing the messages as "Message." , "Record.",  "FullRecordMapClassName." , "Document." . Does anyone know how to reference the properties of a record map in a routing rule, or if it is even possible? Thanks!

Last answer 13 January 2018 Last comment 24 January 2018
0   0 4
268

views

0

rating

[SOLVED]

added 

>/tmp/compilew.log &>/tmp/compilew.log ; tail /tmp/compilew.log

to redirect the output to the stdout. Somehow the javac has wierd behavior with the output on errors and verbose information.

Hi,

i want the JAVA-Projections and wrappers to compile after Caché created the files. The creation of the files works 100%.

My addition to createProjection in our Projectionclass is following

Last comment 15 March 2016
0   0 2
0

answers

145

views

0

rating

I have classes A and B, B derived from A, A has method Abc.

From INT of class B I see that compiler copies implementation of Abc to class B, so that Abc exists both in A and B.

As result, when B invokes Abs, B.Abs() is executed instead of A.Abs(). In result debuger is not able to step into Abs and breakpoints in A.Abs never hit.

Why this happens and how can I avoid this?

Update:

OK, now I know the reason: compiler makes the copy if Abc has this line:

cn=##Expression($$$quote(%classname))

hmmmm... compiler needs name of method's class so it "moves" the method to child class. Well, perhaps there is a good reason for that but for the moment the solution looks strange

Last answer 12 April 2017 Last comment 12 April 2017
0   0 4
201

views

0

rating

"Help me, Obi Wan Kenobi"?

I’ve hit the wall. I’m a one person shop who wants to start developing Cache on a mac using Eclipse/Atelier, after using Studio for the last 5 years. I’ve installed the 1.1 beta plugin, watched 6 or 7 videos from the September conference, tried several times to work through the cheat sheets, only to have connection issues or compilation issues, so at this point, I’m feeling very frustrated. The videos were interesting, but generally didn’t work as tutorials for fundamental programming operations, for me.

I feel comfortable with Objectscript and Zen development in Studio. What I need are step by step Atelier instructions, such as have been offered in previous excellent Cache tutorials to:

1. Run compiled Cache class and routine serverside code and see its output on a Terminal equivalent.
2. Run compiled CSP/Zen code and see its output to a web browser

Last answer 13 November 2017 Last comment 14 November 2017
0   0 1
154

views

0

rating

Here's my code (download):

Class Utils.Generators [ Abstract ]
{

ClassMethod B()
{
    s ^a = 1
}

ClassMethod A() [ CodeMode = objectgenerator, GenerateAfter = B, PlaceAfter = B ]
{
    k ^a
    do ..B()
}

Now, obviously for it to work I need method B compiled and ready to use before compiling method A().

I test it with the following code:

do $system.OBJ.UnCompile("Utils.Generator")
do $system.OBJ.Compile("Utils.Generator")

Yet, I receive the following compilation error

Last answer 10 April 2016 Last comment 10 April 2016
0   0 1
414

views

0

rating