Berry animation fix dsl (#23950)
* Berry animation fixes * Berry animation fix dsl
This commit is contained in:
parent
e5cd43010a
commit
53ec08cc18
@ -60,6 +60,7 @@ register_to_dsl(dsl_named_colors)
|
||||
# @param source: string - DSL source code
|
||||
# @return string - Generated Berry code
|
||||
def compile_dsl_source(source)
|
||||
import animation_dsl
|
||||
return animation_dsl.compile_dsl(source)
|
||||
end
|
||||
animation_dsl.compile = compile_dsl_source
|
||||
@ -70,6 +71,7 @@ animation_dsl.compile = compile_dsl_source
|
||||
# @param source: string - DSL source code
|
||||
# @return any - Result of execution
|
||||
def execute(source)
|
||||
import animation_dsl
|
||||
var berry_code = animation_dsl.compile(source)
|
||||
var compiled_fn = compile(berry_code)
|
||||
return compiled_fn()
|
||||
@ -81,6 +83,7 @@ animation_dsl.execute = execute
|
||||
# @param filename: string - Path to DSL file
|
||||
# @return any - Result of execution
|
||||
def load_file(filename)
|
||||
import animation_dsl
|
||||
var f = open(filename, "r")
|
||||
if f == nil
|
||||
raise "io_error", f"Cannot open DSL file: {filename}"
|
||||
@ -97,6 +100,7 @@ animation_dsl.load_file = load_file
|
||||
#
|
||||
# @return DSLRuntime - New runtime instance
|
||||
def create_runtime(strip, debug_mode)
|
||||
import animation_dsl
|
||||
var engine = animation.create_engine(strip)
|
||||
return animation_dsl.DSLRuntime(engine, debug_mode)
|
||||
end
|
||||
@ -112,6 +116,7 @@ animation_dsl.create_runtime = create_runtime
|
||||
# @raises "invalid_filename" - If filename doesn't have .anim extension
|
||||
def compile_file(filename)
|
||||
import string
|
||||
import animation_dsl
|
||||
|
||||
# Validate input filename
|
||||
if !string.endswith(filename, ".anim")
|
||||
|
||||
@ -15,6 +15,7 @@ class DSLRuntime
|
||||
|
||||
# Load and execute DSL from string
|
||||
def load_dsl(source_code)
|
||||
import animation_dsl
|
||||
if source_code == nil || size(source_code) == 0
|
||||
if self.debug_mode
|
||||
print("DSL: Empty source code")
|
||||
@ -90,6 +91,7 @@ class DSLRuntime
|
||||
|
||||
# Get generated Berry code for inspection (debugging)
|
||||
def get_generated_code(source_code)
|
||||
import animation_dsl
|
||||
if source_code == nil
|
||||
source_code = self.active_source
|
||||
end
|
||||
@ -165,6 +167,7 @@ end
|
||||
|
||||
# Factory function for easy creation
|
||||
def create_dsl_runtime(strip, debug_mode)
|
||||
import animation_dsl
|
||||
var engine = animation.create_engine(strip)
|
||||
return animation_dsl.DSLRuntime(engine, debug_mode)
|
||||
end
|
||||
|
||||
@ -318,12 +318,14 @@ class SymbolTable
|
||||
var mock_engine # MockEngine for validation
|
||||
|
||||
def init()
|
||||
import animation_dsl
|
||||
self.entries = {}
|
||||
self.mock_engine = animation_dsl.MockEngine()
|
||||
end
|
||||
|
||||
# Dynamically detect and cache symbol type when first encountered
|
||||
def _detect_and_cache_symbol(name)
|
||||
import animation_dsl
|
||||
if self.entries.contains(name)
|
||||
return self.entries[name] # Already cached
|
||||
end
|
||||
@ -459,11 +461,12 @@ class SymbolTable
|
||||
|
||||
# Get symbol reference for code generation (with dynamic detection)
|
||||
def get_reference(name)
|
||||
import animation_dsl
|
||||
# Try to get from cache or detect dynamically (includes named colors)
|
||||
var entry = self.get(name)
|
||||
if entry != nil
|
||||
# For builtin color entries, return the actual color value directly
|
||||
if entry.is_builtin && entry.type == animation_dsl._symbol_entry.TYPE_COLOR
|
||||
if entry.is_builtin && entry.type == 11 #-animation_dsl._symbol_entry.TYPE_COLOR-#
|
||||
return animation_dsl.named_colors[name]
|
||||
end
|
||||
return entry.get_reference()
|
||||
@ -481,42 +484,49 @@ class SymbolTable
|
||||
|
||||
# Create and register a palette instance symbol (user-defined)
|
||||
def create_palette(name, instance)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_palette_instance(name, instance, false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
|
||||
# Create and register a color instance symbol (user-defined)
|
||||
def create_color(name, instance)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_color_instance(name, instance, false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
|
||||
# Create and register an animation instance symbol (user-defined)
|
||||
def create_animation(name, instance)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_animation_instance(name, instance, false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
|
||||
# Create and register a value provider instance symbol (user-defined)
|
||||
def create_value_provider(name, instance)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_value_provider_instance(name, instance, false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
|
||||
# Create and register a variable symbol (user-defined)
|
||||
def create_variable(name)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_variable(name, false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
|
||||
# Create and register a sequence symbol (user-defined)
|
||||
def create_sequence(name)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_sequence(name, false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
|
||||
# Create and register a template symbol (user-defined)
|
||||
def create_template(name, param_types)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry.create_template(name, false)
|
||||
entry.set_param_types(param_types != nil ? param_types : {})
|
||||
return self.add(name, entry)
|
||||
@ -525,6 +535,7 @@ class SymbolTable
|
||||
|
||||
# Register a user function (detected at runtime)
|
||||
def register_user_function(name)
|
||||
import animation_dsl
|
||||
if !self.contains(name)
|
||||
var entry = animation_dsl._symbol_entry.create_user_function(name, false)
|
||||
self.add(name, entry)
|
||||
@ -533,6 +544,7 @@ class SymbolTable
|
||||
|
||||
# Generic create function that can specify name/type/instance/builtin directly
|
||||
def create_generic(name, typ, instance, is_builtin)
|
||||
import animation_dsl
|
||||
var entry = animation_dsl._symbol_entry(name, typ, instance, is_builtin != nil ? is_builtin : false)
|
||||
return self.add(name, entry)
|
||||
end
|
||||
@ -575,8 +587,9 @@ class SymbolTable
|
||||
|
||||
# Helper method to get named color value (uses proper discovery)
|
||||
def _get_named_color_value(color_name)
|
||||
import animation_dsl
|
||||
var entry = self.get(color_name) # This will trigger _detect_and_cache_symbol if needed
|
||||
if entry != nil && entry.is_builtin && entry.type == animation_dsl._symbol_entry.TYPE_COLOR
|
||||
if entry != nil && entry.is_builtin && entry.type == 11 #-animation_dsl._symbol_entry.TYPE_COLOR-#
|
||||
return animation_dsl.named_colors[color_name]
|
||||
end
|
||||
return "0xFFFFFFFF" # Default fallback
|
||||
|
||||
@ -218,6 +218,7 @@ class Token
|
||||
# @param new_type: int - New token type
|
||||
# @return Token - New token with same position but different type
|
||||
def with_type(new_type)
|
||||
import animation_dsl
|
||||
return animation_dsl.Token(new_type, self.value, self.line, self.column, self.length)
|
||||
end
|
||||
|
||||
@ -226,6 +227,7 @@ class Token
|
||||
# @param new_value: string - New value
|
||||
# @return Token - New token with same position but different value
|
||||
def with_value(new_value)
|
||||
import animation_dsl
|
||||
return animation_dsl.Token(self.type, new_value, self.line, self.column, size(new_value))
|
||||
end
|
||||
|
||||
@ -415,6 +417,7 @@ end
|
||||
# @param column: int - Column number
|
||||
# @return Token - EOF token
|
||||
def create_eof_token(line, column)
|
||||
import animation_dsl
|
||||
return animation_dsl.Token(38 #-animation_dsl.Token.EOF-#, "", line, column, 0)
|
||||
end
|
||||
|
||||
@ -425,6 +428,7 @@ end
|
||||
# @param column: int - Column number
|
||||
# @return Token - Error token
|
||||
def create_error_token(message, line, column)
|
||||
import animation_dsl
|
||||
return animation_dsl.Token(39 #-animation_dsl.Token.ERROR-#, message, line, column, size(message))
|
||||
end
|
||||
|
||||
@ -434,6 +438,7 @@ end
|
||||
# @param column: int - Column number
|
||||
# @return Token - Newline token
|
||||
def create_newline_token(line, column)
|
||||
import animation_dsl
|
||||
return animation_dsl.Token(35 #-animation_dsl.Token.NEWLINE-#, "\n", line, column, 1)
|
||||
end
|
||||
|
||||
@ -442,6 +447,7 @@ end
|
||||
# @param word: string - Word to check
|
||||
# @return bool - True if word is a reserved keyword
|
||||
def is_keyword(word)
|
||||
import animation_dsl
|
||||
for keyword : animation_dsl.Token.keywords
|
||||
if word == keyword
|
||||
return true
|
||||
@ -455,6 +461,7 @@ end
|
||||
# @param word: string - Word to check
|
||||
# @return bool - True if word is a predefined color name
|
||||
def is_color_name(word)
|
||||
import animation_dsl
|
||||
for color : animation_dsl.Token.color_names
|
||||
if word == color
|
||||
return true
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -62,6 +62,10 @@ const char be_berry_init_code[] =
|
||||
"do import extension_manager end "
|
||||
#endif
|
||||
|
||||
#ifdef USE_BERRY_ANIMATION
|
||||
"import animation "
|
||||
#endif // USE_BERRY_ANIMATION
|
||||
|
||||
#ifdef USE_LVGL
|
||||
"import lv "
|
||||
"import lv_tasmota "
|
||||
|
||||
Loading…
Reference in New Issue
Block a user