From 008d2dceb68be38ce6435739b7c089a9576447ef Mon Sep 17 00:00:00 2001 From: rpeco001 Date: Wed, 24 Apr 2019 17:13:51 -0700 Subject: [PATCH 1/2] Added visitGradient and accounted for common invalid operations --- compiler/semantics/symbol_visitor.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/compiler/semantics/symbol_visitor.py b/compiler/semantics/symbol_visitor.py index aa2a615..adb031e 100644 --- a/compiler/semantics/symbol_visitor.py +++ b/compiler/semantics/symbol_visitor.py @@ -162,6 +162,31 @@ def visitDispose(self, ctx: BSParser.DisposeContext): self.symbol_table.update_symbol(name, types) return {'types': types, 'size': 1, 'instruction': IRInstruction.DISPOSE, "name": IRInstruction.DISPOSE.name} + def visitGradient(self, ctx: BSParser.GradientContext): + name = ctx.IDENTIFIER(0).__str__() + types = {ChemTypes.MAT} + self.symbol_table.update_symbol(name, types) + start_interval = float(ctx.FLOAT_LITERAL(0).__str__()) + if not (0.0 <= start_interval <= 100.0): + raise InvalidOperation('The interval must start between 0.0 and 100.0.'.format(start_interval)) + end_interval = float(ctx.FLOAT_LITERAL(1).__str__()) + if not (0.0 <= end_interval <= 100.0): + raise InvalidOperation('The interval must end between 0.0 and 100.0.'.format(endInterval)) + if end_interval < start_interval: + end_interval, start_interval = start_interval, end_interval + increment = float(ctx.FLOAT_LITERAL(2).__str__()) + if increment > (end_interval - start_interval): + raise InvalidOperation('The increment must be smaller than the interval.'.format(increment)) + if increment < 0.0: + raise InvalidOperation('The increment must be greater than 0.0.'.format(increment)) + count = start_interval + while count < end_interval: + dropName = 'gradient'+str(count) + var = self.identifier.identify(dropName, types, self.symbol_table.current_scope.name) + self.symbol_table.update_symbol(dropName, var['types']) + count += increment + return {'types': types, 'size': 1, 'instruction': IRInstruction.GRADIENT, "name": IRInstruction.GRADIENT.name} + def visitExpression(self, ctx: BSParser.ExpressionContext): return {"types": {ChemTypes.REAL, ChemTypes.NAT}, "size": 1, 'instruction': IRInstruction.BINARYOP, "name": IRInstruction.BINARYOP.name} @@ -315,3 +340,4 @@ def isPower(x, y): power = power * x return power == y + From dc3b0d91cf7141b2d89376297d4a6788221fbdba Mon Sep 17 00:00:00 2001 From: rpeco001 Date: Wed, 24 Apr 2019 17:15:50 -0700 Subject: [PATCH 2/2] Create gradient.bs --- resources/programs/gradient.bs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 resources/programs/gradient.bs diff --git a/resources/programs/gradient.bs b/resources/programs/gradient.bs new file mode 100644 index 0000000..b09ef6a --- /dev/null +++ b/resources/programs/gradient.bs @@ -0,0 +1,13 @@ +module mod +stationary ccc +manifest aaa +manifest bbb + +functions: + +instructions: + +a = dispense aaa +b = dispense bbb +c = gradient a with b for 0.0 , 100.0 at 5.0 +dispose c