summary refs log tree commit diff stats
path: root/src/cratera/compiler.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/cratera/compiler.lua')
-rw-r--r--src/cratera/compiler.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cratera/compiler.lua b/src/cratera/compiler.lua
index 2f4a998..cb0681f 100644
--- a/src/cratera/compiler.lua
+++ b/src/cratera/compiler.lua
@@ -1,6 +1,6 @@
 --[[
     This file is part of Cratera Compiler
-    Copyright (C) 2019  Soni L.
+    Copyright (C) 2019, 2024  Soni L.
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU Affero General Public License as published by
@@ -42,7 +42,9 @@ local END_OF_STMT = {}
 local END_OF_CRATERA = {}
 
 -- implementation of myobj:[mytrait].myfunction(...)
-local CRATERA_FUNCTION = "function(myobj, mytrait, myfunction, ...) return myobj[mytrait][myfunction](myobj, ...) end"
+-- TODO benchmark under luajit?
+local CRATERA_FUNCTION = "_CRATERA_INVOKE_TRAIT"
+local CRATERA_INIT = "local function "..CRATERA_FUNCTION.."(myobj, mytrait, myfunction, ...) return myobj[mytrait][myfunction](myobj, ...) end "
 
 local EXTRA_DATA = {[TK.NAME] = true, [TK.INT] = true, [TK.FLT] = true, [TK.STRING] = true, [END_OF_STMT] = true}
 
@@ -134,7 +136,7 @@ defs[parser.EOZ] = function(state, token)
     return FINISH
 end
 defs[parser.FALLBACK] = function(state, token)
-    local results = state.results or (function() state.results = {} return state.results end)()
+    local results = state.results or (function() state.results = {CRATERA_INIT, n=1} return state.results end)()
 
     do -- handle newlines. this allows error messages to correctly map between lua and cratera
         local oldline = state.oldline or 1